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")
|
|
12 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
13 |
endif()
|
|
14 |
|
9153
|
15 |
#check for full relro on ELF, Debian security
|
|
16 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
|
|
17 |
check_c_compiler_flag("" HAVE_RELROFULL)
|
|
18 |
if(HAVE_RELROFULL)
|
|
19 |
list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
|
|
20 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
21 |
else()
|
|
22 |
#if full relro is not available, try partial relro
|
|
23 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
|
|
24 |
check_c_compiler_flag("" HAVE_RELROPARTIAL)
|
|
25 |
if(HAVE_RELROPARTIAL)
|
|
26 |
list(APPEND pascal_flags "-k-z" "-krelro")
|
|
27 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
28 |
endif()
|
|
29 |
endif()
|
|
30 |
|
9152
|
31 |
#check for ASLR on Windows Vista or later, requires binutils >= 2.20
|
|
32 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
|
|
33 |
check_c_compiler_flag("" HAVE_WINASLR)
|
|
34 |
if(HAVE_WINASLR)
|
|
35 |
list(APPEND pascal_flags "-k--nxcompat")
|
|
36 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
37 |
endif()
|
|
38 |
|
|
39 |
#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
|
|
40 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
|
|
41 |
check_c_compiler_flag("" HAVE_WINDEP)
|
|
42 |
if(HAVE_WINDEP)
|
|
43 |
list(APPEND pascal_flags "-k--dynamicbase")
|
|
44 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
|
|
45 |
endif()
|
|
46 |
|
|
47 |
|
|
48 |
#always unset or these flags will be spread everywhere
|
|
49 |
unset(CMAKE_REQUIRED_FLAGS)
|
|
50 |
|