"-werr" was added to CHECK_C_COMPILER_FLAG to
make sure FORTIFY_SOURCE is only turned on if
the flag generates no warnings.
Added "-U_FORTIFY_SOURCE" to CMAKE_C_FLAGS to
mimic PR #9761.
Signed-off-by: Ali Maredia <amaredia@redhat.com>
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic -Wall -Wtype-limits -Wignored-qualifiers -Winit-self -Wpointer-arith -Werror=format-security -fno-strict-aliasing -fsigned-char -fPIC")
include(CheckCCompilerFlag)
-CHECK_C_COMPILER_FLAG("-Wp,-D_FORTIFY_SOURCE=2" HAS_FORTIFY_SOURCE)
-if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
+CHECK_C_COMPILER_FLAG("-Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=2 -Werror" HAS_FORTIFY_SOURCE)
if(HAS_FORTIFY_SOURCE)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wp,-D_FORTIFY_SOURCE=2")
-endif()
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=2")
endif()
CHECK_C_COMPILER_FLAG(-fstack-protector-strong HAS_STACK_PROTECT)
if (HAS_STACK_PROTECT)