-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProjectOptions.cmake
216 lines (189 loc) · 7.17 KB
/
ProjectOptions.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
include(cmake/SystemLink.cmake)
include(cmake/LibFuzzer.cmake)
include(CMakeDependentOption)
include(CheckCXXCompilerFlag)
macro(RAVL2_supports_sanitizers)
if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND NOT WIN32)
set(SUPPORTS_UBSAN ON)
else()
set(SUPPORTS_UBSAN OFF)
endif()
if((CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*" OR CMAKE_CXX_COMPILER_ID MATCHES ".*GNU.*") AND WIN32)
set(SUPPORTS_ASAN OFF)
else()
set(SUPPORTS_ASAN ON)
endif()
endmacro()
macro(RAVL2_setup_options)
# CMAKE_BUILD_TYPE STREQUAL "Debug" OR
if(CMAKE_BUILD_TYPE STREQUAL "Default")
option(RAVL2_ENABLE_HARDENING "Enable hardening" ON)
else()
option(RAVL2_ENABLE_HARDENING "Enable hardening" OFF)
endif()
option(RAVL2_ENABLE_COVERAGE "Enable coverage reporting" OFF)
cmake_dependent_option(
RAVL2_ENABLE_GLOBAL_HARDENING
"Attempt to push hardening options to built dependencies"
ON
RAVL2_ENABLE_HARDENING
OFF)
RAVL2_supports_sanitizers()
if(NOT PROJECT_IS_TOP_LEVEL OR RAVL2_PACKAGING_MAINTAINER_MODE)
option(RAVL2_ENABLE_IPO "Enable IPO/LTO" OFF)
option(RAVL2_WARNINGS_AS_ERRORS "Treat Warnings As Errors" OFF)
option(RAVL2_ENABLE_USER_LINKER "Enable user-selected linker" OFF)
option(RAVL2_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" OFF)
option(RAVL2_ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF)
option(RAVL2_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" OFF)
option(RAVL2_ENABLE_SANITIZER_THREAD "Enable thread sanitizer" OFF)
option(RAVL2_ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" OFF)
option(RAVL2_ENABLE_UNITY_BUILD "Enable unity builds" OFF)
option(RAVL2_ENABLE_CLANG_TIDY "Enable clang-tidy" OFF)
option(RAVL2_ENABLE_CPPCHECK "Enable cpp-check analysis" OFF)
option(RAVL2_ENABLE_PCH "Enable precompiled headers" OFF)
option(RAVL2_ENABLE_CACHE "Enable ccache" OFF)
else()
# LTO seems to stop debug builds from working
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Default")
option(RAVL2_ENABLE_IPO "Enable IPO/LTO" OFF)
else()
option(RAVL2_ENABLE_IPO "Enable IPO/LTO" ON)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Release")
option(RAVL2_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" OFF)
option(RAVL2_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" OFF)
else()
option(RAVL2_ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" ${SUPPORTS_ASAN})
option(RAVL2_ENABLE_SANITIZER_UNDEFINED "Enable undefined sanitizer" ${SUPPORTS_UBSAN})
endif()
option(RAVL2_WARNINGS_AS_ERRORS "Treat Warnings As Errors" ON)
option(RAVL2_ENABLE_USER_LINKER "Enable user-selected linker" OFF)
option(RAVL2_ENABLE_SANITIZER_LEAK "Enable leak sanitizer" OFF)
option(RAVL2_ENABLE_SANITIZER_THREAD "Enable thread sanitizer" OFF)
option(RAVL2_ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" OFF)
option(RAVL2_ENABLE_UNITY_BUILD "Enable unity builds" OFF)
option(RAVL2_ENABLE_CLANG_TIDY "Enable clang-tidy" ON)
option(RAVL2_ENABLE_CPPCHECK "Enable cpp-check analysis" OFF)
option(RAVL2_ENABLE_PCH "Enable precompiled headers" OFF)
option(RAVL2_ENABLE_CACHE "Enable ccache" ON)
endif()
if(NOT PROJECT_IS_TOP_LEVEL)
mark_as_advanced(
RAVL2_ENABLE_IPO
RAVL2_WARNINGS_AS_ERRORS
RAVL2_ENABLE_USER_LINKER
RAVL2_ENABLE_SANITIZER_ADDRESS
RAVL2_ENABLE_SANITIZER_LEAK
RAVL2_ENABLE_SANITIZER_UNDEFINED
RAVL2_ENABLE_SANITIZER_THREAD
RAVL2_ENABLE_SANITIZER_MEMORY
RAVL2_ENABLE_UNITY_BUILD
RAVL2_ENABLE_CLANG_TIDY
RAVL2_ENABLE_CPPCHECK
RAVL2_ENABLE_COVERAGE
RAVL2_ENABLE_PCH
RAVL2_ENABLE_CACHE)
endif()
RAVL2_check_libfuzzer_support(LIBFUZZER_SUPPORTED)
if(LIBFUZZER_SUPPORTED AND (RAVL2_ENABLE_SANITIZER_ADDRESS OR RAVL2_ENABLE_SANITIZER_THREAD OR RAVL2_ENABLE_SANITIZER_UNDEFINED))
set(DEFAULT_FUZZER ON)
else()
set(DEFAULT_FUZZER OFF)
endif()
option(RAVL2_BUILD_FUZZ_TESTS "Enable fuzz testing executable" ${DEFAULT_FUZZER})
option(RAVL2_BUILD_EXAMPLES "Enable building examples" ON)
endmacro()
macro(RAVL2_global_options)
if(RAVL2_ENABLE_IPO)
include(cmake/InterproceduralOptimization.cmake)
RAVL2_enable_ipo()
endif()
RAVL2_supports_sanitizers()
if(RAVL2_ENABLE_HARDENING AND RAVL2_ENABLE_GLOBAL_HARDENING)
include(cmake/Hardening.cmake)
if(NOT SUPPORTS_UBSAN
OR RAVL2_ENABLE_SANITIZER_UNDEFINED
OR RAVL2_ENABLE_SANITIZER_ADDRESS
OR RAVL2_ENABLE_SANITIZER_THREAD
OR RAVL2_ENABLE_SANITIZER_LEAK)
set(ENABLE_UBSAN_MINIMAL_RUNTIME FALSE)
else()
set(ENABLE_UBSAN_MINIMAL_RUNTIME TRUE)
endif()
message("${RAVL2_ENABLE_HARDENING} ${ENABLE_UBSAN_MINIMAL_RUNTIME} ${RAVL2_ENABLE_SANITIZER_UNDEFINED}")
RAVL2_enable_hardening(RAVL2_options ON ${ENABLE_UBSAN_MINIMAL_RUNTIME})
endif()
endmacro()
macro(RAVL2_local_options)
if(PROJECT_IS_TOP_LEVEL)
include(cmake/StandardProjectSettings.cmake)
endif()
add_library(RAVL2_warnings INTERFACE)
add_library(RAVL2_options INTERFACE)
include(cmake/CompilerWarnings.cmake)
RAVL2_set_project_warnings(
RAVL2_warnings
${RAVL2_WARNINGS_AS_ERRORS}
""
""
""
"")
if(RAVL2_ENABLE_USER_LINKER)
include(cmake/Linker.cmake)
RAVL2_configure_linker(RAVL2_options)
endif()
include(cmake/Sanitizers.cmake)
RAVL2_enable_sanitizers(
RAVL2_options
${RAVL2_ENABLE_SANITIZER_ADDRESS}
${RAVL2_ENABLE_SANITIZER_LEAK}
${RAVL2_ENABLE_SANITIZER_UNDEFINED}
${RAVL2_ENABLE_SANITIZER_THREAD}
${RAVL2_ENABLE_SANITIZER_MEMORY})
set_target_properties(RAVL2_options PROPERTIES UNITY_BUILD ${RAVL2_ENABLE_UNITY_BUILD})
if(RAVL2_ENABLE_PCH)
target_precompile_headers(
RAVL2_options
INTERFACE
<vector>
<string>
<utility>)
endif()
if(RAVL2_ENABLE_CACHE)
include(cmake/Cache.cmake)
RAVL2_enable_cache()
endif()
include(cmake/StaticAnalyzers.cmake)
if(RAVL2_ENABLE_CLANG_TIDY)
RAVL2_enable_clang_tidy(RAVL2_options ${RAVL2_WARNINGS_AS_ERRORS})
endif()
if(RAVL2_ENABLE_CPPCHECK)
RAVL2_enable_cppcheck(${RAVL2_WARNINGS_AS_ERRORS} "" # override cppcheck options
)
endif()
if(RAVL2_ENABLE_COVERAGE)
include(cmake/Tests.cmake)
RAVL2_enable_coverage(RAVL2_options)
endif()
if(RAVL2_WARNINGS_AS_ERRORS)
check_cxx_compiler_flag("-Wl,--fatal-warnings" LINKER_FATAL_WARNINGS)
if(LINKER_FATAL_WARNINGS)
# This is not working consistently, so disabling for now
# target_link_options(RAVL2_options INTERFACE -Wl,--fatal-warnings)
endif()
endif()
if(RAVL2_ENABLE_HARDENING AND NOT RAVL2_ENABLE_GLOBAL_HARDENING)
include(cmake/Hardening.cmake)
if(NOT SUPPORTS_UBSAN
OR RAVL2_ENABLE_SANITIZER_UNDEFINED
OR RAVL2_ENABLE_SANITIZER_ADDRESS
OR RAVL2_ENABLE_SANITIZER_THREAD
OR RAVL2_ENABLE_SANITIZER_LEAK)
set(ENABLE_UBSAN_MINIMAL_RUNTIME FALSE)
else()
set(ENABLE_UBSAN_MINIMAL_RUNTIME TRUE)
endif()
RAVL2_enable_hardening(RAVL2_options OFF ${ENABLE_UBSAN_MINIMAL_RUNTIME})
endif()
endmacro()