mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
add build option for constrained node ops and make sure everything is now target-optimised in all configurations (allows debugging on the target using the debug build config)
link libatomic if we're targeting 486 link libatomic.a if we're targeting windows idk what the hell MSVC does for -arch:IA32 we already set the c++14 flag early on strip target selection flags from MSVC builds and clang-cl c++14 does not propagate to compile tests
This commit is contained in:
parent
dcdc7dc904
commit
4246caf8a1
3 changed files with 107 additions and 7 deletions
|
@ -14,6 +14,7 @@ option(USE_AVX2 "enable avx2 code" )
|
|||
option(USE_NETNS "enable networking namespace support. Linux only" )
|
||||
option(AMD_RYZEN_HACK "hack for AMD Ryzen FPU bug (support FMA3 and FMA4 in FPU, but does not show in CPUID)" )
|
||||
option(NATIVE_BUILD "optimise for host system and FPU, may not be portable" )
|
||||
option(EMBEDDED_CFG "optimise for older hardware or embedded systems")
|
||||
if (NOT MSVC)
|
||||
option(STATIC_LINK_RUNTIME "link statically against compiler runtime, standard library and pthreads")
|
||||
endif()
|
||||
|
@ -111,8 +112,6 @@ endif(WITH_SHELLHOOKS)
|
|||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
set(ABSEIL_DIR vendor/abseil-cpp)
|
||||
add_subdirectory(vendor/gtest)
|
||||
add_subdirectory(${ABSEIL_DIR})
|
||||
include_directories(SYSTEM ${ABSEIL_DIR})
|
||||
add_subdirectory(vendor/cxxopts)
|
||||
add_subdirectory(vendor/nlohmann)
|
||||
|
@ -163,7 +162,17 @@ if(NATIVE_BUILD)
|
|||
set(CRYPTO_FLAGS -march=native -mfpmath=sse -mtune=native)
|
||||
endif()
|
||||
|
||||
add_compile_options(${OPTIMIZE_FLAGS} ${CRYPTO_FLAGS})
|
||||
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!")
|
||||
set(CRYPTO_FLAGS -march=i486 -mtune=i486)
|
||||
endif()
|
||||
|
||||
if (NOT MSVC OR NOT MSVC_VERSION)
|
||||
add_compile_options(${OPTIMIZE_FLAGS} ${CRYPTO_FLAGS})
|
||||
endif()
|
||||
add_subdirectory(${ABSEIL_DIR})
|
||||
add_subdirectory(vendor/gtest)
|
||||
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
|
|
|
@ -26,7 +26,12 @@ include_directories(${LIBUV_INCLUDE_DIRS})
|
|||
|
||||
function(check_working_cxx_atomics64 varname)
|
||||
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++14")
|
||||
if (EMBEDDED_CFG)
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -m32 -march=i486")
|
||||
else()
|
||||
# CMAKE_CXX_STANDARD does not propagate to cmake compile tests
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++14")
|
||||
endif()
|
||||
check_cxx_source_compiles("
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
@ -62,10 +67,13 @@ function(link_libatomic)
|
|||
message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!")
|
||||
endfunction()
|
||||
|
||||
if(EMBEDDED_CFG)
|
||||
link_libatomic()
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set(FS_LIB stdc++fs)
|
||||
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE)
|
||||
|
||||
link_libatomic()
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||
find_library(FS_LIB NAMES c++fs c++experimental stdc++fs)
|
||||
|
@ -96,6 +104,9 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
|
|||
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c)
|
||||
# Apple C++ screws up name decorations in stdc++fs, causing link to fail
|
||||
# Samsung does not build c++experimental or c++fs in their Apple libc++ pkgsrc build
|
||||
if (LIBUV_USE_STATIC)
|
||||
link_libraries(-lkstat -lsendfile)
|
||||
endif()
|
||||
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
add_subdirectory(vendor)
|
||||
include_directories("${CMAKE_CURRENT_LIST_DIR}/../vendor/cppbackport-master/lib")
|
||||
|
|
|
@ -8,6 +8,47 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|||
if (MSVC OR MSVC_VERSION)
|
||||
add_compile_options(/EHca /arch:AVX2 /MD)
|
||||
add_definitions(-D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING)
|
||||
# If we're building a lokinet for windows, but need to target ancient hardware
|
||||
function(check_working_cxx_atomics64 varname)
|
||||
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -arch:IA32")
|
||||
check_cxx_source_compiles("
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
std::atomic<uint64_t> x (0);
|
||||
int main() {
|
||||
uint64_t i = x.load(std::memory_order_relaxed);
|
||||
return 0;
|
||||
}
|
||||
" ${varname})
|
||||
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
|
||||
endfunction()
|
||||
|
||||
function(link_libatomic)
|
||||
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
|
||||
|
||||
if(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
|
||||
message(STATUS "Have working 64bit atomics")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
|
||||
# if (HAVE_CXX_LIBATOMICS64)
|
||||
# message(STATUS "Have 64bit atomics via library")
|
||||
# list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
|
||||
# check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
|
||||
# if (HAVE_CXX_ATOMICS64_WITH_LIB)
|
||||
# message(STATUS "Can link with libatomic")
|
||||
# link_libraries(-latomic)
|
||||
# return()
|
||||
# endif()
|
||||
# endif()
|
||||
message(FATAL_ERROR "Host compiler must support 64-bit std::atomic! (What do, MSVC doesn't emit __atomic_load_x)")
|
||||
endfunction()
|
||||
|
||||
if(EMBEDDED_CFG)
|
||||
link_libatomic()
|
||||
endif()
|
||||
|
||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
|
||||
add_compile_options(-Wno-nonportable-system-include-path)
|
||||
|
@ -25,8 +66,47 @@ if(NOT MSVC_VERSION)
|
|||
add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500)
|
||||
# Wait a minute, if we're not Microsoft C++, nor a Clang paired with Microsoft C++,
|
||||
# then the only possible option has to be GNU or a GNU-linked Clang!
|
||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0 OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
set(FS_LIB stdc++fs)
|
||||
set(FS_LIB stdc++fs)
|
||||
# If we're building a lokinet for windows, but need to target ancient hardware
|
||||
function(check_working_cxx_atomics64 varname)
|
||||
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
||||
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -march=i486")
|
||||
check_cxx_source_compiles("
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
std::atomic<uint64_t> x (0);
|
||||
int main() {
|
||||
uint64_t i = x.load(std::memory_order_relaxed);
|
||||
return 0;
|
||||
}
|
||||
" ${varname})
|
||||
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
|
||||
endfunction()
|
||||
|
||||
function(link_libatomic)
|
||||
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
|
||||
|
||||
if(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
|
||||
message(STATUS "Have working 64bit atomics")
|
||||
return()
|
||||
endif()
|
||||
|
||||
check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
|
||||
if (HAVE_CXX_LIBATOMICS64)
|
||||
message(STATUS "Have 64bit atomics via library")
|
||||
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
|
||||
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
|
||||
if (HAVE_CXX_ATOMICS64_WITH_LIB)
|
||||
message(STATUS "Can link with libatomic")
|
||||
link_libraries(-latomic)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!")
|
||||
endfunction()
|
||||
|
||||
if(EMBEDDED_CFG)
|
||||
link_libatomic()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
|
Loading…
Reference in a new issue