author | koda |
Sat, 08 Jun 2013 02:16:38 +0200 | |
changeset 9155 | 480f483de544 |
parent 9154 | a43406054648 |
child 9156 | 6bf5359d5d14 |
permissions | -rw-r--r-- |
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 |
||
9155
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
7 |
#stack protection |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
8 |
check_c_compiler_flag("-fstack-protector" HAVE_STACKPROTECTOR) |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
9 |
if(HAVE_STACKPROTECTOR) |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
10 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
11 |
endif() |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
12 |
|
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
13 |
#symbol visibility |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
14 |
check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITYH) |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
15 |
if(HAVE_VISIBILITYH) |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
16 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
17 |
endif() |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
18 |
|
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
19 |
|
9152 | 20 |
#check for noexecstack on ELF, Gentoo security |
21 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack") |
|
22 |
check_c_compiler_flag("" HAVE_NOEXECSTACK) |
|
23 |
if(HAVE_NOEXECSTACK) |
|
24 |
list(APPEND pascal_flags "-k-z" "-knoexecstack") |
|
9154 | 25 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "noexecstack") |
9152 | 26 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
27 |
endif() |
|
28 |
||
9153 | 29 |
#check for full relro on ELF, Debian security |
30 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now") |
|
31 |
check_c_compiler_flag("" HAVE_RELROFULL) |
|
32 |
if(HAVE_RELROFULL) |
|
33 |
list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know") |
|
9154 | 34 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "relro" "-optl" "-z" "-optl" "now") |
9153 | 35 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
36 |
else() |
|
37 |
#if full relro is not available, try partial relro |
|
38 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro") |
|
39 |
check_c_compiler_flag("" HAVE_RELROPARTIAL) |
|
40 |
if(HAVE_RELROPARTIAL) |
|
41 |
list(APPEND pascal_flags "-k-z" "-krelro") |
|
9154 | 42 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "relro") |
9153 | 43 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
44 |
endif() |
|
45 |
endif() |
|
46 |
||
9152 | 47 |
#check for ASLR on Windows Vista or later, requires binutils >= 2.20 |
48 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") |
|
49 |
check_c_compiler_flag("" HAVE_WINASLR) |
|
50 |
if(HAVE_WINASLR) |
|
51 |
list(APPEND pascal_flags "-k--nxcompat") |
|
9154 | 52 |
list(APPEND haskell_flags "-optl" "--nxcompat") |
9152 | 53 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
54 |
endif() |
|
55 |
||
56 |
#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20 |
|
57 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") |
|
58 |
check_c_compiler_flag("" HAVE_WINDEP) |
|
59 |
if(HAVE_WINDEP) |
|
60 |
list(APPEND pascal_flags "-k--dynamicbase") |
|
9154 | 61 |
list(APPEND haskell_flags "-optl" "--dynamicbase") |
9152 | 62 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
63 |
endif() |
|
64 |
||
65 |
||
66 |
#always unset or these flags will be spread everywhere |
|
67 |
unset(CMAKE_REQUIRED_FLAGS) |
|
68 |