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).
pull/1273/head
Jason Rhinelander 4 years ago
parent ab4ee954b9
commit c5faa86926

@ -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_MAJOR=${lokinet_VERSION_MAJOR})
add_definitions(-DLLARP_VERSION_MINOR=${lokinet_VERSION_MINOR}) add_definitions(-DLLARP_VERSION_MINOR=${lokinet_VERSION_MINOR})
add_definitions(-DLLARP_VERSION_PATCH=${lokinet_VERSION_PATCH}) add_definitions(-DLLARP_VERSION_PATCH=${lokinet_VERSION_PATCH})
if(RELEASE_MOTTO)
add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}")
endif()
# Core options # Core options
@ -25,16 +28,12 @@ option(USE_AVX2 "enable avx2 code" OFF)
option(USE_NETNS "enable networking namespace support. Linux only" OFF) option(USE_NETNS "enable networking namespace support. Linux only" OFF)
option(NATIVE_BUILD "optimise for host system and FPU" ON) option(NATIVE_BUILD "optimise for host system and FPU" ON)
option(EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF) option(EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF)
if (WIN32) option(STATIC_LINK "link statically against dependencies" OFF)
option(STATIC_LINK_RUNTIME "link statically against compiler runtime, standard library and pthreads" OFF) option(BUILD_SHARED_LIBS "build lokinet libraries as shared libraries instead of static" ON)
else()
option(STATIC_LINK "link statically against dependencies" OFF)
endif()
option(SHADOW "use shadow testing framework. linux only" OFF) 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(JEMALLOC "use jemalloc. Not required on BSD" OFF)
option(TESTNET "testnet build" OFF) option(TESTNET "testnet build" OFF)
option(WITH_SHARED "build shared library" OFF)
option(WITH_COVERAGE "generate coverage data" OFF) option(WITH_COVERAGE "generate coverage data" OFF)
option(USE_SHELLHOOKS "enable shell hooks on compile time (dangerous)" 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) 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) set(TRAVIS_CI_SUCKS ON)
endif() endif()
if(WITH_HIVE) if(NOT CMAKE_BUILD_TYPE)
set(WITH_SHARED ON) set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif() endif()
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
include(CheckLibraryExists) include(CheckLibraryExists)
include(cmake/enable_lto.cmake)
include(cmake/target_link_libraries_system.cmake) include(cmake/target_link_libraries_system.cmake)
include(cmake/add_import_library.cmake) include(cmake/add_import_library.cmake)
include(cmake/add_log_tag.cmake) include(cmake/add_log_tag.cmake)
include(cmake/libatomic.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) if (STATIC_LINK)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX}) set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
message(STATUS "setting static library suffix search") message(STATUS "setting static library suffix search")
endif() endif()
include(cmake/basic_definitions.cmake) add_definitions(-D${CMAKE_SYSTEM_NAME})
if(MSVC_VERSION) if(MSVC_VERSION)
enable_language(ASM_MASM) enable_language(ASM_MASM)
@ -76,7 +72,7 @@ if(MSVC_VERSION)
add_definitions(-D_WIN32_WINNT=0x0600 -DNOMINMAX -DSODIUM_STATIC) add_definitions(-D_WIN32_WINNT=0x0600 -DNOMINMAX -DSODIUM_STATIC)
else() else()
enable_language(ASM) enable_language(ASM)
endif(MSVC_VERSION) endif()
include(cmake/solaris.cmake) include(cmake/solaris.cmake)
include(cmake/win32.cmake) include(cmake/win32.cmake)
@ -95,6 +91,9 @@ set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_EXTENSIONS OFF)
# Always build PIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(cmake/unix.cmake) include(cmake/unix.cmake)
include(cmake/check_for_std_optional.cmake) include(cmake/check_for_std_optional.cmake)
include(cmake/check_for_std_filesystem.cmake) include(cmake/check_for_std_filesystem.cmake)
@ -116,35 +115,25 @@ endif()
# this is messing with release builds # this is messing with release builds
add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0) 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" ) 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() endif()
if(XSAN) if(XSAN)
set(DEBUG_FLAGS ${DEBUG_FLAGS} "-fsanitize=${XSAN}" -fno-omit-frame-pointer) string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fsanitize=${XSAN} -fno-omit-frame-pointer")
set(OPTIMIZE_FLAGS "-O0") 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") message(STATUS "Doing a ${XSAN} sanitizer build")
endif(XSAN) endif()
if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
set(OPTIMIZE_FLAGS "")
add_definitions(-DLOKINET_DEBUG=1) add_definitions(-DLOKINET_DEBUG=1)
set(CRYPTO_FLAGS "") endif()
add_compile_options( ${DEBUG_FLAGS} )
link_libraries( ${DEBUG_FLAGS} )
endif(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
if(WITH_SHELLHOOKS) if(WITH_SHELLHOOKS)
add_definitions(-DENABLE_SHELLHOOKS) add_definitions(-DENABLE_SHELLHOOKS)
endif(WITH_SHELLHOOKS) endif()
# Always build PIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(TRACY_ROOT) if(TRACY_ROOT)
include_directories(${TRACY_ROOT}) include_directories(${TRACY_ROOT})
@ -174,52 +163,48 @@ include(cmake/coverage.cmake)
# these vars are set by the cmake toolchain spec # these vars are set by the cmake toolchain spec
if (WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE) if (WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE)
include(cmake/cross_compile.cmake) include(cmake/cross_compile.cmake)
endif(WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE) endif()
if(NATIVE_BUILD) if(NATIVE_BUILD)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le) if(CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le)
set(CRYPTO_FLAGS -mcpu=native -mtune=native) add_compile_options(-mcpu=native -mtune=native)
else() else()
set(CRYPTO_FLAGS -march=native -mtune=native) add_compile_options(-march=native -mtune=native)
endif() endif()
elseif(NOT NON_PC_TARGET) elseif(NOT NON_PC_TARGET)
if (USE_AVX2) if (USE_AVX2)
set(CRYPTO_FLAGS -march=haswell -mtune=haswell -mfpmath=sse) add_compile_options(-march=haswell -mtune=haswell -mfpmath=sse)
else() else()
# Public binary releases # Public binary releases
set(CRYPTO_FLAGS -march=nocona -mtune=haswell -mfpmath=sse) add_compile_options(-march=nocona -mtune=haswell -mfpmath=sse)
endif() endif()
endif() endif()
if(EMBEDDED_CFG) 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 "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!") 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() endif()
add_compile_options(${OPTIMIZE_FLAGS} ${CRYPTO_FLAGS})
set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
include(cmake/static_link.cmake)
if(USE_NETNS) if(USE_NETNS)
add_definitions(-DNETNS=1) add_definitions(-DNETNS=1)
else() else()
add_definitions(-DNETNS=0) add_definitions(-DNETNS=0)
endif(USE_NETNS) endif()
if(TESTNET) if(TESTNET)
add_definitions(-DTESTNET=1) add_definitions(-DTESTNET=1)
# 5 times slower than realtime # 5 times slower than realtime
add_definitions(-DTESTNET_SPEED=5) add_definitions(-DTESTNET_SPEED=5)
endif(TESTNET) endif()
if(SHADOW) if(SHADOW)
include(cmake/shadow.cmake) include(cmake/shadow.cmake)
endif(SHADOW) endif()
unset(GIT_VERSION) unset(GIT_VERSION)
unset(GIT_VERSION_REAL) unset(GIT_VERSION_REAL)
@ -227,7 +212,7 @@ unset(GIT_VERSION_REAL)
if(NOT GIT_VERSION) if(NOT GIT_VERSION)
exec_program("git" ${CMAKE_CURRENT_SOURCE_DIR} ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_VERSION_UNSTRIP) exec_program("git" ${CMAKE_CURRENT_SOURCE_DIR} ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_VERSION_UNSTRIP)
string(STRIP "${GIT_VERSION_UNSTRIP}" GIT_VERSION) string(STRIP "${GIT_VERSION_UNSTRIP}" GIT_VERSION)
endif(NOT GIT_VERSION) endif()
string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}") 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 # long ago
if(JEMALLOC) if(JEMALLOC)
set(MALLOC_LIB jemalloc) set(MALLOC_LIB jemalloc)
endif(JEMALLOC) endif()
find_package(PkgConfig QUIET) 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/cxxopts EXCLUDE_FROM_ALL)
add_subdirectory(external/date EXCLUDE_FROM_ALL) add_subdirectory(external/date EXCLUDE_FROM_ALL)
add_subdirectory(vendor)
if(ANDROID) if(ANDROID)
list(APPEND LIBS log) list(APPEND LIBS log)
add_definitions(-DANDROID) add_definitions(-DANDROID)
set(ANDROID_PLATFORM_SRC android/ifaddrs.c) set(ANDROID_PLATFORM_SRC android/ifaddrs.c)
endif(ANDROID) endif()
set(LIBS ${MALLOC_LIB} ${LIBUV_LIBRARY} ${SD_LIBS}) set(LIBS ${MALLOC_LIB} ${LIBUV_LIBRARY} ${SD_LIBS})
if(TRACY_ROOT) if(TRACY_ROOT)
@ -333,7 +320,7 @@ if (NOT SHADOW)
endif() endif()
if(ANDROID) if(ANDROID)
add_subdirectory(jni) add_subdirectory(jni)
endif(ANDROID) endif()
endif() endif()
add_subdirectory(docs) add_subdirectory(docs)

