From a8c757eaff21e927976c2f6a1b3cc848d06a0ef8 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 4 Jan 2021 20:57:18 -0800 Subject: [PATCH] Add preprocessor check in ZeroTierSockets.h for inclusion of integer definitions. A response to e94ca31. --- CMakeLists.txt | 14 ++++++++++++-- include/ZeroTierSockets.h | 13 ++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bfe856..e072e3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,7 +270,12 @@ file (GLOB libminiupnpcSrcGlob ${ZTO_SRC_DIR}/ext/miniupnpc/upnperrors.c ${ZTO_SRC_DIR}/ext/miniupnpc/upnpreplyparse.c) -file (GLOB libztSrcGlob ${LIBZT_SRC_DIR}/*.cpp) +if (ZTS_PINVOKE) + set (ZTS_SWIG_WRAPPER_FILE ${PROJ_DIR}/examples/csharp/*.cxx) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DZTS_PINVOKE=1") +endif () + +file (GLOB libztSrcGlob ${LIBZT_SRC_DIR}/*.cpp ${ZTS_SWIG_WRAPPER_FILE}) if (UNIX) set (LWIP_PORT_DIR ${PROJ_DIR}/ext/lwip-contrib/ports/unix/port) @@ -466,8 +471,13 @@ endif () # xcode framework if (IN_XCODE) - include_directories (${frameworkHeaderGlob}) + # stdint.h is needed for API definitions but can cause conflicts + # in certain projects where integers may already be defined. + # Thus this flag is used to exclude their definition in ZeroTierSockets.h + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DZTS_NO_STDINT_H=1") + + include_directories (${frameworkHeaderGlob}) add_library(${XCODE_FRAMEWORK_NAME} STATIC $ diff --git a/include/ZeroTierSockets.h b/include/ZeroTierSockets.h index d0aea33..b12e9c3 100644 --- a/include/ZeroTierSockets.h +++ b/include/ZeroTierSockets.h @@ -17,6 +17,10 @@ * This defines the external C API for ZeroTier Sockets */ +#if !ZTS_NO_STDINT_H +#include +#endif + #ifndef ZT_SOCKETS_H #define ZT_SOCKETS_H @@ -885,7 +889,14 @@ ZTS_API int ZTCALL zts_allow_local_conf(uint8_t allowed); * @param callback User-specified callback for ZTS_EVENT_* events * @return ZTS_ERR_OK on success. ZTS_ERR_SERVICE or ZTS_ERR_ARG on failure */ -ZTS_API int ZTCALL zts_start(const char *path, void (*callback)(void *), uint16_t port); + +#ifdef ZTS_PINVOKE + // Used by P/INVOKE wrappers + typedef void (*CppCallback)(void *msg); + ZTS_API int ZTCALL zts_start(const char *path, CppCallback callback, uint16_t port); +#else + ZTS_API int ZTCALL zts_start(const char *path, void (*callback)(void *), uint16_t port); +#endif /** * @brief Stops the ZeroTier service and brings down all virtual network interfaces