make sure that also CXX sources pick up the flags (although I'm not 100% of the correctness of the tests)
authorkoda
Sat, 08 Jun 2013 02:21:31 +0200
changeset 9156 6bf5359d5d14
parent 9155 480f483de544
child 9157 2f8b60b89121
make sure that also CXX sources pick up the flags (although I'm not 100% of the correctness of the tests)
cmake_modules/compilerchecks.cmake
--- a/cmake_modules/compilerchecks.cmake	Sat Jun 08 02:16:38 2013 +0200
+++ b/cmake_modules/compilerchecks.cmake	Sat Jun 08 02:21:31 2013 +0200
@@ -4,16 +4,20 @@
 #when you need to check for a linker flag, just leave the argument of "check_c_compiler_flag" empty
 
 
+#TODO: should there be two different checks for C and CXX?
+
 #stack protection
 check_c_compiler_flag("-fstack-protector" HAVE_STACKPROTECTOR)
 if(HAVE_STACKPROTECTOR)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
 endif()
 
 #symbol visibility
 check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITYH)
 if(HAVE_VISIBILITYH)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
 endif()
 
 
@@ -24,6 +28,7 @@
     list(APPEND pascal_flags "-k-z" "-knoexecstack")
     list(APPEND haskell_flags "-optl" "-z" "-optl" "noexecstack")
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
 endif()
 
 #check for full relro on ELF, Debian security
@@ -33,6 +38,7 @@
     list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
     list(APPEND haskell_flags "-optl" "-z" "-optl" "relro" "-optl" "-z" "-optl" "now")
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
 else()
     #if full relro is not available, try partial relro
     set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
@@ -41,6 +47,7 @@
         list(APPEND pascal_flags "-k-z" "-krelro")
         list(APPEND haskell_flags "-optl" "-z" "-optl" "relro")
         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
     endif()
 endif()
 
@@ -51,6 +58,7 @@
     list(APPEND pascal_flags "-k--nxcompat")
     list(APPEND haskell_flags "-optl" "--nxcompat")
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
 endif()
 
 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
@@ -60,6 +68,7 @@
     list(APPEND pascal_flags "-k--dynamicbase")
     list(APPEND haskell_flags "-optl" "--dynamicbase")
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
 endif()