stack-protector flag needs to be passed to the linker as well
authorkoda
Mon, 10 Jun 2013 10:47:59 +0200
changeset 9165 7b0d5388abc4
parent 9163 67334acaaac7
child 9167 ecf19179b37e
stack-protector flag needs to be passed to the linker as well
CMakeLists.txt
cmake_modules/compilerchecks.cmake
--- a/CMakeLists.txt	Thu Jun 06 15:55:10 2013 +0200
+++ b/CMakeLists.txt	Mon Jun 10 10:47:59 2013 +0200
@@ -2,7 +2,7 @@
 
 #initialise cmake environment
 cmake_minimum_required(VERSION 2.6.0)
-foreach(hwpolicy CMP0003 CMP0012 CMP0017)
+foreach(hwpolicy CMP0003 CMP0012 CMP0017 CMP0018)
     if(POLICY ${hwpolicy})
         cmake_policy(SET ${hwpolicy} NEW)
     endif()
--- a/cmake_modules/compilerchecks.cmake	Thu Jun 06 15:55:10 2013 +0200
+++ b/cmake_modules/compilerchecks.cmake	Mon Jun 10 10:47:59 2013 +0200
@@ -5,15 +5,18 @@
 
 # CMAKE_C{XX}_FLAGS is for compiler flags (c and c++)
 # CMAKE_EXE_LINKER_FLAGS is for linker flags (also add them to pascal_flags and haskell_flags)
-
+# CMAKE_SHARED_LIBRARY_<lang>_FLAGS same but for shared libraries
 
 #TODO: should there be two different checks for C and CXX?
 
-#stack protection
+#stack protection, when found it needs to go in the linker flags too (-lssp is added)
 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")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fstack-protector")
+    set(CMAKE_SHARED_LIBRARY_C_FLAGS  "${CMAKE_SHARED_LIBRARY_C_FLAGS} -fstack-protector")
+    set(CMAKE_SHARED_LIBRARY_CXX_FLAGS  "${CMAKE_SHARED_LIBRARY_C_FLAGS} -fstack-protector")
 endif()
 
 #symbol visibility