2020-04-18 20:02:22 +02:00
cmake_minimum_required ( VERSION 3.10 ) # bionic's cmake version
2018-05-16 15:56:51 +02:00
2021-02-25 17:50:34 +01:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
2020-05-20 04:14:21 +02:00
# Has to be set before `project()`, and ignored on non-macos:
2021-07-29 22:40:25 +02:00
set ( CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "macOS deployment target (Apple clang only)" )
2020-04-22 01:00:37 +02:00
2021-05-14 19:07:44 +02:00
set ( LANGS ASM C CXX )
if ( APPLE )
set ( LANGS ${ LANGS } OBJC Swift )
endif ( )
2019-06-26 23:39:29 +02:00
find_program ( CCACHE_PROGRAM ccache )
if ( CCACHE_PROGRAM )
2021-05-14 19:07:44 +02:00
foreach ( lang ${ LANGS } )
2020-06-10 18:34:02 +02:00
if ( NOT DEFINED CMAKE_ ${ lang } _COMPILER_LAUNCHER AND NOT CMAKE_ ${ lang } _COMPILER MATCHES ".*/ccache" )
message ( STATUS "Enabling ccache for ${lang}" )
set ( CMAKE_ ${ lang } _COMPILER_LAUNCHER ${ CCACHE_PROGRAM } CACHE STRING "" )
endif ( )
endforeach ( )
2019-06-26 23:39:29 +02:00
endif ( )
2021-05-14 19:07:44 +02:00
2020-11-18 12:08:56 +01:00
project ( lokinet
2021-07-05 15:13:05 +02:00
V E R S I O N 0 . 9 . 5
2020-04-18 20:02:22 +02:00
D E S C R I P T I O N " l o k i n e t - I P p a c k e t o n i o n r o u t e r "
2021-05-14 19:07:44 +02:00
L A N G U A G E S $ { L A N G S } )
2018-06-14 16:04:42 +02:00
2021-07-28 16:30:42 +02:00
if ( APPLE )
# Apple build number: must be incremented to submit a new build for the same lokinet version,
# should be reset to 0 when the lokinet version increments.
set ( LOKINET_APPLE_BUILD 0 )
endif ( )
2021-05-14 21:15:00 +02:00
set ( RELEASE_MOTTO "A Series of Tubes" CACHE STRING "Release motto" )
2020-04-20 04:13:39 +02:00
2020-04-18 20:02:22 +02:00
add_definitions ( -DLLARP_VERSION_MAJOR= ${ lokinet_VERSION_MAJOR } )
add_definitions ( -DLLARP_VERSION_MINOR= ${ lokinet_VERSION_MINOR } )
add_definitions ( -DLLARP_VERSION_PATCH= ${ lokinet_VERSION_PATCH } )
2021-01-12 00:13:22 +01:00
if ( RELEASE_MOTTO AND CMAKE_BUILD_TYPE MATCHES "[Rr][Ee][Ll][Ee][Aa][Ss][Ee]" )
2020-05-17 21:41:48 +02:00
add_definitions ( -DLLARP_RELEASE_MOTTO= "${RELEASE_MOTTO}" )
endif ( )
2020-01-10 20:59:45 +01:00
2021-06-30 13:21:17 +02:00
set ( LOKINET_VERSION "${lokinet_VERSION_MAJOR}.${lokinet_VERSION_MINOR}.${lokinet_VERSION_PATCH}" )
2020-01-10 20:59:45 +01:00
2020-06-17 00:17:41 +02:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" )
2019-02-09 17:16:00 +01:00
# Core options
2019-11-05 12:45:49 +01:00
option ( USE_AVX2 "enable avx2 code" OFF )
option ( USE_NETNS "enable networking namespace support. Linux only" OFF )
2019-11-05 13:11:05 +01:00
option ( NATIVE_BUILD "optimise for host system and FPU" ON )
2019-11-05 12:45:49 +01:00
option ( EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF )
2021-03-08 20:19:20 +01:00
option ( BUILD_LIBLOKINET "build liblokinet.so" ON )
2019-11-05 12:45:49 +01:00
option ( SHADOW "use shadow testing framework. linux only" OFF )
2020-05-17 21:41:48 +02:00
option ( XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF )
2020-05-21 16:18:23 +02:00
option ( WITH_JEMALLOC "use jemalloc as allocator" OFF )
2019-11-05 12:45:49 +01:00
option ( TESTNET "testnet build" OFF )
option ( WITH_COVERAGE "generate coverage data" OFF )
2019-07-29 14:14:35 +02:00
option ( USE_SHELLHOOKS "enable shell hooks on compile time (dangerous)" OFF )
2019-03-19 01:22:37 +01:00
option ( WARNINGS_AS_ERRORS "treat all warnings as errors. turn off for development, on for release" OFF )
2019-11-05 12:45:49 +01:00
option ( TRACY_ROOT "include tracy profiler source" OFF )
option ( WITH_TESTS "build unit tests" ON )
2020-02-27 20:43:16 +01:00
option ( WITH_HIVE "build simulation stubs" OFF )
2020-04-18 23:50:07 +02:00
option ( BUILD_PACKAGE "builds extra components for making an installer (with 'make package')" OFF )
2020-05-15 15:12:00 +02:00
2020-06-15 22:25:28 +02:00
include ( cmake/enable_lto.cmake )
option ( BUILD_STATIC_DEPS "Download, build, and statically link against core dependencies" OFF )
option ( STATIC_LINK "link statically against dependencies" ${ BUILD_STATIC_DEPS } )
if ( BUILD_STATIC_DEPS AND NOT STATIC_LINK )
message ( FATAL_ERROR "Option BUILD_STATIC_DEPS requires STATIC_LINK to be enabled as well" )
endif ( )
if ( BUILD_STATIC_DEPS )
2021-04-15 19:39:45 +02:00
set ( CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE )
2020-06-15 22:25:28 +02:00
include ( StaticBuild )
endif ( )
2020-05-17 21:41:48 +02:00
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE RelWithDebInfo )
2020-03-03 05:15:18 +01:00
endif ( )
2018-06-15 15:42:49 +02:00
2021-06-19 13:54:44 +02:00
if ( BUILD_STATIC_DEPS AND STATIC_LINK )
message ( STATUS "we are building static deps so we won't build shared libs" )
set ( BUILD_SHARED_LIBS OFF )
endif ( )
2020-05-15 15:40:24 +02:00
include ( CheckCXXSourceCompiles )
include ( CheckLibraryExists )
2020-05-21 16:18:23 +02:00
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
set ( CMAKE_C_STANDARD 99 )
set ( CMAKE_C_STANDARD_REQUIRED ON )
set ( CMAKE_C_EXTENSIONS OFF )
2020-05-15 15:40:24 +02:00
2019-04-25 01:27:31 +02:00
include ( cmake/target_link_libraries_system.cmake )
2019-04-30 01:48:43 +02:00
include ( cmake/add_import_library.cmake )
include ( cmake/add_log_tag.cmake )
2019-08-29 15:59:04 +02:00
include ( cmake/libatomic.cmake )
2020-09-19 15:50:54 +02:00
include ( cmake/link_dep_libs.cmake )
2019-04-25 01:27:31 +02:00
2019-12-23 07:50:59 +01:00
if ( STATIC_LINK )
set ( CMAKE_FIND_LIBRARY_SUFFIXES ${ CMAKE_STATIC_LIBRARY_SUFFIX } )
message ( STATUS "setting static library suffix search" )
endif ( )
2020-05-17 21:41:48 +02:00
add_definitions ( -D ${ CMAKE_SYSTEM_NAME } )
2019-02-09 17:16:00 +01:00
2019-04-28 17:57:41 +02:00
include ( cmake/solaris.cmake )
2019-07-22 01:39:56 +02:00
include ( cmake/win32.cmake )
2020-03-12 17:22:33 +01:00
# No in-source building
include ( MacroEnsureOutOfSourceBuild )
macro_ensure_out_of_source_build ( "${PROJECT_NAME} requires an out-of-source build. Create a build directory and run 'cmake ${CMAKE_SOURCE_DIR} [options]'." )
2020-05-17 21:41:48 +02:00
# Always build PIC
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
2020-03-12 17:29:12 +01:00
include ( cmake/unix.cmake )
2020-05-15 15:43:53 +02:00
include ( cmake/check_for_std_optional.cmake )
include ( cmake/check_for_std_filesystem.cmake )
2020-03-12 17:29:12 +01:00
2019-11-05 12:58:40 +01:00
if ( NOT WIN32 )
2019-11-05 13:01:14 +01:00
if ( IOS OR ANDROID )
2019-11-05 12:58:40 +01:00
set ( NON_PC_TARGET ON )
2019-11-05 13:01:14 +01:00
else ( )
include ( TargetArch )
target_architecture ( COMPILE_ARCH )
if ( COMPILE_ARCH MATCHES i386 OR COMPILE_ARCH MATCHES x86_64 )
set ( NON_PC_TARGET OFF )
else ( )
set ( NON_PC_TARGET ON )
endif ( )
2019-11-05 12:58:40 +01:00
endif ( )
endif ( )
2019-03-24 01:40:19 +01:00
2020-09-22 19:59:33 +02:00
find_package ( PkgConfig REQUIRED )
2021-01-17 01:11:28 +01:00
if ( NOT BUILD_STATIC_DEPS )
2021-01-18 23:24:28 +01:00
pkg_check_modules ( LIBUV libuv>=1.18.0 IMPORTED_TARGET )
2021-01-17 01:11:28 +01:00
endif ( )
if ( LIBUV_FOUND AND NOT BUILD_STATIC_DEPS )
add_library ( libuv INTERFACE )
target_link_libraries ( libuv INTERFACE PkgConfig::LIBUV )
else ( )
if ( NOT BUILD_STATIC_DEPS )
2021-07-05 15:40:48 +02:00
message ( FATAL_ERROR "Could not find libuv >= 1.28.0; install it on your system or use -DBUILD_STATIC_DEPS=ON" )
2021-01-17 01:11:28 +01:00
endif ( )
endif ( )
2020-06-26 19:59:36 +02:00
if ( NOT TARGET sodium )
# Allow -D DOWNLOAD_SODIUM=FORCE to download without even checking for a local libsodium
option ( DOWNLOAD_SODIUM "Allow libsodium to be downloaded and built locally if not found on the system" OFF )
if ( NOT DOWNLOAD_SODIUM STREQUAL "FORCE" AND NOT BUILD_STATIC_DEPS )
pkg_check_modules ( SODIUM libsodium>=1.0.18 IMPORTED_TARGET )
endif ( )
2020-06-16 13:34:57 +02:00
2020-06-26 19:59:36 +02:00
add_library ( sodium INTERFACE )
if ( SODIUM_FOUND AND NOT DOWNLOAD_SODIUM STREQUAL "FORCE" AND NOT BUILD_STATIC_DEPS )
target_link_libraries ( sodium INTERFACE PkgConfig::SODIUM )
else ( )
if ( NOT DOWNLOAD_SODIUM AND NOT BUILD_STATIC_DEPS )
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 ( )
message ( STATUS "Sodium >= 1.0.18 not found, but DOWNLOAD_SODIUM specified, so downloading it" )
include ( DownloadLibSodium )
target_link_libraries ( sodium INTERFACE sodium_vendor )
endif ( )
2020-06-26 19:45:08 +02:00
2020-06-26 19:59:36 +02:00
# Need this target export so that loki-mq properly picks up sodium
export ( TARGETS sodium NAMESPACE sodium:: FILE sodium-exports.cmake )
2020-06-26 19:45:08 +02:00
endif ( )
2021-03-01 13:57:13 +01:00
option ( FORCE_OXENMQ_SUBMODULE "force using oxenmq submodule" OFF )
if ( NOT FORCE_OXENMQ_SUBMODULE )
2021-02-25 17:54:18 +01:00
pkg_check_modules ( OXENMQ liboxenmq>=1.2.4 )
2020-06-16 13:34:57 +02:00
endif ( )
2021-03-01 13:57:13 +01:00
if ( OXENMQ_FOUND )
2021-02-02 15:35:40 +01:00
add_library ( oxenmq INTERFACE )
2021-03-01 13:57:13 +01:00
link_dep_libs ( oxenmq INTERFACE "${OXENMQ_LIBRARY_DIRS}" ${ OXENMQ_LIBRARIES } )
target_include_directories ( oxenmq INTERFACE ${ OXENMQ_INCLUDE_DIRS } )
2021-02-02 15:35:40 +01:00
add_library ( oxenmq::oxenmq ALIAS oxenmq )
2021-03-01 13:57:13 +01:00
message ( STATUS "Found system liboxenmq ${OXENMQ_VERSION}" )
2020-06-16 13:34:57 +02:00
else ( )
2021-02-02 15:35:40 +01:00
message ( STATUS "using oxenmq submodule" )
2021-03-01 13:57:13 +01:00
add_subdirectory ( ${ CMAKE_SOURCE_DIR } /external/oxen-mq )
2020-06-16 13:34:57 +02:00
endif ( )
2021-05-14 19:07:44 +02:00
if ( NOT APPLE )
add_compile_options ( -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-function -Wno-deprecated-declarations -Werror=vla )
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
add_compile_options ( -Wno-unknown-warning-option )
endif ( )
endif ( )
2019-10-17 06:14:03 +02:00
2020-05-17 21:41:48 +02:00
if ( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" AND SHADOW )
2019-01-19 04:20:24 +01:00
message ( FATAL_ERROR "shadow-framework is Linux only" )
2019-05-18 17:34:03 +02:00
endif ( )
2019-09-22 16:32:03 +02:00
if ( XSAN )
2020-05-22 16:22:27 +02:00
string ( APPEND CMAKE_CXX_FLAGS_DEBUG " -fsanitize=${XSAN} -fno-omit-frame-pointer -fno-sanitize-recover" )
2020-05-17 21:41:48 +02:00
foreach ( type EXE MODULE SHARED STATIC )
2020-05-22 16:22:27 +02:00
string ( APPEND CMAKE_ ${ type } _LINKER_FLAGS_DEBUG " -fsanitize=${XSAN} -fno-omit-frame-pointer -fno-sanitize-recover" )
2020-05-17 21:41:48 +02:00
endforeach ( )
2020-02-24 18:40:38 +01:00
message ( STATUS "Doing a ${XSAN} sanitizer build" )
2020-05-17 21:41:48 +02:00
endif ( )
2019-05-18 17:34:03 +02:00
if ( CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]" )
add_definitions ( -DLOKINET_DEBUG=1 )
2020-05-17 21:41:48 +02:00
endif ( )
2019-05-18 17:34:03 +02:00
2019-07-12 15:06:59 +02:00
if ( WITH_SHELLHOOKS )
add_definitions ( -DENABLE_SHELLHOOKS )
2020-05-17 21:41:48 +02:00
endif ( )
2019-08-27 01:10:48 +02:00
2019-10-07 12:08:47 +02:00
if ( TRACY_ROOT )
include_directories ( ${ TRACY_ROOT } )
add_definitions ( -DTRACY_ENABLE )
endif ( )
2019-03-02 03:01:04 +01:00
2019-04-28 17:57:41 +02:00
include ( cmake/coverage.cmake )
2019-01-12 02:19:24 +01:00
2018-12-12 05:51:22 +01:00
# these vars are set by the cmake toolchain spec
2018-09-25 10:31:29 +02:00
if ( WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE )
2019-04-30 01:48:43 +02:00
include ( cmake/cross_compile.cmake )
2020-05-17 21:41:48 +02:00
endif ( )
2018-11-19 14:39:35 +01:00
2021-05-14 19:07:44 +02:00
if ( NOT APPLE )
if ( NATIVE_BUILD )
if ( CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le )
add_compile_options ( -mcpu=native -mtune=native )
else ( )
add_compile_options ( -march=native -mtune=native )
endif ( )
elseif ( NOT NON_PC_TARGET )
if ( USE_AVX2 )
add_compile_options ( -march=haswell -mtune=haswell -mfpmath=sse )
else ( )
# Public binary releases
add_compile_options ( -march=nocona -mtune=haswell -mfpmath=sse )
endif ( )
2019-10-30 21:55:12 +01:00
endif ( )
2019-02-09 17:16:00 +01:00
endif ( )
2018-12-12 05:51:22 +01:00
2018-10-28 19:57:04 +01:00
set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
set ( THREADS_PREFER_PTHREAD_FLAG TRUE )
find_package ( Threads REQUIRED )
2018-07-17 01:26:58 +02:00
2018-11-19 14:39:35 +01:00
if ( USE_NETNS )
add_definitions ( -DNETNS=1 )
else ( )
add_definitions ( -DNETNS=0 )
2020-05-17 21:41:48 +02:00
endif ( )
2018-06-06 19:02:57 +02:00
2018-10-21 16:19:49 +02:00
if ( TESTNET )
add_definitions ( -DTESTNET=1 )
2020-01-23 13:59:51 +01:00
# 5 times slower than realtime
2021-04-12 13:39:07 +02:00
# add_definitions(-DTESTNET_SPEED=5)
2020-05-17 21:41:48 +02:00
endif ( )
2018-10-21 16:19:49 +02:00
2018-06-06 14:59:15 +02:00
if ( SHADOW )
2019-04-28 17:57:41 +02:00
include ( cmake/shadow.cmake )
2020-05-17 21:41:48 +02:00
endif ( )
2018-06-01 19:47:37 +02:00
2019-12-14 02:20:45 +01:00
unset ( GIT_VERSION )
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 )
2020-05-17 21:41:48 +02:00
endif ( )
2019-12-14 02:20:45 +01:00
string ( REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}" )
2019-11-05 13:28:08 +01:00
2020-06-17 02:36:18 +02:00
find_package ( PkgConfig REQUIRED )
2020-06-16 00:44:59 +02:00
if ( NOT BUILD_STATIC_DEPS )
pkg_check_modules ( UNBOUND libunbound REQUIRED IMPORTED_TARGET )
add_library ( libunbound INTERFACE )
target_link_libraries ( libunbound INTERFACE PkgConfig::UNBOUND )
endif ( )
2020-06-11 21:27:29 +02:00
2020-10-28 23:26:43 +01:00
pkg_check_modules ( SD libsystemd IMPORTED_TARGET )
2020-06-11 21:27:29 +02:00
# Default WITH_SYSTEMD to true if we found it
option ( WITH_SYSTEMD "enable systemd integration for sd_notify" ${ SD_FOUND } )
2020-10-28 23:26:43 +01:00
# Base interface target where we set up global link libraries, definitions, includes, etc.
add_library ( base_libs INTERFACE )
2020-09-22 21:04:15 +02:00
if ( WITH_SYSTEMD AND ( NOT ANDROID ) )
2020-06-11 21:27:29 +02:00
if ( NOT SD_FOUND )
message ( FATAL_ERROR "libsystemd not found" )
endif ( )
2020-10-28 23:26:43 +01:00
target_link_libraries ( base_libs INTERFACE PkgConfig::SD )
target_compile_definitions ( base_libs INTERFACE WITH_SYSTEMD )
2020-02-25 22:42:07 +01:00
endif ( )
2020-02-13 18:42:16 +01:00
2021-04-15 19:39:45 +02:00
add_subdirectory ( external )
2020-05-20 19:26:45 +02:00
include_directories ( SYSTEM external/sqlite_orm/include )
2021-06-29 21:00:14 +02:00
option ( USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON )
if ( USE_JEMALLOC AND NOT STATIC_LINK )
pkg_check_modules ( JEMALLOC jemalloc IMPORTED_TARGET )
if ( JEMALLOC_FOUND )
target_link_libraries ( base_libs INTERFACE PkgConfig::JEMALLOC )
else ( )
message ( STATUS "jemalloc not found, not linking to jemalloc" )
endif ( )
else ( )
message ( STATUS "jemalloc support disabled" )
endif ( )
2018-11-06 15:06:09 +01:00
if ( ANDROID )
2020-10-28 23:26:43 +01:00
target_link_libraries ( base_libs INTERFACE log )
target_compile_definitions ( base_libs INTERFACE ANDROID )
2019-04-08 16:27:55 +02:00
set ( ANDROID_PLATFORM_SRC android/ifaddrs.c )
2020-05-17 21:41:48 +02:00
endif ( )
2018-11-19 14:39:35 +01:00
2019-09-03 17:56:56 +02:00
if ( TRACY_ROOT )
2020-10-28 23:26:43 +01:00
target_link_libraries ( base_libs INTERFACE dl )
2019-09-03 17:56:56 +02:00
endif ( )
2019-06-24 17:51:58 +02:00
2020-02-27 20:43:16 +01:00
if ( WITH_HIVE )
add_definitions ( -DLOKINET_HIVE=1 )
endif ( )
2019-02-09 17:16:00 +01:00
add_subdirectory ( crypto )
add_subdirectory ( llarp )
2019-10-05 17:03:25 +02:00
add_subdirectory ( daemon )
2021-05-14 19:07:44 +02:00
2020-04-18 21:58:41 +02:00
if ( WITH_HIVE )
add_subdirectory ( pybind )
endif ( )
2019-07-17 11:08:04 +02:00
if ( NOT SHADOW )
2020-03-03 05:15:18 +01:00
if ( WITH_TESTS OR WITH_HIVE )
2019-11-05 12:45:49 +01:00
add_subdirectory ( test )
endif ( )
2018-08-06 01:48:59 +02:00
if ( ANDROID )
2019-10-21 14:01:29 +02:00
add_subdirectory ( jni )
2020-05-17 21:41:48 +02:00
endif ( )
2019-02-09 17:16:00 +01:00
endif ( )
2020-01-10 20:59:45 +01:00
2020-03-27 16:04:13 +01:00
add_subdirectory ( docs )
2020-09-09 18:06:57 +02:00
# uninstall target
if ( NOT TARGET uninstall )
configure_file (
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c m a k e / c m a k e _ u n i n s t a l l . c m a k e . i n "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e _ u n i n s t a l l . c m a k e "
I M M E D I A T E @ O N L Y )
add_custom_target ( uninstall
C O M M A N D $ { C M A K E _ C O M M A N D } - P $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e _ u n i n s t a l l . c m a k e )
endif ( )
2020-04-18 23:50:07 +02:00
if ( BUILD_PACKAGE )
include ( cmake/installer.cmake )
endif ( )