2022-09-10 14:20:41 +00:00
cmake_minimum_required ( VERSION 3.13...3.24 ) # 3.13 is buster's version
2018-05-16 13:56:51 +00:00
2023-10-26 20:09:01 +00:00
# Cmake 3.24+ breaks extraction timestamps by default, hurray, but the option to not break
# timestamps fails in cmake <3.24, extra hurray!
if ( CMAKE_VERSION VERSION_GREATER_EQUAL 3.24 )
cmake_policy ( SET CMP0135 OLD )
endif ( )
2021-02-25 16:50:34 +00:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )
2020-05-20 02:14:21 +00:00
# Has to be set before `project()`, and ignored on non-macos:
2022-06-22 21:56:35 +00:00
set ( CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "macOS deployment target (Apple clang only)" )
2020-04-21 23:00:37 +00:00
2021-09-25 17:07:52 +00:00
option ( BUILD_DAEMON "build lokinet daemon and associated utils" ON )
2023-10-23 22:58:58 +00:00
option ( GRAPH_DEPENDENCIES "Produce graphviz representation of cmake dependencies" OFF )
2021-09-25 17:07:52 +00:00
2021-09-01 20:28:11 +00:00
set ( LANGS C CXX )
2021-09-25 17:07:52 +00:00
if ( APPLE AND BUILD_DAEMON )
2021-05-14 17:07:44 +00:00
set ( LANGS ${ LANGS } OBJC Swift )
endif ( )
2019-06-26 21:39:29 +00:00
find_program ( CCACHE_PROGRAM ccache )
if ( CCACHE_PROGRAM )
2021-05-14 17:07:44 +00:00
foreach ( lang ${ LANGS } )
2020-06-10 16:34:02 +00: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 21:39:29 +00:00
endif ( )
2021-05-14 17:07:44 +00:00
2020-11-18 11:08:56 +00:00
project ( lokinet
2022-11-29 16:26:35 +00:00
V E R S I O N 0 . 9 . 1 1
2020-04-18 18:02:22 +00: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 17:07:44 +00:00
L A N G U A G E S $ { L A N G S } )
2018-06-14 14:04:42 +00:00
2021-07-28 14:30:42 +00: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.
2022-09-29 13:31:38 +00:00
set ( LOKINET_APPLE_BUILD 5 )
2021-07-28 14:30:42 +00:00
endif ( )
2023-10-31 20:49:01 +00:00
set ( LOKINET_RELEASE_MOTTO "Anonymous, decentralized, IP-based overlay network" CACHE STRING "Release motto" )
2020-01-10 19:59:45 +00:00
2020-06-16 22:17:41 +00:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" )
2021-09-24 14:10:08 +00:00
set ( DEFAULT_WITH_BOOTSTRAP ON )
if ( APPLE )
set ( DEFAULT_WITH_BOOTSTRAP OFF )
endif ( )
2019-02-09 16:16:00 +00:00
# Core options
2019-11-05 11:45:49 +00:00
option ( USE_AVX2 "enable avx2 code" OFF )
option ( USE_NETNS "enable networking namespace support. Linux only" OFF )
2019-11-05 12:11:05 +00:00
option ( NATIVE_BUILD "optimise for host system and FPU" ON )
2023-01-09 17:48:13 +00:00
option ( WITH_EMBEDDED_LOKINET "build liblokinet.so for embedded lokinet" OFF )
2020-05-17 19:41:48 +00:00
option ( XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF )
2021-09-13 16:21:12 +00:00
option ( USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON )
2019-11-05 11:45:49 +00:00
option ( TESTNET "testnet build" OFF )
option ( WITH_COVERAGE "generate coverage data" OFF )
2019-03-19 00:22:37 +00:00
option ( WARNINGS_AS_ERRORS "treat all warnings as errors. turn off for development, on for release" OFF )
2022-01-25 18:13:20 +00:00
option ( WITH_TESTS "build unit tests" OFF )
2020-02-27 19:43:16 +00:00
option ( WITH_HIVE "build simulation stubs" OFF )
2020-04-18 21:50:07 +00:00
option ( BUILD_PACKAGE "builds extra components for making an installer (with 'make package')" OFF )
2021-09-24 14:10:08 +00:00
option ( WITH_BOOTSTRAP "build lokinet-bootstrap tool" ${ DEFAULT_WITH_BOOTSTRAP } )
2022-08-12 22:52:42 +00:00
option ( WITH_PEERSTATS "build with experimental peerstats db support" OFF )
2022-07-28 16:07:38 +00:00
option ( STRIP_SYMBOLS "strip off all debug symbols into an external archive for all executables built" OFF )
2022-10-04 19:19:42 +00:00
set ( BOOTSTRAP_FALLBACK_MAINNET "${PROJECT_SOURCE_DIR}/contrib/bootstrap/mainnet.signed" CACHE PATH "Fallback bootstrap path (mainnet)" )
set ( BOOTSTRAP_FALLBACK_TESTNET "${PROJECT_SOURCE_DIR}/contrib/bootstrap/testnet.signed" CACHE PATH "Fallback bootstrap path (testnet)" )
2020-05-15 13:12:00 +00:00
2020-06-15 20:25:28 +00:00
include ( cmake/enable_lto.cmake )
2022-02-02 14:07:47 +00:00
option ( CROSS_PLATFORM "cross compiler platform" "Linux" )
option ( CROSS_PREFIX "toolchain cross compiler prefix" "" )
2023-08-29 17:17:55 +00:00
option ( BUILD_SHARED_LIBS "Build shared library" OFF )
2020-06-15 20:25:28 +00:00
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 ( )
2023-08-29 17:17:55 +00:00
if ( BUILD_STATIC_DEPS AND BUILD_SHARED_LIBS )
message ( FATAL_ERROR "Incompatible options: BUILD_STATIC_DEPS cannot be used with BUILD_SHARED_LIBS" )
endif ( )
2020-06-15 20:25:28 +00:00
if ( BUILD_STATIC_DEPS )
2021-04-15 17:39:45 +00:00
set ( CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE )
2023-08-28 16:13:35 +00:00
include ( cmake/StaticBuild.cmake )
2020-06-15 20:25:28 +00:00
endif ( )
2020-05-17 19:41:48 +00:00
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE RelWithDebInfo )
2020-03-03 04:15:18 +00:00
endif ( )
2018-06-15 13:42:49 +00:00
2022-07-28 16:07:38 +00:00
set ( debug OFF )
if ( CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]" )
set ( debug ON )
add_definitions ( -DLOKINET_DEBUG )
endif ( )
2023-08-29 14:26:59 +00:00
option ( WARN_DEPRECATED "show deprecation warnings" OFF )
2022-09-03 15:43:40 +00:00
2020-05-15 13:40:24 +00:00
include ( CheckCXXSourceCompiles )
include ( CheckLibraryExists )
2020-05-21 14:18:23 +00:00
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
2023-08-28 22:23:46 +00:00
set ( CMAKE_C_STANDARD 11 )
2020-05-21 14:18:23 +00:00
set ( CMAKE_C_STANDARD_REQUIRED ON )
2020-05-15 13:40:24 +00:00
2019-04-24 23:27:31 +00:00
include ( cmake/target_link_libraries_system.cmake )
2019-04-29 23:48:43 +00:00
include ( cmake/add_import_library.cmake )
2019-08-29 13:59:04 +00:00
include ( cmake/libatomic.cmake )
2019-04-24 23:27:31 +00:00
2019-12-23 06:50:59 +00:00
if ( STATIC_LINK )
set ( CMAKE_FIND_LIBRARY_SUFFIXES ${ CMAKE_STATIC_LIBRARY_SUFFIX } )
message ( STATUS "setting static library suffix search" )
endif ( )
2022-10-03 15:18:40 +00:00
include ( cmake/gui-option.cmake )
2019-04-28 15:57:41 +00:00
include ( cmake/solaris.cmake )
2019-07-21 23:39:56 +00:00
include ( cmake/win32.cmake )
2022-08-12 22:57:00 +00:00
include ( cmake/macos.cmake )
2020-03-12 16:22:33 +00: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 19:41:48 +00:00
# Always build PIC
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
2020-03-12 16:29:12 +00:00
include ( cmake/unix.cmake )
2020-05-15 13:43:53 +00:00
include ( cmake/check_for_std_optional.cmake )
2023-07-31 15:49:06 +00:00
#include(cmake/check_for_std_filesystem.cmake)
2020-03-12 16:29:12 +00:00
2019-11-05 11:58:40 +00:00
if ( NOT WIN32 )
2019-11-05 12:01:14 +00:00
if ( IOS OR ANDROID )
2019-11-05 11:58:40 +00:00
set ( NON_PC_TARGET ON )
2019-11-05 12:01:14 +00: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 11:58:40 +00:00
endif ( )
endif ( )
2019-03-24 00:40:19 +00:00
2020-09-22 17:59:33 +00:00
find_package ( PkgConfig REQUIRED )
2021-01-17 00:11:28 +00:00
if ( NOT BUILD_STATIC_DEPS )
2021-01-18 22:24:28 +00:00
pkg_check_modules ( LIBUV libuv>=1.18.0 IMPORTED_TARGET )
2021-01-17 00:11:28 +00: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 13:40:48 +00: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 00:11:28 +00:00
endif ( )
endif ( )
2020-06-26 17:59:36 +00: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 11:34:57 +00:00
2020-06-26 17:59:36 +00: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 17:45:08 +00:00
2020-06-26 17:59:36 +00: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 17:45:08 +00:00
endif ( )
2022-09-19 15:38:54 +00:00
set ( warning_flags -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-function -Werror=vla )
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
list ( APPEND warning_flags -Wno-unknown-warning-option )
endif ( )
2023-08-31 16:28:02 +00:00
list ( APPEND warning_flags -Wno-deprecated-declarations )
2022-09-19 15:38:54 +00:00
# If we blindly add these directly as compile_options then they get passed to swiftc on Apple and
# break, so we use a generate expression to set them only for C++/C/ObjC
add_compile_options ( "$<$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:OBJC>>:${warning_flags}>" )
2019-10-17 04:14:03 +00:00
2019-09-22 14:32:03 +00:00
if ( XSAN )
2020-05-22 14:22:27 +00:00
string ( APPEND CMAKE_CXX_FLAGS_DEBUG " -fsanitize=${XSAN} -fno-omit-frame-pointer -fno-sanitize-recover" )
2020-05-17 19:41:48 +00:00
foreach ( type EXE MODULE SHARED STATIC )
2020-05-22 14:22:27 +00:00
string ( APPEND CMAKE_ ${ type } _LINKER_FLAGS_DEBUG " -fsanitize=${XSAN} -fno-omit-frame-pointer -fno-sanitize-recover" )
2020-05-17 19:41:48 +00:00
endforeach ( )
2020-02-24 17:40:38 +00:00
message ( STATUS "Doing a ${XSAN} sanitizer build" )
2020-05-17 19:41:48 +00:00
endif ( )
2019-05-18 15:34:03 +00:00
2019-04-28 15:57:41 +00:00
include ( cmake/coverage.cmake )
2019-01-12 01:19:24 +00:00
2018-12-12 04:51:22 +00:00
# these vars are set by the cmake toolchain spec
2018-09-25 08:31:29 +00:00
if ( WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE )
2019-04-29 23:48:43 +00:00
include ( cmake/cross_compile.cmake )
2020-05-17 19:41:48 +00:00
endif ( )
2018-11-19 13:39:35 +00:00
2021-05-14 17:07:44 +00: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 20:55:12 +00:00
endif ( )
2019-02-09 16:16:00 +00:00
endif ( )
2018-12-12 04:51:22 +00:00
2018-10-28 18:57:04 +00:00
set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
set ( THREADS_PREFER_PTHREAD_FLAG TRUE )
find_package ( Threads REQUIRED )
2018-07-16 23:26:58 +00:00
2018-10-21 14:19:49 +00:00
if ( TESTNET )
2022-06-21 21:57:36 +00:00
add_definitions ( -DTESTNET )
2020-01-23 12:59:51 +00:00
# 5 times slower than realtime
2021-04-12 11:39:07 +00:00
# add_definitions(-DTESTNET_SPEED=5)
2020-05-17 19:41:48 +00:00
endif ( )
2018-10-21 14:19:49 +00:00
2019-12-14 01:20:45 +00: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 19:41:48 +00:00
endif ( )
2019-12-14 01:20:45 +00:00
string ( REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}" )
2019-11-05 12:28:08 +00:00
2020-06-17 00:36:18 +00:00
find_package ( PkgConfig REQUIRED )
2020-06-15 22:44:59 +00: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 19:27:29 +00:00
2020-10-28 22:26:43 +00:00
pkg_check_modules ( SD libsystemd IMPORTED_TARGET )
2020-06-11 19:27:29 +00:00
# Default WITH_SYSTEMD to true if we found it
option ( WITH_SYSTEMD "enable systemd integration for sd_notify" ${ SD_FOUND } )
2023-10-23 22:58:58 +00:00
add_subdirectory ( external )
# interface library for setting common includes, linkage and flags
add_library ( lokinet-base INTERFACE )
target_include_directories ( lokinet-base INTERFACE . include )
2023-10-24 13:18:03 +00:00
target_link_libraries ( lokinet-base INTERFACE quic nlohmann_json::nlohmann_json )
2020-10-28 22:26:43 +00:00
2020-09-22 19:04:15 +00:00
if ( WITH_SYSTEMD AND ( NOT ANDROID ) )
2020-06-11 19:27:29 +00:00
if ( NOT SD_FOUND )
message ( FATAL_ERROR "libsystemd not found" )
endif ( )
2023-10-23 22:58:58 +00:00
target_link_libraries ( lokinet-base INTERFACE PkgConfig::SD )
target_compile_definitions ( lokinet-base INTERFACE WITH_SYSTEMD )
2020-02-25 21:42:07 +00:00
endif ( )
2020-02-13 17:42:16 +00:00
2020-05-20 17:26:45 +00:00
2021-06-29 19:00:14 +00:00
if ( USE_JEMALLOC AND NOT STATIC_LINK )
pkg_check_modules ( JEMALLOC jemalloc IMPORTED_TARGET )
if ( JEMALLOC_FOUND )
2023-10-23 22:58:58 +00:00
target_link_libraries ( lokinet-base INTERFACE PkgConfig::JEMALLOC )
2021-06-29 19:00:14 +00:00
else ( )
message ( STATUS "jemalloc not found, not linking to jemalloc" )
endif ( )
else ( )
message ( STATUS "jemalloc support disabled" )
endif ( )
2018-11-06 14:06:09 +00:00
if ( ANDROID )
2023-10-23 22:58:58 +00:00
target_link_libraries ( lokinet-base INTERFACE log )
target_compile_definitions ( lokinet-base INTERFACE ANDROID )
2019-04-08 14:27:55 +00:00
set ( ANDROID_PLATFORM_SRC android/ifaddrs.c )
2020-05-17 19:41:48 +00:00
endif ( )
2018-11-19 13:39:35 +00:00
2020-02-27 19:43:16 +00:00
if ( WITH_HIVE )
2022-06-21 21:57:36 +00:00
add_definitions ( -DLOKINET_HIVE )
2020-02-27 19:43:16 +00:00
endif ( )
2019-02-09 16:16:00 +00:00
add_subdirectory ( crypto )
add_subdirectory ( llarp )
2021-09-20 20:16:46 +00:00
if ( BUILD_DAEMON )
add_subdirectory ( daemon )
endif ( )
2021-05-14 17:07:44 +00:00
2020-04-18 19:58:41 +00:00
if ( WITH_HIVE )
add_subdirectory ( pybind )
endif ( )
2022-06-22 14:08:07 +00:00
if ( WITH_TESTS OR WITH_HIVE )
add_subdirectory ( test )
endif ( )
if ( ANDROID )
add_subdirectory ( jni )
2019-02-09 16:16:00 +00:00
endif ( )
2020-01-10 19:59:45 +00:00
2020-03-27 15:04:13 +00:00
add_subdirectory ( docs )
2022-07-25 21:12:33 +00:00
include ( cmake/gui.cmake )
2022-08-12 22:57:00 +00:00
if ( APPLE )
macos_target_setup ( )
endif ( )
2020-09-09 16:06:57 +00: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 ( )
2022-07-28 16:07:38 +00:00
if ( BUILD_PACKAGE AND NOT APPLE )
include ( cmake/installer.cmake )
endif ( )
if ( TARGET package )
add_dependencies ( package assemble_gui )
2020-04-18 21:50:07 +00:00
endif ( )