@ -83,18 +83,16 @@ TOOLCHAIN ?=
WINDOWS_ARCH ?= 64 WINDOWS_ARCH ?= 64
# native avx2 code # native avx2 code
AVX2 ?= OFF AVX2 ?= OFF
# statically link everything
STATIC_LINK ?= OFF
# statically link dependencies # 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 # enable network namespace isolation
NETNS ?= OFF NETNS ?= OFF
# enable shell hooks callbacks # enable shell hooks callbacks
SHELL_HOOKS ?= OFF SHELL_HOOKS ?= OFF
# cross compile? # cross compile?
CROSS ?= OFF CROSS ?= OFF
# build liblokinet-shared.so
SHARED_LIB ?= OFF
# enable generating coverage # enable generating coverage
COVERAGE ?= OFF COVERAGE ?= OFF
# allow downloading libsodium if >= 1.0.18 not installed # allow downloading libsodium if >= 1.0.18 not installed
@ -126,7 +124,7 @@ SCAN_BUILD ?= scan-build
UNAME = $(shell which uname) 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) 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)'") 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 test: check
static-configure: $(LIBUV_PREFIX) $(LIBCURL_PREFIX) 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 static: static-configure
$(MAKE) -C '$(BUILD_ROOT)' $(MAKE) -C '$(BUILD_ROOT)'

