9152
|
1 |
|
|
2 |
#TESTING TIME
|
|
3 |
include(CheckCCompilerFlag)
|
|
4 |
#when you need to check for a linker flag, just leave the argument of "check_c_compiler_flag" empty
|
|
5 |
|
|
6 |
|
|
7 |
#check for noexecstack on ELF, Gentoo security
|
|
8 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack")
|
|
9 |
check_c_compiler_flag("" HAVE_NOEXECSTACK)
|
|
10 |
if(HAVE_NOEXECSTACK)
|
|
11 |
list(APPEND pascal_flags "-k-z" "-knoexecstack")
|
9154
|
12 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "noexecstack")
|
9152
|
13 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
14 |
endif()
|
|
15 |
|
9153
|
16 |
#check for full relro on ELF, Debian security
|
|
17 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
|
|
18 |
check_c_compiler_flag("" HAVE_RELROFULL)
|
|
19 |
if(HAVE_RELROFULL)
|
|
20 |
list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
|
9154
|
21 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "relro" "-optl" "-z" "-optl" "now")
|
9153
|
22 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
23 |
else()
|
|
24 |
#if full relro is not available, try partial relro
|
|
25 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
|
|
26 |
check_c_compiler_flag("" HAVE_RELROPARTIAL)
|
|
27 |
if(HAVE_RELROPARTIAL)
|
|
28 |
list(APPEND pascal_flags "-k-z" "-krelro")
|
9154
|
29 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "relro")
|
9153
|
30 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
31 |
endif()
|
|
32 |
endif()
|
|
33 |
|
9152
|
34 |
#check for ASLR on Windows Vista or later, requires binutils >= 2.20
|
|
35 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
|
|
36 |
check_c_compiler_flag("" HAVE_WINASLR)
|
|
37 |
if(HAVE_WINASLR)
|
|
38 |
list(APPEND pascal_flags "-k--nxcompat")
|
9154
|
39 |
list(APPEND haskell_flags "-optl" "--nxcompat")
|
9152
|
40 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
41 |
endif()
|
|
42 |
|
|
43 |
#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
|
|
44 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
|
|
45 |
check_c_compiler_flag("" HAVE_WINDEP)
|
|
46 |
if(HAVE_WINDEP)
|
|
47 |
list(APPEND pascal_flags "-k--dynamicbase")
|
9154
|
48 |
list(APPEND haskell_flags "-optl" "--dynamicbase")
|
9152
|
49 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
50 |
endif()
|
|
51 |
|
|
52 |
|
|
53 |
#always unset or these flags will be spread everywhere
|
|
54 |
unset(CMAKE_REQUIRED_FLAGS)
|
|
55 |
|