From 3cc41db0bdd73de57289e1bddc383e32bade743d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 1 Aug 2013 11:09:35 +0200 Subject: [PATCH] Fix warning with clang /usr/include/features.h:330:4: error: _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror,-W#warnings] # warning _FORTIFY_SOURCE requires compiling with optimization (-O) --- cmake/Modules/DefineCompilerFlags.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/DefineCompilerFlags.cmake b/cmake/Modules/DefineCompilerFlags.cmake index edabca42d..79b47603f 100644 --- a/cmake/Modules/DefineCompilerFlags.cmake +++ b/cmake/Modules/DefineCompilerFlags.cmake @@ -33,10 +33,12 @@ if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") endif (WITH_STACK_PROTECTOR AND NOT WIN32) + if (WITH_OPTIMIZATION) check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE) - if (WITH_FORTIFY_SOURCE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2") - endif (WITH_FORTIFY_SOURCE) + if (WITH_FORTIFY_SOURCE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O -D_FORTIFY_SOURCE=2") + endif (WITH_FORTIFY_SOURCE) + endif (WITH_OPTIMIZATION) endif (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)") if (UNIX AND NOT WIN32)