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