Skip to content

Commit 87534e7

Browse files
committed
cmake: Rework tests target for Coverage and multi-config generators
1 parent b307614 commit 87534e7

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ mark_as_advanced(
200200
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
201201
)
202202

203+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
203204
if(PROJECT_IS_TOP_LEVEL)
204-
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
205205
set(default_build_type "RelWithDebInfo")
206206
if(is_multi_config)
207207
set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
@@ -311,10 +311,15 @@ message("Optional binaries:")
311311
message(" benchmark ........................... ${SECP256K1_BUILD_BENCHMARK}")
312312
message(" noverify_tests ...................... ${SECP256K1_BUILD_TESTS}")
313313
set(tests_status "${SECP256K1_BUILD_TESTS}")
314-
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
315-
set(tests_status OFF)
314+
if(tests_status)
315+
if(is_multi_config)
316+
set(tests_status "${tests_status}, except for the 'Coverage' configuration")
317+
elseif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
318+
set(tests_status OFF)
319+
endif()
316320
endif()
317321
message(" tests ............................... ${tests_status}")
322+
unset(tests_status)
318323
message(" exhaustive tests .................... ${SECP256K1_BUILD_EXHAUSTIVE_TESTS}")
319324
message(" ctime_tests ......................... ${SECP256K1_BUILD_CTIME_TESTS}")
320325
message(" examples ............................ ${SECP256K1_BUILD_EXAMPLES}")
@@ -363,6 +368,14 @@ if(print_msan_notice)
363368
" to avoid false positives in ctime_tests. Pass -DSECP256K1_BUILD_CTIME_TESTS=OFF to avoid this.\n"
364369
)
365370
endif()
371+
if($CACHE{SECP256K1_print_coverage_notice})
372+
message(
373+
"Note:\n"
374+
" CMake ${CMAKE_VERSION} does not support the '${CMAKE_GENERATOR}' generator fully. Consequently,\n"
375+
" the build system will still compile the 'tests' binary for the 'Coverage' configuration,\n"
376+
" which is meaningless.\n"
377+
)
378+
endif()
366379
if(SECP256K1_EXPERIMENTAL)
367380
message(
368381
" ******\n"

src/CMakeLists.txt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,24 @@ if(SECP256K1_BUILD_TESTS)
8888
add_executable(noverify_tests tests.c)
8989
target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm)
9090
add_test(NAME noverify_tests COMMAND noverify_tests)
91-
if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
92-
add_executable(tests tests.c)
93-
target_compile_definitions(tests PRIVATE VERIFY)
94-
target_link_libraries(tests secp256k1_precomputed secp256k1_asm)
95-
add_test(NAME tests COMMAND tests)
91+
92+
add_executable(tests tests.c)
93+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
94+
set_target_properties(tests PROPERTIES EXCLUDE_FROM_ALL $<CONFIG:Coverage>)
95+
else()
96+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
97+
if(is_multi_config)
98+
set(SECP256K1_print_coverage_notice YES CACHE INTERNAL "")
99+
endif()
100+
endif()
101+
target_compile_definitions(tests PRIVATE VERIFY)
102+
target_link_libraries(tests secp256k1_precomputed secp256k1_asm)
103+
set(configs ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES})
104+
list(REMOVE_ITEM configs Coverage)
105+
if(configs)
106+
add_test(NAME tests COMMAND tests CONFIGURATIONS ${configs})
96107
endif()
108+
unset(configs)
97109
endif()
98110

99111
if(SECP256K1_BUILD_EXHAUSTIVE_TESTS)

0 commit comments

Comments
 (0)