@@ -22,41 +22,45 @@ include(CheckCCompilerFlagStackSmashing)
2222
2323if ("${CMAKE_C_COMPILER_ID} " STREQUAL "GNU" )
2424
25- # Detect position independent code flag
26- check_c_compiler_flag("-fPIC" PIC_C_FLAG)
25+ if (OPTION_BUILD_PIC)
26+ # Detect position independent code flag
27+ check_c_compiler_flag("-fPIC" PIC_C_FLAG)
2728
28- if (PIC_C_FLAG)
29- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" )
29+ if (PIC_C_FLAG)
30+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" )
31+ endif ()
3032 endif ()
3133
32- # Detect stack protector
33- check_c_compiler_flag_stack_smashing("-fstack-protector-strong" STACK_PROTECTOR_STRONG_C_FLAG)
34-
35- if (STACK_PROTECTOR_STRONG_C_FLAG)
36- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong" )
34+ if (OPTION_BUILD_SECURITY)
35+ # Detect stack protector
36+ check_c_compiler_flag_stack_smashing("-fstack-protector-strong" STACK_PROTECTOR_STRONG_C_FLAG)
3737
38- # use ssp-buffer-size if it is supported
39- if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9)
40- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --param ssp-buffer-size=4" )
41- endif ()
42- else ()
43- check_c_compiler_flag_stack_smashing("-fstack-protector" STACK_PROTECTOR_CXX_FLAG)
44-
45- if (STACK_PROTECTOR_C_FLAG)
46- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector" )
38+ if (STACK_PROTECTOR_STRONG_C_FLAG)
39+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong" )
4740
4841 # use ssp-buffer-size if it is supported
4942 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9)
5043 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --param ssp-buffer-size=4" )
5144 endif ()
45+ else ()
46+ check_c_compiler_flag_stack_smashing("-fstack-protector" STACK_PROTECTOR_CXX_FLAG)
47+
48+ if (STACK_PROTECTOR_C_FLAG)
49+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector" )
50+
51+ # use ssp-buffer-size if it is supported
52+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9)
53+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --param ssp-buffer-size=4" )
54+ endif ()
55+ endif ()
5256 endif ()
53- endif ()
5457
55- # Detect fortify source
56- check_c_compiler_flag("-D_FORTIFY_SOURCE=2" FORTIFY_SOURCE_C_FLAG)
58+ # Detect fortify source
59+ check_c_compiler_flag("-D_FORTIFY_SOURCE=2" FORTIFY_SOURCE_C_FLAG)
5760
58- if (FORTIFY_SOURCE_C_FLAG)
59- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -D_FORTIFY_SOURCE=2" )
61+ if (FORTIFY_SOURCE_C_FLAG)
62+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -D_FORTIFY_SOURCE=2" )
63+ endif ()
6064 endif ()
6165
6266endif ()
@@ -66,41 +70,45 @@ include(CheckCXXCompilerFlagStackSmashing)
6670
6771if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
6872
69- # Detect position independent code flag
70- check_cxx_compiler_flag("-fPIC" PIC_CXX_FLAG)
73+ if (OPTION_BUILD_PIC)
74+ # Detect position independent code flag
75+ check_cxx_compiler_flag("-fPIC" PIC_CXX_FLAG)
7176
72- if (PIC_CXX_FLAG)
73- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" )
77+ if (PIC_CXX_FLAG)
78+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" )
79+ endif ()
7480 endif ()
7581
76- # Detect stack protector
77- check_cxx_compiler_flag_stack_smashing("-fstack-protector-strong" STACK_PROTECTOR_STRONG_CXX_FLAG)
78-
79- if (STACK_PROTECTOR_STRONG_CXX_FLAG)
80- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong" )
82+ if (OPTION_BUILD_SECURITY)
83+ # Detect stack protector
84+ check_cxx_compiler_flag_stack_smashing("-fstack-protector-strong" STACK_PROTECTOR_STRONG_CXX_FLAG)
8185
82- # use ssp-buffer-size if it is supported
83- if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
84- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --param ssp-buffer-size=4" )
85- endif ()
86- else ()
87- check_cxx_compiler_flag_stack_smashing("-fstack-protector" STACK_PROTECTOR_CXX_FLAG)
88-
89- if (STACK_PROTECTOR_CXX_FLAG)
90- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector" )
86+ if (STACK_PROTECTOR_STRONG_CXX_FLAG)
87+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong" )
9188
9289 # use ssp-buffer-size if it is supported
9390 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
9491 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --param ssp-buffer-size=4" )
9592 endif ()
93+ else ()
94+ check_cxx_compiler_flag_stack_smashing("-fstack-protector" STACK_PROTECTOR_CXX_FLAG)
95+
96+ if (STACK_PROTECTOR_CXX_FLAG)
97+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector" )
98+
99+ # use ssp-buffer-size if it is supported
100+ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
101+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --param ssp-buffer-size=4" )
102+ endif ()
103+ endif ()
96104 endif ()
97- endif ()
98105
99- # Detect fortify source
100- check_cxx_compiler_flag("-D_FORTIFY_SOURCE=2" FORTIFY_SOURCE_CXX_FLAG)
106+ # Detect fortify source
107+ check_cxx_compiler_flag("-D_FORTIFY_SOURCE=2" FORTIFY_SOURCE_CXX_FLAG)
101108
102- if (FORTIFY_SOURCE_CXX_FLAG)
103- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -D_FORTIFY_SOURCE=2" )
109+ if (FORTIFY_SOURCE_CXX_FLAG)
110+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -D_FORTIFY_SOURCE=2" )
111+ endif ()
104112 endif ()
105113
106114endif ()
0 commit comments