@ -1,8 +1,6 @@
function(add_log_tag target) function(add_log_tag target)
if(TARGET ${target}) get_target_property(TARGET_SRCS ${target} SOURCES)
get_target_property(TARGET_SRCS ${target} SOURCES) foreach(F ${TARGET_SRCS})
foreach(F ${TARGET_SRCS}) set_property(SOURCE ${F} APPEND PROPERTY COMPILE_DEFINITIONS LOG_TAG=\"${F}\")
set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\") endforeach()
endforeach(F)
endif()
endfunction() endfunction()

@ -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)

@ -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()

@ -1,38 +1,7 @@
if(NOT STATIC_LINK) if(STATIC_LINK)
return() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
endif() link_libraries( -static-libstdc++ )
# 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)
else() else()
link_libraries( -static -static-libstdc++ -pthread -flto ) link_libraries( -static-libstdc++ -static-libgcc )
endif() endif()
return()
endif()
if(NOT CMAKE_CROSSCOMPILING)
set(CMAKE_AR "gcc-ar")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "true")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
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() endif()

@ -5,6 +5,7 @@ endif()
include(CheckCXXSourceCompiles) include(CheckCXXSourceCompiles)
include(CheckLibraryExists) include(CheckLibraryExists)
add_library(curl INTERFACE)
option(DOWNLOAD_CURL "download and statically compile in CURL" OFF) option(DOWNLOAD_CURL "download and statically compile in CURL" OFF)
# Allow -DDOWNLOAD_CURL=FORCE to download without even checking for a local libcurl # Allow -DDOWNLOAD_CURL=FORCE to download without even checking for a local libcurl
@ -14,17 +15,22 @@ endif()
if(CURL_FOUND) if(CURL_FOUND)
message(STATUS "using system curl") 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) elseif(DOWNLOAD_CURL)
message(STATUS "libcurl not found, but DOWNLOAD_CURL specified, so downloading it") message(STATUS "libcurl not found, but DOWNLOAD_CURL specified, so downloading it")
include(DownloadLibCurl) include(DownloadLibCurl)
set(CURL_LIBRARIES curl_vendor) target_link_libraries(curl INTERFACE curl_vendor)
else() 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") 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() endif()
add_definitions(-DUNIX) add_definitions(-DUNIX)
add_definitions(-DPOSIX) add_definitions(-DPOSIX)
list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix.c)
if (STATIC_LINK_RUNTIME OR STATIC_LINK) if (STATIC_LINK_RUNTIME OR STATIC_LINK)
set(LIBUV_USE_STATIC ON) set(LIBUV_USE_STATIC ON)
@ -54,32 +60,12 @@ if(EMBEDDED_CFG OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
link_libatomic() link_libatomic()
endif() endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") if (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
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")
add_definitions(-D_BSD_SOURCE) add_definitions(-D_BSD_SOURCE)
add_definitions(-D_GNU_SOURCE) add_definitions(-D_GNU_SOURCE)
add_definitions(-D_XOPEN_SOURCE=700) 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") elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-sunos.c)
if (LIBUV_USE_STATIC) if (LIBUV_USE_STATIC)
link_libraries(-lkstat -lsendfile) link_libraries(-lkstat -lsendfile)
endif() 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() endif()

@ -15,35 +15,20 @@ if(NOT MSVC_VERSION)
add_compile_options(-fno-ident -Wa,-mbig-obj) add_compile_options(-fno-ident -Wa,-mbig-obj)
link_libraries( -lws2_32 -lshlwapi -ldbghelp -luser32 -liphlpapi -lpsapi -luserenv ) link_libraries( -lws2_32 -lshlwapi -ldbghelp -luser32 -liphlpapi -lpsapi -luserenv )
add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500) 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 "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "true")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_FINISH "true")
link_libraries( -static-libstdc++ -static-libgcc -static ${CMAKE_CXX_FLAGS} ${CRYPTO_FLAGS} )
endif()
endif() endif()
if(EMBEDDED_CFG) if(EMBEDDED_CFG)
link_libatomic() link_libatomic()
endif() 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) add_definitions(-DWIN32_LEAN_AND_MEAN -DWIN32)
set(EXE_LIBS ${STATIC_LIB} ws2_32 iphlpapi)
if(RELEASE_MOTTO) if (NOT STATIC_LINK AND NOT MSVC)
add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}")
endif()
if (NOT STATIC_LINK_RUNTIME 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("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() endif()
if (STATIC_LINK_RUNTIME) if (STATIC_LINK)
set(LIBUV_USE_STATIC ON) set(LIBUV_USE_STATIC ON)
endif() endif()

@ -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/randomsmall.c
libntrup/src/ref/swap.c libntrup/src/ref/swap.c
libntrup/src/ref/rq_round3.c libntrup/src/ref/rq_round3.c
@ -36,33 +19,56 @@ set(NTRU_REF_SRC
libntrup/src/ref/rq.c libntrup/src/ref/rq.c
) )
set(NTRU_SRC target_include_directories(lokinet-cryptography PUBLIC libntrup/include)
${NTRU_REF_SRC}
libntrup/src/ntru.cpp
)
set(CRYPTOGRAPHY_SRC ${NTRU_SRC})
add_library(${CRYPTOGRAPHY_LIB} STATIC ${CRYPTOGRAPHY_SRC})
add_log_tag(${CRYPTOGRAPHY_LIB})
# The avx implementation uses runtime CPU feature detection to enable itself, so we *always* want to # 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. # compile it with avx2/fma support when supported by the compiler even if we aren't compiling with
add_library(cryptography_avx_lib STATIC ${NTRU_AVX_SRC}) # general AVX2 enabled.
if(USE_AVX2) 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 # Assume cxxflags are already enabling AVX2
target_sources(lokinet-cryptography PRIVATE ${NTRU_AVX_SRC})
else() else()
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_AVX2) check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_AVX2)
check_cxx_compiler_flag(-mfma COMPILER_SUPPORTS_FMA) check_cxx_compiler_flag(-mfma COMPILER_SUPPORTS_FMA)
if(COMPILER_SUPPORTS_AVX2 AND 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") message(STATUS "Building libntrup with runtime AVX2/FMA support")
else() 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)") 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()
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) 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() endif()
if(sodium_FOUND) if(sodium_FOUND)
target_include_directories(${CRYPTOGRAPHY_LIB} PUBLIC ${sodium_INCLUDE_DIR}) target_link_libraries(lokinet-cryptography PUBLIC sodium)
target_include_directories(cryptography_avx_lib PUBLIC ${sodium_INCLUDE_DIR})
target_link_libraries(${CRYPTOGRAPHY_LIB} PUBLIC ${sodium_LIBRARY_RELEASE})
elseif(DOWNLOAD_SODIUM) elseif(DOWNLOAD_SODIUM)
message(STATUS "Sodium >= 1.0.18 not found, but DOWNLOAD_SODIUM specified, so downloading it") message(STATUS "Sodium >= 1.0.18 not found, but DOWNLOAD_SODIUM specified, so downloading it")
include(DownloadLibSodium) include(DownloadLibSodium)
target_link_libraries(${CRYPTOGRAPHY_LIB} PUBLIC sodium_vendor) target_link_libraries(lokinet-cryptography PUBLIC sodium_vendor)
target_link_libraries(cryptography_avx_lib PUBLIC sodium_vendor)
else() 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") 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() 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")

