set linker flags where appropriate
authorkoda
Sun, 09 Jun 2013 12:20:19 +0200
changeset 9159 3e9d4bbc4053
parent 9158 b4d8baf4669a
child 9160 fc46e75f6b72
child 9161 b2f02b083374
set linker flags where appropriate
cmake_modules/compilerchecks.cmake
--- a/cmake_modules/compilerchecks.cmake	Sun Jun 09 11:41:04 2013 +0200
+++ b/cmake_modules/compilerchecks.cmake	Sun Jun 09 12:20:19 2013 +0200
@@ -3,6 +3,9 @@
 include(CheckCCompilerFlag)
 #when you need to check for a linker flag, just leave the argument of "check_c_compiler_flag" empty
 
+# 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)
+
 
 #TODO: should there be two different checks for C and CXX?
 
@@ -27,8 +30,7 @@
 if(HAVE_NOEXECSTACK)
     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}")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
 endif()
 
 #check for full relro on ELF, Debian security
@@ -37,8 +39,7 @@
 if(HAVE_RELROFULL)
     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}")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
 else()
     #if full relro is not available, try partial relro
     set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
@@ -46,8 +47,7 @@
     if(HAVE_RELROPARTIAL)
         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}")
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
     endif()
 endif()
 
@@ -57,8 +57,7 @@
 if(HAVE_WINASLR)
     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}")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
 endif()
 
 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
@@ -67,8 +66,7 @@
 if(HAVE_WINDEP)
     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}")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
 endif()