Updated CMake build script for Windows. Moving away from MinGW requirement for build

This commit is contained in:
Joseph Henry
2017-12-19 16:23:52 -08:00
parent 3fe2ed6893
commit 402083a5d8
16 changed files with 163 additions and 133 deletions

View File

@@ -33,9 +33,14 @@
#ifndef LIBZT_SYSUTILS_H
#define LIBZT_SYSUTILS_H
#include <sys/time.h>
#include <stdint.h>
#ifdef _WIN32
#include <Windows.h>
#else
#include <sys/time.h>
#endif
/**
* @brief Returns the thread-id. Used in debug traces.
*
@@ -52,7 +57,7 @@ inline unsigned int gettid();
*/
inline uint64_t time_now()
{
#ifdef __WINDOWS__
#ifdef _WIN32
FILETIME ft;
SYSTEMTIME st;
ULARGE_INTEGER tmp;

View File

@@ -39,7 +39,7 @@ namespace ZeroTier {
struct InetAddress;
}
#if defined(__MINGW32__)
#if defined(_WIN32_FALSE)
#define NS_INADDRSZ 4
#define NS_IN6ADDRSZ 16

View File

@@ -30,7 +30,7 @@
* VirtualSocket management layer
*/
//#include "InetAddress.hpp"
#include "libztDefs.h"
namespace ZeroTier {
class Mutex;

View File

@@ -42,21 +42,19 @@ extern int errno;
#include "Thread.hpp"
#include "Phy.hpp"
#include "libztDefs.h"
#include "libzt.h"
#include <vector>
extern std::vector<void*> vtaps;
extern ZeroTier::Mutex _vtaps_lock;
#if defined(__MINGW32__) || defined(__MINGW64__)
#if defined(_WIN32)
#include <WinSock2.h>
#include <Windows.h>
#include <IPHlpApi.h>
#include <Ifdef.h>
#endif
using namespace ZeroTier;
class VirtualSocket;

View File

@@ -30,6 +30,10 @@
* ZeroTier One service control wrapper header file
*/
#if defined(_WIN32)
#include <Windows.h>
#endif
#include "ZeroTierOne.h"
#include "InetAddress.hpp"
#include "libztDefs.h"
@@ -67,7 +71,11 @@ std::vector<ZT_VirtualNetworkRoute> *zts_get_network_routes(const uint64_t nwid)
* @param
* @return
*/
#if defined(_WIN32)
DWORD WINAPI zts_start_service(LPVOID thread_id);
#else
void *zts_start_service(void *thread_id);
#endif
/**
* @brief Returns masked address for subnet comparisons

View File

@@ -34,30 +34,27 @@
#define LIBZT_H
#include "libztDebug.h"
#include "libztDefs.h"
#include <stdlib.h>
#include <unistd.h>
#include <cstdint>
#if defined(__linux__) || defined(__APPLE__)
#include <sys/socket.h>
#include <unistd.h>
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#if defined(_WIN32)
#include <WinSock2.h>
#include <stdint.h>
#include <WS2tcpip.h>
int inet_pton(int af, const char *src, void *dst);
//int inet_pton(int af, const char *src, void *dst);
#endif
/****************************************************************************/
/* DLL export for Windows (and other cruft) */
/****************************************************************************/
#if (defined(_WIN32) || defined(_WIN64)) && !(defined(__MINGW32__) || defined(__MINGW64__))
typedef int ssize_t;
#endif
#if defined(__MING32__) || defined(__MING64__)
#ifdef ADD_EXPORTS
#define ZT_SOCKET_API __declspec(dllexport)

View File

@@ -33,15 +33,12 @@
#ifndef LIBZT_DEBUG_HPP
#define LIBZT_DEBUG_HPP
#if defined(__MINGW32__) || !defined(_WIN32)
#if defined(__linux__) || defined(__APPLE__)
#include <sys/syscall.h>
#include <pthread.h>
#include <unistd.h>
#endif
#if defined(__linux__)
#include <sys/syscall.h>
#endif
#include <string.h>
#define ZT_MSG_ERROR true // Errors
@@ -56,7 +53,7 @@
#if defined(__APPLE__)
#include "TargetConditionals.h"
#endif
#if defined(ZT_COLOR) && !defined(__MINGW32__) && !defined(__ANDROID__) && !defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR) && !defined(__APP_FRAMEWORK__)
#if defined(ZT_COLOR) && !defined(_WIN32) && !defined(__ANDROID__) && !defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR) && !defined(__APP_FRAMEWORK__)
#define ZT_RED "\x1B[31m"
#define ZT_GRN "\x1B[32m"
#define ZT_YEL "\x1B[33m"
@@ -86,7 +83,7 @@ extern unsigned int gettid();
#ifdef __APPLE__
#define ZT_THREAD_ID (long)0 //(long)gettid()
#endif
#ifdef __MINGW32__
#ifdef _WIN32
#define ZT_THREAD_ID (long)0
#endif
@@ -103,7 +100,7 @@ extern unsigned int gettid();
#define DEBUG_STACK(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"STACK[%ld]: %17s:%5d:%20s: " fmt "\n", ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32) && !(defined(__MINGW32__) || defined(__MINGW64__)) // WINDOWS
#if defined(_WIN32)
#define DEBUG_STACK(fmt, args, ...) fprintf(stderr, ZT_YEL "STACK[%ld]: %17s:%5d:%25s: " fmt \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#else
@@ -119,8 +116,8 @@ extern unsigned int gettid();
#define DEBUG_TEST(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"TEST : %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32) && !(defined(__MINGW32__) || defined(__MINGW64__)) // WINDOWS
#define DEBUG_TEST(fmt, args, ...) fprintf(stderr, ZT_CYN "TEST [%ld]: %17s:%5d:%25s: " fmt "\n" \
#if defined(_WIN32)
#define DEBUG_TEST(fmt, args, ...) fprintf(stderr, ZT_CYN "TEST [%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#else
#define DEBUG_TEST(fmt, args ...) fprintf(stderr, ZT_CYN "TEST [%ld]: %17s:%5d:%25s: " fmt "\n" \
@@ -136,7 +133,7 @@ extern unsigned int gettid();
#define DEBUG_ERROR(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"ERROR: %17s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32) && !(defined(__MINGW32__) || defined(__MINGW64__)) // WINDOWS
#if defined(_WIN32)
#define DEBUG_ERROR(fmt, args, ...) fprintf(stderr, ZT_RED "ERROR[%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#else
@@ -153,8 +150,8 @@ extern unsigned int gettid();
#define DEBUG_INFO(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"INFO : %17s:%5d:%20s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32) && !(defined(__MINGW32__) || defined(__MINGW64__)) // WINDOWS
#define DEBUG_INFO(fmt, args, ...) fprintf(stderr, ZT_WHT "INFO [%ld]: %17s:%5d:%25s: " fmt "\n" \
#if defined(_WIN32)
#define DEBUG_INFO(fmt, args, ...) fprintf(stderr, ZT_WHT "INFO [%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#else
#define DEBUG_INFO(fmt, args ...) fprintf(stderr, ZT_WHT "INFO [%ld]: %17s:%5d:%25s: " fmt "\n" \
@@ -170,8 +167,8 @@ extern unsigned int gettid();
#define DEBUG_TRANS(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"TRANS: %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32) && !(defined(__MINGW32__) || defined(__MINGW64__)) // WINDOWS
#define DEBUG_TRANS(fmt, args, ...) fprintf(stderr, ZT_GRN "TRANS[%ld]: %17s:%5d:%25s: " fmt "\n" \
#if defined(_WIN32)
#define DEBUG_TRANS(fmt, args, ...) fprintf(stderr, ZT_GRN "TRANS[%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
#else
#define DEBUG_TRANS(fmt, args ...) fprintf(stderr, ZT_GRN "TRANS[%ld]: %17s:%5d:%25s: " fmt "\n" \
@@ -187,9 +184,9 @@ extern unsigned int gettid();
#define DEBUG_EXTRA(fmt, args...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ZT_LOG_TAG, \
"EXTRA: %17s:%5d:%25s: " fmt "\n", ZT_FILENAME, __LINE__, __FUNCTION__, ##args))
#endif
#if defined(_WIN32) && !(defined(__MINGW32__) || defined(__MINGW64__)) // WINDOWS
#if defined(_WIN32)
#define DEBUG_EXTRA(fmt, args, ...) fprintf(stderr, ZT_WHT "EXTRA[%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args, (long)0)
#else
#define DEBUG_EXTRA(fmt, args ...) fprintf(stderr, ZT_WHT "EXTRA[%ld]: %17s:%5d:%25s: " fmt "\n" \
ZT_RESET, ZT_THREAD_ID, ZT_FILENAME, __LINE__, __FUNCTION__, ##args)
@@ -199,14 +196,14 @@ extern unsigned int gettid();
#endif
#else // !LIBZT_DEBUG || !__NATIVE_TEST__
#if defined(_WIN32) && !(defined(__MINGW32__) || defined(__MINGW64__)) // WINDOWS
#define DEBUG_ERROR(fmt, args, ...)
#define DEBUG_TEST(fmt, args, ...)
#define DEBUG_INFO(fmt, args, ...)
#define DEBUG_BLANK(fmt, args, ...)
#define DEBUG_ATTN(fmt, args, ...)
#define DEBUG_TRANS(fmt, args, ...)
#define DEBUG_EXTRA(fmt, args, ...)
#if defined(_WIN32)
#define DEBUG_ERROR(...)
#define DEBUG_TEST(...)
#define DEBUG_INFO(...)
#define DEBUG_BLANK(...)
#define DEBUG_ATTN(...)
#define DEBUG_TRANS(...)
#define DEBUG_EXTRA(...)
#else
#define DEBUG_ERROR(fmt, args...)
#define DEBUG_TEST(fmt, args...)

View File

@@ -127,8 +127,13 @@
*/
#define ZTO_ID_LEN 16
#if !defined(__MINGW32__)
typedef unsigned int socklen_t;
//#if !defined(__WIN32__)
//typedef unsigned int socklen_t;
//#endif
#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
/****************************************************************************/