@ -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) if(SHADOW)
set(LOKINET_SHADOW shadow-plugin-${SHARED_LIB}) add_shadow_plugin(shadow-plugin main.cpp ${TRACY_ROOT}/TracyClient.cpp)
set(LOKINET_SHADOW_LIBS ${SHARED_LIB}) target_link_libraries(shadow-plugin liblokinet)
add_shadow_plugin(${LOKINET_SHADOW} ${EXE_SRC}) enable_lto(shadow-plugin)
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)
else() else()
if(WIN32 AND NOT MSVC_VERSION) add_executable(lokinet main.cpp)
list(APPEND EXE_SRC ../llarp/win32/version.rc) add_executable(lokinetctl lokinetctl.cpp)
list(APPEND CTL_SRC ../llarp/win32/version.rc) enable_lto(lokinet lokinetctl)
endif()
add_executable(${EXE} ${EXE_SRC})
add_executable(${CTL} ${CTL_SRC})
target_compile_definitions(${EXE} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) if(TRACY_ROOT)
target_compile_definitions(${CTL} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL}) target_sources(lokinet PRIVATE ${TRACY_ROOT}/TracyClient.cpp)
endif()
add_log_tag(${EXE})
add_log_tag(${CTL})
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) if(WIN32)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.ps1 DESTINATION bin COMPONENT lokinet) install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.ps1 DESTINATION bin COMPONENT lokinet)
else() else()
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin COMPONENT lokinet) install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin COMPONENT lokinet)
endif() 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)") 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() endif()
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS} ${CRYPTOGRAPHY_LIB})
target_link_libraries(${CTL} PUBLIC ${EXE_LIBS} ${LIBS} ${CRYPTOGRAPHY_LIB})
if(CURL_FOUND) if(CURL_FOUND)
target_include_directories(${CTL} PRIVATE ${CURL_INCLUDE_DIRS}) target_include_directories(lokinetctl PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(${CTL} PRIVATE ${CURL_LIBRARIES}) target_link_libraries(lokinetctl PRIVATE ${CURL_LIBRARIES})
endif(CURL_FOUND) endif(CURL_FOUND)
endif(SHADOW) endif()

@ -1,10 +1,6 @@
add_library(lokinet-android
set(ANDROID_SRC lokinet_config.cpp
lokinet_config.cpp lokinet_daemon.cpp
lokinet_daemon.cpp lokinet_vpn.cpp)
lokinet_vpn.cpp add_log_tag(lokinet-android)
) target_link_libraries(lokinet-android liblokinet)
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})

