move compiler checks in a separate cmake module
authorkoda
Sat, 08 Jun 2013 01:52:32 +0200
changeset 9152 c884e40dca9e
parent 9151 1d2df388fcc6
child 9153 354a9803fe91
move compiler checks in a separate cmake module
CMakeLists.txt
cmake_modules/compilerchecks.cmake
--- a/CMakeLists.txt	Sat Jun 08 01:31:53 2013 +0200
+++ b/CMakeLists.txt	Sat Jun 08 01:52:32 2013 +0200
@@ -94,6 +94,9 @@
 endif (CMAKE_BUILD_TYPE)
 
 
+#perform safe check that enable/disable compilation features
+include(${CMAKE_MODULE_PATH}/compilerchecks.cmake)
+
 #set default flags values for all projects (unless MINIMAL_FLAGS is true)
 if(NOT ${MINIMAL_FLAGS})
     set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}")
@@ -110,29 +113,6 @@
     set(CMAKE_CXX_FLAGS_DEBUG "-Wall -DDEBUG")
 endif()
 
-
-#TESTING TIME
-include(CheckCCompilerFlag)
-
-#check for noexecstack on ELF, should be set on Gentoo and similar
-set(CMAKE_REQUIRED_FLAGS "-Wl,-z -Wl,noexecstack")
-check_c_compiler_flag("" HAVE_NOEXECSTACK) #empty because we are testing a linker flag
-if(HAVE_NOEXECSTACK)
-    list(APPEND pascal_flags "-k-z" "-knoexecstack")
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
-endif()
-unset(CMAKE_REQUIRED_FLAGS)
-
-#check for ASLR and DEP security features on Windows
-#both supported in binutils >= 2.20, available since Vista and XP SP2 respectively
-set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat -Wl,--dynamicbase")
-check_c_compiler_flag("" HAVE_WINASLRDEP) #empty because we are testing a linker flag
-if(HAVE_WINASLRDEP)
-    list(APPEND pascal_flags "-k--nxcompat" "-k--dynamicbase")
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
-endif()
-unset(CMAKE_REQUIRED_FLAGS)
-
 #parse additional parameters
 if(FPFLAGS OR GHFLAGS)
     if(CMAKE_VERSION VERSION_GREATER "2.6")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/compilerchecks.cmake	Sat Jun 08 01:52:32 2013 +0200
@@ -0,0 +1,34 @@
+
+#TESTING TIME
+include(CheckCCompilerFlag)
+#when you need to check for a linker flag, just leave the argument of "check_c_compiler_flag" empty
+
+
+#check for noexecstack on ELF, Gentoo security
+set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack")
+check_c_compiler_flag("" HAVE_NOEXECSTACK)
+if(HAVE_NOEXECSTACK)
+    list(APPEND pascal_flags "-k-z" "-knoexecstack")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+endif()
+
+#check for ASLR on Windows Vista or later, requires binutils >= 2.20
+set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
+check_c_compiler_flag("" HAVE_WINASLR)
+if(HAVE_WINASLR)
+    list(APPEND pascal_flags "-k--nxcompat")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+endif()
+
+#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
+set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
+check_c_compiler_flag("" HAVE_WINDEP)
+if(HAVE_WINDEP)
+    list(APPEND pascal_flags "-k--dynamicbase")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+endif()
+
+
+#always unset or these flags will be spread everywhere
+unset(CMAKE_REQUIRED_FLAGS)
+