author | unc0rr |
Sun, 16 Jun 2013 00:46:11 +0400 | |
branch | webgl |
changeset 9168 | 20ff80421736 |
parent 9159 | 3e9d4bbc4053 |
child 9165 | 7b0d5388abc4 |
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 |
||
9159 | 6 |
# CMAKE_C{XX}_FLAGS is for compiler flags (c and c++) |
7 |
# CMAKE_EXE_LINKER_FLAGS is for linker flags (also add them to pascal_flags and haskell_flags) |
|
8 |
||
9152 | 9 |
|
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
|
10 |
#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
|
11 |
|
9155
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
12 |
#stack protection |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
13 |
check_c_compiler_flag("-fstack-protector" HAVE_STACKPROTECTOR) |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
14 |
if(HAVE_STACKPROTECTOR) |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
15 |
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
|
16 |
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
|
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 |
#symbol visibility |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
20 |
check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITYH) |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
21 |
if(HAVE_VISIBILITYH) |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
22 |
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
|
23 |
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
|
24 |
endif() |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
25 |
|
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
26 |
|
9152 | 27 |
#check for noexecstack on ELF, Gentoo security |
28 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack") |
|
29 |
check_c_compiler_flag("" HAVE_NOEXECSTACK) |
|
30 |
if(HAVE_NOEXECSTACK) |
|
31 |
list(APPEND pascal_flags "-k-z" "-knoexecstack") |
|
9154 | 32 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "noexecstack") |
9159 | 33 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9152 | 34 |
endif() |
35 |
||
9153 | 36 |
#check for full relro on ELF, Debian security |
37 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now") |
|
38 |
check_c_compiler_flag("" HAVE_RELROFULL) |
|
39 |
if(HAVE_RELROFULL) |
|
40 |
list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know") |
|
9154 | 41 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "relro" "-optl" "-z" "-optl" "now") |
9159 | 42 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9153 | 43 |
else() |
44 |
#if full relro is not available, try partial relro |
|
45 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro") |
|
46 |
check_c_compiler_flag("" HAVE_RELROPARTIAL) |
|
47 |
if(HAVE_RELROPARTIAL) |
|
48 |
list(APPEND pascal_flags "-k-z" "-krelro") |
|
9154 | 49 |
list(APPEND haskell_flags "-optl" "-z" "-optl" "relro") |
9159 | 50 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_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") |
9159 | 60 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9152 | 61 |
endif() |
62 |
||
63 |
#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20 |
|
64 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") |
|
65 |
check_c_compiler_flag("" HAVE_WINDEP) |
|
66 |
if(HAVE_WINDEP) |
|
67 |
list(APPEND pascal_flags "-k--dynamicbase") |
|
9154 | 68 |
list(APPEND haskell_flags "-optl" "--dynamicbase") |
9159 | 69 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9152 | 70 |
endif() |
71 |
||
72 |
||
73 |
#always unset or these flags will be spread everywhere |
|
74 |
unset(CMAKE_REQUIRED_FLAGS) |
|
75 |