CMakeLists.txt: use -fstack-protector-strong if available
authorAntonio Ospite <ao2@ao2.it>
Thu, 1 Mar 2018 22:12:48 +0000 (23:12 +0100)
committerAntonio Ospite <ao2@ao2.it>
Fri, 2 Mar 2018 11:54:51 +0000 (12:54 +0100)
This is available since gcc-4.9.

CMakeLists.txt

index 9b733f3..73657f8 100644 (file)
@@ -65,8 +65,15 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
     -Wswitch-enum
     -Wundef
     -Wunreachable-code
     -Wswitch-enum
     -Wundef
     -Wunreachable-code
-    -Wwrite-strings
-    -fstack-protector)
+    -Wwrite-strings)
+
+  include(CheckCCompilerFlag)
+  CHECK_C_COMPILER_FLAG(-fstack-protector-strong COMPILER_SUPPORTS_STACK_PROTECTOR_STRONG)
+  if (COMPILER_SUPPORTS_STACK_PROTECTOR_STRONG)
+    add_flags(CMAKE_C_FLAGS -fstack-protector-strong)
+  else()
+    add_flags(CMAKE_C_FLAGS -fstack-protector)
+  endif()
 
   add_flags(DEBUG_FLAGS
     -ggdb)
 
   add_flags(DEBUG_FLAGS
     -ggdb)