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

@@ -35,10 +35,19 @@ set (CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin)
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
# Flags for various build types
if (WIN32)
set (CMAKE_C_FLAGS "-DZT_SDK=1")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc -DNOMINMAX")
set (LWIP_PORT_DIR ${PROJ_DIR}/ext/lwip-contrib/ports/win32/include)
#set (COMMON_DEBUG_FLAGS "-DLIBZT_TRACE=1 -DLIBZT_DEBUG=1 -DNS_TRACE=1 -DNS_DEBUG=1")
else()
set (CMAKE_C_FLAGS "-fvisibility=hidden -fstack-protector -DZT_SDK=1")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11")
set (LWIP_PORT_DIR ${PROJ_DIR}/ext/lwip-contrib/ports/unix/include)
set (COMMON_DEBUG_FLAGS "-g -DLIBZT_TRACE=1 -DLIBZT_DEBUG=1 -DNS_TRACE=1 -DNS_DEBUG=1")
endif()
# Flags for various build types
set (CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS} -std=c++11")
# C
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS} ${COMMON_DEBUG_FLAGS}")
set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${CMAKE_C_FLAGS}")
@@ -60,11 +69,11 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS}")
# lwIP Userspace Networking Stack
set (LWIP_SRC_DIR ${PROJ_DIR}/ext/lwip/src)
include_directories (${LWIP_SRC_DIR}/include)
include_directories(${PROJ_DIR}/ext/lwip-contrib/ports/unix/include)
include_directories (${LWIP_PORT_DIR})
file (GLOB lwip_src_glob
${LWIP_SRC_DIR}/netif/*.c
${LWIP_SRC_DIR}/api/*.c
${PROJ_DIR}/ext/lwip-contrib/ports/unix/port/sys_arch.c
${LWIP_PORT_DIR}/sys_arch.c
${LWIP_SRC_DIR}/core/*.c
${LWIP_SRC_DIR}/core/ipv4/*.c
${LWIP_SRC_DIR}/core/ipv6/*.c)

View File

@@ -25,21 +25,19 @@
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <string>
#include <inttypes.h>
#if defined(__linux__) || defined(__APPLE__)
#if defined(_WIN32)
#include <WinSock2.h>
#include <stdint.h>
#else
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#include <WinSock2.h>
#include <stdint.h>
#include <unistd.h>
#endif
#include "libzt.h"

View File

@@ -76,7 +76,7 @@ typedef int sys_prot_t;
printf("Assertion \"%s\" failed at line %d in %s\n", message, __LINE__, __FILE__); \
fflush(NULL);handler;} } while(0)
#ifdef _MSC_VER
#if _MSC_VER < 1900
/* C runtime functions redefined */
#define snprintf _snprintf
#define strdup _strdup

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,7 +116,7 @@ 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
#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
@@ -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,7 +150,7 @@ 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
#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
@@ -170,7 +167,7 @@ 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
#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
@@ -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
/****************************************************************************/

View File

@@ -43,11 +43,11 @@
#if defined(__linux__) || defined(__APPLE__)
#include <sys/socket.h>
#include <pthread.h>
#endif
#include "SysUtils.h"
#include <stdint.h>
#include <pthread.h>
#ifdef __linux__
#include <sys/syscall.h>

View File

@@ -32,7 +32,7 @@
#include "Utilities.h"
#if defined(__MINGW32__) || defined(__MINGW64__)
#if defined(_WIN32_FALSE)
#include <WinSock2.h>
#include <stdint.h>

View File

@@ -54,8 +54,9 @@ std::string netDir; // Where network .conf files are to be written
ZeroTier::Mutex _multiplexer_lock;
#if defined(__MINGW32__) || defined(__MINGW64__)
#if defined(_WIN32)
WSADATA wsaData;
#include <Windows.h>
#endif
// prototype
@@ -180,7 +181,11 @@ uint64_t zts_get_node_id_from_file(const char *filepath)
}
// Starts a ZeroTier service in the background
#if defined(_WIN32)
DWORD WINAPI zts_start_service(LPVOID thread_id)
#else
void *zts_start_service(void *thread_id)
#endif
{
DEBUG_INFO("zto-thread, path=%s", homeDir.c_str());
// Where network .conf files will be stored
@@ -414,11 +419,15 @@ int zts_start(const char *path, bool blocking = false)
if (path) {
homeDir = path;
}
#if defined(__MINGW32__) || defined(__MINGW64__)
int err;
#if defined(_WIN32)
WSAStartup(MAKEWORD(2, 2), &wsaData); // initialize WinSock. Used in Phy for loopback pipe
#endif
HANDLE thr = CreateThread(NULL, 0, zts_start_service, NULL, 0, NULL);
#else
pthread_t service_thread;
int err = pthread_create(&service_thread, NULL, zts_start_service, NULL);
err = pthread_create(&service_thread, NULL, zts_start_service, NULL);
#endif
if (blocking) { // block to prevent service calls before we're ready
ZT_NodeStatus status;
while (zts_core_running() == false || zt1Service->getNode() == NULL) {
@@ -463,7 +472,7 @@ void zts_stop()
zt1Service->terminate();
// disableTaps();
}
#if defined(__MINGW32__) || defined(__MINGW64__)
#if defined(_WIN32)
WSACleanup();
#endif
}
@@ -555,9 +564,13 @@ bool _ipv6_in_subnet(ZeroTier::InetAddress *subnet, ZeroTier::InetAddress *addr)
void api_sleep(int interval_ms)
{
#if defined(_WIN32)
Sleep(interval_ms);
#else
struct timespec sleepValue = {0};
sleepValue.tv_nsec = interval_ms * 500000;
nanosleep(&sleepValue, NULL);
#endif
}
#ifdef __cplusplus

View File

@@ -673,7 +673,7 @@ int platform_adjusted_socket_family(int family)
#if defined(__APPLE__)
return family == 30 ? AF_INET6 : family; // 10
#endif
#if defined(__MINGW32__) || defined(__MINGW64__)
#if defined(_WIN32)
return family == 23 ? AF_INET6 : family; // 10
#endif
}

View File

@@ -134,7 +134,7 @@ void lwip_driver_init()
if (lwip_driver_initialized == true) {
return;
}
#if defined(__MINGW32__)
#if defined(_WIN32)
sys_init(); // required for win32 initializtion of critical sections
#endif
sys_thread_new("main_thread", main_thread,