Windows cmake build updates
This commit is contained in:
@@ -28,6 +28,7 @@ cmake_minimum_required (VERSION 2.8)
|
|||||||
project (libzt)
|
project (libzt)
|
||||||
|
|
||||||
# --- SETUP
|
# --- SETUP
|
||||||
|
set(CMAKE_SUPPRESS_REGENERATION true)
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
set (PROJ_DIR ${PROJECT_SOURCE_DIR})
|
set (PROJ_DIR ${PROJECT_SOURCE_DIR})
|
||||||
@@ -36,14 +37,24 @@ set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
|||||||
set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
# get literal paths for Windows libraries
|
||||||
|
set (WIN_LIB_HINT_PATH "C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.16299.0\\um\\x86")
|
||||||
|
message (STATUS ${WIN_LIB_HINT_PATH})
|
||||||
|
find_library(ws2_32_LIBRARY_PATH NAMES WS2_32 HINTS ${WIN_LIB_HINT_PATH})
|
||||||
|
find_library(lshlwapi_LIBRARY_PATH NAMES ShLwApi HINTS ${WIN_LIB_HINT_PATH})
|
||||||
|
#find_library(liphlpapi_LIBRARY_PATH NAMES iphlpapi.lib HINTS ${WIN_LIB_HINT_PATH})
|
||||||
|
set (liphlpapi_LIBRARY_PATH "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.16299.0/um/x86/iphlpapi.Lib")
|
||||||
|
message (STATUS ${ws2_32_LIBRARY_PATH})
|
||||||
|
message (STATUS ${lshlwapi_LIBRARY_PATH})
|
||||||
|
message (STATUS ${liphlpapi_LIBRARY_PATH})
|
||||||
add_definitions(-DSDK=1)
|
add_definitions(-DSDK=1)
|
||||||
add_definitions(-DZT_SDK=1)
|
add_definitions(-DZT_SDK=1)
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc -DNOMINMAX")
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc -DNOMINMAX")
|
||||||
set (LWIP_PORT_DIR ${PROJ_DIR}/ext/lwip-contrib/ports/win32/include)
|
set (LWIP_PORT_DIR ${PROJ_DIR}/ext/lwip-contrib/ports/win32)
|
||||||
#set (COMMON_DEBUG_FLAGS "-DLIBZT_TRACE=1 -DLIBZT_DEBUG=1 -DNS_TRACE=1 -DNS_DEBUG=1")
|
set (COMMON_DEBUG_FLAGS "-DLIBZT_TRACE=1 -DLIBZT_DEBUG=1 -DNS_TRACE=1 -DNS_DEBUG=1")
|
||||||
else()
|
else()
|
||||||
set (CMAKE_C_FLAGS "-fvisibility=hidden -fstack-protector -DZT_SDK=1")
|
set (CMAKE_C_FLAGS "-fvisibility=hidden -fstack-protector -DZT_SDK=1")
|
||||||
set (LWIP_PORT_DIR ${PROJ_DIR}/ext/lwip-contrib/ports/unix/include)
|
set (LWIP_PORT_DIR ${PROJ_DIR}/ext/lwip-contrib/ports/unix)
|
||||||
set (COMMON_DEBUG_FLAGS "-g -DLIBZT_TRACE=1 -DLIBZT_DEBUG=1 -DNS_TRACE=1 -DNS_DEBUG=1")
|
set (COMMON_DEBUG_FLAGS "-g -DLIBZT_TRACE=1 -DLIBZT_DEBUG=1 -DNS_TRACE=1 -DNS_DEBUG=1")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -70,7 +81,7 @@ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS}")
|
|||||||
# lwIP Userspace Networking Stack
|
# lwIP Userspace Networking Stack
|
||||||
set (LWIP_SRC_DIR ${PROJ_DIR}/ext/lwip/src)
|
set (LWIP_SRC_DIR ${PROJ_DIR}/ext/lwip/src)
|
||||||
include_directories (${LWIP_SRC_DIR}/include)
|
include_directories (${LWIP_SRC_DIR}/include)
|
||||||
include_directories (${LWIP_PORT_DIR})
|
include_directories (${LWIP_PORT_DIR}/include)
|
||||||
file (GLOB lwip_src_glob
|
file (GLOB lwip_src_glob
|
||||||
${LWIP_SRC_DIR}/netif/*.c
|
${LWIP_SRC_DIR}/netif/*.c
|
||||||
${LWIP_SRC_DIR}/api/*.c
|
${LWIP_SRC_DIR}/api/*.c
|
||||||
@@ -99,6 +110,9 @@ file (GLOB zto_src_glob
|
|||||||
add_library (zto STATIC ${zto_src_glob})
|
add_library (zto STATIC ${zto_src_glob})
|
||||||
target_link_libraries (zto http)
|
target_link_libraries (zto http)
|
||||||
target_link_libraries (zto zt)
|
target_link_libraries (zto zt)
|
||||||
|
target_link_libraries (zto ws2_32)
|
||||||
|
target_link_libraries (zto ${lshlwapi_LIBRARY_PATH})
|
||||||
|
target_link_libraries (zto ${liphlpapi_LIBRARY_PATH})
|
||||||
add_library (zto_pic STATIC ${zto_src_glob})
|
add_library (zto_pic STATIC ${zto_src_glob})
|
||||||
target_link_libraries (zto_pic http_pic zt)
|
target_link_libraries (zto_pic http_pic zt)
|
||||||
set_target_properties (zto_pic PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
set_target_properties (zto_pic PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
@@ -119,7 +133,10 @@ include_directories ("${PROJ_DIR}/include")
|
|||||||
file (GLOB libzt_src_glob ${LIBZT_SRC_DIR}/*.cpp)
|
file (GLOB libzt_src_glob ${LIBZT_SRC_DIR}/*.cpp)
|
||||||
add_library (zt ${libzt_src_glob})
|
add_library (zt ${libzt_src_glob})
|
||||||
target_link_libraries (zt lwip zto)
|
target_link_libraries (zt lwip zto)
|
||||||
#set_target_properties (zt PROPERTIES OUTPUT_NAME zt)
|
target_link_libraries (zt ws2_32)
|
||||||
|
target_link_libraries (zt ${lshlwapi_LIBRARY_PATH})
|
||||||
|
target_link_libraries (zt ${liphlpapi_LIBRARY_PATH})
|
||||||
|
set_target_properties (zt PROPERTIES OUTPUT_NAME zt)
|
||||||
# (libzt) Shared Library variant of ZeroTier paired with userspace stack and virtual tap interface
|
# (libzt) Shared Library variant of ZeroTier paired with userspace stack and virtual tap interface
|
||||||
#add_library (ztshared SHARED ${libzt_src_glob})
|
#add_library (ztshared SHARED ${libzt_src_glob})
|
||||||
#target_link_libraries (ztshared zto_pic lwip_pic)
|
#target_link_libraries (ztshared zto_pic lwip_pic)
|
||||||
@@ -128,27 +145,31 @@ target_link_libraries (zt lwip zto)
|
|||||||
|
|
||||||
# --- Test applications, examples, etc ---
|
# --- 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/ipv6simple/*
|
||||||
# ${PROJ_DIR}/examples/bindings/cpp/ipv6adhoc/*
|
${PROJ_DIR}/examples/bindings/cpp/ipv6adhoc/*
|
||||||
# ${PROJ_DIR}/examples/apps/ztproxy/*.cpp
|
${PROJ_DIR}/examples/apps/ztproxy/*.cpp
|
||||||
#)
|
)
|
||||||
#foreach (testsourcefile ${APP_SOURCES})
|
foreach (testsourcefile ${APP_SOURCES})
|
||||||
# string (REPLACE ".cpp" "" testname ${testsourcefile})
|
string (REPLACE ".cpp" "" testname ${testsourcefile})
|
||||||
# get_filename_component (testname ${testname} NAME)
|
get_filename_component (testname ${testname} NAME)
|
||||||
# add_executable (${testname} ${testsourcefile})
|
add_executable (${testname} ${testsourcefile})
|
||||||
# target_link_libraries (${testname} lwip zto zt pthread)
|
target_link_libraries (${testname} lwip zto zt)
|
||||||
#endforeach (testsourcefile ${APP_SOURCES})
|
endforeach (testsourcefile ${APP_SOURCES})
|
||||||
|
|
||||||
# selftest
|
# selftest
|
||||||
add_executable (selftest ${PROJ_DIR}/test/selftest.cpp)
|
add_executable (selftest ${PROJ_DIR}/test/selftest.cpp)
|
||||||
target_compile_options (selftest PRIVATE -std=c++1 -D__SELFTEST__)
|
target_compile_options (selftest PRIVATE -std=c++1 -D__SELFTEST__)
|
||||||
|
if (WIN32)
|
||||||
|
target_link_libraries (selftest lwip zto zt ${ws2_32_LIBRARY_PATH} ${lshlwapi_LIBRARY_PATH} ${liphlpapi_LIBRARY_PATH})
|
||||||
|
else()
|
||||||
target_link_libraries (selftest lwip zto zt)
|
target_link_libraries (selftest lwip zto zt)
|
||||||
|
endif()
|
||||||
|
|
||||||
# nativetest
|
# nativetest
|
||||||
#add_executable (nativetest ${PROJ_DIR}/test/selftest.cpp)
|
add_executable (nativetest ${PROJ_DIR}/test/selftest.cpp)
|
||||||
#target_compile_options (nativetest PRIVATE -D__NATIVETEST__)
|
target_compile_options (nativetest PRIVATE -D__NATIVETEST__)
|
||||||
#target_link_libraries (nativetest lwip zto zt pthread)
|
target_link_libraries (nativetest lwip zto zt)
|
||||||
|
|
||||||
# Clean up intermediate library targets
|
# Clean up intermediate library targets
|
||||||
#file (REMOVE ${LIBRARY_OUTPUT_PATH}/libhttp.a)
|
#file (REMOVE ${LIBRARY_OUTPUT_PATH}/libhttp.a)
|
||||||
|
|||||||
@@ -25,10 +25,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__APPLE__)
|
#if defined(__linux__) || defined(__APPLE__)
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -43,6 +43,14 @@
|
|||||||
#include "RingBuffer.h"
|
#include "RingBuffer.h"
|
||||||
#include "ztproxy.hpp"
|
#include "ztproxy.hpp"
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <time.h>
|
||||||
|
void sleep(unsigned long ms)
|
||||||
|
{
|
||||||
|
Sleep(ms);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
typedef void PhySocket;
|
typedef void PhySocket;
|
||||||
@@ -329,7 +337,11 @@ namespace ZeroTier {
|
|||||||
delete conn;
|
delete conn;
|
||||||
conn = NULL;
|
conn = NULL;
|
||||||
}
|
}
|
||||||
|
#if defined(_WIN32)
|
||||||
|
closesocket(_phy.getDescriptor(sock));
|
||||||
|
#else
|
||||||
close(_phy.getDescriptor(sock));
|
close(_phy.getDescriptor(sock));
|
||||||
|
#endif
|
||||||
conn_m.unlock();
|
conn_m.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ int zts_start(const char *path, bool blocking = false)
|
|||||||
if (path) {
|
if (path) {
|
||||||
homeDir = path;
|
homeDir = path;
|
||||||
}
|
}
|
||||||
int err;
|
int err = 0;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
WSAStartup(MAKEWORD(2, 2), &wsaData); // initialize WinSock. Used in Phy for loopback pipe
|
WSAStartup(MAKEWORD(2, 2), &wsaData); // initialize WinSock. Used in Phy for loopback pipe
|
||||||
HANDLE thr = CreateThread(NULL, 0, zts_start_service, NULL, 0, NULL);
|
HANDLE thr = CreateThread(NULL, 0, zts_start_service, NULL, 0, NULL);
|
||||||
@@ -431,6 +431,7 @@ int zts_start(const char *path, bool blocking = false)
|
|||||||
|
|
||||||
if (blocking) { // block to prevent service calls before we're ready
|
if (blocking) { // block to prevent service calls before we're ready
|
||||||
ZT_NodeStatus status;
|
ZT_NodeStatus status;
|
||||||
|
status.online = 0;
|
||||||
while (zts_core_running() == false || zt1Service->getNode() == NULL) {
|
while (zts_core_running() == false || zt1Service->getNode() == NULL) {
|
||||||
api_sleep(ZTO_WRAPPER_CHECK_INTERVAL);
|
api_sleep(ZTO_WRAPPER_CHECK_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -674,14 +674,20 @@ int platform_adjusted_socket_family(int family)
|
|||||||
return family == 30 ? AF_INET6 : family; // 10
|
return family == 30 ? AF_INET6 : family; // 10
|
||||||
#endif
|
#endif
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return family == 23 ? AF_INET6 : family; // 10
|
if (family == 23) {
|
||||||
|
return AF_INET6;
|
||||||
|
}
|
||||||
|
if (family == 2) {
|
||||||
|
return AF_INET;
|
||||||
|
}
|
||||||
|
family; // 10
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void fix_addr_socket_family(struct sockaddr *addr)
|
void fix_addr_socket_family(struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
#if defined(__linux__)
|
#if defined(__linux__) || defined(_WIN32)
|
||||||
/* linux's socket.h's sockaddr definition doesn't contain an sa_len field
|
/* struct sockaddr on Linux and Windows don't contain an sa_len field
|
||||||
so we must adjust it here before feeding it into the stack. */
|
so we must adjust it here before feeding it into the stack. */
|
||||||
#if defined(STACK_LWIP)
|
#if defined(STACK_LWIP)
|
||||||
if (addr->sa_len == 2) {
|
if (addr->sa_len == 2) {
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ static void main_thread(void *arg)
|
|||||||
sys_sem_t sem;
|
sys_sem_t sem;
|
||||||
LWIP_UNUSED_ARG(arg);
|
LWIP_UNUSED_ARG(arg);
|
||||||
if (sys_sem_new(&sem, 0) != ERR_OK) {
|
if (sys_sem_new(&sem, 0) != ERR_OK) {
|
||||||
DEBUG_ERROR("failed to create semaphore", 0);
|
DEBUG_ERROR("failed to create semaphore");
|
||||||
}
|
}
|
||||||
tcpip_init(tcpip_init_done, &sem);
|
tcpip_init(tcpip_init_done, &sem);
|
||||||
sys_sem_wait(&sem);
|
sys_sem_wait(&sem);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user