@@ -156,9 +156,20 @@ if(SECP256K1_VALGRIND)
156
156
endif ()
157
157
158
158
option (SECP256K1_BUILD_BENCHMARK "Build benchmarks." ON )
159
+
160
+ include (CMakeDependentOption )
161
+ cmake_dependent_option (SECP256K1_COVERAGE "Enable coverage analysis support." OFF "NOT MSVC" OFF )
162
+ include (TryAppendCFlags )
163
+ if (SECP256K1_COVERAGE )
164
+ add_compile_definitions (COVERAGE )
165
+ try_append_c_flags (-O0 --coverage )
166
+ add_link_options (--coverage )
167
+ endif ()
168
+
159
169
option (SECP256K1_BUILD_TESTS "Build tests." ON )
160
170
option (SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON )
161
171
option (SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND} )
172
+
162
173
option (SECP256K1_BUILD_EXAMPLES "Build examples." OFF )
163
174
164
175
include (ProcessConfigurations )
@@ -170,37 +181,14 @@ if(MSVC)
170
181
remove_flag_from_all_configs (/DNDEBUG )
171
182
else ()
172
183
remove_flag_from_all_configs (-DNDEBUG )
173
- # Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
174
- replace_flag_in_config (Release -O3 -O2 )
175
- endif ()
176
-
177
- # Define custom "Coverage" build type.
178
- set (CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O0 -DCOVERAGE=1 --coverage" CACHE STRING
179
- "Flags used by the C compiler during \" Coverage\" builds."
180
- FORCE
181
- )
182
- set (CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING
183
- "Flags used for linking binaries during \" Coverage\" builds."
184
- FORCE
185
- )
186
- set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING
187
- "Flags used by the shared libraries linker during \" Coverage\" builds."
188
- FORCE
189
- )
190
- mark_as_advanced (
191
- CMAKE_C_FLAGS_COVERAGE
192
- CMAKE_EXE_LINKER_FLAGS_COVERAGE
193
- CMAKE_SHARED_LINKER_FLAGS_COVERAGE
194
- )
195
-
196
- get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
197
- if (is_multi_config )
198
- list (APPEND CMAKE_CONFIGURATION_TYPES Coverage )
199
- else ()
200
- set_property (CACHE CMAKE_BUILD_TYPE APPEND PROPERTY STRINGS Coverage )
184
+ if (SECP256K1_COVERAGE )
185
+ remove_flag_from_all_configs (-O[s0-9] )
186
+ else ()
187
+ # Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
188
+ replace_flag_in_config (Release -O3 -O2 )
189
+ endif ()
201
190
endif ()
202
191
203
- include (TryAppendCFlags )
204
192
if (MSVC )
205
193
# Keep the following commands ordered lexicographically.
206
194
try_append_c_flags (/W3 ) # Production quality warning level.
@@ -275,7 +263,7 @@ message("Optional binaries:")
275
263
message (" benchmark ........................... ${SECP256K1_BUILD_BENCHMARK} " )
276
264
message (" noverify_tests ...................... ${SECP256K1_BUILD_TESTS} " )
277
265
set (tests_status "${SECP256K1_BUILD_TESTS} " )
278
- if (CMAKE_BUILD_TYPE STREQUAL "Coverage" )
266
+ if (SECP256K1_COVERAGE )
279
267
set (tests_status OFF )
280
268
endif ()
281
269
message (" tests ............................... ${tests_status} " )
0 commit comments