Changeset View
Changeset View
Standalone View
Standalone View
src/CMakeLists.txt
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -DDEBUG -DDEBUG_LOCKORDER") | string(APPEND CMAKE_CXX_FLAGS_DEBUG " -DDEBUG -DDEBUG_LOCKORDER") | ||||
# Ensure that WINDRES_PREPROC is enabled when using windres. | # Ensure that WINDRES_PREPROC is enabled when using windres. | ||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||||
# Ensure that WINDRES_PREPROC is enabled when using windres. | # Ensure that WINDRES_PREPROC is enabled when using windres. | ||||
list(APPEND CMAKE_RC_FLAGS "-DWINDRES_PREPROC") | list(APPEND CMAKE_RC_FLAGS "-DWINDRES_PREPROC") | ||||
# Build all static so there is no dll file to distribute. | # Build all static so there is no dll file to distribute. | ||||
add_compiler_flag(-static) | add_compiler_flags(-static) | ||||
endif() | endif() | ||||
if(ENABLE_REDUCE_EXPORTS) | if(ENABLE_REDUCE_EXPORTS) | ||||
# Default visibility is set by CMAKE_<LANG>_VISIBILITY_PRESET, but this | # Default visibility is set by CMAKE_<LANG>_VISIBILITY_PRESET, but this | ||||
# doesn't tell if the visibility set is effective. | # doesn't tell if the visibility set is effective. | ||||
# Check if the flag -fvisibility=hidden is supported, as using the hidden | # Check if the flag -fvisibility=hidden is supported, as using the hidden | ||||
# visibility is a requirement to reduce exports. | # visibility is a requirement to reduce exports. | ||||
check_compiler_flag(HAS_CXX_FVISIBILITY CXX -fvisibility=hidden) | check_compiler_flag(HAS_CXX_FVISIBILITY CXX -fvisibility=hidden) | ||||
if(NOT HAS_CXX_FVISIBILITY) | if(NOT HAS_CXX_FVISIBILITY) | ||||
message(FATAL_ERROR "Cannot set default symbol visibility. Use -DENABLE_REDUCE_EXPORTS=OFF.") | message(FATAL_ERROR "Cannot set default symbol visibility. Use -DENABLE_REDUCE_EXPORTS=OFF.") | ||||
endif() | endif() | ||||
# Also hide symbols from static libraries | # Also hide symbols from static libraries | ||||
add_linker_flag(-Wl,--exclude-libs,ALL) | add_linker_flags(-Wl,--exclude-libs,ALL) | ||||
endif() | endif() | ||||
# Enable statically linking libstdc++ | # Enable statically linking libstdc++ | ||||
if(ENABLE_STATIC_LIBSTDCXX) | if(ENABLE_STATIC_LIBSTDCXX) | ||||
add_linker_flag(-static-libstdc++) | add_linker_flags(-static-libstdc++) | ||||
endif() | endif() | ||||
# All windows code is PIC, forcing it on just adds useless compile warnings | # All windows code is PIC, forcing it on just adds useless compile warnings | ||||
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") | if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||||
add_compiler_flag(-fPIC) | add_compiler_flags(-fPIC) | ||||
endif() | endif() | ||||
if(ENABLE_HARDENING) | if(ENABLE_HARDENING) | ||||
# Enable stack protection | # Enable stack protection | ||||
add_cxx_compiler_flag(-fstack-protector-all -Wstack-protector) | add_cxx_compiler_flags(-fstack-protector-all -Wstack-protector) | ||||
# Enable some buffer overflow checking | # Enable some buffer overflow checking | ||||
add_compiler_flag(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2) | add_compiler_flags(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2) | ||||
# Enable ASLR (these flags are primarily targeting MinGw) | # Enable ASLR (these flags are primarily targeting MinGw) | ||||
add_linker_flag(-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va) | add_linker_flags(-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va) | ||||
# Make the relocated sections read-only | # Make the relocated sections read-only | ||||
add_linker_flag(-Wl,-z,relro -Wl,-z,now) | add_linker_flags(-Wl,-z,relro -Wl,-z,now) | ||||
# CMake provides the POSITION_INDEPENDENT_CODE property to set PIC/PIE. | # CMake provides the POSITION_INDEPENDENT_CODE property to set PIC/PIE. | ||||
# Unfortunately setting the -pie linker flag this way require CMake >= 3.14, | # Unfortunately setting the -pie linker flag this way require CMake >= 3.14, | ||||
# which is not widely distributed at the time of writing. | # which is not widely distributed at the time of writing. | ||||
# FIXME: use the POSITION_INDEPENDENT_CODE property instead | # FIXME: use the POSITION_INDEPENDENT_CODE property instead | ||||
add_compiler_flag(-fPIE) | add_compiler_flags(-fPIE) | ||||
add_linker_flag(-pie) | add_linker_flags(-pie) | ||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||||
# MinGw provides its own libssp for stack smashing protection | # MinGw provides its own libssp for stack smashing protection | ||||
link_libraries(ssp) | link_libraries(ssp) | ||||
endif() | endif() | ||||
endif() | endif() | ||||
# Enable warning | # Enable warning | ||||
add_c_compiler_flag(-Wnested-externs -Wstrict-prototypes) | add_c_compiler_flags(-Wnested-externs -Wstrict-prototypes) | ||||
add_compiler_flag( | add_compiler_flags( | ||||
-Wall | -Wall | ||||
-Wextra | -Wextra | ||||
-Wformat | -Wformat | ||||
-Wvla | -Wvla | ||||
-Wformat-security | -Wformat-security | ||||
-Wcast-align | -Wcast-align | ||||
-Wunused-parameter | -Wunused-parameter | ||||
-Wmissing-braces | -Wmissing-braces | ||||
# FIXME: Activating this flag cause cmake to fail on leveldb. | # FIXME: Activating this flag cause cmake to fail on leveldb. | ||||
# -Wthread-safety-analysis | # -Wthread-safety-analysis | ||||
-Wshadow | -Wshadow | ||||
-Wrange-loop-analysis | -Wrange-loop-analysis | ||||
) | ) | ||||
option(EXTRA_WARNINGS "Enable extra warnings" OFF) | option(EXTRA_WARNINGS "Enable extra warnings" OFF) | ||||
if(EXTRA_WARNINGS) | if(EXTRA_WARNINGS) | ||||
add_cxx_compiler_flag(-Wsuggest-override) | add_cxx_compiler_flags(-Wsuggest-override) | ||||
else() | else() | ||||
add_compiler_flag(-Wno-unused-parameter) | add_compiler_flags(-Wno-unused-parameter) | ||||
add_compiler_flag(-Wno-implicit-fallthrough) | add_compiler_flags(-Wno-implicit-fallthrough) | ||||
endif() | endif() | ||||
# Create a target for OpenSSL | # Create a target for OpenSSL | ||||
include(BrewHelper) | include(BrewHelper) | ||||
find_brew_prefix(OPENSSL_ROOT_DIR openssl) | find_brew_prefix(OPENSSL_ROOT_DIR openssl) | ||||
find_package(OpenSSL REQUIRED) | find_package(OpenSSL REQUIRED) | ||||
# libtool style configure | # libtool style configure | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | if(FDELT_PROTOTYPE_LONG_UNSIGNED_INT) | ||||
set(FDELT_TYPE "long unsigned int") | set(FDELT_TYPE "long unsigned int") | ||||
else() | else() | ||||
set(FDELT_TYPE "long int") | set(FDELT_TYPE "long int") | ||||
endif() | endif() | ||||
target_compile_definitions(util PRIVATE "-DFDELT_TYPE=${FDELT_TYPE}") | target_compile_definitions(util PRIVATE "-DFDELT_TYPE=${FDELT_TYPE}") | ||||
# Wrap some glibc functions with ours | # Wrap some glibc functions with ours | ||||
add_linker_flag(-Wl,--wrap=__divmoddi4) | add_linker_flags(-Wl,--wrap=__divmoddi4) | ||||
add_linker_flag(-Wl,--wrap=log2f) | add_linker_flags(-Wl,--wrap=log2f) | ||||
target_sources(util PRIVATE compat/glibc_compat.cpp) | target_sources(util PRIVATE compat/glibc_compat.cpp) | ||||
endif() | endif() | ||||
# Target specific configs | # Target specific configs | ||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||||
set(Boost_USE_STATIC_LIBS ON) | set(Boost_USE_STATIC_LIBS ON) | ||||
set(Boost_THREADAPI win32) | set(Boost_THREADAPI win32) | ||||
▲ Show 20 Lines • Show All 220 Lines • Show Last 20 Lines |