CMakeLists.txt: Check for _FORTIFY_SOURCE defines even harder

This commit is contained in:
heinrich5991 2017-03-13 16:42:40 +01:00
parent 32a1fa0c07
commit 5b8052ff9d

View file

@ -124,8 +124,8 @@ else()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES Clang OR CMAKE_CXX_COMPILER_ID MATCHES GNU)
include(CheckSymbolExists)
check_symbol_exists(_FORTIFY_SOURCE "" FORTIFY_SOURCE_DEFINED)
include(CheckCCompilerFlag)
check_c_compiler_flag("-O2;-Wp,-Werror;-D_FORTIFY_SOURCE=2" DEFINE_FORTIFY_SOURCE)
endif()
@ -419,8 +419,8 @@ foreach(target ${TARGETS})
target_compile_options(${target} PRIVATE /wd4996) # Use of non-_s functions.
elseif(CMAKE_CXX_COMPILER_ID MATCHES Clang OR CMAKE_CXX_COMPILER_ID MATCHES GNU)
target_compile_options(${target} PRIVATE -fstack-protector-all) # Protect the stack pointer.
if(NOT FORTIFY_SOURCE_DEFINED)
target_compile_definitions(${target} PRIVATE $<$<NOT:$<CONFIG:Debug>>:_FORTIFY_SOURCE=1>) # Detect some buffer overflows.
if(DEFINE_FORTIFY_SOURCE)
target_compile_definitions(${target} PRIVATE $<$<NOT:$<CONFIG:Debug>>:_FORTIFY_SOURCE=2>) # Detect some buffer overflows.
endif()
endif()
endforeach()