2018-11-06 14:27:25 +00:00
|
|
|
# Lowest version - android ndk 3.6.0
|
|
|
|
cmake_minimum_required(VERSION 3.6.0)
|
2018-05-16 13:56:51 +00:00
|
|
|
|
2018-08-12 17:22:29 +00:00
|
|
|
set(PROJECT_NAME lokinet)
|
2018-10-23 11:29:37 +00:00
|
|
|
project(${PROJECT_NAME} C CXX ASM)
|
2018-06-14 14:04:42 +00:00
|
|
|
|
2019-02-09 16:16:00 +00:00
|
|
|
# Core options
|
2018-11-06 22:48:17 +00:00
|
|
|
option(USE_AVX2 "enable avx2 code" )
|
2019-01-19 03:08:32 +00:00
|
|
|
option(USE_NETNS "enable networking namespace support. Linux only" )
|
2019-03-05 22:05:00 +00:00
|
|
|
option(AMD_RYZEN_HACK "hack for AMD Ryzen FPU bug (support FMA3 and FMA4 in FPU, but does not show in CPUID)" )
|
2019-02-06 03:11:09 +00:00
|
|
|
option(STATIC_LINK_RUNTIME "link statically against compiler runtime, standard library and pthreads")
|
2018-12-13 23:16:44 +00:00
|
|
|
option(NON_PC_TARGET "non-pc target build: iphone, andriod, embedded non-i386 SBC, etc" )
|
2018-12-12 04:51:22 +00:00
|
|
|
option(SHADOW "use shadow testing framework. linux only" )
|
|
|
|
option(ASAN "use address sanitiser, if your system has it" )
|
|
|
|
option(JEMALLOC "use jemalloc. Not required on BSD" )
|
|
|
|
option(DEBIAN "build for debian" )
|
|
|
|
option(TESTNET "testnet build" )
|
2019-01-08 22:30:21 +00:00
|
|
|
option(WITH_SHARED "build shared library")
|
2019-01-12 01:19:24 +00:00
|
|
|
option(WITH_COVERAGE "generate coverage data")
|
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)
|
2018-06-15 13:42:49 +00:00
|
|
|
|
2019-02-09 16:16:00 +00:00
|
|
|
# Basic definitions
|
|
|
|
get_filename_component(CORE_INCLUDE include ABSOLUTE)
|
2019-03-02 02:01:04 +00:00
|
|
|
get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/${ABYSS}/include" ABSOLUTE)
|
2019-02-09 16:16:00 +00:00
|
|
|
|
2019-02-09 12:38:49 +00:00
|
|
|
find_program(CCACHE_PROGRAM ccache)
|
|
|
|
if(CCACHE_PROGRAM)
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
|
|
|
|
endif()
|
|
|
|
|
2019-03-24 00:40:19 +00:00
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
|
|
|
|
# check if we have the (saner) emulation of epoll here
|
2019-03-29 22:14:22 +00:00
|
|
|
# it's basically linux epoll but with a sane method of
|
2019-03-24 00:40:19 +00:00
|
|
|
# dealing with closed file handles that still exist in the
|
|
|
|
# epoll set
|
|
|
|
#
|
|
|
|
# Note that the zombie of Oracle Solaris 2.11.x will NOT have
|
|
|
|
# this, the header check is the only method we have to distinguish
|
|
|
|
# them. -rick the svr4 guy
|
2019-03-24 00:54:25 +00:00
|
|
|
set(SOLARIS ON)
|
2019-03-25 07:22:44 +00:00
|
|
|
option(USE_POLL "Revert to using poll(2) event loop (useful if targeting Oracle Solaris)" OFF)
|
2019-03-24 05:14:29 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lsocket -lnsl")
|
|
|
|
add_definitions(-D_POSIX_PTHREAD_SEMANTICS)
|
2019-03-24 00:40:19 +00:00
|
|
|
INCLUDE(CheckIncludeFiles)
|
|
|
|
CHECK_INCLUDE_FILES(sys/epoll.h SOLARIS_HAVE_EPOLL)
|
2019-03-25 07:22:44 +00:00
|
|
|
if (SOLARIS_HAVE_EPOLL AND NOT USE_POLL)
|
2019-03-24 00:54:25 +00:00
|
|
|
message(STATUS "Using fast emulation of Linux epoll(5) on Solaris.")
|
2019-03-26 22:12:28 +00:00
|
|
|
add_definitions(-DSOLARIS_HAVE_EPOLL)
|
2019-03-24 00:40:19 +00:00
|
|
|
else()
|
2019-03-26 22:12:28 +00:00
|
|
|
set(SOLARIS_HAVE_EPOLL OFF)
|
2019-03-25 07:22:44 +00:00
|
|
|
message(STATUS "Falling back to poll(2)-based event loop.")
|
2019-03-24 00:40:19 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-12-03 14:39:30 +00:00
|
|
|
if(WIN32)
|
2019-04-11 15:17:58 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2018-12-25 02:38:43 +00:00
|
|
|
ENABLE_LANGUAGE(RC)
|
2019-03-06 04:44:43 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lshlwapi")
|
2018-12-03 14:39:30 +00:00
|
|
|
else()
|
2019-01-13 14:10:38 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(WIN32)
|
|
|
|
|
2018-10-28 18:57:04 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
2018-06-15 13:42:49 +00:00
|
|
|
|
2018-12-12 04:51:22 +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" )
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND SHADOW)
|
2018-12-03 14:39:30 +00:00
|
|
|
|
2019-02-06 03:11:09 +00:00
|
|
|
if (WIN32 AND NOT STATIC_LINK_RUNTIME)
|
2019-02-01 21:26:49 +00:00
|
|
|
message("must ship compiler runtime libraries with this build: libwinpthread-1.dll, libgcc_s_dw2-1.dll, and libstdc++-6.dll")
|
2019-02-06 03:11:09 +00:00
|
|
|
message("for release builds, turn on STATIC_LINK_RUNTIME in cmake options")
|
|
|
|
endif(WIN32 AND NOT STATIC_LINK_RUNTIME)
|
2019-01-19 03:20:24 +00:00
|
|
|
|
2019-03-02 02:01:04 +00:00
|
|
|
add_subdirectory(vendor/nlohmann)
|
|
|
|
|
2019-02-06 16:13:58 +00:00
|
|
|
# still need the headers unconditionally
|
2019-02-03 02:13:31 +00:00
|
|
|
set(ABSEIL_DIR vendor/abseil-cpp)
|
2019-02-01 21:26:49 +00:00
|
|
|
if (NOT WIN32)
|
2019-02-09 16:16:00 +00:00
|
|
|
add_compile_options(-fPIC)
|
2019-02-01 21:26:49 +00:00
|
|
|
endif(NOT WIN32)
|
2019-02-05 21:19:20 +00:00
|
|
|
|
2018-10-28 02:07:25 +00:00
|
|
|
# turns off those annoying warnings for
|
|
|
|
# target-specific crypto code paths not
|
|
|
|
# applicable to the host's FPU -rick
|
2019-03-19 00:22:37 +00:00
|
|
|
if (WARNINGS_AS_ERRORS)
|
|
|
|
add_compile_options(-Werror)
|
|
|
|
endif()
|
2019-03-24 00:54:25 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
add_compile_options(-Wno-unknown-warning-option)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_compile_options(-Wall -Wextra -Wno-unknown-pragmas)
|
2018-11-09 12:25:14 +00:00
|
|
|
# vla are evil
|
|
|
|
add_compile_options(-Wvla)
|
2018-10-28 02:07:25 +00:00
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fpermissive>)
|
2018-11-02 07:56:42 +00:00
|
|
|
add_compile_options(-Wno-unused-function -Wno-deprecated-declarations -Wno-unknown-pragmas)
|
2018-09-07 20:54:50 +00:00
|
|
|
|
2019-03-24 00:54:25 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2019-03-12 10:13:33 +00:00
|
|
|
add_compile_options(-Wthread-safety)
|
2019-03-03 20:51:47 +00:00
|
|
|
endif()
|
|
|
|
|
2019-01-12 01:19:24 +00:00
|
|
|
if (WITH_COVERAGE)
|
2019-03-24 00:54:25 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2019-01-12 01:19:24 +00:00
|
|
|
add_compile_options( -fprofile-instr-generate -fcoverage-mapping )
|
|
|
|
link_libraries( -fprofile-instr-generate )
|
|
|
|
else()
|
|
|
|
add_compile_options( --coverage -g0 )
|
|
|
|
link_libraries( --coverage )
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
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)
|
2018-11-08 01:03:05 +00:00
|
|
|
# dynamic linking does this all the time
|
2019-03-24 00:54:25 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2019-03-19 04:09:29 +00:00
|
|
|
option(NO_LIBGCC "use libunwind+compiler-rt instead, must already be installed in mingw-w64 sysroot" OFF)
|
2018-12-12 04:51:22 +00:00
|
|
|
add_compile_options(-Wno-unused-command-line-argument -Wno-c++11-narrowing)
|
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-bad-function-cast>)
|
|
|
|
if (NO_LIBGCC)
|
2019-03-19 04:09:29 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_LIBRARIES "-lunwind -lpsapi ${CMAKE_CXX_STANDARD_LIBRARIES}")
|
|
|
|
set(CMAKE_C_STANDARD_LIBRARIES "-lunwind -lpsapi ${CMAKE_C_STANDARD_LIBRARIES}")
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(NO_LIBGCC)
|
|
|
|
else()
|
|
|
|
# found it. this is GNU only
|
|
|
|
add_compile_options(-Wno-cast-function-type)
|
2019-03-24 00:54:25 +00:00
|
|
|
endif()
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE)
|
2018-11-19 13:39:35 +00:00
|
|
|
|
2018-11-08 16:50:34 +00:00
|
|
|
if(WIN32)
|
2018-12-12 04:51:22 +00:00
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-bad-function-cast>)
|
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-cast-function-type>)
|
2019-02-01 19:41:17 +00:00
|
|
|
# unlike unix where you get a *single* compiler ID string in .comment
|
|
|
|
# GNU ld sees fit to merge *all* the .ident sections in object files
|
|
|
|
# to .r[o]data section one after the other!
|
|
|
|
add_compile_options(-fno-ident)
|
2018-12-12 04:51:22 +00:00
|
|
|
set(FS_LIB stdc++fs)
|
2018-11-08 16:50:34 +00:00
|
|
|
endif(WIN32)
|
|
|
|
|
2018-08-09 13:55:51 +00:00
|
|
|
if(DEBIAN)
|
|
|
|
add_definitions(-DDEBIAN)
|
2019-02-09 16:16:00 +00:00
|
|
|
elseif(NOT ANDROID AND NOT NON_PC_TARGET)
|
|
|
|
if (NOT USE_AVX2)
|
2019-03-21 02:13:14 +00:00
|
|
|
# Public binary releases
|
|
|
|
set(CRYPTO_FLAGS -march=nocona -mtune=core2 -mfpmath=sse)
|
2019-02-09 16:16:00 +00:00
|
|
|
else()
|
|
|
|
set(CRYPTO_FLAGS -march=haswell -mtune=native -mfpmath=sse)
|
|
|
|
endif()
|
|
|
|
endif()
|
2018-12-12 04:51:22 +00:00
|
|
|
|
2019-03-05 22:05:00 +00:00
|
|
|
# only needed if using AVX2
|
|
|
|
if(AMD_RYZEN_HACK AND USE_AVX2)
|
|
|
|
set(CRYPTO_FLAGS -march=native -mfpmath=sse -mavx -mavx2 -mfma)
|
|
|
|
message(WARNING "This option may be removed in a future release. Contact your computer manufacturer for updated ROMs or microcode patches.")
|
|
|
|
endif(AMD_RYZEN_HACK AND USE_AVX2)
|
|
|
|
|
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
|
|
|
|
2019-03-24 00:54:25 +00:00
|
|
|
# not supported on Solaris - system libraries are not available as archives
|
2019-02-06 03:11:09 +00:00
|
|
|
if(STATIC_LINK_RUNTIME)
|
2019-03-24 00:54:25 +00:00
|
|
|
if (NOT SOLARIS)
|
2019-03-29 22:14:22 +00:00
|
|
|
add_compile_options(-static)
|
2019-03-24 00:54:25 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libstdc++ -pthread" )
|
|
|
|
else()
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive" )
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
|
|
|
endif()
|
2018-11-19 13:39:35 +00:00
|
|
|
else()
|
2019-03-24 00:54:25 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc" )
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
|
|
|
|
endif()
|
2019-02-06 03:11:09 +00:00
|
|
|
endif(STATIC_LINK_RUNTIME)
|
2018-06-15 13:42:49 +00:00
|
|
|
|
2018-11-19 13:39:35 +00:00
|
|
|
if(USE_NETNS)
|
|
|
|
add_definitions(-DNETNS=1)
|
|
|
|
else()
|
|
|
|
add_definitions(-DNETNS=0)
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(USE_NETNS)
|
2018-06-06 17:02:57 +00:00
|
|
|
|
2018-10-21 14:19:49 +00:00
|
|
|
if(TESTNET)
|
|
|
|
add_definitions(-DTESTNET=1)
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(TESTNET)
|
2018-10-21 14:19:49 +00:00
|
|
|
|
2018-11-13 15:16:14 +00:00
|
|
|
if(NOT DEBIAN)
|
2018-12-12 04:51:22 +00:00
|
|
|
set(OPTIMIZE_FLAGS -O3)
|
|
|
|
set(DEBUG_FLAGS -O0 -g3)
|
|
|
|
endif(NOT DEBIAN)
|
2018-06-15 13:42:49 +00:00
|
|
|
|
2018-05-27 16:45:04 +00:00
|
|
|
if(ASAN)
|
2019-04-02 09:03:53 +00:00
|
|
|
set(DEBUG_FLAGS ${DEBUG_FLAGS} -fsanitize=address -fno-omit-frame-pointer)
|
2018-06-01 17:47:37 +00:00
|
|
|
set(OPTIMIZE_FLAGS "-O0")
|
2018-05-27 16:45:04 +00:00
|
|
|
endif(ASAN)
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2018-06-06 12:59:15 +00:00
|
|
|
if(SHADOW)
|
2019-03-05 16:21:56 +00:00
|
|
|
set(WITH_STATIC OFF)
|
2019-03-11 13:01:43 +00:00
|
|
|
set(WITH_SHARED ON)
|
2018-06-06 17:02:57 +00:00
|
|
|
if("${SHADOW_ROOT}" STREQUAL "")
|
|
|
|
set(SHADOW_ROOT "$ENV{HOME}/.shadow")
|
|
|
|
endif("${SHADOW_ROOT}" STREQUAL "")
|
|
|
|
if(EXISTS "${SHADOW_ROOT}")
|
|
|
|
message(STATUS "SHADOW_ROOT = ${SHADOW_ROOT}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "SHADOW_ROOT path does not exist: '${SHADOW_ROOT}'")
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(EXISTS "${SHADOW_ROOT}")
|
|
|
|
|
2018-06-06 17:02:57 +00:00
|
|
|
set(CMAKE_MODULE_PATH "${SHADOW_ROOT}/share/cmake/Modules")
|
|
|
|
include_directories(${CMAKE_MODULE_PATH})
|
|
|
|
include(ShadowTools)
|
2019-03-11 13:01:43 +00:00
|
|
|
add_compile_options(-fno-inline -fno-strict-aliasing )
|
|
|
|
add_definitions(-DTESTNET=1)
|
2018-06-06 17:02:57 +00:00
|
|
|
add_definitions(-DSHADOW_TESTNET)
|
|
|
|
include_directories(${SHADOW_ROOT}/include)
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(SHADOW)
|
2018-06-01 17:47:37 +00:00
|
|
|
|
2018-09-20 19:24:13 +00:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
|
|
|
|
set(OPTIMIZE_FLAGS "")
|
2019-03-03 15:01:05 +00:00
|
|
|
add_definitions(-DLOKINET_DEBUG=1)
|
2019-03-05 15:06:14 +00:00
|
|
|
set(CRYPTO_FLAGS "")
|
|
|
|
add_compile_options( ${DEBUG_FLAGS} )
|
2019-01-03 21:25:09 +00:00
|
|
|
link_libraries( ${DEBUG_FLAGS} )
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
|
2018-09-20 19:24:13 +00:00
|
|
|
|
2018-12-13 23:16:44 +00:00
|
|
|
# Add non-386 target-specific options here
|
|
|
|
if(NON_PC_TARGET)
|
2018-11-08 12:31:50 +00:00
|
|
|
add_definitions(-DRPI)
|
|
|
|
set(WITH_STATIC ON)
|
2018-12-13 23:16:44 +00:00
|
|
|
endif(NON_PC_TARGET)
|
2018-10-23 11:29:37 +00:00
|
|
|
|
2018-11-02 07:51:33 +00:00
|
|
|
add_compile_options(${OPTIMIZE_FLAGS} ${CRYPTO_FLAGS})
|
2018-06-15 13:42:49 +00:00
|
|
|
|
2018-05-28 13:49:44 +00:00
|
|
|
if(NOT GIT_VERSION)
|
|
|
|
exec_program("git" ${CMAKE_CURRENT_SOURCE_DIR} ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_VERSION)
|
|
|
|
add_definitions(-DGIT_REV="${GIT_VERSION}")
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(NOT GIT_VERSION)
|
2018-05-28 13:49:44 +00:00
|
|
|
|
|
|
|
if(RELEASE_MOTTO)
|
|
|
|
add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}")
|
2019-01-19 03:08:32 +00:00
|
|
|
if(WIN32)
|
|
|
|
add_definitions(-DRELEASE_MOTTO=${RELEASE_MOTTO})
|
|
|
|
endif(WIN32)
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(RELEASE_MOTTO)
|
2018-05-28 13:49:44 +00:00
|
|
|
|
2018-08-12 17:22:29 +00:00
|
|
|
set(EXE lokinet)
|
2018-07-09 04:09:54 +00:00
|
|
|
set(EXE_SRC daemon/main.cpp)
|
2018-05-16 13:56:51 +00:00
|
|
|
|
2018-09-20 19:24:13 +00:00
|
|
|
# HeapAlloc(2) on Windows was significantly revamped in 2009
|
|
|
|
# but the old algorithm isn't too bad either
|
|
|
|
# this is _the_ system allocator on BSD UNIX
|
|
|
|
# openbsd replaced it with a secure/randomised malloc not too
|
|
|
|
# long ago
|
2018-09-06 11:46:19 +00:00
|
|
|
if(JEMALLOC)
|
|
|
|
set(MALLOC_LIB jemalloc)
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(JEMALLOC)
|
2018-09-19 12:22:34 +00:00
|
|
|
|
2019-01-05 13:45:05 +00:00
|
|
|
|
2018-10-28 02:07:25 +00:00
|
|
|
# FS_LIB should resolve to nothing on all other platforms
|
|
|
|
# it is only required on win32 -rick
|
2019-02-09 16:16:00 +00:00
|
|
|
set(LIBS ${MALLOC_LIB} ${FS_LIB})
|
2018-05-22 18:41:38 +00:00
|
|
|
|
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)
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(ANDROID)
|
2018-11-19 13:39:35 +00:00
|
|
|
|
2018-07-30 04:38:14 +00:00
|
|
|
set(LIB lokinet)
|
2019-01-08 22:30:21 +00:00
|
|
|
set(SHARED_LIB ${LIB}-shared)
|
2018-05-27 18:03:10 +00:00
|
|
|
set(STATIC_LIB ${LIB}-static)
|
2018-10-23 11:45:14 +00:00
|
|
|
set(CRYPTOGRAPHY_LIB ${LIB}-cryptography)
|
2019-01-10 19:41:51 +00:00
|
|
|
set(UTIL_LIB ${LIB}-util)
|
2018-10-23 11:45:14 +00:00
|
|
|
set(PLATFORM_LIB ${LIB}-platform)
|
|
|
|
set(ANDROID_LIB ${LIB}android)
|
2019-02-15 22:19:19 +00:00
|
|
|
set(ABYSS libabyss)
|
|
|
|
set(ABYSS_LIB abyss)
|
|
|
|
set(ABYSS_EXE ${ABYSS_LIB}-main)
|
2019-02-09 16:16:00 +00:00
|
|
|
get_filename_component(TT_ROOT "vendor/libtuntap-master" ABSOLUTE)
|
2018-06-29 12:14:20 +00:00
|
|
|
add_definitions(-D${CMAKE_SYSTEM_NAME})
|
2018-07-30 04:38:14 +00:00
|
|
|
|
2019-02-11 00:02:20 +00:00
|
|
|
function(add_import_library libname)
|
|
|
|
add_library(libname SHARED IMPORTED)
|
|
|
|
if(NOT TARGET libname)
|
|
|
|
message(FATAL "unable to find library ${libname}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2018-12-12 04:51:22 +00:00
|
|
|
if(UNIX)
|
2018-09-04 12:41:25 +00:00
|
|
|
add_definitions(-DUNIX)
|
|
|
|
add_definitions(-DPOSIX)
|
2018-12-10 14:20:35 +00:00
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
2019-02-09 16:16:00 +00:00
|
|
|
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_epoll.cpp" ABSOLUTE)
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
|
|
|
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_epoll.cpp" ABSOLUTE)
|
|
|
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
|
|
|
|
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
|
|
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
|
|
|
|
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
|
|
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
|
|
|
|
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
|
|
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
|
|
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c)
|
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_kqueue.cpp" ABSOLUTE)
|
|
|
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
|
|
|
|
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c)
|
2019-03-24 00:54:25 +00:00
|
|
|
if (SOLARIS_HAVE_EPOLL)
|
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_epoll.cpp" ABSOLUTE)
|
|
|
|
else()
|
2019-03-26 21:07:16 +00:00
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_sun.cpp" ABSOLUTE)
|
2019-03-24 00:54:25 +00:00
|
|
|
endif()
|
2019-02-09 16:16:00 +00:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Your operating system is not supported yet")
|
|
|
|
endif()
|
2018-08-24 18:40:56 +00:00
|
|
|
elseif(WIN32)
|
2019-02-14 00:22:21 +00:00
|
|
|
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-windows.c ABSOLUTE)
|
2019-02-09 16:16:00 +00:00
|
|
|
get_filename_component(EV_SRC "llarp/ev/ev_win32.cpp" ABSOLUTE)
|
2018-11-19 07:55:19 +00:00
|
|
|
add_definitions(-DWIN32_LEAN_AND_MEAN -DWIN32 -DWINVER=0x500 -D_WIN32_WINNT=0x500)
|
2018-07-30 04:38:14 +00:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "What operating system _are_ you building on/for?")
|
2018-06-29 12:14:20 +00:00
|
|
|
endif(UNIX)
|
|
|
|
|
2018-08-15 15:36:34 +00:00
|
|
|
set(LIBTUNTAP_SRC_BASE
|
2018-08-20 19:12:12 +00:00
|
|
|
${TT_ROOT}/tuntap.cpp
|
2018-08-08 19:37:33 +00:00
|
|
|
${TT_ROOT}/tuntap_log.cpp
|
|
|
|
${LIBTUNTAP_IMPL})
|
2018-09-24 10:25:29 +00:00
|
|
|
|
2019-02-09 16:16:00 +00:00
|
|
|
if(UNIX)
|
|
|
|
set(LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix.c ${LIBTUNTAP_SRC_BASE})
|
2018-09-29 08:16:54 +00:00
|
|
|
else()
|
2018-12-12 04:51:22 +00:00
|
|
|
set(LIBTUNTAP_SRC ${LIBTUNTAP_SRC_BASE})
|
2018-09-29 08:16:54 +00:00
|
|
|
endif(UNIX)
|
2018-07-13 13:14:42 +00:00
|
|
|
|
2018-10-23 15:50:22 +00:00
|
|
|
if(NOT WIN32)
|
2019-02-09 16:16:00 +00:00
|
|
|
add_subdirectory(vendor)
|
2018-10-23 15:50:22 +00:00
|
|
|
endif(NOT WIN32)
|
2018-08-26 12:51:22 +00:00
|
|
|
|
2019-02-15 20:49:10 +00:00
|
|
|
function(add_log_tag target)
|
|
|
|
get_target_property(TARGET_SRCS ${target} SOURCES)
|
|
|
|
foreach(F ${TARGET_SRCS})
|
|
|
|
set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\")
|
|
|
|
endforeach(F)
|
|
|
|
endfunction()
|
|
|
|
|
2019-02-19 09:43:17 +00:00
|
|
|
set(ABYSS_SRC
|
2019-03-13 20:01:10 +00:00
|
|
|
${ABYSS}/src/md5.cpp
|
2019-02-19 09:43:17 +00:00
|
|
|
${ABYSS}/src/http.cpp
|
|
|
|
${ABYSS}/src/client.cpp
|
|
|
|
${ABYSS}/src/server.cpp)
|
|
|
|
add_library(${ABYSS_LIB} STATIC ${ABYSS_SRC})
|
2019-02-15 22:19:19 +00:00
|
|
|
|
2019-03-24 04:38:06 +00:00
|
|
|
add_subdirectory(${ABSEIL_DIR})
|
|
|
|
include_directories(${ABSEIL_DIR})
|
|
|
|
|
2019-02-09 16:16:00 +00:00
|
|
|
add_subdirectory(crypto)
|
|
|
|
add_subdirectory(libutp)
|
|
|
|
add_subdirectory(llarp)
|
2018-05-16 13:56:51 +00:00
|
|
|
|
2019-02-19 09:43:17 +00:00
|
|
|
target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB})
|
2019-02-15 22:19:19 +00:00
|
|
|
|
2019-02-19 09:43:17 +00:00
|
|
|
if (NOT WIN32)
|
|
|
|
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp)
|
2019-04-08 12:01:52 +00:00
|
|
|
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads)
|
2019-02-19 09:43:17 +00:00
|
|
|
else()
|
|
|
|
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp llarp/win32/abyss.rc)
|
|
|
|
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
|
|
|
|
endif(NOT WIN32)
|
|
|
|
target_include_directories(${ABYSS_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
|
|
|
|
target_include_directories(${ABYSS_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include")
|
|
|
|
# for freebsd
|
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
|
|
|
target_include_directories(${ABYSS_LIB} /usr/local/include)
|
|
|
|
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
|
|
|
add_log_tag(${ABYSS_EXE})
|
|
|
|
add_log_tag(${ABYSS_LIB})
|
2019-02-15 22:19:19 +00:00
|
|
|
|
2019-03-11 13:01:43 +00:00
|
|
|
if (WIN32)
|
|
|
|
set(EXE_LIBS ${STATIC_LIB} ws2_32 iphlpapi)
|
|
|
|
else()
|
|
|
|
set(EXE_LIBS ${STATIC_LIB} cppbackport libutp)
|
|
|
|
endif(WIN32)
|
|
|
|
|
|
|
|
|
2018-06-06 12:59:15 +00:00
|
|
|
if(SHADOW)
|
2019-03-11 13:01:43 +00:00
|
|
|
set(LOKINET_SHADOW shadow-plugin-${SHARED_LIB})
|
|
|
|
set(LOKINET_SHADOW_LIBS ${SHARED_LIB})
|
|
|
|
add_shadow_plugin(${LOKINET_SHADOW} ${EXE_SRC})
|
|
|
|
target_link_libraries(${LOKINET_SHADOW} ${LOKINET_SHADOW_LIBS})
|
|
|
|
target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include ${PROJECT_SOURCE_DIR}/vendor/cppbackport-master/lib)
|
2018-06-06 17:02:57 +00:00
|
|
|
else()
|
2019-01-19 03:08:32 +00:00
|
|
|
if(NOT WIN32)
|
|
|
|
add_executable(${EXE} ${EXE_SRC})
|
|
|
|
else()
|
2019-02-02 08:51:33 +00:00
|
|
|
add_executable(${EXE} ${EXE_SRC} llarp/win32/version.rc)
|
2019-01-19 03:08:32 +00:00
|
|
|
endif(NOT WIN32)
|
2019-01-15 00:42:50 +00:00
|
|
|
|
2019-02-15 20:49:10 +00:00
|
|
|
add_log_tag(${EXE})
|
|
|
|
|
2018-12-12 04:51:22 +00:00
|
|
|
install(TARGETS ${EXE} RUNTIME DESTINATION bin)
|
2018-12-16 22:31:32 +00:00
|
|
|
if(WIN32)
|
2018-12-17 04:07:00 +00:00
|
|
|
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin)
|
2018-12-16 22:31:32 +00:00
|
|
|
else()
|
2018-12-17 04:07:00 +00:00
|
|
|
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin)
|
2018-12-16 22:31:32 +00:00
|
|
|
endif()
|
2019-01-19 03:08:32 +00:00
|
|
|
|
2018-12-16 22:28:09 +00:00
|
|
|
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)")
|
|
|
|
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
2018-10-19 11:41:36 +00:00
|
|
|
|
2019-03-11 13:01:43 +00:00
|
|
|
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS})
|
2019-01-08 22:30:21 +00:00
|
|
|
|
2018-08-05 23:48:59 +00:00
|
|
|
if(ANDROID)
|
2018-09-03 11:41:04 +00:00
|
|
|
add_library(${ANDROID_LIB} SHARED jni/lokinet_android.cpp)
|
2019-04-08 15:54:19 +00:00
|
|
|
set_property(TARGET ${ANDROID_LIB} PROPERTY CXX_STANDARD 14)
|
2019-02-15 20:49:10 +00:00
|
|
|
add_log_tag(${ANDROID_LIB})
|
2018-11-06 14:06:09 +00:00
|
|
|
target_link_libraries(${ANDROID_LIB} ${STATIC_LIB} ${LIBS})
|
2018-12-12 04:51:22 +00:00
|
|
|
endif(ANDROID)
|
2019-01-22 23:58:24 +00:00
|
|
|
endif(SHADOW)
|
2019-02-09 16:16:00 +00:00
|
|
|
|
|
|
|
enable_testing()
|
|
|
|
|
|
|
|
if (NOT SHADOW)
|
|
|
|
add_subdirectory(test)
|
|
|
|
endif()
|