Updated CMake build script for Windows. Moving away from MinGW requirement for build
This commit is contained in:
157
CMakeLists.txt
157
CMakeLists.txt
@@ -35,126 +35,135 @@ set (CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin)
|
||||
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||
set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
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 (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_C_FLAGS "-fvisibility=hidden -fstack-protector -DZT_SDK=1")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11")
|
||||
set(COMMON_DEBUG_FLAGS "-g -DLIBZT_TRACE=1 -DLIBZT_DEBUG=1 -DNS_TRACE=1 -DNS_DEBUG=1")
|
||||
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}")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS}")
|
||||
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}")
|
||||
set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_FLAGS}")
|
||||
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS}")
|
||||
# C++
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS} ${COMMON_DEBUG_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS} ${COMMON_DEBUG_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${CMAKE_CXX_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS}")
|
||||
# Linker
|
||||
#set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
|
||||
#set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
|
||||
#set(CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS} --whole-archive)
|
||||
#set (CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
|
||||
#set (CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
|
||||
#set (CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS} --whole-archive)
|
||||
|
||||
# --- LIBRARY TARGETS
|
||||
|
||||
# lwip
|
||||
# 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)
|
||||
file(GLOB lwip_src_glob
|
||||
set (LWIP_SRC_DIR ${PROJ_DIR}/ext/lwip/src)
|
||||
include_directories (${LWIP_SRC_DIR}/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)
|
||||
add_library(lwip STATIC ${lwip_src_glob})
|
||||
add_library(lwip_pic STATIC ${lwip_src_glob})
|
||||
#target_compile_options(lwip_pic PRIVATE ${NS_DEFS})
|
||||
set_target_properties(lwip_pic PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
add_library (lwip STATIC ${lwip_src_glob})
|
||||
add_library (lwip_pic STATIC ${lwip_src_glob})
|
||||
#target_compile_options (lwip_pic PRIVATE ${NS_DEFS})
|
||||
set_target_properties (lwip_pic PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
|
||||
# zto
|
||||
# ZeroTier Core Service
|
||||
set(ZTO_SRC_DIR ${PROJ_DIR}/zto)
|
||||
include_directories(${ZTO_SRC_DIR}/include)
|
||||
include_directories(${ZTO_SRC_DIR}/osdep)
|
||||
include_directories(${ZTO_SRC_DIR}/node)
|
||||
include_directories(${ZTO_SRC_DIR}/service)
|
||||
file(GLOB zto_src_glob
|
||||
set (ZTO_SRC_DIR ${PROJ_DIR}/zto)
|
||||
include_directories (${ZTO_SRC_DIR}/include)
|
||||
include_directories (${ZTO_SRC_DIR}/osdep)
|
||||
include_directories (${ZTO_SRC_DIR}/node)
|
||||
include_directories (${ZTO_SRC_DIR}/service)
|
||||
file (GLOB zto_src_glob
|
||||
${ZTO_SRC_DIR}/node/*.cpp
|
||||
${ZTO_SRC_DIR}/service/*.cpp
|
||||
${ZTO_SRC_DIR}/osdep/OSUtils.cpp
|
||||
${ZTO_SRC_DIR}/controller/*.cpp
|
||||
${ZTO_SRC_DIR}/osdep/ManagedRoute.cpp)
|
||||
add_library(zto STATIC ${zto_src_glob})
|
||||
#set(zto "--whole-archive")
|
||||
target_link_libraries(zto http)
|
||||
target_link_libraries(zto zt)
|
||||
add_library(zto_pic STATIC ${zto_src_glob})
|
||||
target_link_libraries(zto_pic http_pic zt)
|
||||
set_target_properties(zto_pic PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
add_library (zto STATIC ${zto_src_glob})
|
||||
#set (zto "--whole-archive")
|
||||
target_link_libraries (zto http)
|
||||
target_link_libraries (zto zt)
|
||||
add_library (zto_pic STATIC ${zto_src_glob})
|
||||
target_link_libraries (zto_pic http_pic zt)
|
||||
set_target_properties (zto_pic PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
|
||||
# http
|
||||
# HTTP Control Plane for ZT Service
|
||||
add_library(http STATIC "${ZTO_SRC_DIR}/ext/http-parser/http_parser.c")
|
||||
add_library(http_pic STATIC "${ZTO_SRC_DIR}/ext/http-parser/http_parser.c")
|
||||
set_target_properties(http_pic PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
add_library (http STATIC "${ZTO_SRC_DIR}/ext/http-parser/http_parser.c")
|
||||
add_library (http_pic STATIC "${ZTO_SRC_DIR}/ext/http-parser/http_parser.c")
|
||||
set_target_properties (http_pic PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
|
||||
# libzt
|
||||
# Static Library variant of ZeroTier paired with userspace stack and virtual tap interface
|
||||
set (LIBZT_SRC_DIR ${PROJ_DIR}/src)
|
||||
include_directories("${LIBZT_SRC_DIR}")
|
||||
include_directories("${PROJ_DIR}/include")
|
||||
file(GLOB libzt_src_glob ${LIBZT_SRC_DIR}/*.cpp)
|
||||
add_library(zt ${libzt_src_glob})
|
||||
#set(zt "--whole-archive")
|
||||
target_link_libraries(zt lwip zto)
|
||||
set_target_properties(zt PROPERTIES OUTPUT_NAME zt)
|
||||
include_directories ("${LIBZT_SRC_DIR}")
|
||||
include_directories ("${PROJ_DIR}/include")
|
||||
file (GLOB libzt_src_glob ${LIBZT_SRC_DIR}/*.cpp)
|
||||
add_library (zt ${libzt_src_glob})
|
||||
#set (zt "--whole-archive")
|
||||
target_link_libraries (zt lwip zto)
|
||||
set_target_properties (zt PROPERTIES OUTPUT_NAME zt)
|
||||
# (libzt) Shared Library variant of ZeroTier paired with userspace stack and virtual tap interface
|
||||
add_library(ztshared SHARED ${libzt_src_glob})
|
||||
target_link_libraries(ztshared zto_pic lwip_pic)
|
||||
set_target_properties(ztshared PROPERTIES OUTPUT_NAME zt)
|
||||
add_library (ztshared SHARED ${libzt_src_glob})
|
||||
target_link_libraries (ztshared zto_pic lwip_pic)
|
||||
set_target_properties (ztshared PROPERTIES OUTPUT_NAME zt)
|
||||
|
||||
|
||||
# --- Test applications, examples, etc ---
|
||||
|
||||
file(GLOB APP_SOURCES ${PROJ_DIR}/examples/bindings/cpp/ipv4simple/*
|
||||
file (GLOB APP_SOURCES ${PROJ_DIR}/examples/bindings/cpp/ipv4simple/*
|
||||
${PROJ_DIR}/examples/bindings/cpp/ipv6simple/*
|
||||
${PROJ_DIR}/examples/bindings/cpp/ipv6adhoc/*
|
||||
${PROJ_DIR}/examples/apps/ztproxy/*.cpp
|
||||
)
|
||||
foreach(testsourcefile ${APP_SOURCES})
|
||||
string(REPLACE ".cpp" "" testname ${testsourcefile})
|
||||
get_filename_component(testname ${testname} NAME)
|
||||
add_executable(${testname} ${testsourcefile})
|
||||
target_link_libraries(${testname} lwip zto zt pthread)
|
||||
endforeach(testsourcefile ${APP_SOURCES})
|
||||
foreach (testsourcefile ${APP_SOURCES})
|
||||
string (REPLACE ".cpp" "" testname ${testsourcefile})
|
||||
get_filename_component (testname ${testname} NAME)
|
||||
add_executable (${testname} ${testsourcefile})
|
||||
target_link_libraries (${testname} lwip zto zt pthread)
|
||||
endforeach (testsourcefile ${APP_SOURCES})
|
||||
|
||||
# selftest
|
||||
add_executable(selftest ${PROJ_DIR}/test/selftest.cpp)
|
||||
target_compile_options(selftest PRIVATE -D__SELFTEST__)
|
||||
target_link_libraries(selftest lwip zto zt pthread)
|
||||
add_executable (selftest ${PROJ_DIR}/test/selftest.cpp)
|
||||
target_compile_options (selftest PRIVATE -D__SELFTEST__)
|
||||
target_link_libraries (selftest lwip zto zt pthread)
|
||||
|
||||
# nativetest
|
||||
add_executable(nativetest ${PROJ_DIR}/test/selftest.cpp)
|
||||
target_compile_options(nativetest PRIVATE -D__NATIVETEST__)
|
||||
target_link_libraries(nativetest lwip zto zt pthread)
|
||||
add_executable (nativetest ${PROJ_DIR}/test/selftest.cpp)
|
||||
target_compile_options (nativetest PRIVATE -D__NATIVETEST__)
|
||||
target_link_libraries (nativetest lwip zto zt pthread)
|
||||
|
||||
# Clean up intermediate library targets
|
||||
#file(REMOVE ${LIBRARY_OUTPUT_PATH}/libhttp.a)
|
||||
#file(REMOVE ${LIBRARY_OUTPUT_PATH}/libhttp_pic.a)
|
||||
#file(REMOVE ${LIBRARY_OUTPUT_PATH}/libzto.a)
|
||||
#file(REMOVE ${LIBRARY_OUTPUT_PATH}/libzto_pic.a)
|
||||
#file(REMOVE ${LIBRARY_OUTPUT_PATH}/liblwip.a)
|
||||
#file(REMOVE ${LIBRARY_OUTPUT_PATH}/liblwip_pic.a)
|
||||
#file (REMOVE ${LIBRARY_OUTPUT_PATH}/libhttp.a)
|
||||
#file (REMOVE ${LIBRARY_OUTPUT_PATH}/libhttp_pic.a)
|
||||
#file (REMOVE ${LIBRARY_OUTPUT_PATH}/libzto.a)
|
||||
#file (REMOVE ${LIBRARY_OUTPUT_PATH}/libzto_pic.a)
|
||||
#file (REMOVE ${LIBRARY_OUTPUT_PATH}/liblwip.a)
|
||||
#file (REMOVE ${LIBRARY_OUTPUT_PATH}/liblwip_pic.a)
|
||||
|
||||
|
||||
# --- INSTALL
|
||||
|
||||
install(TARGETS zt DESTINATION lib)
|
||||
install (TARGETS zt DESTINATION lib)
|
||||
|
||||
# --- CONFIGURATION
|
||||
|
||||
@@ -178,19 +187,19 @@ set (NS_DEFS "${NS_DEFS} -DNS_DEBUG=1")
|
||||
endif()
|
||||
|
||||
if (JNI EQUAL 1)
|
||||
MESSAGE(STATUS "Looking for JNI headers")
|
||||
MESSAGE (STATUS "Looking for JNI headers")
|
||||
# --- Locate JNI headers
|
||||
find_package(JNI)
|
||||
find_package (JNI)
|
||||
if (JNI_FOUND)
|
||||
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
|
||||
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
|
||||
list(GET JNI_INCLUDE_DIRS 0 JNI_INCLUDE_DIR)
|
||||
list (GET JNI_INCLUDE_DIRS 0 JNI_INCLUDE_DIR)
|
||||
message (STATUS "chosen=${JNI_INCLUDE_DIR}")
|
||||
include_directories("${JNI_INCLUDE_DIR}")
|
||||
include_directories ("${JNI_INCLUDE_DIR}")
|
||||
else()
|
||||
message (STATUS "JNI not found")
|
||||
endif()
|
||||
target_compile_options(zt PRIVATE -std=c++11 -DZT_SDK=1 -DLIBZT_TRACE=1 -DSDK_JNI=1)
|
||||
target_compile_options (zt PRIVATE -std=c++11 -DZT_SDK=1 -DLIBZT_TRACE=1 -DSDK_JNI=1)
|
||||
# JNI
|
||||
option (USE_JNI
|
||||
"Use Java JNI for shared/dynamic libraries" ON)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace ZeroTier {
|
||||
struct InetAddress;
|
||||
}
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
#if defined(_WIN32_FALSE)
|
||||
|
||||
#define NS_INADDRSZ 4
|
||||
#define NS_IN6ADDRSZ 16
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
* VirtualSocket management layer
|
||||
*/
|
||||
|
||||
//#include "InetAddress.hpp"
|
||||
#include "libztDefs.h"
|
||||
|
||||
namespace ZeroTier {
|
||||
class Mutex;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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...)
|
||||
|
||||
@@ -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
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "Utilities.h"
|
||||
|
||||
#if defined(__MINGW32__) || defined(__MINGW64__)
|
||||
#if defined(_WIN32_FALSE)
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -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
|
||||
HANDLE thr = CreateThread(NULL, 0, zts_start_service, NULL, 0, NULL);
|
||||
#else
|
||||
pthread_t service_thread;
|
||||
err = pthread_create(&service_thread, NULL, zts_start_service, NULL);
|
||||
#endif
|
||||
pthread_t service_thread;
|
||||
int err = pthread_create(&service_thread, NULL, zts_start_service, NULL);
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user