author | Periklis Ntanasis <pntanasis@gmail.com> |
Fri, 05 Jul 2013 04:32:39 +0300 | |
branch | spacecampaign |
changeset 9312 | f6bec1cfbfbd |
parent 9298 | 2d88d01bad07 |
child 9307 | a0fef7134ade |
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 |
|
9298 | 14 |
#some bsd installations reported problems too |
9191 | 15 |
#(see 822312 654424 on bugzilla.redhat.com) |
9222 | 16 |
check_c_compiler_flag("-fstack-protector-all -fstack-protector" HAVE_STACKPROTECTOR) |
9298 | 17 |
if(HAVE_STACKPROTECTOR AND ((NOT WIN32) OR (CMAKE_SYSTEM_NAME MATCHES BSD.OS))) |
9225
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
18 |
add_flag_append(CMAKE_C_FLAGS "-fstack-protector-all -fstack-protector") |
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
19 |
add_flag_append(CMAKE_CXX_FLAGS "-fstack-protector-all -fstack-protector") |
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
20 |
add_flag_append(CMAKE_EXE_LINKER_FLAGS "-fstack-protector-all -fstack-protector") |
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
21 |
add_flag_append(CMAKE_SHARED_LIBRARY_C_FLAGS "-fstack-protector-all -fstack-protector") |
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
22 |
add_flag_append(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
|
23 |
endif() |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
24 |
|
9223
71fc5893071c
actually tests are there to be tested, just skip the variable assignment on windows
koda
parents:
9222
diff
changeset
|
25 |
#symbol visibility, not supported on Windows |
71fc5893071c
actually tests are there to be tested, just skip the variable assignment on windows
koda
parents:
9222
diff
changeset
|
26 |
check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITY) |
71fc5893071c
actually tests are there to be tested, just skip the variable assignment on windows
koda
parents:
9222
diff
changeset
|
27 |
if(HAVE_VISIBILITY AND (NOT WIN32)) |
9225
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
28 |
add_flag_append(CMAKE_C_FLAGS "-fvisibility=hidden") |
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
29 |
add_flag_append(CMAKE_CXX_FLAGS "-fvisibility=hidden") |
9155
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
30 |
endif() |
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
31 |
|
480f483de544
add fstack-protector and fvisibility=hidden to cmake tests
koda
parents:
9154
diff
changeset
|
32 |
|
9152 | 33 |
#check for noexecstack on ELF, Gentoo security |
34 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack") |
|
35 |
check_c_compiler_flag("" HAVE_NOEXECSTACK) |
|
36 |
if(HAVE_NOEXECSTACK) |
|
9225
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
37 |
add_linker_flag("-znoexecstack") |
9152 | 38 |
endif() |
39 |
||
9153 | 40 |
#check for full relro on ELF, Debian security |
9220 | 41 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro,-znow") |
9153 | 42 |
check_c_compiler_flag("" HAVE_RELROFULL) |
43 |
if(HAVE_RELROFULL) |
|
9225
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
44 |
add_linker_flag("-zrelro") |
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
45 |
add_linker_flag("-znow") |
9153 | 46 |
else() |
47 |
#if full relro is not available, try partial relro |
|
9220 | 48 |
set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro") |
9153 | 49 |
check_c_compiler_flag("" HAVE_RELROPARTIAL) |
50 |
if(HAVE_RELROPARTIAL) |
|
9225
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
51 |
add_linker_flag("-zrelro") |
9153 | 52 |
endif() |
53 |
endif() |
|
54 |
||
9152 | 55 |
#check for ASLR on Windows Vista or later, requires binutils >= 2.20 |
56 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") |
|
57 |
check_c_compiler_flag("" HAVE_WINASLR) |
|
58 |
if(HAVE_WINASLR) |
|
9225
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
59 |
add_linker_flag("--nxcompat") |
9152 | 60 |
endif() |
61 |
||
62 |
#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20 |
|
63 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") |
|
64 |
check_c_compiler_flag("" HAVE_WINDEP) |
|
65 |
if(HAVE_WINDEP) |
|
9225
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
66 |
add_linker_flag("--dynamicbase") |
9152 | 67 |
endif() |
68 |
||
9206
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
69 |
#this is actually an optimisation |
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
70 |
set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed") |
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
71 |
check_c_compiler_flag("" HAVE_ASNEEDED) |
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
72 |
if(HAVE_ASNEEDED) |
9225
d8d929f92633
use target name instead of the resulting library, use more macros around
koda
parents:
9223
diff
changeset
|
73 |
add_linker_flag("--as-needed") |
9206
4788b24fee05
since shared libs are now our friends, let's optimise them
koda
parents:
9169
diff
changeset
|
74 |
endif() |
9152 | 75 |
|
76 |
#always unset or these flags will be spread everywhere |
|
77 |
unset(CMAKE_REQUIRED_FLAGS) |
|
78 |