@ -1,14 +1,20 @@
add_library(${ABYSS_LIB} "${CMAKE_CURRENT_SOURCE_DIR}/src/md5.cpp" add_library(abyss
"${CMAKE_CURRENT_SOURCE_DIR}/src/http.cpp" src/md5.cpp
"${CMAKE_CURRENT_SOURCE_DIR}/src/client.cpp" src/http.cpp
"${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp") src/client.cpp
src/server.cpp)
target_include_directories(${ABYSS_LIB} PUBLIC include) target_include_directories(abyss PUBLIC include)
target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB}) target_link_libraries(abyss PUBLIC lokinet-platform)
enable_lto(abyss)
# for freebsd # for freebsd
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include) target_include_directories(abyss SYSTEM PUBLIC /usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") endif()
add_log_tag(${ABYSS_LIB}) if(BUILD_SHARED_LIBS)
install(TARGETS abyss LIBRARY DESTINATION lib)
endif()
add_log_tag(abyss)

@ -1,6 +1,6 @@
include(Version) include(Version)
set(LIB_UTIL_SRC add_library(lokinet-util
config/config.cpp config/config.cpp
config/definition.cpp config/definition.cpp
config/ini.cpp config/ini.cpp
@ -31,28 +31,27 @@ set(LIB_UTIL_SRC
util/thread/threadpool.cpp util/thread/threadpool.cpp
util/time.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) if(ANDROID)
set(LOG_LIB log) target_link_libraries(lokinet-util PUBLIC log)
endif() 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 # for networking
ev/ev.cpp ev/ev.cpp
ev/pipe.cpp ev/pipe.cpp
@ -61,52 +60,49 @@ set(LIB_PLATFORM_SRC
net/ip.cpp net/ip.cpp
net/net.cpp net/net.cpp
net/net_int.cpp net/net_int.cpp
# for android shim $<TARGET_OBJECTS:tuntap>
${ANDROID_PLATFORM_SRC}
# process isolation implementation
${ISOLATE_PROC_SRC}
# tun
${LIBTUNTAP_SRC}
${EV_SRC}
) )
if (WIN32) target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography lokinet-util Threads::Threads ${LIBS})
set(LIB_PLATFORM_SRC
ev/ev_win32.cpp
${LIB_PLATFORM_SRC} if (ANDROID)
win32/win32_inet.c target_sources(lokinet-platform PRIVATE android/ifaddrs.c)
win32/win32_intrnl.c) endif()
endif(WIN32)
add_library(${PLATFORM_LIB} STATIC ${LIB_PLATFORM_SRC}) if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(${PLATFORM_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${UTIL_LIB} Threads::Threads ${LIBS}) target_sources(lokinet-platform PRIVATE linux/netns.cpp)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(NON_PC_TARGET) if(NON_PC_TARGET)
add_import_library(rt) add_import_library(rt)
target_link_libraries(${PLATFORM_LIB} PUBLIC rt) target_link_libraries(lokinet-platform PUBLIC rt)
endif() endif()
endif() endif()
if(WIN32) if (WIN32)
target_link_libraries(${PLATFORM_LIB} PUBLIC iphlpapi) 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() endif()
set(DNSLIB_SRC
add_library(liblokinet
dns/message.cpp dns/message.cpp
dns/name.cpp dns/name.cpp
dns/question.cpp dns/question.cpp
dns/rr.cpp dns/rr.cpp
dns/serialize.cpp dns/serialize.cpp
dns/server.cpp dns/server.cpp
)
set(CONSENSUS_SRC
consensus/table.cpp consensus/table.cpp
)
set(LIB_SRC
${CONSENSUS_SRC}
${DNSLIB_SRC}
bootstrap.cpp bootstrap.cpp
context.cpp context.cpp
crypto/crypto_libsodium.cpp crypto/crypto_libsodium.cpp
@ -197,50 +193,35 @@ set(LIB_SRC
service/tag_lookup_job.cpp service/tag_lookup_job.cpp
service/tag.cpp service/tag.cpp
) )
set_target_properties(liblokinet PROPERTIES OUTPUT_NAME lokinet)
enable_lto(lokinet-util lokinet-platform liblokinet)
if(TRACY_ROOT) if(TRACY_ROOT)
set(LIB_SRC ${LIB_SRC} ${TRACY_ROOT}/TracyClient.cpp) target_sources(liblokinet PRIVATE ${TRACY_ROOT}/TracyClient.cpp)
endif() endif()
if(TESTNET) if(TESTNET)
set(LIB_SRC ${LIB_SRC} testnet.c) target_sources(liblokinet PRIVATE testnet.c)
endif() endif()
if(WITH_HIVE) if(WITH_HIVE)
set(LIB_SRC ${LIB_SRC} tooling/router_hive.cpp) target_sources(liblokinet PRIVATE tooling/router_hive.cpp)
endif() endif()
add_library(${STATIC_LIB} STATIC ${LIB_SRC}) target_link_libraries(liblokinet PUBLIC cxxopts abyss lokinet-platform lokinet-util lokinet-cryptography)
target_include_directories(${STATIC_LIB} PUBLIC ${CURL_INCLUDE_DIRS})
target_link_libraries(${STATIC_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB})
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if(BUILD_SHARED_LIBS)
target_include_directories(${PLATFORM_LIB} SYSTEM PUBLIC /usr/local/include) install(TARGETS lokinet-util lokinet-platform liblokinet LIBRARY DESTINATION lib)
target_include_directories(${STATIC_LIB} SYSTEM PUBLIC /usr/local/include) if(WIN32)
endif() target_link_libraries(liblokinet PUBLIC ws2_32 iphlpapi)
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)
endif() endif()
add_log_tag(${SHARED_LIB})
endif() endif()
if (WARNINGS_AS_ERRORS) foreach(lokinet_lib liblokinet lokinet-platform lokinet-util lokinet-cryptography)
set(WARN_FLAGS -Wall -Wextra -Werror) add_log_tag(${lokinet_lib})
target_compile_options(${UTIL_LIB} PUBLIC ${WARN_FLAGS}) endforeach()
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})
file(GLOB_RECURSE docs_SRC */*.hpp *.hpp) file(GLOB_RECURSE docs_SRC */*.hpp *.hpp)

