@@ -145,9 +145,20 @@ if(SECP256K1_VALGRIND)
145
145
endif ()
146
146
147
147
option (SECP256K1_BUILD_BENCHMARK "Build benchmarks." ON )
148
+
149
+ include (CMakeDependentOption )
150
+ cmake_dependent_option (SECP256K1_COVERAGE "Enable coverage analysis support." OFF "NOT MSVC" OFF )
151
+ include (TryAppendCFlags )
152
+ if (SECP256K1_COVERAGE )
153
+ add_compile_definitions (COVERAGE )
154
+ try_append_c_flags (-O0 --coverage )
155
+ add_link_options (--coverage )
156
+ endif ()
157
+
148
158
option (SECP256K1_BUILD_TESTS "Build tests." ON )
149
159
option (SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON )
150
160
option (SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND} )
161
+
151
162
option (SECP256K1_BUILD_EXAMPLES "Build examples." OFF )
152
163
153
164
include (ProcessConfigurations )
@@ -159,37 +170,14 @@ if(MSVC)
159
170
remove_flag_from_all_configs (/DNDEBUG )
160
171
else ()
161
172
remove_flag_from_all_configs (-DNDEBUG )
162
- # Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
163
- replace_flag_in_config (Release -O3 -O2 )
164
- endif ()
165
-
166
- # Define custom "Coverage" build type.
167
- set (CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O0 -DCOVERAGE=1 --coverage" CACHE STRING
168
- "Flags used by the C compiler during \" Coverage\" builds."
169
- FORCE
170
- )
171
- set (CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING
172
- "Flags used for linking binaries during \" Coverage\" builds."
173
- FORCE
174
- )
175
- set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING
176
- "Flags used by the shared libraries linker during \" Coverage\" builds."
177
- FORCE
178
- )
179
- mark_as_advanced (
180
- CMAKE_C_FLAGS_COVERAGE
181
- CMAKE_EXE_LINKER_FLAGS_COVERAGE
182
- CMAKE_SHARED_LINKER_FLAGS_COVERAGE
183
- )
184
-
185
- get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
186
- if (is_multi_config )
187
- list (APPEND CMAKE_CONFIGURATION_TYPES Coverage )
188
- else ()
189
- set_property (CACHE CMAKE_BUILD_TYPE APPEND PROPERTY STRINGS Coverage )
173
+ if (SECP256K1_COVERAGE )
174
+ remove_flag_from_all_configs (-O[s0-9] )
175
+ else ()
176
+ # Prefer -O2 optimization level. (-O3 is CMake's default for Release for many compilers.)
177
+ replace_flag_in_config (Release -O3 -O2 )
178
+ endif ()
190
179
endif ()
191
180
192
- include (TryAppendCFlags )
193
181
if (MSVC )
194
182
# Keep the following commands ordered lexicographically.
195
183
try_append_c_flags (/W2 ) # Moderate warning level.
@@ -259,7 +247,7 @@ message("Optional binaries:")
259
247
message (" benchmark ........................... ${SECP256K1_BUILD_BENCHMARK} " )
260
248
message (" noverify_tests ...................... ${SECP256K1_BUILD_TESTS} " )
261
249
set (tests_status "${SECP256K1_BUILD_TESTS} " )
262
- if (CMAKE_BUILD_TYPE STREQUAL "Coverage" )
250
+ if (SECP256K1_COVERAGE )
263
251
set (tests_status OFF )
264
252
endif ()
265
253
message (" tests ............................... ${tests_status} " )
0 commit comments