2020-04-18 18:02:22 +00:00
cmake_minimum_required ( VERSION 3.10 ) # bionic's cmake version
2018-05-16 13:56:51 +00:00
2020-05-20 02:14:21 +00:00
# Has to be set before `project()`, and ignored on non-macos:
2020-06-11 11:44:02 +00:00
set ( CMAKE_OSX_DEPLOYMENT_TARGET 10.14 CACHE STRING "macOS deployment target (Apple clang only)" )
2020-04-21 23:00:37 +00:00
2019-06-26 21:39:29 +00:00
find_program ( CCACHE_PROGRAM ccache )
if ( CCACHE_PROGRAM )
2020-06-10 16:34:02 +00:00
foreach ( lang C CXX )
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 ( )
2018-08-12 17:22:29 +00:00
set ( PROJECT_NAME lokinet )
2020-04-18 18:02:22 +00:00
project ( ${ PROJECT_NAME }
2020-04-21 19:27:21 +00:00
V E R S I O N 0 . 7 . 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 "
L A N G U A G E S C C X X )
2018-06-14 14:04:42 +00:00
2020-04-20 02:13:39 +00:00
set ( RELEASE_MOTTO "I'll remember that..." CACHE STRING "Release motto" )
2020-04-18 18:02:22 +00: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 } )
2020-05-17 19:41:48 +00:00
if ( RELEASE_MOTTO )
add_definitions ( -DLLARP_RELEASE_MOTTO= "${RELEASE_MOTTO}" )
endif ( )
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" )
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 )
2019-11-05 11:45:49 +00:00
option ( EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF )
2020-05-17 19:41:48 +00:00
option ( BUILD_SHARED_LIBS "build lokinet libraries as shared libraries instead of static" ON )
2019-11-05 11:45:49 +00:00
option ( SHADOW "use shadow testing framework. linux only" OFF )
2020-05-17 19:41:48 +00:00
option ( XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF )
2020-05-21 14:18:23 +00:00
option ( WITH_JEMALLOC "use jemalloc as allocator" OFF )
2019-11-05 11:45:49 +00:00
option ( TESTNET "testnet build" OFF )
option ( WITH_COVERAGE "generate coverage data" OFF )
2019-07-29 12:14:35 +00:00
option ( USE_SHELLHOOKS "enable shell hooks on compile time (dangerous)" 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 )
2019-11-05 11:45:49 +00:00
option ( TRACY_ROOT "include tracy profiler source" OFF )
option ( WITH_TESTS "build unit tests" ON )
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 )
2020-05-15 13:12:00 +00:00
2020-06-15 20:25:28 +00: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 )
include ( StaticBuild )
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
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 )
set ( CMAKE_C_STANDARD 99 )
set ( CMAKE_C_STANDARD_REQUIRED ON )
set ( CMAKE_C_EXTENSIONS OFF )
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 )
include ( cmake/add_log_tag.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 ( )
2020-05-17 19:41:48 +00:00
add_definitions ( -D ${ CMAKE_SYSTEM_NAME } )
2019-02-09 16:16:00 +00:00
2019-04-29 23:48:43 +00:00
if ( MSVC_VERSION )
2019-04-19 18:24:33 +00:00
enable_language ( ASM_MASM )
list ( APPEND CMAKE_ASM_MASM_SOURCE_FILE_EXTENSIONS s )
2019-07-17 18:57:15 +00:00
add_definitions ( -D_WIN32_WINNT=0x0600 -DNOMINMAX -DSODIUM_STATIC )
2019-04-19 18:24:33 +00:00
else ( )
enable_language ( ASM )
2020-05-17 19:41:48 +00:00
endif ( )
2019-04-19 18:24:33 +00:00
2019-04-28 15:57:41 +00:00
include ( cmake/solaris.cmake )
2019-07-21 23:39:56 +00:00
include ( cmake/win32.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 )
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-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 )
find_package ( PkgConfig REQUIRED )
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 ( )
2020-06-16 11:34:57 +00:00
option ( FORCE_LOKIMQ_SUBMODULE "force using lokimq submodule" OFF )
if ( NOT FORCE_LOKIMQ_SUBMODULE )
find_package ( LokiMQ 1.2 )
endif ( )
if ( LokiMQ_FOUND )
message ( STATUS "using system lokimq" )
else ( )
message ( STATUS "using lokimq submodule" )
add_subdirectory ( ${ CMAKE_SOURCE_DIR } /external/loki-mq EXCLUDE_FROM_ALL )
endif ( )
2019-10-17 04:14:03 +00:00
# this is messing with release builds
add_compile_options ( -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 )
2020-05-17 19:41:48 +00:00
if ( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" AND SHADOW )
2019-01-19 03:20:24 +00:00
message ( FATAL_ERROR "shadow-framework is Linux only" )
2019-05-18 15:34:03 +00:00
endif ( )
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
if ( CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]" )
add_definitions ( -DLOKINET_DEBUG=1 )
2020-05-17 19:41:48 +00:00
endif ( )
2019-05-18 15:34:03 +00:00
2019-07-12 13:06:59 +00:00
if ( WITH_SHELLHOOKS )
add_definitions ( -DENABLE_SHELLHOOKS )
2020-05-17 19:41:48 +00:00
endif ( )
2019-08-26 23:10:48 +00:00
2019-10-07 10:08:47 +00:00
if ( TRACY_ROOT )
include_directories ( ${ TRACY_ROOT } )
add_definitions ( -DTRACY_ENABLE )
endif ( )
2019-03-02 02:01:04 +00:00
2019-03-24 00:54:25 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
add_compile_options ( -Wno-unknown-warning-option )
endif ( )
2019-04-19 18:24:33 +00:00
if ( NOT MSVC_VERSION )
add_compile_options ( -Wall -Wextra -Wno-unknown-pragmas )
# vla are evil
add_compile_options ( -Wvla )
add_compile_options ( $< $<COMPILE_LANGUAGE:CXX > :-fpermissive> )
add_compile_options ( -Wno-unused-function -Wno-deprecated-declarations -Wno-unknown-pragmas )
endif ( )
2018-09-07 20:54:50 +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
2020-05-17 22:21:00 +00:00
if ( NATIVE_BUILD )
2020-02-07 04:22:27 +00:00
if ( CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le )
2020-05-17 19:41:48 +00:00
add_compile_options ( -mcpu=native -mtune=native )
2020-02-07 04:22:27 +00:00
else ( )
2020-05-17 19:41:48 +00:00
add_compile_options ( -march=native -mtune=native )
2020-02-07 04:22:27 +00:00
endif ( )
2019-12-31 15:12:17 +00:00
elseif ( NOT NON_PC_TARGET )
2019-11-05 11:45:49 +00:00
if ( USE_AVX2 )
2020-05-17 19:41:48 +00:00
add_compile_options ( -march=haswell -mtune=haswell -mfpmath=sse )
2019-11-05 11:45:49 +00:00
else ( )
# Public binary releases
2020-05-17 19:41:48 +00:00
add_compile_options ( -march=nocona -mtune=haswell -mfpmath=sse )
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
2019-08-27 13:47:44 +00:00
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!" )
2020-05-17 19:41:48 +00:00
add_compile_options ( -march=i486 -mtune=i486 )
2019-08-27 13:47:44 +00:00
endif ( )
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-11-19 13:39:35 +00:00
if ( USE_NETNS )
add_definitions ( -DNETNS=1 )
else ( )
add_definitions ( -DNETNS=0 )
2020-05-17 19:41:48 +00:00
endif ( )
2018-06-06 17:02:57 +00:00
2018-10-21 14:19:49 +00:00
if ( TESTNET )
add_definitions ( -DTESTNET=1 )
2020-01-23 12:59:51 +00:00
# 5 times slower than realtime
add_definitions ( -DTESTNET_SPEED=5 )
2020-05-17 19:41:48 +00:00
endif ( )
2018-10-21 14:19:49 +00:00
2018-06-06 12:59:15 +00:00
if ( SHADOW )
2019-04-28 15:57:41 +00:00
include ( cmake/shadow.cmake )
2020-05-17 19:41:48 +00:00
endif ( )
2018-06-01 17:47:37 +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
pkg_check_modules ( SD libsystemd )
# Default WITH_SYSTEMD to true if we found it
option ( WITH_SYSTEMD "enable systemd integration for sd_notify" ${ SD_FOUND } )
if ( WITH_SYSTEMD )
if ( NOT SD_FOUND )
message ( FATAL_ERROR "libsystemd not found" )
endif ( )
add_definitions ( -DWITH_SYSTEMD )
include_directories ( ${ SD_INCLUDE_DIRS } )
set ( SD_LIBS ${ SD_LDFLAGS } )
2020-02-25 21:42:07 +00:00
endif ( )
2020-02-13 17:42:16 +00:00
option ( SUBMODULE_CHECK "Enables checking that vendored library submodules are up to date" ON )
if ( SUBMODULE_CHECK )
find_package ( Git )
if ( GIT_FOUND )
function ( check_submodule relative_path )
execute_process ( COMMAND git rev-parse "HEAD" WORKING_DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR } / ${ relative_path } OUTPUT_VARIABLE localHead )
execute_process ( COMMAND git rev-parse "HEAD:${relative_path}" WORKING_DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR } OUTPUT_VARIABLE checkedHead )
string ( COMPARE EQUAL "${localHead}" "${checkedHead}" upToDate )
if ( upToDate )
message ( STATUS "Submodule '${relative_path}' is up-to-date" )
else ( )
2020-02-18 00:22:13 +00:00
message ( FATAL_ERROR "Submodule '${relative_path}' is not up-to-date. Please update with\ngit submodule update --init --recursive\nor run cmake with -DSUBMODULE_CHECK=OFF" )
2020-02-13 17:42:16 +00:00
endif ( )
endfunction ( )
message ( STATUS "Checking submodules" )
check_submodule ( external/nlohmann )
2020-02-13 18:41:53 +00:00
check_submodule ( external/googletest )
2020-02-13 19:18:17 +00:00
check_submodule ( external/cxxopts )
2020-05-20 02:14:21 +00:00
check_submodule ( external/ghc-filesystem )
2020-02-22 23:01:36 +00:00
check_submodule ( external/date )
2020-01-17 13:22:08 +00:00
check_submodule ( external/pybind11 )
2020-05-20 17:26:45 +00:00
check_submodule ( external/sqlite_orm )
2020-05-19 01:53:17 +00:00
if ( NOT WIN32 ) # we grab libuv for windows separately in win32-setup/libuv. see note in cmake/win32.cmake.
check_submodule ( external/libuv )
endif ( )
2020-05-14 19:20:43 +00:00
check_submodule ( external/loki-mq )
2020-02-13 17:42:16 +00:00
endif ( )
endif ( )
2020-06-16 11:28:20 +00:00
if ( WITH_HIVE )
2020-05-19 02:11:37 +00:00
add_subdirectory ( external/pybind11 EXCLUDE_FROM_ALL )
endif ( )
2019-11-05 12:29:43 +00:00
if ( WITH_TESTS )
2020-02-13 18:41:53 +00:00
add_subdirectory ( external/googletest EXCLUDE_FROM_ALL )
2019-11-05 12:29:43 +00:00
endif ( )
2020-02-13 17:42:16 +00:00
set ( JSON_BuildTests OFF CACHE INTERNAL "" )
add_subdirectory ( external/nlohmann EXCLUDE_FROM_ALL )
2020-02-26 02:00:33 +00:00
add_subdirectory ( external/cxxopts EXCLUDE_FROM_ALL )
add_subdirectory ( external/date EXCLUDE_FROM_ALL )
2019-11-05 12:28:08 +00:00
2020-05-20 17:26:45 +00:00
include_directories ( SYSTEM external/sqlite_orm/include )
2020-05-17 19:41:48 +00:00
add_subdirectory ( vendor )
2018-11-06 14:06:09 +00:00
if ( ANDROID )
2019-02-09 16:16:00 +00:00
list ( APPEND LIBS log )
2018-12-12 04:51:22 +00:00
add_definitions ( -DANDROID )
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
2019-12-12 19:58:46 +00:00
set ( LIBS ${ MALLOC_LIB } ${ LIBUV_LIBRARY } ${ SD_LIBS } )
2019-09-03 15:56:56 +00:00
if ( TRACY_ROOT )
list ( APPEND LIBS -ldl )
endif ( )
2019-06-24 15:51:58 +00:00
2020-02-27 19:43:16 +00:00
if ( WITH_HIVE )
add_definitions ( -DLOKINET_HIVE=1 )
endif ( )
2019-02-09 16:16:00 +00:00
add_subdirectory ( crypto )
add_subdirectory ( llarp )
2019-10-05 15:03:25 +00:00
add_subdirectory ( daemon )
2020-04-18 19:58:41 +00:00
if ( WITH_HIVE )
add_subdirectory ( pybind )
endif ( )
2020-01-17 13:22:08 +00:00
2019-02-09 16:16:00 +00:00
2019-07-17 09:08:04 +00:00
if ( NOT SHADOW )
2020-03-03 04:15:18 +00:00
if ( WITH_TESTS OR WITH_HIVE )
2019-11-05 11:45:49 +00:00
add_subdirectory ( test )
endif ( )
2018-08-05 23:48:59 +00:00
if ( ANDROID )
2019-10-21 12:01:29 +00:00
add_subdirectory ( jni )
2020-05-17 19:41:48 +00:00
endif ( )
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 )
2020-04-18 21:50:07 +00:00
if ( BUILD_PACKAGE )
include ( cmake/installer.cmake )
endif ( )
2020-01-10 19:59:45 +00:00
2020-04-18 21:50:07 +00:00
if ( BUILD_PACKAGE )
include ( cmake/installer.cmake )
endif ( )