From c5faa8692643e970851a52c710365facf0203587 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Sun, 17 May 2020 16:41:48 -0300 Subject: [PATCH] cmake refactor Refactors many things in cmake to improve and simplify: - don't use variable indirection for target names; target names are *already* a variable of sorts. (e.g. ${UTIL_LIB} is now just lokinet-util). cmake/basic_definitions.cmake is now gone. - fix LTO enabling to use the standard cmake (3.9+) LTO mechanism rather than shoving a bunch of flag hacks through link_libraries and add_compile_options. This also now enables LTO when building a shared library (because previously the -flto hacks were only turned on in the static code for some reason). - build liblokinet as *either* shared library or static library, but not both. Building both makes things more complicated because they had different names (lokinet-shared or lokinet-static) and seems pointless: you generally want one or the other. Now there is just the liblokinet target, which will be shared or static depending on the value of BUILD_SHARED_LIBS. - Simplify lokinet-cryptography AVX2 code: just build *one* library, and add in the additional AVX2 files when possible, rather than building two and needing to merge them. - Compress STATIC_LINK and STATIC_LINK_RUNTIME into just STATIC_LINK. It makes no sense to use one of these (_RUNTIME) on Windows and the other on non-Windows when they appear to try to do the same thing. - remove a bunch of annotations from `endif(FOO)` -> `endif()`. - move all the tuntap compilation code (including OS-specific source file selection) into vendor/CMakeLists.txt and build tuntap as an intermediate OBJECT library rather than keeping a global variable in 5 different files. - move release motto define to root cmake; it made no sense being duplicated in both unix.cmake and win32.cmake - fix add_log_tag to not stomp on any existing source compile flags with its definition. Also use proper compile definition property instead of cramming it into compile flags. - make optimization/linker flags less hacky. There's no reason for us to force particular optimization flags because the cmake build type already does that (e.g. -DCMAKE_BUILD_TYPE=Release does -O3). Not doing that also silences a bunch of cmake warnings because it thinks "-O0 -g3" etc. are link libraries (which is reasonable: that's what the code was telling cmake they are). - sets the default build type to RelWithDebInfo which gives us `-O2 -g` if you don't specify a build type. - Move PIC up (so that the things loaded in unix.cmake, notably libuv, have it set). - Add a custom `curl` interface library that carries the correct link target and include paths for curl (system or bundled). --- CMakeLists.txt | 87 ++++++++++------------- Makefile | 12 ++-- cmake/add_log_tag.cmake | 10 ++- cmake/basic_definitions.cmake | 20 ------ cmake/enable_lto.cmake | 14 ++++ cmake/static_link.cmake | 39 ++--------- cmake/unix.cmake | 32 +++------ cmake/win32.cmake | 21 +----- crypto/CMakeLists.txt | 83 +++++++++++----------- daemon/CMakeLists.txt | 61 +++++++--------- jni/CMakeLists.txt | 16 ++--- libabyss/CMakeLists.txt | 26 ++++--- llarp/CMakeLists.txt | 127 +++++++++++++++------------------- pybind/CMakeLists.txt | 8 +-- test/CMakeLists.txt | 43 +++++------- vendor/CMakeLists.txt | 28 ++++++++ 16 files changed, 268 insertions(+), 359 deletions(-) delete mode 100644 cmake/basic_definitions.cmake create mode 100644 cmake/enable_lto.cmake create mode 100644 vendor/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index d88f7c24d..10f33cbe2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ set(RELEASE_MOTTO "I'll remember that..." CACHE STRING "Release motto") add_definitions(-DLLARP_VERSION_MAJOR=${lokinet_VERSION_MAJOR}) add_definitions(-DLLARP_VERSION_MINOR=${lokinet_VERSION_MINOR}) add_definitions(-DLLARP_VERSION_PATCH=${lokinet_VERSION_PATCH}) +if(RELEASE_MOTTO) + add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}") +endif() # Core options @@ -25,16 +28,12 @@ option(USE_AVX2 "enable avx2 code" OFF) option(USE_NETNS "enable networking namespace support. Linux only" OFF) option(NATIVE_BUILD "optimise for host system and FPU" ON) option(EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF) -if (WIN32) - option(STATIC_LINK_RUNTIME "link statically against compiler runtime, standard library and pthreads" OFF) -else() - option(STATIC_LINK "link statically against dependencies" OFF) -endif() +option(STATIC_LINK "link statically against dependencies" OFF) +option(BUILD_SHARED_LIBS "build lokinet libraries as shared libraries instead of static" ON) option(SHADOW "use shadow testing framework. linux only" OFF) -option(XSAN "use sanitiser, if your system has it" OFF) +option(XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF) option(JEMALLOC "use jemalloc. Not required on BSD" OFF) option(TESTNET "testnet build" OFF) -option(WITH_SHARED "build shared library" OFF) option(WITH_COVERAGE "generate coverage data" OFF) option(USE_SHELLHOOKS "enable shell hooks on compile time (dangerous)" OFF) option(WARNINGS_AS_ERRORS "treat all warnings as errors. turn off for development, on for release" OFF) @@ -47,28 +46,25 @@ if($ENV{TRAVIS}) set(TRAVIS_CI_SUCKS ON) endif() -if(WITH_HIVE) - set(WITH_SHARED ON) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo) endif() include(CheckCXXSourceCompiles) include(CheckLibraryExists) +include(cmake/enable_lto.cmake) include(cmake/target_link_libraries_system.cmake) include(cmake/add_import_library.cmake) include(cmake/add_log_tag.cmake) include(cmake/libatomic.cmake) -if (STATIC_LINK AND STATIC_LINK_RUNTIME) - message(FATAL "Cannot set both STATIC_LINK and STATIC_LINK_RUNTIME") -endif() - if (STATIC_LINK) set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX}) message(STATUS "setting static library suffix search") endif() -include(cmake/basic_definitions.cmake) +add_definitions(-D${CMAKE_SYSTEM_NAME}) if(MSVC_VERSION) enable_language(ASM_MASM) @@ -76,7 +72,7 @@ if(MSVC_VERSION) add_definitions(-D_WIN32_WINNT=0x0600 -DNOMINMAX -DSODIUM_STATIC) else() enable_language(ASM) -endif(MSVC_VERSION) +endif() include(cmake/solaris.cmake) include(cmake/win32.cmake) @@ -95,6 +91,9 @@ set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) +# Always build PIC +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + include(cmake/unix.cmake) include(cmake/check_for_std_optional.cmake) include(cmake/check_for_std_filesystem.cmake) @@ -116,35 +115,25 @@ endif() # this is messing with release builds add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0) -if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW) +if (NOT CMAKE_SYSTEM_NAME MATCHES "Linux" AND SHADOW) message( FATAL_ERROR "shadow-framework is Linux only" ) -endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW) - -if(NOT MSVC_VERSION) - set(OPTIMIZE_FLAGS -O3) - set(DEBUG_FLAGS -O0 -g3) endif() if(XSAN) - set(DEBUG_FLAGS ${DEBUG_FLAGS} "-fsanitize=${XSAN}" -fno-omit-frame-pointer) - set(OPTIMIZE_FLAGS "-O0") + string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fsanitize=${XSAN} -fno-omit-frame-pointer") + foreach(type EXE MODULE SHARED STATIC) + string(APPEND CMAKE_${type}_LINKER_FLAGS_DEBUG " -fsanitize=${XSAN} -fno-omit-frame-pointer") + endforeach() message(STATUS "Doing a ${XSAN} sanitizer build") -endif(XSAN) +endif() if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") - set(OPTIMIZE_FLAGS "") add_definitions(-DLOKINET_DEBUG=1) - set(CRYPTO_FLAGS "") - add_compile_options( ${DEBUG_FLAGS} ) - link_libraries( ${DEBUG_FLAGS} ) -endif(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") +endif() if(WITH_SHELLHOOKS) add_definitions(-DENABLE_SHELLHOOKS) -endif(WITH_SHELLHOOKS) - -# Always build PIC -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() if(TRACY_ROOT) include_directories(${TRACY_ROOT}) @@ -174,52 +163,48 @@ include(cmake/coverage.cmake) # these vars are set by the cmake toolchain spec if (WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE) include(cmake/cross_compile.cmake) -endif(WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE) +endif() if(NATIVE_BUILD) if(CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le) - set(CRYPTO_FLAGS -mcpu=native -mtune=native) + add_compile_options(-mcpu=native -mtune=native) else() - set(CRYPTO_FLAGS -march=native -mtune=native) + add_compile_options(-march=native -mtune=native) endif() elseif(NOT NON_PC_TARGET) if (USE_AVX2) - set(CRYPTO_FLAGS -march=haswell -mtune=haswell -mfpmath=sse) + add_compile_options(-march=haswell -mtune=haswell -mfpmath=sse) else() # Public binary releases - set(CRYPTO_FLAGS -march=nocona -mtune=haswell -mfpmath=sse) + add_compile_options(-march=nocona -mtune=haswell -mfpmath=sse) endif() endif() if(EMBEDDED_CFG) message(WARNING "This configuration is optimised for older hardware and/or constrained node operation, may result in poor performance on desktop systems") message(WARNING "For deployment on such systems, all external code (currently, libuv) must also be compiled for the target!") - set(CRYPTO_FLAGS -march=i486 -mtune=i486) + add_compile_options(-march=i486 -mtune=i486) endif() -add_compile_options(${OPTIMIZE_FLAGS} ${CRYPTO_FLAGS}) - set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) -include(cmake/static_link.cmake) - if(USE_NETNS) add_definitions(-DNETNS=1) else() add_definitions(-DNETNS=0) -endif(USE_NETNS) +endif() if(TESTNET) add_definitions(-DTESTNET=1) # 5 times slower than realtime add_definitions(-DTESTNET_SPEED=5) -endif(TESTNET) +endif() if(SHADOW) include(cmake/shadow.cmake) -endif(SHADOW) +endif() unset(GIT_VERSION) unset(GIT_VERSION_REAL) @@ -227,7 +212,7 @@ unset(GIT_VERSION_REAL) if(NOT GIT_VERSION) exec_program("git" ${CMAKE_CURRENT_SOURCE_DIR} ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_VERSION_UNSTRIP) string(STRIP "${GIT_VERSION_UNSTRIP}" GIT_VERSION) -endif(NOT GIT_VERSION) +endif() string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}") @@ -238,7 +223,7 @@ string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}") # long ago if(JEMALLOC) set(MALLOC_LIB jemalloc) -endif(JEMALLOC) +endif() find_package(PkgConfig QUIET) @@ -302,11 +287,13 @@ add_subdirectory(external/nlohmann EXCLUDE_FROM_ALL) add_subdirectory(external/cxxopts EXCLUDE_FROM_ALL) add_subdirectory(external/date EXCLUDE_FROM_ALL) +add_subdirectory(vendor) + if(ANDROID) list(APPEND LIBS log) add_definitions(-DANDROID) set(ANDROID_PLATFORM_SRC android/ifaddrs.c) -endif(ANDROID) +endif() set(LIBS ${MALLOC_LIB} ${LIBUV_LIBRARY} ${SD_LIBS}) if(TRACY_ROOT) @@ -333,7 +320,7 @@ if (NOT SHADOW) endif() if(ANDROID) add_subdirectory(jni) - endif(ANDROID) + endif() endif() add_subdirectory(docs) diff --git a/Makefile b/Makefile index 3309f50b0..a62dda67c 100644 --- a/Makefile +++ b/Makefile @@ -83,18 +83,16 @@ TOOLCHAIN ?= WINDOWS_ARCH ?= 64 # native avx2 code AVX2 ?= OFF -# statically link everything -STATIC_LINK ?= OFF # statically link dependencies -STATIC ?= OFF +STATIC_LINK ?= OFF +# build shared lib liblokinet.so instead of static library +BUILD_SHARED_LIBS ?= ON # enable network namespace isolation NETNS ?= OFF # enable shell hooks callbacks SHELL_HOOKS ?= OFF # cross compile? CROSS ?= OFF -# build liblokinet-shared.so -SHARED_LIB ?= OFF # enable generating coverage COVERAGE ?= OFF # allow downloading libsodium if >= 1.0.18 not installed @@ -126,7 +124,7 @@ SCAN_BUILD ?= scan-build UNAME = $(shell which uname) -COMMON_CMAKE_OPTIONS = -DSTATIC_LINK_RUNTIME=$(STATIC_LINK) -DUSE_NETNS=$(NETNS) -DUSE_AVX2=$(AVX2) -DWITH_SHARED=$(SHARED_LIB) -DDOWNLOAD_SODIUM=$(DOWNLOAD_SODIUM) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DXSAN=$(XSAN) -DWITH_HIVE=$(HIVE) -DWITH_TESTS=$(TESTS) +COMMON_CMAKE_OPTIONS = -DSTATIC_LINK=$(STATIC_LINK) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DUSE_NETNS=$(NETNS) -DUSE_AVX2=$(AVX2) -DDOWNLOAD_SODIUM=$(DOWNLOAD_SODIUM) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DXSAN=$(XSAN) -DWITH_HIVE=$(HIVE) -DWITH_TESTS=$(TESTS) ifeq ($(shell $(UNAME)),SunOS) CONFIG_CMD = $(shell gecho -n "cd '$(BUILD_ROOT)' && " ; gecho -n "cmake -G'$(CMAKE_GEN)' -DCMAKE_CROSSCOMPILING=$(CROSS) -DUSE_SHELLHOOKS=$(SHELL_HOOKS) $(COMMON_CMAKE_OPTIONS) '$(REPO)'") @@ -235,7 +233,7 @@ check: debug test: check static-configure: $(LIBUV_PREFIX) $(LIBCURL_PREFIX) - (test x$(TOOLCHAIN) = x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Release -DSTATIC_LINK=ON -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DLIBUV_ROOT='$(LIBUV_PREFIX)' -DLIBCURL_ROOT='$(LIBCURL_PREFIX)' -DNATIVE_BUILD=OFF ) || (test x$(TOOLCHAIN) != x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Release -DSTATIC_LINK=ON -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DLIBUV_ROOT='$(LIBUV_PREFIX)' -DLIBCURL_ROOT='$(LIBCURL_PREFIX)' -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN) -DNATIVE_BUILD=OFF ) + (test x$(TOOLCHAIN) = x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Release -DSTATIC_LINK=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DLIBUV_ROOT='$(LIBUV_PREFIX)' -DLIBCURL_ROOT='$(LIBCURL_PREFIX)' -DNATIVE_BUILD=OFF ) || (test x$(TOOLCHAIN) != x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Release -DSTATIC_LINK=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DLIBUV_ROOT='$(LIBUV_PREFIX)' -DLIBCURL_ROOT='$(LIBCURL_PREFIX)' -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN) -DNATIVE_BUILD=OFF ) static: static-configure $(MAKE) -C '$(BUILD_ROOT)' diff --git a/cmake/add_log_tag.cmake b/cmake/add_log_tag.cmake index c91fc809f..8492b1346 100644 --- a/cmake/add_log_tag.cmake +++ b/cmake/add_log_tag.cmake @@ -1,8 +1,6 @@ function(add_log_tag target) - if(TARGET ${target}) - get_target_property(TARGET_SRCS ${target} SOURCES) - foreach(F ${TARGET_SRCS}) - set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\") - endforeach(F) - endif() + get_target_property(TARGET_SRCS ${target} SOURCES) + foreach(F ${TARGET_SRCS}) + set_property(SOURCE ${F} APPEND PROPERTY COMPILE_DEFINITIONS LOG_TAG=\"${F}\") + endforeach() endfunction() diff --git a/cmake/basic_definitions.cmake b/cmake/basic_definitions.cmake deleted file mode 100644 index b372f76df..000000000 --- a/cmake/basic_definitions.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# Basic definitions -set(LIB lokinet) -set(SHARED_LIB ${LIB}-shared) -set(STATIC_LIB ${LIB}-static) -set(CRYPTOGRAPHY_LIB ${LIB}-cryptography) -set(UTIL_LIB ${LIB}-util) -set(PLATFORM_LIB ${LIB}-platform) -set(ANDROID_LIB ${LIB}android) -set(ABYSS libabyss) -set(ABYSS_LIB abyss) -set(DOCS_SRC "") -get_filename_component(TT_ROOT "${CMAKE_CURRENT_LIST_DIR}/../vendor/libtuntap-master" ABSOLUTE) -add_definitions(-D${CMAKE_SYSTEM_NAME}) - -get_filename_component(CORE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include" ABSOLUTE) -get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" ABSOLUTE) - -set(LIBTUNTAP_SRC - ${TT_ROOT}/tuntap.cpp - ${TT_ROOT}/tuntap_log.cpp) diff --git a/cmake/enable_lto.cmake b/cmake/enable_lto.cmake new file mode 100644 index 000000000..643385150 --- /dev/null +++ b/cmake/enable_lto.cmake @@ -0,0 +1,14 @@ +# -flto +include(CheckIPOSupported) +check_ipo_supported(RESULT IPO_ENABLED OUTPUT ipo_error) +if(IPO_ENABLED) + message(STATUS "LTO enabled") +else() + message(WARNING "LTO not supported by compiler: ${ipo_error}") +endif() + +function(enable_lto) + if(IPO_ENABLED) + set_target_properties(${ARGN} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON) + endif() +endfunction() diff --git a/cmake/static_link.cmake b/cmake/static_link.cmake index 2c87705a9..6dc602c25 100644 --- a/cmake/static_link.cmake +++ b/cmake/static_link.cmake @@ -1,38 +1,7 @@ -if(NOT STATIC_LINK) - return() -endif() - -# not supported on Solaris - system libraries are not available as archives -# LTO is supported only for native builds -if(SOLARIS) - link_libraries( -static-libstdc++ -static-libgcc ) - return() -endif() - -if(NOT CMAKE_CROSSCOMPILING) - add_compile_options(-static -flto) -else() - add_compile_options(-static) -endif() - -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(APPLE) - link_libraries( -flto) +if(STATIC_LINK) + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + link_libraries( -static-libstdc++ ) else() - link_libraries( -static -static-libstdc++ -pthread -flto ) + link_libraries( -static-libstdc++ -static-libgcc ) endif() - - return() -endif() - -if(NOT CMAKE_CROSSCOMPILING) - set(CMAKE_AR "gcc-ar") - set(CMAKE_C_ARCHIVE_CREATE " qcs ") - set(CMAKE_C_ARCHIVE_FINISH "true") - set(CMAKE_CXX_ARCHIVE_CREATE " qcs ") - set(CMAKE_CXX_ARCHIVE_FINISH "true") - link_libraries( -flto -static-libstdc++ -static-libgcc -static ${CMAKE_CXX_FLAGS} ${CRYPTO_FLAGS} ) -else() - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static" ) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") endif() diff --git a/cmake/unix.cmake b/cmake/unix.cmake index 9f416eaad..f0553f7c5 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -5,6 +5,7 @@ endif() include(CheckCXXSourceCompiles) include(CheckLibraryExists) +add_library(curl INTERFACE) option(DOWNLOAD_CURL "download and statically compile in CURL" OFF) # Allow -DDOWNLOAD_CURL=FORCE to download without even checking for a local libcurl @@ -14,17 +15,22 @@ endif() if(CURL_FOUND) message(STATUS "using system curl") + if(TARGET CURL::libcurl) # cmake 3.12+ + target_link_libraries(curl INTERFACE CURL::libcurl) + else() + target_link_libraries(curl INTERFACE ${CURL_LIBRARIES}) + target_include_directories(curl INTERFACE ${CURL_INCLUDE_DIRS}) + endif() elseif(DOWNLOAD_CURL) message(STATUS "libcurl not found, but DOWNLOAD_CURL specified, so downloading it") include(DownloadLibCurl) - set(CURL_LIBRARIES curl_vendor) + target_link_libraries(curl INTERFACE curl_vendor) else() message(FATAL_ERROR "Could not find libcurl; either install it on your system or use -DDOWNLOAD_CURL=ON to download and build an internal copy") endif() add_definitions(-DUNIX) add_definitions(-DPOSIX) -list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix.c) if (STATIC_LINK_RUNTIME OR STATIC_LINK) set(LIBUV_USE_STATIC ON) @@ -54,32 +60,12 @@ if(EMBEDDED_CFG OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux") link_libatomic() endif() -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-linux.c) -elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") - list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-linux.c) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") +if (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") add_definitions(-D_BSD_SOURCE) add_definitions(-D_GNU_SOURCE) add_definitions(-D_XOPEN_SOURCE=700) - list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") - list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") - list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c) -elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "iOS") - list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c) elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") - list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-sunos.c) if (LIBUV_USE_STATIC) link_libraries(-lkstat -lsendfile) endif() -else() - message(FATAL_ERROR "Your operating system - ${CMAKE_SYSTEM_NAME} is not supported yet") -endif() - -set(EXE_LIBS ${STATIC_LIB}) - -if(RELEASE_MOTTO) - add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}") endif() diff --git a/cmake/win32.cmake b/cmake/win32.cmake index 1b1b2b9ec..df1f2819a 100644 --- a/cmake/win32.cmake +++ b/cmake/win32.cmake @@ -15,35 +15,20 @@ if(NOT MSVC_VERSION) add_compile_options(-fno-ident -Wa,-mbig-obj) link_libraries( -lws2_32 -lshlwapi -ldbghelp -luser32 -liphlpapi -lpsapi -luserenv ) add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500) - if (CMAKE_C_COMPILER_AR AND STATIC_LINK_RUNTIME) - set(CMAKE_AR ${CMAKE_C_COMPILER_AR}) - set(CMAKE_C_ARCHIVE_CREATE " qcs ") - set(CMAKE_C_ARCHIVE_FINISH "true") - set(CMAKE_CXX_ARCHIVE_CREATE " qcs ") - set(CMAKE_CXX_ARCHIVE_FINISH "true") - link_libraries( -static-libstdc++ -static-libgcc -static ${CMAKE_CXX_FLAGS} ${CRYPTO_FLAGS} ) - endif() endif() if(EMBEDDED_CFG) link_libatomic() endif() -list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-windows.c) -get_filename_component(EV_SRC "llarp/ev/ev_libuv.cpp" ABSOLUTE) add_definitions(-DWIN32_LEAN_AND_MEAN -DWIN32) -set(EXE_LIBS ${STATIC_LIB} ws2_32 iphlpapi) -if(RELEASE_MOTTO) - add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}") -endif() - -if (NOT STATIC_LINK_RUNTIME AND NOT MSVC) +if (NOT STATIC_LINK AND NOT MSVC) message("must ship compiler runtime libraries with this build: libwinpthread-1.dll, libgcc_s_dw2-1.dll, and libstdc++-6.dll") - message("for release builds, turn on STATIC_LINK_RUNTIME in cmake options") + message("for release builds, turn on STATIC_LINK in cmake options") endif() -if (STATIC_LINK_RUNTIME) +if (STATIC_LINK) set(LIBUV_USE_STATIC ON) endif() diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 651ed865e..935543386 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -1,23 +1,6 @@ -set(NTRU_AVX_SRC - libntrup/src/avx/randomsmall.c - libntrup/src/avx/weight.c - libntrup/src/avx/swap.c - libntrup/src/avx/rq_round3.c - libntrup/src/avx/rq_recip3.c - libntrup/src/avx/small.c - libntrup/src/avx/randomweightw.c - libntrup/src/avx/dec.c - libntrup/src/avx/r3_recip.c - libntrup/src/avx/keypair.c - libntrup/src/avx/rq_rounded.c - libntrup/src/avx/mult.c - libntrup/src/avx/enc.c - libntrup/src/avx/int32_sort.c - libntrup/src/avx/rq.c - libntrup/src/avx/rq_mod3.c -) -set(NTRU_REF_SRC +add_library(lokinet-cryptography + libntrup/src/ntru.cpp libntrup/src/ref/randomsmall.c libntrup/src/ref/swap.c libntrup/src/ref/rq_round3.c @@ -36,33 +19,56 @@ set(NTRU_REF_SRC libntrup/src/ref/rq.c ) -set(NTRU_SRC - ${NTRU_REF_SRC} - libntrup/src/ntru.cpp - ) - -set(CRYPTOGRAPHY_SRC ${NTRU_SRC}) - -add_library(${CRYPTOGRAPHY_LIB} STATIC ${CRYPTOGRAPHY_SRC}) -add_log_tag(${CRYPTOGRAPHY_LIB}) +target_include_directories(lokinet-cryptography PUBLIC libntrup/include) # The avx implementation uses runtime CPU feature detection to enable itself, so we *always* want to -# compile it with avx2 support even if we aren't compiling with AVX2 enabled. -add_library(cryptography_avx_lib STATIC ${NTRU_AVX_SRC}) -if(USE_AVX2) +# compile it with avx2/fma support when supported by the compiler even if we aren't compiling with +# general AVX2 enabled. +set(NTRU_AVX_SRC + libntrup/src/avx/randomsmall.c + libntrup/src/avx/weight.c + libntrup/src/avx/swap.c + libntrup/src/avx/rq_round3.c + libntrup/src/avx/rq_recip3.c + libntrup/src/avx/small.c + libntrup/src/avx/randomweightw.c + libntrup/src/avx/dec.c + libntrup/src/avx/r3_recip.c + libntrup/src/avx/keypair.c + libntrup/src/avx/rq_rounded.c + libntrup/src/avx/mult.c + libntrup/src/avx/enc.c + libntrup/src/avx/int32_sort.c + libntrup/src/avx/rq.c + libntrup/src/avx/rq_mod3.c +) +if(NOT NATIVE_BUILD AND USE_AVX2) # Assume cxxflags are already enabling AVX2 + target_sources(lokinet-cryptography PRIVATE ${NTRU_AVX_SRC}) else() include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_AVX2) check_cxx_compiler_flag(-mfma COMPILER_SUPPORTS_FMA) if(COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA) - target_compile_options(cryptography_avx_lib PRIVATE -mavx2 -mfma) + target_sources(lokinet-cryptography PRIVATE ${NTRU_AVX_SRC}) + set_property(SOURCE ${NTRU_AVX_SRC} APPEND PROPERTY COMPILE_FLAGS "-mavx2 -mfma") message(STATUS "Building libntrup with runtime AVX2/FMA support") else() message(STATUS "Not building with libntrup runtime AVX2/FMA support (can't figure out how to compile with AVX2/FMA: -mavx2 -mfma didn't work)") endif() endif() -target_link_libraries(${CRYPTOGRAPHY_LIB} PRIVATE cryptography_avx_lib) + +enable_lto(lokinet-cryptography) +add_log_tag(lokinet-cryptography) + +if(BUILD_SHARED_LIBS) + install(TARGETS lokinet-cryptography LIBRARY DESTINATION lib) +endif() + +if (WARNINGS_AS_ERRORS) + target_compile_options(lokinet-cryptography PUBLIC -Wall -Wextra -Werror) +endif() + option(DOWNLOAD_SODIUM "Allow libsodium to be downloaded and built locally if not found on the system" OFF) @@ -72,19 +78,12 @@ if(NOT DOWNLOAD_SODIUM STREQUAL "FORCE") endif() if(sodium_FOUND) - target_include_directories(${CRYPTOGRAPHY_LIB} PUBLIC ${sodium_INCLUDE_DIR}) - target_include_directories(cryptography_avx_lib PUBLIC ${sodium_INCLUDE_DIR}) - target_link_libraries(${CRYPTOGRAPHY_LIB} PUBLIC ${sodium_LIBRARY_RELEASE}) + target_link_libraries(lokinet-cryptography PUBLIC sodium) elseif(DOWNLOAD_SODIUM) message(STATUS "Sodium >= 1.0.18 not found, but DOWNLOAD_SODIUM specified, so downloading it") include(DownloadLibSodium) - target_link_libraries(${CRYPTOGRAPHY_LIB} PUBLIC sodium_vendor) - target_link_libraries(cryptography_avx_lib PUBLIC sodium_vendor) + target_link_libraries(lokinet-cryptography PUBLIC sodium_vendor) else() message(FATAL_ERROR "Could not find libsodium >= 1.0.18; either install it on your system or use -DDOWNLOAD_SODIUM=ON to download and build an internal copy") endif() -target_include_directories(${CRYPTOGRAPHY_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libntrup/include") -target_include_directories(cryptography_avx_lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libntrup/include") - - diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 337918e5f..88a638215 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -1,52 +1,43 @@ -set(EXE lokinet) -set(EXE_SRC main.cpp) -set(CTL lokinetctl) -set(CTL_SRC lokinetctl.cpp) - -if(TRACY_ROOT) - list(APPEND EXE_SRC ${TRACY_ROOT}/TracyClient.cpp) -endif() if(SHADOW) - set(LOKINET_SHADOW shadow-plugin-${SHARED_LIB}) - set(LOKINET_SHADOW_LIBS ${SHARED_LIB}) - add_shadow_plugin(${LOKINET_SHADOW} ${EXE_SRC}) - target_link_libraries(${LOKINET_SHADOW} ${LOKINET_SHADOW_LIBS}) - target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include) + add_shadow_plugin(shadow-plugin main.cpp ${TRACY_ROOT}/TracyClient.cpp) + target_link_libraries(shadow-plugin liblokinet) + enable_lto(shadow-plugin) else() - if(WIN32 AND NOT MSVC_VERSION) - list(APPEND EXE_SRC ../llarp/win32/version.rc) - list(APPEND CTL_SRC ../llarp/win32/version.rc) - endif() - - add_executable(${EXE} ${EXE_SRC}) - add_executable(${CTL} ${CTL_SRC}) + add_executable(lokinet main.cpp) + add_executable(lokinetctl lokinetctl.cpp) + enable_lto(lokinet lokinetctl) - target_compile_definitions(${EXE} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) - target_compile_definitions(${CTL} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) - - add_log_tag(${EXE}) - add_log_tag(${CTL}) + if(TRACY_ROOT) + target_sources(lokinet PRIVATE ${TRACY_ROOT}/TracyClient.cpp) + endif() - install(TARGETS ${EXE} RUNTIME DESTINATION bin COMPONENT lokinet) + foreach(exe lokinet lokinetctl) + if(WIN32 AND NOT MSVC_VERSION) + target_sources(${exe} PRIVATE ../llarp/win32/version.rc) + target_link_libraries(${exe} PRIVATE ws2_32 iphlpapi) + elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + target_link_directories(${exe} PRIVATE /usr/local/lib) + endif() + target_link_libraries(${exe} PRIVATE liblokinet) + target_compile_definitions(${exe} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) + add_log_tag(${exe}) + endforeach() + + install(TARGETS lokinet RUNTIME DESTINATION bin COMPONENT lokinet) if(WIN32) install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.ps1 DESTINATION bin COMPONENT lokinet) else() install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin COMPONENT lokinet) endif() - if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + if(CMAKE_SYSTEM_NAME MATCHES "Linux") install(CODE "execute_process(COMMAND setcap cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)") - elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - target_link_directories(${EXE} PRIVATE /usr/local/lib) - target_link_directories(${CTL} PRIVATE /usr/local/lib) endif() - target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS} ${CRYPTOGRAPHY_LIB}) - target_link_libraries(${CTL} PUBLIC ${EXE_LIBS} ${LIBS} ${CRYPTOGRAPHY_LIB}) if(CURL_FOUND) - target_include_directories(${CTL} PRIVATE ${CURL_INCLUDE_DIRS}) - target_link_libraries(${CTL} PRIVATE ${CURL_LIBRARIES}) + target_include_directories(lokinetctl PRIVATE ${CURL_INCLUDE_DIRS}) + target_link_libraries(lokinetctl PRIVATE ${CURL_LIBRARIES}) endif(CURL_FOUND) -endif(SHADOW) +endif() diff --git a/jni/CMakeLists.txt b/jni/CMakeLists.txt index d265d4c87..0a4a2825c 100644 --- a/jni/CMakeLists.txt +++ b/jni/CMakeLists.txt @@ -1,10 +1,6 @@ - - set(ANDROID_SRC - lokinet_config.cpp - lokinet_daemon.cpp - lokinet_vpn.cpp - ) - add_library(${ANDROID_LIB} SHARED ${ANDROID_SRC}) - set_property(TARGET ${ANDROID_LIB} PROPERTY CXX_STANDARD 14) - add_log_tag(${ANDROID_LIB}) - target_link_libraries(${ANDROID_LIB} ${STATIC_LIB} ${LIBS}) \ No newline at end of file +add_library(lokinet-android + lokinet_config.cpp + lokinet_daemon.cpp + lokinet_vpn.cpp) +add_log_tag(lokinet-android) +target_link_libraries(lokinet-android liblokinet) diff --git a/libabyss/CMakeLists.txt b/libabyss/CMakeLists.txt index 5485f9df1..dfe7c227d 100644 --- a/libabyss/CMakeLists.txt +++ b/libabyss/CMakeLists.txt @@ -1,14 +1,20 @@ -add_library(${ABYSS_LIB} "${CMAKE_CURRENT_SOURCE_DIR}/src/md5.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/src/http.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/src/client.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp") +add_library(abyss + src/md5.cpp + src/http.cpp + src/client.cpp + src/server.cpp) -target_include_directories(${ABYSS_LIB} PUBLIC include) -target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB}) +target_include_directories(abyss PUBLIC include) +target_link_libraries(abyss PUBLIC lokinet-platform) +enable_lto(abyss) # for freebsd -if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include) -endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") +if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + target_include_directories(abyss SYSTEM PUBLIC /usr/local/include) +endif() -add_log_tag(${ABYSS_LIB}) +if(BUILD_SHARED_LIBS) + install(TARGETS abyss LIBRARY DESTINATION lib) +endif() + +add_log_tag(abyss) diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 8f7175f06..b84e5942f 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -1,6 +1,6 @@ include(Version) -set(LIB_UTIL_SRC +add_library(lokinet-util config/config.cpp config/definition.cpp config/ini.cpp @@ -31,28 +31,27 @@ set(LIB_UTIL_SRC util/thread/threadpool.cpp util/time.cpp ) +add_dependencies(lokinet-util genversion) -add_library(${UTIL_LIB} STATIC ${LIB_UTIL_SRC} ${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp) +target_include_directories(lokinet-util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include) -add_dependencies(${UTIL_LIB} genversion) +target_link_libraries(lokinet-util PUBLIC + lokinet-cryptography + curl + nlohmann_json::nlohmann_json + filesystem + date::date +) +if(TARGET libcurl_external) + add_dependencies(lokinet-util libcurl_external) +endif() -target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${CURL_INCLUDE_DIRS}) if(ANDROID) - set(LOG_LIB log) + target_link_libraries(lokinet-util PUBLIC log) endif() -target_link_libraries(${UTIL_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${LOG_LIB} ${CURL_LIBRARIES}) -target_link_libraries(${UTIL_LIB} PUBLIC - nlohmann_json::nlohmann_json - filesystem - date::date - ) - -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - set(ISOLATE_PROC_SRC linux/netns.cpp) -endif() -set(LIB_PLATFORM_SRC +add_library(lokinet-platform # for networking ev/ev.cpp ev/pipe.cpp @@ -61,52 +60,49 @@ set(LIB_PLATFORM_SRC net/ip.cpp net/net.cpp net/net_int.cpp -# for android shim - ${ANDROID_PLATFORM_SRC} -# process isolation implementation - ${ISOLATE_PROC_SRC} -# tun - ${LIBTUNTAP_SRC} - ${EV_SRC} + $ ) -if (WIN32) - set(LIB_PLATFORM_SRC - ev/ev_win32.cpp - ${LIB_PLATFORM_SRC} - win32/win32_inet.c - win32/win32_intrnl.c) -endif(WIN32) +target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography lokinet-util Threads::Threads ${LIBS}) + + +if (ANDROID) + target_sources(lokinet-platform PRIVATE android/ifaddrs.c) +endif() -add_library(${PLATFORM_LIB} STATIC ${LIB_PLATFORM_SRC}) -target_link_libraries(${PLATFORM_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${UTIL_LIB} Threads::Threads ${LIBS}) +if(CMAKE_SYSTEM_NAME MATCHES "Linux") + target_sources(lokinet-platform PRIVATE linux/netns.cpp) -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") if(NON_PC_TARGET) add_import_library(rt) - target_link_libraries(${PLATFORM_LIB} PUBLIC rt) + target_link_libraries(lokinet-platform PUBLIC rt) endif() endif() -if(WIN32) - target_link_libraries(${PLATFORM_LIB} PUBLIC iphlpapi) +if (WIN32) + target_sources(lokinet-platform PRIVATE + ev/ev_libuv.cpp + ev/ev_win32.cpp + win32/win32_inet.c + win32/win32_intrnl.c) + + target_link_libraries(lokinet-platform PUBLIC iphlpapi) +endif() + +if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + target_include_directories(lokinet-platform SYSTEM PUBLIC /usr/local/include) endif() -set(DNSLIB_SRC + +add_library(liblokinet dns/message.cpp dns/name.cpp dns/question.cpp dns/rr.cpp dns/serialize.cpp dns/server.cpp -) -set(CONSENSUS_SRC consensus/table.cpp -) -set(LIB_SRC - ${CONSENSUS_SRC} - ${DNSLIB_SRC} bootstrap.cpp context.cpp crypto/crypto_libsodium.cpp @@ -197,50 +193,35 @@ set(LIB_SRC service/tag_lookup_job.cpp service/tag.cpp ) + +set_target_properties(liblokinet PROPERTIES OUTPUT_NAME lokinet) + +enable_lto(lokinet-util lokinet-platform liblokinet) if(TRACY_ROOT) - set(LIB_SRC ${LIB_SRC} ${TRACY_ROOT}/TracyClient.cpp) + target_sources(liblokinet PRIVATE ${TRACY_ROOT}/TracyClient.cpp) endif() if(TESTNET) - set(LIB_SRC ${LIB_SRC} testnet.c) + target_sources(liblokinet PRIVATE testnet.c) endif() if(WITH_HIVE) - set(LIB_SRC ${LIB_SRC} tooling/router_hive.cpp) + target_sources(liblokinet PRIVATE tooling/router_hive.cpp) endif() -add_library(${STATIC_LIB} STATIC ${LIB_SRC}) - -target_include_directories(${STATIC_LIB} PUBLIC ${CURL_INCLUDE_DIRS}) -target_link_libraries(${STATIC_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB}) +target_link_libraries(liblokinet PUBLIC cxxopts abyss lokinet-platform lokinet-util lokinet-cryptography) -if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - target_include_directories(${PLATFORM_LIB} SYSTEM PUBLIC /usr/local/include) - target_include_directories(${STATIC_LIB} SYSTEM PUBLIC /usr/local/include) -endif() - -if(WITH_SHARED) - add_library(${SHARED_LIB} SHARED ${LIB_SRC}) - set(LIBS ${LIBS} Threads::Threads) - target_link_libraries(${SHARED_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${CRYPTOGRAPHY_LIB} ${UTIL_LIB} ${PLATFORM_LIB} ${LIBS}) - if (WIN32) - target_link_libraries(${SHARED_LIB} PUBLIC ws2_32 iphlpapi) - else() - install(TARGETS ${SHARED_LIB} LIBRARY DESTINATION lib) +if(BUILD_SHARED_LIBS) + install(TARGETS lokinet-util lokinet-platform liblokinet LIBRARY DESTINATION lib) + if(WIN32) + target_link_libraries(liblokinet PUBLIC ws2_32 iphlpapi) endif() - add_log_tag(${SHARED_LIB}) endif() -if (WARNINGS_AS_ERRORS) - set(WARN_FLAGS -Wall -Wextra -Werror) - target_compile_options(${UTIL_LIB} PUBLIC ${WARN_FLAGS}) - target_compile_options(${PLATFORM_LIB} PUBLIC ${WARN_FLAGS}) - target_compile_options(${STATIC_LIB} PUBLIC ${WARN_FLAGS}) -endif() -add_log_tag(${UTIL_LIB}) -add_log_tag(${PLATFORM_LIB}) -add_log_tag(${STATIC_LIB}) +foreach(lokinet_lib liblokinet lokinet-platform lokinet-util lokinet-cryptography) + add_log_tag(${lokinet_lib}) +endforeach() file(GLOB_RECURSE docs_SRC */*.hpp *.hpp) diff --git a/pybind/CMakeLists.txt b/pybind/CMakeLists.txt index 481f49a51..e9e514e6a 100644 --- a/pybind/CMakeLists.txt +++ b/pybind/CMakeLists.txt @@ -1,4 +1,4 @@ -set(LLARP_PYBIND_SRC +pybind11_add_module(pyllarp MODULE module.cpp llarp/context.cpp llarp/router_id.cpp @@ -13,8 +13,6 @@ set(LLARP_PYBIND_SRC llarp/tooling/router_event.cpp llarp/service/address.cpp ) - -pybind11_add_module(pyllarp MODULE ${LLARP_PYBIND_SRC}) -target_include_directories(pyllarp PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/crypto/libntrup/include ${CMAKE_SOURCE_DIR}/llarp ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(pyllarp PUBLIC ${EXE_LIBS}) +target_link_libraries(pyllarp PUBLIC liblokinet) +target_include_directories(pyllarp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3b27a818a..bae1d3b42 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,5 @@ if (WITH_HIVE) - add_custom_target(hive_build DEPENDS ${STATIC_LIB} pyllarp) + add_custom_target(hive_build DEPENDS liblokinet pyllarp) add_custom_target(hive ${CMAKE_COMMAND} -E env PYTHONPATH="$ENV{PYTHONPATH}:${CMAKE_BINARY_DIR}/pybind" ${PYTHON_EXECUTABLE} -m pytest @@ -8,11 +8,14 @@ if (WITH_HIVE) hive_build) endif() -set(GTEST_EXE testAll) -set(CATCH_EXE catchAll) - # Old gtest-based tests; new tests should use Catch2, instead. -list(APPEND GTEST_SRC +add_executable(testAll + # helpers + main.cpp + crypto/mock_crypto.cpp + dht/mock_context.cpp + test_util.cpp + # actual test cases config/test_llarp_config_ini.cpp crypto/test_llarp_crypto_types.cpp crypto/test_llarp_crypto.cpp @@ -49,31 +52,21 @@ list(APPEND GTEST_SRC util/thread/test_llarp_util_thread_pool.cpp ) -add_executable(${GTEST_EXE} - # helpers - main.cpp - crypto/mock_crypto.cpp - dht/mock_context.cpp - test_util.cpp - # actual test cases - ${GTEST_SRC} -) - -target_link_libraries(${GTEST_EXE} PUBLIC gmock gtest ${STATIC_LIB}) -target_include_directories(${GTEST_EXE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(testAll PUBLIC gmock gtest liblokinet) +target_include_directories(testAll PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) if(WIN32) - target_sources(${GTEST_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/win32/test.rc") - target_link_libraries(${GTEST_EXE} PUBLIC ws2_32 iphlpapi shlwapi) + target_sources(testAll PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/win32/test.rc") + target_link_libraries(testAll PUBLIC ws2_32 iphlpapi shlwapi) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - target_link_directories(${GTEST_EXE} PRIVATE /usr/local/lib) + target_link_directories(testAll PRIVATE /usr/local/lib) endif() add_subdirectory(Catch2) -add_executable(${CATCH_EXE} +add_executable(catchAll nodedb/test_nodedb.cpp path/test_path.cpp util/test_llarp_util_bits.cpp @@ -86,12 +79,12 @@ add_executable(${CATCH_EXE} net/test_sock_addr.cpp check_main.cpp) -target_link_libraries(${CATCH_EXE} PUBLIC ${STATIC_LIB} Catch2::Catch2) -target_include_directories(${CATCH_EXE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(catchAll PUBLIC liblokinet Catch2::Catch2) +target_include_directories(catchAll PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) # Custom targets to invoke the different test suites: -add_custom_target(catch COMMAND ${CATCH_EXE}) -add_custom_target(rungtest COMMAND ${GTEST_EXE}) +add_custom_target(catch COMMAND catchAll) +add_custom_target(rungtest COMMAND testAll) # Add a custom "check" target that runs all the test suites: add_custom_target(check DEPENDS rungtest catch) diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt new file mode 100644 index 000000000..fc2ada3ba --- /dev/null +++ b/vendor/CMakeLists.txt @@ -0,0 +1,28 @@ +add_library(tuntap OBJECT + libtuntap-master/tuntap.cpp + libtuntap-master/tuntap_log.cpp) + +get_target_property(nlohmann_inc nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) +target_include_directories(tuntap PRIVATE ../llarp ../include ${nlohmann_inc}) + +if(WIN32) + target_sources(tuntap PRIVATE libtuntap-master/tuntap-windows.c) +else() + target_sources(tuntap PRIVATE libtuntap-master/tuntap-unix.c) + + if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android") + target_sources(tuntap PRIVATE libtuntap-master/tuntap-unix-linux.c) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") + target_sources(tuntap PRIVATE libtuntap-master/tuntap-unix-openbsd.c libtuntap-master/tuntap-unix-bsd.c) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") + target_sources(tuntap PRIVATE libtuntap-master/tuntap-unix-netbsd.c libtuntap-master/tuntap-unix-bsd.c) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|DragonFly") + target_sources(tuntap PRIVATE libtuntap-master/tuntap-unix-freebsd.c libtuntap-master/tuntap-unix-bsd.c) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS") + target_sources(tuntap PRIVATE libtuntap-master/tuntap-unix-darwin.c libtuntap-master/tuntap-unix-bsd.c) + elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + target_sources(tuntap PRIVATE libtuntap-master/tuntap-unix-sunos.c) + else() + message(FATAL_ERROR "Your operating system - ${CMAKE_SYSTEM_NAME} is not supported yet for libtuntap") + endif() +endif()