polish new build script

pass cxxflags down to c++ driver
pull/36/head
despair 6 years ago
parent 5a32ccf220
commit 9afe63d738

4
.gitignore vendored

@ -37,4 +37,6 @@ testnet_tmp
vsproject/
daemon.ini
lokinet-win32.exe
lokinet-win32.exe
lokinet
rapidjson/

@ -1,32 +1,32 @@
cmake_minimum_required(VERSION 2.8.10)
# Lowest version - debian stable is 3.7.2
cmake_minimum_required(VERSION 3.7.0)
set(PROJECT_NAME lokinet)
project(${PROJECT_NAME} C CXX ASM)
option(USE_LIBABYSS "enable libabyss" OFF)
macro(add_cflags)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGN}")
endmacro(add_cflags)
macro(add_cxxflags)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGN}")
endmacro(add_cxxflags)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
add_cxxflags("-std=c++11")
# Require C++11
# or C++17 on win32
if (NOT WIN32)
set(CMAKE_CXX_STANDARD 11)
else()
message(ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
set(CMAKE_CXX_STANDARD 17)
endif(NOT WIN32)
add_cxxflags("-fpermissive")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# turns off those annoying warnings for
# target-specific crypto code paths not
# applicable to the host's FPU -rick
add_compile_options(-Wall)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fpermissive>)
add_compile_options(-Wno-unused-function)
if (WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE)
if (USING_CLANG)
add_cxxflags("-Wno-unused-command-line-argument -Wno-c++11-narrowing")
add_cflags("-Wno-unused-command-line-argument")
add_compile_options(-Wno-unused-command-line-argument -Wno-c++11-narrowing)
# because clang is insane enough to inline whole sections of the C++ library!
# May have been fixed in llvm-7.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-multiple-definition --rtlib=libgcc")
@ -37,15 +37,14 @@ if(DEBIAN)
add_definitions(-DDEBIAN)
endif()
if(ANDROID)
set(THREAD_LIB "-pthread")
else()
set(THREAD_LIB pthread)
endif()
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
# hmm if I allow ld/lld to pick and choose what parts of
# pthread to link in, does it break anything?
if(STATIC_LINK)
add_cflags("-static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
add_cxxflags("-static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static" )
endif()
if(DNS_PORT)
@ -62,11 +61,8 @@ if(TESTNET)
add_definitions(-DTESTNET=1)
endif()
add_cflags("-Wall")
add_cxxflags("-Wall")
set(OPTIMIZE_FLAGS "-O3")
set(DEBUG_FLAGS "-O0 -g3")
set(OPTIMIZE_FLAGS -O3 )
set(DEBUG_FLAGS -O0 -g3 )
if(ASAN)
set(DEBUG_FLAGS "${DEBUG_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
@ -85,8 +81,7 @@ if(SHADOW)
set(CMAKE_MODULE_PATH "${SHADOW_ROOT}/share/cmake/Modules")
include_directories(${CMAKE_MODULE_PATH})
include(ShadowTools)
add_cxxflags("-fno-inline -fno-strict-aliasing")
add_cflags("-fno-inline -fno-strict-aliasing")
add_compile_options( -fno-inline -fno-strict-aliasing )
add_definitions(-DTESTNET=true)
add_definitions(-DSHADOW_TESTNET)
include_directories(${SHADOW_ROOT}/include)
@ -94,19 +89,16 @@ endif()
if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
set(OPTIMIZE_FLAGS "")
add_cflags("${DEBUG_FLAGS}")
add_cxxflags("${DEBUG_FLAGS}")
add_compile_options(${DEBUG_FLAGS})
endif()
set(CRYPTO_FLAGS "-march=native $ENV{CFLAGS}")
set(CMAKE_ASM_FLAGS "-march=native $ENV{CFLAGS}")
add_cflags("-Wall -Wno-deprecated-declarations ${OPTIMIZE_FLAGS} ${CRYPTO_FLAGS}")
add_cxxflags("-Wall -Wno-deprecated-declarations ${OPTIMIZE_FLAGS} ${CRYPTO_FLAGS}")
add_compile_options(-Wall -Wno-deprecated-declarations -march=native)
add_compile_options(${OPTIMIZE_FLAGS})
add_compile_options($ENV{CFLAGS})
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:$ENV{CXXFLAGS}>)
if(SHADOW)
add_cflags("-fPIC")
add_cxxflags("-fPIC")
add_compile_options(-fPIC)
endif()
if(NOT GIT_VERSION)
@ -131,13 +123,12 @@ if(JEMALLOC)
endif()
if (WIN32)
add_cflags("-Wno-unused-function")
add_cxxflags("-Wno-unused-function")
add_cxxflags("-std=c++17")
set(FS_LIB stdc++fs)
endif(WIN32)
set(LIBS ${THREAD_LIB} ${MALLOC_LIB} ${FS_LIB})
# FS_LIB should resolve to nothing on all other platforms
# it is only required on win32 -rick
set(LIBS Threads::Threads ${MALLOC_LIB} ${FS_LIB})
set(LIB lokinet)
set(SHARED_LIB ${LIB})
@ -168,6 +159,7 @@ if(UNIX)
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c)
# TODO: _actually_ port to solaris/illumos (it's fairly complete...except for TUN) -rick
elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c)
else()
@ -318,7 +310,7 @@ set(CHACHA_SRC
crypto/salsa20/xmm6int/salsa20_xmm6int-sse2.c
crypto/xchacha20/hchacha.c
crypto/xchacha20/stream_xchacha20.c)
set(CSRNG_SRC
crypto/csrng/randombytes_salsa20_random.c
crypto/csrng/randombytes.c)
@ -334,7 +326,7 @@ set(BLAKE2B_SRC
crypto/blake2b/blake2b-ref.c
crypto/blake2b/generichash_blake2b.c)
set(X25519_SRC
set(X25519_SRC
crypto/curve25519/crypto_scalarmult.c
crypto/curve25519/ref10/x25519_ref10.c
crypto/curve25519/ref10/ed25519_ref10.c
@ -491,11 +483,9 @@ include_directories(include)
# TODO: exclude this from includes and expose stuff properly for rcutil
include_directories(llarp)
set(RC_EXE rcutil)
set(DNS_EXE dns)
set(ALL_SRC ${CLIENT_SRC} ${RC_SRC} ${EXE_SRC} ${DNS_SRC} ${LIB_PLATFORM_SRC} ${LIB_SRC} ${TEST_SRC})
if(USE_LIBABYSS)
@ -534,9 +524,9 @@ if(WITH_STATIC)
add_library(${STATIC_LIB} STATIC ${LIB_SRC})
add_library(${PLATFORM_LIB} STATIC ${LIB_PLATFORM_SRC})
if(USE_LIBABYSS)
target_link_libraries(${PLATFORM_LIB} ${THREAD_LIB} ${ABYSS_LIB})
target_link_libraries(${PLATFORM_LIB} Threads::Threads ${ABYSS_LIB})
else()
target_link_libraries(${PLATFORM_LIB} ${THREAD_LIB})
target_link_libraries(${PLATFORM_LIB} Threads::Threads)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(${PLATFORM_LIB} -lcap)
@ -547,13 +537,13 @@ if(WITH_STATIC)
target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB})
target_link_libraries(${RC_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB})
target_link_libraries(${TEST_EXE} ${STATIC_LINK_LIBS} gtest_main ${STATIC_LIB} ${PLATFORM_LIB})
target_link_libraries(${DNS_EXE} ${STATIC_LIB} ${PLATFORM_LIB} ${THREAD_LIB})
target_link_libraries(${DNS_EXE} ${STATIC_LIB} ${PLATFORM_LIB})
if (WIN32)
target_link_libraries(${EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
target_link_libraries(${CLIENT_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
target_link_libraries(${RC_EXE} ${STATIC_LINK_LIBS} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
target_link_libraries(${TEST_EXE} ${STATIC_LINK_LIBS} gtest_main ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
target_link_libraries(${DNS_EXE} ${STATIC_LIB} ${PLATFORM_LIB} ${THREAD_LIB} ws2_32 iphlpapi)
target_link_libraries(${DNS_EXE} ${STATIC_LIB} ${PLATFORM_LIB} ws2_32 iphlpapi)
endif(WIN32)
endif(NOT WITH_SHARED)
endif(WITH_STATIC)
@ -567,9 +557,9 @@ if(WITH_STATIC)
if (WIN32)
set(${LIBS} ${LIBS} ws2_32 iphlpapi)
endif(WIN32)
target_link_libraries(${SHARED_LIB} ${LIBS} ${THREAD_LIB})
target_link_libraries(${SHARED_LIB} ${LIBS} Threads::Threads)
target_link_libraries(${EXE} ${SHARED_LIB})
target_link_libraries(${RC_EXE} ${SHARED_LIB})
target_link_libraries(${DNS_EXE} ${SHARED_LIB} ${THREAD_LIB})
target_link_libraries(${DNS_EXE} ${SHARED_LIB} Threads::Threads)
endif(WITH_SHARED)
endif(SHADOW)

@ -255,11 +255,17 @@ namespace llarp
{
if(_shouldClose)
return -1;
#ifdef __linux__
#if defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(__FreeBSD__) || defined(__sun)
// pretty much every UNIX system still extant, plus linux _and_ solaris
// (on both sides of the fork) can ignore SIGPIPE....except Macintosh,
// and the other vendored systems... -rick
return ::send(fd, buf, sz, MSG_NOSIGNAL); // ignore sigpipe
#else
#elif defined(_WIN32)
// TODO: make async
return ::send(std::get< SOCKET >(fd), (char*)buf, sz, 0);
#else
return ::send(fd, buf, sz, 0);
#endif
}

@ -123,7 +123,7 @@ macro(config_compiler_and_linker)
set(cxx_no_rtti_flags "")
endif()
if (CMAKE_USE_PTHREADS_INIT) # The pthreads library is available and allowed.
if (CMAKE_USE_PTHREADS_INIT AND NOT WIN32) # The pthreads library is available and allowed.
set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=1")
else()
set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=0")

Loading…
Cancel
Save