12 #stack protection, when found it needs to go in the linker flags too |
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 |
13 #it is disabled on win32 because it adds a dll and messes with linker |
14 #(see 822312 654424 on bugzilla.redhat.com) |
14 #(see 822312 654424 on bugzilla.redhat.com) |
15 check_c_compiler_flag("-fstack-protector-all -fstack-protector" HAVE_STACKPROTECTOR) |
15 check_c_compiler_flag("-fstack-protector-all -fstack-protector" HAVE_STACKPROTECTOR) |
16 if(HAVE_STACKPROTECTOR AND (NOT WIN32)) |
16 if(HAVE_STACKPROTECTOR AND (NOT WIN32)) |
17 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all -fstack-protector") |
17 add_flag_append(CMAKE_C_FLAGS "-fstack-protector-all -fstack-protector") |
18 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -fstack-protector") |
18 add_flag_append(CMAKE_CXX_FLAGS "-fstack-protector-all -fstack-protector") |
19 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fstack-protector-all -fstack-protector") |
19 add_flag_append(CMAKE_EXE_LINKER_FLAGS "-fstack-protector-all -fstack-protector") |
20 set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -fstack-protector-all -fstack-protector") |
20 add_flag_append(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") |
21 add_flag_append(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-fstack-protector-all -fstack-protector") |
22 endif() |
22 endif() |
23 |
23 |
24 #symbol visibility, not supported on Windows |
24 #symbol visibility, not supported on Windows |
25 check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITY) |
25 check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITY) |
26 if(HAVE_VISIBILITY AND (NOT WIN32)) |
26 if(HAVE_VISIBILITY AND (NOT WIN32)) |
27 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") |
27 add_flag_append(CMAKE_C_FLAGS "-fvisibility=hidden") |
28 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") |
28 add_flag_append(CMAKE_CXX_FLAGS "-fvisibility=hidden") |
29 endif() |
29 endif() |
30 |
30 |
31 |
31 |
32 #check for noexecstack on ELF, Gentoo security |
32 #check for noexecstack on ELF, Gentoo security |
33 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack") |
33 set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack") |
34 check_c_compiler_flag("" HAVE_NOEXECSTACK) |
34 check_c_compiler_flag("" HAVE_NOEXECSTACK) |
35 if(HAVE_NOEXECSTACK) |
35 if(HAVE_NOEXECSTACK) |
36 append_linker_flag("-znoexecstack") |
36 add_linker_flag("-znoexecstack") |
37 endif() |
37 endif() |
38 |
38 |
39 #check for full relro on ELF, Debian security |
39 #check for full relro on ELF, Debian security |
40 set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro,-znow") |
40 set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro,-znow") |
41 check_c_compiler_flag("" HAVE_RELROFULL) |
41 check_c_compiler_flag("" HAVE_RELROFULL) |
42 if(HAVE_RELROFULL) |
42 if(HAVE_RELROFULL) |
43 append_linker_flag("-zrelro") |
43 add_linker_flag("-zrelro") |
44 append_linker_flag("-znow") |
44 add_linker_flag("-znow") |
45 else() |
45 else() |
46 #if full relro is not available, try partial relro |
46 #if full relro is not available, try partial relro |
47 set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro") |
47 set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro") |
48 check_c_compiler_flag("" HAVE_RELROPARTIAL) |
48 check_c_compiler_flag("" HAVE_RELROPARTIAL) |
49 if(HAVE_RELROPARTIAL) |
49 if(HAVE_RELROPARTIAL) |
50 append_linker_flag("-zrelro") |
50 add_linker_flag("-zrelro") |
51 endif() |
51 endif() |
52 endif() |
52 endif() |
53 |
53 |
54 #check for ASLR on Windows Vista or later, requires binutils >= 2.20 |
54 #check for ASLR on Windows Vista or later, requires binutils >= 2.20 |
55 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") |
55 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") |
56 check_c_compiler_flag("" HAVE_WINASLR) |
56 check_c_compiler_flag("" HAVE_WINASLR) |
57 if(HAVE_WINASLR) |
57 if(HAVE_WINASLR) |
58 append_linker_flag("--nxcompat") |
58 add_linker_flag("--nxcompat") |
59 endif() |
59 endif() |
60 |
60 |
61 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20 |
61 #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20 |
62 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") |
62 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") |
63 check_c_compiler_flag("" HAVE_WINDEP) |
63 check_c_compiler_flag("" HAVE_WINDEP) |
64 if(HAVE_WINDEP) |
64 if(HAVE_WINDEP) |
65 append_linker_flag("--dynamicbase") |
65 add_linker_flag("--dynamicbase") |
66 endif() |
66 endif() |
67 |
67 |
68 #this is actually an optimisation |
68 #this is actually an optimisation |
69 set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed") |
69 set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed") |
70 check_c_compiler_flag("" HAVE_ASNEEDED) |
70 check_c_compiler_flag("" HAVE_ASNEEDED) |
71 if(HAVE_ASNEEDED) |
71 if(HAVE_ASNEEDED) |
72 append_linker_flag("--as-needed") |
72 add_linker_flag("--as-needed") |
73 endif() |
73 endif() |
74 |
74 |
75 #always unset or these flags will be spread everywhere |
75 #always unset or these flags will be spread everywhere |
76 unset(CMAKE_REQUIRED_FLAGS) |
76 unset(CMAKE_REQUIRED_FLAGS) |
77 |
77 |