mirror of https://github.com/oxen-io/lokinet
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
parent
ab4ee954b9
commit
c5faa86926
@ -1,8 +1,6 @@
|
||||
function(add_log_tag target)
|
||||
if(TARGET ${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)
|
||||
endif()
|
||||
get_target_property(TARGET_SRCS ${target} SOURCES)
|
||||
foreach(F ${TARGET_SRCS})
|
||||
set_property(SOURCE ${F} APPEND PROPERTY COMPILE_DEFINITIONS LOG_TAG=\"${F}\")
|
||||
endforeach()
|
||||
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)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# 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)
|
||||
if(STATIC_LINK)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
link_libraries( -static-libstdc++ )
|
||||
else()
|
||||
link_libraries( -static -static-libstdc++ -pthread -flto )
|
||||
link_libraries( -static-libstdc++ -static-libgcc )
|
||||
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()
|
||||
|
@ -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)
|
||||
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)
|
||||
add_shadow_plugin(shadow-plugin main.cpp ${TRACY_ROOT}/TracyClient.cpp)
|
||||
target_link_libraries(shadow-plugin liblokinet)
|
||||
enable_lto(shadow-plugin)
|
||||
else()
|
||||
if(WIN32 AND NOT MSVC_VERSION)
|
||||
list(APPEND EXE_SRC ../llarp/win32/version.rc)
|
||||
list(APPEND CTL_SRC ../llarp/win32/version.rc)
|
||||
endif()
|
||||
|
||||
add_executable(${EXE} ${EXE_SRC})
|
||||
add_executable(${CTL} ${CTL_SRC})
|
||||
add_executable(lokinet main.cpp)
|
||||
add_executable(lokinetctl lokinetctl.cpp)
|
||||
enable_lto(lokinet lokinetctl)
|
||||
|
||||
target_compile_definitions(${EXE} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL})
|
||||
target_compile_definitions(${CTL} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL})
|
||||
|
||||
add_log_tag(${EXE})
|
||||
add_log_tag(${CTL})
|
||||
if(TRACY_ROOT)
|
||||
target_sources(lokinet PRIVATE ${TRACY_ROOT}/TracyClient.cpp)
|
||||
endif()
|
||||
|
||||
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)
|
||||
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.ps1 DESTINATION bin COMPONENT lokinet)
|
||||
else()
|
||||
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin COMPONENT lokinet)
|
||||
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)")
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
target_link_directories(${EXE} PRIVATE /usr/local/lib)
|
||||
target_link_directories(${CTL} PRIVATE /usr/local/lib)
|
||||
endif()
|
||||
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS} ${CRYPTOGRAPHY_LIB})
|
||||
target_link_libraries(${CTL} PUBLIC ${EXE_LIBS} ${LIBS} ${CRYPTOGRAPHY_LIB})
|
||||
|
||||
if(CURL_FOUND)
|
||||
target_include_directories(${CTL} PRIVATE ${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(${CTL} PRIVATE ${CURL_LIBRARIES})
|
||||
target_include_directories(lokinetctl PRIVATE ${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(lokinetctl PRIVATE ${CURL_LIBRARIES})
|
||||
endif(CURL_FOUND)
|
||||
|
||||
endif(SHADOW)
|
||||
endif()
|
||||
|
@ -1,10 +1,6 @@
|
||||
|
||||
set(ANDROID_SRC
|
||||
lokinet_config.cpp
|
||||
lokinet_daemon.cpp
|
||||
lokinet_vpn.cpp
|
||||
)
|
||||
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})
|
||||
add_library(lokinet-android
|
||||
lokinet_config.cpp
|
||||
lokinet_daemon.cpp
|
||||
lokinet_vpn.cpp)
|
||||
add_log_tag(lokinet-android)
|
||||
target_link_libraries(lokinet-android liblokinet)
|
||||
|
@ -1,14 +1,20 @@
|
||||
add_library(${ABYSS_LIB} "${CMAKE_CURRENT_SOURCE_DIR}/src/md5.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/http.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/client.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp")
|
||||
add_library(abyss
|
||||
src/md5.cpp
|
||||
src/http.cpp
|
||||
src/client.cpp
|
||||
src/server.cpp)
|
||||
|
||||
target_include_directories(${ABYSS_LIB} PUBLIC include)
|
||||
target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB})
|
||||
target_include_directories(abyss PUBLIC include)
|
||||
target_link_libraries(abyss PUBLIC lokinet-platform)
|
||||
enable_lto(abyss)
|
||||
|
||||
# for freebsd
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include)
|
||||
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
target_include_directories(abyss SYSTEM PUBLIC /usr/local/include)
|
||||
endif()
|
||||
|
||||
add_log_tag(${ABYSS_LIB})
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(TARGETS abyss LIBRARY DESTINATION lib)
|
||||
endif()
|
||||
|
||||
add_log_tag(abyss)
|
||||
|
@ -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…
Reference in New Issue