@ -1,4 +1,4 @@
set(LLARP_PYBIND_SRC pybind11_add_module(pyllarp MODULE
module.cpp module.cpp
llarp/context.cpp llarp/context.cpp
llarp/router_id.cpp llarp/router_id.cpp
@ -13,8 +13,6 @@ set(LLARP_PYBIND_SRC
llarp/tooling/router_event.cpp llarp/tooling/router_event.cpp
llarp/service/address.cpp llarp/service/address.cpp
) )
target_link_libraries(pyllarp PUBLIC liblokinet)
pybind11_add_module(pyllarp MODULE ${LLARP_PYBIND_SRC}) target_include_directories(pyllarp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
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})

@ -1,5 +1,5 @@
if (WITH_HIVE) 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 add_custom_target(hive ${CMAKE_COMMAND} -E
env PYTHONPATH="$ENV{PYTHONPATH}:${CMAKE_BINARY_DIR}/pybind" env PYTHONPATH="$ENV{PYTHONPATH}:${CMAKE_BINARY_DIR}/pybind"
${PYTHON_EXECUTABLE} -m pytest ${PYTHON_EXECUTABLE} -m pytest
@ -8,11 +8,14 @@ if (WITH_HIVE)
hive_build) hive_build)
endif() endif()
set(GTEST_EXE testAll)
set(CATCH_EXE catchAll)
# Old gtest-based tests; new tests should use Catch2, instead. # 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 config/test_llarp_config_ini.cpp
crypto/test_llarp_crypto_types.cpp crypto/test_llarp_crypto_types.cpp
crypto/test_llarp_crypto.cpp crypto/test_llarp_crypto.cpp
@ -49,31 +52,21 @@ list(APPEND GTEST_SRC
util/thread/test_llarp_util_thread_pool.cpp util/thread/test_llarp_util_thread_pool.cpp
) )
add_executable(${GTEST_EXE} target_link_libraries(testAll PUBLIC gmock gtest liblokinet)
# helpers target_include_directories(testAll PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
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})
if(WIN32) if(WIN32)
target_sources(${GTEST_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/win32/test.rc") target_sources(testAll PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/win32/test.rc")
target_link_libraries(${GTEST_EXE} PUBLIC ws2_32 iphlpapi shlwapi) target_link_libraries(testAll PUBLIC ws2_32 iphlpapi shlwapi)
endif() endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_directories(${GTEST_EXE} PRIVATE /usr/local/lib) target_link_directories(testAll PRIVATE /usr/local/lib)
endif() endif()
add_subdirectory(Catch2) add_subdirectory(Catch2)
add_executable(${CATCH_EXE} add_executable(catchAll
nodedb/test_nodedb.cpp nodedb/test_nodedb.cpp
path/test_path.cpp path/test_path.cpp
util/test_llarp_util_bits.cpp util/test_llarp_util_bits.cpp
@ -86,12 +79,12 @@ add_executable(${CATCH_EXE}
net/test_sock_addr.cpp net/test_sock_addr.cpp
check_main.cpp) check_main.cpp)
target_link_libraries(${CATCH_EXE} PUBLIC ${STATIC_LIB} Catch2::Catch2) target_link_libraries(catchAll PUBLIC liblokinet Catch2::Catch2)
target_include_directories(${CATCH_EXE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(catchAll PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
# Custom targets to invoke the different test suites: # Custom targets to invoke the different test suites:
add_custom_target(catch COMMAND ${CATCH_EXE}) add_custom_target(catch COMMAND catchAll)
add_custom_target(rungtest COMMAND ${GTEST_EXE}) add_custom_target(rungtest COMMAND testAll)
# Add a custom "check" target that runs all the test suites: # Add a custom "check" target that runs all the test suites:
add_custom_target(check DEPENDS rungtest catch) add_custom_target(check DEPENDS rungtest catch)

@ -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()
Loading…
Cancel
Save