Skip to content

Commit 42c93ac

Browse files
committed
cmake: Use "coverage" preset instead of "Coverage" build type
1 parent 72b5472 commit 42c93ac

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

CMakeLists.txt

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ endif()
128128

129129
option(SECP256K1_BUILD_BENCHMARK "Build benchmarks." ON)
130130
option(SECP256K1_BUILD_TESTS "Build tests." ON)
131+
option(SECP256K1_BUILD_VERIFY_TESTS "Build tests with -DVERIFY." ${SECP256K1_BUILD_TESTS})
132+
mark_as_advanced(SECP256K1_BUILD_VERIFY_TESTS)
131133
option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON)
132134
option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND})
133135
option(SECP256K1_BUILD_EXAMPLES "Build examples." OFF)
@@ -146,33 +148,14 @@ else()
146148
string(REGEX REPLACE "-O3[ \t\r\n]*" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
147149
endif()
148150

149-
# Define custom "Coverage" build type.
150-
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O0 -DCOVERAGE=1 --coverage" CACHE STRING
151-
"Flags used by the C compiler during \"Coverage\" builds."
152-
FORCE
153-
)
154-
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING
155-
"Flags used for linking binaries during \"Coverage\" builds."
156-
FORCE
157-
)
158-
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING
159-
"Flags used by the shared libraries linker during \"Coverage\" builds."
160-
FORCE
161-
)
162-
mark_as_advanced(
163-
CMAKE_C_FLAGS_COVERAGE
164-
CMAKE_EXE_LINKER_FLAGS_COVERAGE
165-
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
166-
)
167-
168151
if(CMAKE_CONFIGURATION_TYPES)
169-
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" "Release" "Debug" "MinSizeRel" "Coverage")
152+
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" "Release" "Debug" "MinSizeRel")
170153
endif()
171154

172155
get_property(cached_cmake_build_type CACHE CMAKE_BUILD_TYPE PROPERTY TYPE)
173156
if(cached_cmake_build_type)
174157
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
175-
STRINGS "RelWithDebInfo" "Release" "Debug" "MinSizeRel" "Coverage"
158+
STRINGS "RelWithDebInfo" "Release" "Debug" "MinSizeRel"
176159
)
177160
endif()
178161

@@ -244,11 +227,7 @@ endif()
244227
message("Optional binaries:")
245228
message(" benchmark ........................... ${SECP256K1_BUILD_BENCHMARK}")
246229
message(" noverify_tests ...................... ${SECP256K1_BUILD_TESTS}")
247-
set(tests_status "${SECP256K1_BUILD_TESTS}")
248-
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
249-
set(tests_status OFF)
250-
endif()
251-
message(" tests ............................... ${tests_status}")
230+
message(" tests ............................... ${SECP256K1_BUILD_VERIFY_TESTS}")
252231
message(" exhaustive tests .................... ${SECP256K1_BUILD_EXHAUSTIVE_TESTS}")
253232
message(" ctime_tests ......................... ${SECP256K1_BUILD_CTIME_TESTS}")
254233
message(" examples ............................ ${SECP256K1_BUILD_EXAMPLES}")

CMakePresets.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
"dev": true,
1919
"uninitialized": true
2020
}
21+
},
22+
{
23+
"name": "coverage",
24+
"displayName": "Build for coverage analysis",
25+
"generator": "Unix Makefiles",
26+
"cacheVariables": {
27+
"CMAKE_C_COMPILER": "gcc",
28+
"CMAKE_C_FLAGS": "-DCOVERAGE=1 -O0 --coverage",
29+
"CMAKE_BUILD_TYPE": "None",
30+
"SECP256K1_ENABLE_MODULE_RECOVERY": "ON",
31+
"SECP256K1_BUILD_BENCHMARK": "OFF",
32+
"SECP256K1_BUILD_VERIFY_TESTS": "OFF"
33+
}
2134
}
2235
]
2336
}

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ if(SECP256K1_BUILD_TESTS)
8080
add_executable(noverify_tests tests.c ${internal_obj})
8181
target_link_libraries(noverify_tests binary_interface)
8282
add_test(noverify_tests noverify_tests)
83-
if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
83+
if(SECP256K1_BUILD_VERIFY_TESTS)
8484
add_executable(tests tests.c ${internal_obj})
8585
target_compile_definitions(tests PRIVATE VERIFY)
8686
target_link_libraries(tests binary_interface)
@@ -91,7 +91,7 @@ endif()
9191
if(SECP256K1_BUILD_EXHAUSTIVE_TESTS)
9292
# Note: do not include $<TARGET_OBJECTS:precomputed> in exhaustive_tests (it uses runtime-generated tables).
9393
add_executable(exhaustive_tests tests_exhaustive.c ${common_obj})
94-
target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>)
94+
target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:None>>:VERIFY>)
9595
target_link_libraries(exhaustive_tests binary_interface)
9696
add_test(exhaustive_tests exhaustive_tests)
9797
endif()

0 commit comments

Comments
 (0)