author | koda |
Wed, 12 Jun 2013 19:30:11 +0200 | |
changeset 9217 | 992b7ef2eba3 |
parent 9211 | 6235925d0fa1 |
child 9219 | 0a4b6bb69f99 |
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) |
|
9165
7b0d5388abc4
stack-protector flag needs to be passed to the linker as well
koda
parents:
9159
diff
changeset
|
8 |
# CMAKE_SHARED_LIBRARY_<lang>_FLAGS same but for shared libraries |
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 |
|
9165
7b0d5388abc4
stack-protector flag needs to be passed to the linker as well
koda
parents:
9159
diff
changeset
|
12 |
#stack protection, when found it needs to go in the linker flags too (-lssp is added) |
9167 | 13 |
check_c_compiler_flag("-fstack-protector-all -fstack-protector" HAVE_STACKPROTECTOR) |
9155
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
14 |
if(HAVE_STACKPROTECTOR) |
9167 | 15 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all -fstack-protector") |
16 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -fstack-protector") |
|
17 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fstack-protector-all -fstack-protector") |
|
9217 | 18 |
set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -fstack-protector-all -fstack-protector") |
19 |
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -fstack-protector-all -fstack-protector") |
|
9155
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
20 |
endif() |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
21 |
|
9169 | 22 |
#symbol visibility, not supported on Windows (so we error out to avoid spam) |
23 |
check_c_compiler_flag("-fvisibility=hidden -Werror" HAVE_VISIBILITY) |
|
24 |
if(HAVE_VISIBILITY) |
|
9155
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
25 |
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
|
26 |
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
|
27 |
endif() |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
28 |
|
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
29 |
|
9152 | 30 |
#check for noexecstack on ELF, Gentoo security |
31 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack") |
|
32 |
check_c_compiler_flag("" HAVE_NOEXECSTACK) |
|
33 |
if(HAVE_NOEXECSTACK) |
|
34 |
list(APPEND pascal_flags "-k-z" "-knoexecstack") |
|
9207 | 35 |
list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}") |
9159 | 36 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9217 | 37 |
set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
38 |
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
|
9152 | 39 |
endif() |
40 |
||
9153 | 41 |
#check for full relro on ELF, Debian security |
42 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now") |
|
43 |
check_c_compiler_flag("" HAVE_RELROFULL) |
|
44 |
if(HAVE_RELROFULL) |
|
45 |
list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know") |
|
9207 | 46 |
list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}") |
9159 | 47 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9217 | 48 |
set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
49 |
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
|
9153 | 50 |
else() |
51 |
#if full relro is not available, try partial relro |
|
52 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro") |
|
53 |
check_c_compiler_flag("" HAVE_RELROPARTIAL) |
|
54 |
if(HAVE_RELROPARTIAL) |
|
55 |
list(APPEND pascal_flags "-k-z" "-krelro") |
|
9207 | 56 |
list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}") |
9159 | 57 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9217 | 58 |
set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
59 |
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
|
9153 | 60 |
endif() |
61 |
endif() |
|
62 |
||
9152 | 63 |
#check for ASLR on Windows Vista or later, requires binutils >= 2.20 |
64 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") |
|
65 |
check_c_compiler_flag("" HAVE_WINASLR) |
|
66 |
if(HAVE_WINASLR) |
|
67 |
list(APPEND pascal_flags "-k--nxcompat") |
|
9207 | 68 |
list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}") |
9159 | 69 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9217 | 70 |
set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
71 |
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
|
9152 | 72 |
endif() |
73 |
||
74 |
#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20 |
|
75 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") |
|
76 |
check_c_compiler_flag("" HAVE_WINDEP) |
|
77 |
if(HAVE_WINDEP) |
|
78 |
list(APPEND pascal_flags "-k--dynamicbase") |
|
9207 | 79 |
list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}") |
9159 | 80 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9217 | 81 |
set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
82 |
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
|
9152 | 83 |
endif() |
84 |
||
9206
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
85 |
#this is actually an optimisation |
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
86 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed") |
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
87 |
check_c_compiler_flag("" HAVE_ASNEEDED) |
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
88 |
if(HAVE_ASNEEDED) |
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
89 |
list(APPEND pascal_flags "-k--as-needed") |
9207 | 90 |
list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}") |
9206
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
91 |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
9217 | 92 |
set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
93 |
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}") |
|
9206
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
94 |
endif() |
9152 | 95 |
|
96 |
#always unset or these flags will be spread everywhere |
|
97 |
unset(CMAKE_REQUIRED_FLAGS) |
|
98 |