Add -DSECURITY_COMPILER_FLAGS=OFF option

To disable -D_FORTIFY_SOURCE=2 -fstack-protector-all, see
https://bugs.gentoo.org/888875 for report. Default behavior is not
changed.
This commit is contained in:
Dennis Felsing 2023-01-03 14:37:50 +01:00
parent 29bf49ae31
commit 496b9117ed

View file

@ -132,6 +132,7 @@ option(VULKAN "Enable the vulkan backend" ${AUTO_VULKAN_BACKEND})
option(EXCEPTION_HANDLING "Enable exception handling (only works with Windows as of now)" OFF)
option(IPO "Enable interprocedural optimizations" OFF)
option(FUSE_LD "Linker to use" OFF)
option(SECURITY_COMPILER_FLAGS "Whether to set security-relevant compiler flags like -D_FORTIFY_SOURCE=2 and -fstack-protector-all" ON)
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
include(${PROJECT_SOURCE_DIR}/cmake/toolchains/Emscripten.toolchain)
@ -293,9 +294,11 @@ if(NOT MSVC AND NOT HAIKU)
add_cxx_compiler_flag_if_supported(OUR_FLAGS_OWN -std=gnu++17)
endif()
# Protect the stack pointer.
# -fstack-protector-all doesn't work on MinGW.
add_cxx_compiler_flag_if_supported(OUR_FLAGS -fstack-protector-all)
if(NOT SECURITY_COMPILER_FLAGS STREQUAL OFF)
# Protect the stack pointer.
# -fstack-protector-all doesn't work on MinGW.
add_cxx_compiler_flag_if_supported(OUR_FLAGS -fstack-protector-all)
endif()
# Disable exceptions as DDNet does not use them.
add_cxx_compiler_flag_if_supported(OUR_FLAGS -fno-exceptions)
@ -359,7 +362,7 @@ if(MSVC)
endif()
endif()
if(NOT MSVC AND NOT HAIKU)
if(NOT MSVC AND NOT HAIKU AND NOT SECURITY_COMPILER_FLAGS STREQUAL OFF)
check_c_compiler_flag("-O2;-Wp,-Werror;-D_FORTIFY_SOURCE=2" DEFINE_FORTIFY_SOURCE) # Some distributions define _FORTIFY_SOURCE by themselves.
endif()