From 8ec82b026ab5415e81713bc5e99fe29ebcd7a6ce Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Fri, 15 Dec 2017 16:26:27 -0800 Subject: [PATCH] Officially deprecated old Makefile in favor of CMake --- CMakeLists.txt | 104 +++++++++++++++++-------------------- README.md | 25 +++++---- Makefile => attic/Makefile | 0 src/VirtualTap.cpp | 4 +- test/selftest.cpp | 38 +++++++------- 5 files changed, 85 insertions(+), 86 deletions(-) rename Makefile => attic/Makefile (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04a7965..3bff1fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,44 +24,40 @@ # of your own application. # -# BUILD OUTPUTS: - -#---Libraries -# -# bin/lib/libzt.a -# bin/lib/libzt.so -# bin/lib/libzt.dylib -# -#---Sample apps -# -# bin/ipv4server -# bin/ipv4client -# bin/ipv6server -# bin/ipv6client -# bin/ztproxy -# -#---Tests -# -# bin/selftest -# bin/nativetest - - cmake_minimum_required (VERSION 2.8) project (libzt) -set (libzt_VERSION_MAJOR 1) -set (libzt_VERSION_MINOR 0) -set (ZT_DEFS -std=c++11 "-DZT_SDK=1") -set (LIBZT_DEFS -std=c++11 "-DZT_SDK=1") -# --- dirs --- +# --- SETUP + +# Paths set (PROJ_DIR ${PROJECT_SOURCE_DIR}) set (CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin) set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) -# ---include dirs --- +# Flags for various build types +set(COMMON_C_FLAGS "-fvisibility=hidden -fstack-protector -DZT_SDK=1") +set(COMMON_CXX_FLAGS "${COMMON_C_FLAGS} -std=c++11") +set(COMMON_DEBUG_FLAGS "-g -DLIBZT_TRACE=1 -DLIBZT_DEBUG=1 -DNS_TRACE=1 -DNS_DEBUG=1") +# C +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMMON_C_FLAGS} ${COMMON_DEBUG_FLAGS}") +set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${COMMON_C_FLAGS}") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${COMMON_C_FLAGS}") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${COMMON_C_FLAGS}") +# C++ +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMMON_CXX_FLAGS} ${COMMON_DEBUG_FLAGS}") +set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${COMMON_CXX_FLAGS}") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COMMON_CXX_FLAGS}") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_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) -# (lwip) lwIP Userspace Networking Stack +# --- 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) @@ -73,15 +69,13 @@ file(GLOB lwip_src_glob ${LWIP_SRC_DIR}/core/ipv4/*.c ${LWIP_SRC_DIR}/core/ipv6/*.c) add_library(lwip STATIC ${lwip_src_glob}) -target_compile_options(lwip PRIVATE ${NS_DEFS}) - add_library(lwip_pic STATIC ${lwip_src_glob}) -target_compile_options(lwip_pic PRIVATE ${NS_DEFS}) +#target_compile_options(lwip_pic PRIVATE ${NS_DEFS}) set_target_properties(lwip_pic PROPERTIES POSITION_INDEPENDENT_CODE ON) - -# (zto) ZeroTier Core Service +# zto +# ZeroTier Core Service set(ZTO_SRC_DIR ${PROJ_DIR}/zto) include_directories(${ZTO_SRC_DIR}/include) include_directories(${ZTO_SRC_DIR}/osdep) @@ -94,39 +88,33 @@ file(GLOB zto_src_glob ${ZTO_SRC_DIR}/controller/*.cpp ${ZTO_SRC_DIR}/osdep/ManagedRoute.cpp) add_library(zto STATIC ${zto_src_glob}) -target_compile_options(zto PRIVATE ${ZT_DEFS}) +#set(zto "--whole-archive") target_link_libraries(zto http) target_link_libraries(zto zt) - add_library(zto_pic STATIC ${zto_src_glob}) -target_compile_options(zto_pic PRIVATE ${ZT_DEFS}) 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 +# 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) - -# (libzt) Static Library variant of ZeroTier paired with userspace stack and virtual tap interface +# 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}) -target_compile_options(zt PRIVATE ${LIBZT_DEFS}) -target_link_libraries(zt zto lwip) +#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_compile_options(ztshared PRIVATE ${LIBZT_DEFS}) target_link_libraries(ztshared zto_pic lwip_pic) set_target_properties(ztshared PROPERTIES OUTPUT_NAME zt) @@ -142,27 +130,31 @@ foreach(testsourcefile ${APP_SOURCES}) string(REPLACE ".cpp" "" testname ${testsourcefile}) get_filename_component(testname ${testname} NAME) add_executable(${testname} ${testsourcefile}) - target_compile_options(${testname} PRIVATE -std=c++11) 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 -std=c++11 -D__SELFTEST__) +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 -std=c++11 -D__NATIVETEST__) +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) # --- CONFIGURATION diff --git a/README.md b/README.md index 4682ba3..d189e5d 100644 --- a/README.md +++ b/README.md @@ -60,16 +60,23 @@ For an example using only the [Virtual Layer 2](https://www.zerotier.com/manual. *** -### Building (linux, macos, bsd, win, ios) +### Building using CMake (recommended) - ``` - git submodule init - git submodule update - make static_lib - make tests - ``` - - All targets will output to `build/`. Complete instructions [here](BUILDING.md) +We recommend using [CMake](https://cmake.org/) for its extensive cross-platform build support. + +``` +git submodule init +git submodule update +cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=DEBUG +cmake --build -build +``` + +Builds are placed in `bin\` and `bin\lib`. Change `CMAKE_BUILD_TYPE` to `RELEASE` for a smaller and optmized build. + +### Installing/Uninstalling the library + + - Install: `make install` + - Uninstall: `xargs rm < install_manifest.txt` *** diff --git a/Makefile b/attic/Makefile similarity index 100% rename from Makefile rename to attic/Makefile diff --git a/src/VirtualTap.cpp b/src/VirtualTap.cpp index 50c87e9..7e2f94b 100644 --- a/src/VirtualTap.cpp +++ b/src/VirtualTap.cpp @@ -81,7 +81,7 @@ VirtualTap::VirtualTap( // set virtual tap interface name (full) memset(vtap_full_name, 0, sizeof(vtap_full_name)); ifindex = devno; - snprintf(vtap_full_name, sizeof(vtap_full_name), "libzt%d-%lx", devno++, _nwid); + snprintf(vtap_full_name, sizeof(vtap_full_name), "libzt%d-%llx", devno++, _nwid); _dev = vtap_full_name; DEBUG_INFO("set VirtualTap interface name to: %s", _dev.c_str()); // set virtual tap interface name (abbreviated) @@ -193,7 +193,7 @@ std::string VirtualTap::nodeId() const if (zt1ServiceRef) { char id[ZTO_ID_LEN]; memset(id, 0, sizeof(id)); - sprintf(id, "%lx",((ZeroTier::OneService *)zt1ServiceRef)->getNode()->address()); + sprintf(id, "%llx",((ZeroTier::OneService *)zt1ServiceRef)->getNode()->address()); return std::string(id); } else { diff --git a/test/selftest.cpp b/test/selftest.cpp index d7d4adb..2b1da18 100644 --- a/test/selftest.cpp +++ b/test/selftest.cpp @@ -401,7 +401,7 @@ void tcp_select_server(TCP_UNIT_TEST_SIG_4) { std::string testname = "tcp_select_server"; std::string msg = "tcp_select"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "accept connection, create poll/select loop, read and write strings back and forth\n"); int w=0, r=0, fd, client_fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -490,7 +490,7 @@ void tcp_select_client(TCP_UNIT_TEST_SIG_4) { std::string testname = "tcp_select_client"; std::string msg = "tcp_select"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "connect to remote host, create poll/select loop, read and write strings back and forth\n"); int r, w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -572,7 +572,7 @@ void tcp_client_4(TCP_UNIT_TEST_SIG_4) { std::string testname = "tcp_client_4"; std::string msg = "tcp_cs_4"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "connect to remote host with IPv4 address, write string, read string, compare.\n"); int r, w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -619,7 +619,7 @@ void tcp_server_4(TCP_UNIT_TEST_SIG_4) { std::string testname = "tcp_server_4"; std::string msg = "tcp_cs_4"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "accept connection with IPv4 address, read string, write string, compare.\n"); int w=0, r=0, fd, client_fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -679,7 +679,7 @@ void tcp_client_6(TCP_UNIT_TEST_SIG_6) { std::string testname = "tcp_client_6"; std::string msg = "tcp_cs_6"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "connect to remote host with IPv6 address, write string, read string, compare.\n"); int r, w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -726,7 +726,7 @@ void tcp_server_6(TCP_UNIT_TEST_SIG_6) { std::string testname = "tcp_server_6"; std::string msg = "tcp_cs_6"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "accept connection with IPv6 address, read string, write string, compare.\n"); int w=0, r=0, fd, client_fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -791,7 +791,7 @@ void udp_client_4(UDP_UNIT_TEST_SIG_4) { std::string testname = "udp_client_4"; std::string msg = "udp_cs_4"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "bind to interface with IPv4 address, send string until response is seen. compare.\n"); int r, w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -847,7 +847,7 @@ void udp_server_4(UDP_UNIT_TEST_SIG_4) { std::string testname = "udp_server_4"; std::string msg = "udp_cs_4"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "bind to interface with IPv4 address, read single string, send many responses. compare.\n"); int r, w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -923,7 +923,7 @@ void udp_client_6(UDP_UNIT_TEST_SIG_6) { std::string testname = "udp_client_6"; std::string msg = "udp_cs_6"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "bind to interface with IPv6 address, send string until response is seen. compare.\n"); int r, w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -981,7 +981,7 @@ void udp_server_6(UDP_UNIT_TEST_SIG_6) { std::string testname = "udp_server_6"; std::string msg = "udp_cs_6"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "bind to interface with IPv6 address, read single string, send many responses. compare.\n"); int r, w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -1055,7 +1055,7 @@ void tcp_client_sustained_4(TCP_UNIT_TEST_SIG_4) { std::string testname = "tcp_client_sustained_4"; std::string msg = "tcp_sustained_4"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "connect to remote host with IPv4 address, exchange a sequence of packets, check order.\n"); int n=0, w=0, r=0, fd, err; char *rxbuf = (char*)malloc(cnt*sizeof(char)); @@ -1139,7 +1139,7 @@ void tcp_client_sustained_6(TCP_UNIT_TEST_SIG_6) { std::string testname = "tcp_client_sustained_6"; std::string msg = "tcp_sustained_6"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "connect to remote host with IPv6 address, exchange a sequence of packets, check order.\n"); int n=0, w=0, r=0, fd, err; char *rxbuf = (char*)malloc(cnt*sizeof(char)); @@ -1219,7 +1219,7 @@ void tcp_server_sustained_4(TCP_UNIT_TEST_SIG_4) { std::string testname = "tcp_server_sustained_4"; std::string msg = "tcp_sustained_4"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "accept connection from host with IPv4 address, exchange a sequence of packets, check order.\n"); int n=0, w=0, r=0, fd, client_fd, err; char *rxbuf = (char*)malloc(cnt*sizeof(char)); @@ -1303,7 +1303,7 @@ void tcp_server_sustained_6(TCP_UNIT_TEST_SIG_6) { std::string testname = "tcp_server_sustained_6"; std::string msg = "tcp_sustained_6"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "accept connection from host with IPv6 address, exchange a sequence of packets, check order.\n"); int n=0, w=0, r=0, fd, client_fd, err; char *rxbuf = (char*)malloc(cnt*sizeof(char)); @@ -1391,7 +1391,7 @@ void udp_client_sustained_4(UDP_UNIT_TEST_SIG_4) { std::string testname = "udp_client_sustained_4"; std::string msg = "udp_sustained_4"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "bind to interface with IPv4 address, TX n-datagrams\n"); int w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -1439,7 +1439,7 @@ void udp_server_sustained_4(UDP_UNIT_TEST_SIG_4) { std::string testname = "udp_server_sustained_4"; std::string msg = "udp_sustained_4"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "bind to interface with IPv4 address, RX (n/x)-datagrams\n"); int r, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -1487,7 +1487,7 @@ void udp_client_sustained_6(UDP_UNIT_TEST_SIG_6) { std::string testname = "udp_client_sustained_6"; std::string msg = "udp_sustained_6"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "bind to interface with IPv6 address, TX n-datagrams\n"); int w, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -1536,7 +1536,7 @@ void udp_server_sustained_6(UDP_UNIT_TEST_SIG_6) { std::string testname = "udp_server_sustained_6"; std::string msg = "udp_sustained_6"; - fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts); + fprintf(stderr, "\n\n%s (ts=%lu)\n", testname.c_str(), get_now_ts()); fprintf(stderr, "bind to interface with IPv6 address, RX (n/x)-datagrams\n"); int r, fd, err, len = strlen(msg.c_str()); char rbuf[STR_SIZE]; @@ -2453,7 +2453,7 @@ void* worker_create_socket(void *arg) for (int i=0; i