73 lines
3.3 KiB
CMake
73 lines
3.3 KiB
CMake
|
# Core compile arguments used for dmtools
|
||
|
set(DMTOOLS_CORE_COMPILE_ARGS "-Wall -Wformat=2 -fstrict-flex-arrays=3 -fstack-clash-protection -fstack-protector-strong ")
|
||
|
set(DMTOOLS_CORE_LINKER_ARGS "-fuse-ld=${DMTOOLS_LINKER}")
|
||
|
|
||
|
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
||
|
set(DMTOOLS_CORE_COMPILE_ARGS "${DMTOOLS_CORE_COMPILE_ARGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3")
|
||
|
|
||
|
# If on Release use link-time optimizations.
|
||
|
# On clang we use ThinLTO for even better build performance.
|
||
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||
|
set(DMTOOLS_CORE_COMPILE_ARGS "${DMTOOLS_CORE_COMPILE_ARGS} -flto=thin")
|
||
|
set(DMTOOLS_CORE_LINKER_ARGS "${DMTOOLS_CORE_LINKER_ARGS} -flto=thin")
|
||
|
else()
|
||
|
set(DMTOOLS_CORE_COMPILE_ARGS "${DMTOOLS_CORE_COMPILE_ARGS} -flto")
|
||
|
set(DMTOOLS_CORE_LINKER_ARGS "${DMTOOLS_CORE_LINKER_ARGS} -flto")
|
||
|
endif()
|
||
|
else()
|
||
|
# TODO: This currently assumes libstdc++, later on we should *probably* set this with some detection
|
||
|
# to check the current c++ standard library (but we only will compile and run with libstdc++ anyways since libc++ is a bit lacking with even c++17, so..)
|
||
|
set(DMTOOLS_CORE_COMPILE_ARGS "${DMTOOLS_CORE_COMPILE_ARGS} -D_GLIBCXX_ASSERTIONS")
|
||
|
endif()
|
||
|
|
||
|
set(_DMTOOLS_CORE_WANTED_SANITIZERS "")
|
||
|
|
||
|
if("asan" IN_LIST DMTOOLS_BUILD_FEATURES)
|
||
|
# Error if someone's trying to mix asan and tsan together,
|
||
|
# they aren't compatible.
|
||
|
if("tsan" IN_LIST DMTOOLS_BUILD_FEATURES)
|
||
|
message(FATAL_ERROR "ASAN and TSAN cannot be used together.")
|
||
|
endif()
|
||
|
|
||
|
message(STATUS "Enabling ASAN because it was in DMTOOLS_BUILD_FEATURES")
|
||
|
list(APPEND _DMTOOLS_CORE_WANTED_SANITIZERS "address")
|
||
|
endif()
|
||
|
|
||
|
if("tsan" IN_LIST DMTOOLS_BUILD_FEATURES)
|
||
|
if("asan" IN_LIST DMTOOLS_BUILD_FEATURES)
|
||
|
message(FATAL_ERROR "ASAN and TSAN cannot be used together.")
|
||
|
endif()
|
||
|
|
||
|
message(STATUS "Enabling TSAN because it was in DMTOOLS_BUILD_FEATURES")
|
||
|
list(APPEND _DMTOOLS_CORE_WANTED_SANITIZERS "thread")
|
||
|
endif()
|
||
|
|
||
|
if("ubsan" IN_LIST DMTOOLS_BUILD_FEATURES)
|
||
|
message(STATUS "Enabling UBSAN because it was in DMTOOLS_BUILD_FEATURES")
|
||
|
list(APPEND _DMTOOLS_CORE_WANTED_SANITIZERS "undefined")
|
||
|
endif()
|
||
|
|
||
|
list(LENGTH _DMTOOLS_CORE_WANTED_SANITIZERS _DMTOOLS_CORE_WANTED_SANITIZERS_LENGTH)
|
||
|
if(NOT _DMTOOLS_CORE_WANTED_SANITIZERS_LENGTH EQUAL 0)
|
||
|
list(JOIN _DMTOOLS_CORE_WANTED_SANITIZERS "," _DMTOOLS_CORE_WANTED_SANITIZERS_ARG)
|
||
|
message(STATUS "Enabled sanitizers: ${_DMTOOLS_CORE_WANTED_SANITIZERS_ARG}")
|
||
|
set(DMTOOLS_CORE_COMPILE_ARGS "${DMTOOLS_CORE_COMPILE_ARGS} -fsanitize=${_COLLABVM_CORE_WANTED_SANITIZERS_ARG}")
|
||
|
set(DMTOOLS_CORE_LINKER_ARGS "${DMTOOLS_CORE_LINKER_ARGS} -fsanitize=${_COLLABVM_CORE_WANTED_SANITIZERS_ARG}")
|
||
|
endif()
|
||
|
|
||
|
# Set core CMake toolchain variables so that they get applied to all projects.
|
||
|
# A bit nasty, but /shrug, this way our third party libraries can be mostly sanitized/etc as well.
|
||
|
|
||
|
set(CMAKE_C_FLAGS "${DMTOOLS_CORE_COMPILE_ARGS}")
|
||
|
set(CMAKE_CXX_FLAGS "${DMTOOLS_CORE_COMPILE_ARGS}")
|
||
|
|
||
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O0 -g3")
|
||
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -O3 -g3")
|
||
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3")
|
||
|
|
||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g3")
|
||
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -O3 -g3")
|
||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
|
||
|
|
||
|
set(CMAKE_EXE_LINKER_FLAGS "${DMTOOLS_CORE_LINKER_ARGS} -Wl,-z,noexecstack,-z,relro,-z,now")
|