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