diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ca8cbe8e3..fb30d69458 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,8 +200,8 @@ mark_as_advanced( CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) +get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(PROJECT_IS_TOP_LEVEL) - get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) set(default_build_type "RelWithDebInfo") if(is_multi_config) set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING @@ -311,10 +311,15 @@ message("Optional binaries:") message(" benchmark ........................... ${SECP256K1_BUILD_BENCHMARK}") message(" noverify_tests ...................... ${SECP256K1_BUILD_TESTS}") set(tests_status "${SECP256K1_BUILD_TESTS}") -if(CMAKE_BUILD_TYPE STREQUAL "Coverage") - set(tests_status OFF) +if(tests_status) + if(is_multi_config) + set(tests_status "${tests_status}, except for the 'Coverage' configuration") + elseif(CMAKE_BUILD_TYPE STREQUAL "Coverage") + set(tests_status OFF) + endif() endif() message(" tests ............................... ${tests_status}") +unset(tests_status) message(" exhaustive tests .................... ${SECP256K1_BUILD_EXHAUSTIVE_TESTS}") message(" ctime_tests ......................... ${SECP256K1_BUILD_CTIME_TESTS}") message(" examples ............................ ${SECP256K1_BUILD_EXAMPLES}") @@ -363,6 +368,14 @@ if(print_msan_notice) " to avoid false positives in ctime_tests. Pass -DSECP256K1_BUILD_CTIME_TESTS=OFF to avoid this.\n" ) endif() +if($CACHE{SECP256K1_print_coverage_notice}) + message( + "Note:\n" + " CMake ${CMAKE_VERSION} does not support the '${CMAKE_GENERATOR}' generator fully. Consequently,\n" + " the build system will still compile the 'tests' binary for the 'Coverage' configuration,\n" + " which is meaningless.\n" + ) +endif() if(SECP256K1_EXPERIMENTAL) message( " ******\n" diff --git a/configure.ac b/configure.ac index 6841543f59..a3a405793d 100644 --- a/configure.ac +++ b/configure.ac @@ -145,7 +145,7 @@ AC_ARG_ENABLE(benchmark, [SECP_SET_DEFAULT([enable_benchmark], [yes], [yes])]) AC_ARG_ENABLE(coverage, - AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis [default=no]]), [], + AS_HELP_STRING([--enable-coverage],[enable coverage analysis support [default=no]]), [], [SECP_SET_DEFAULT([enable_coverage], [no], [no])]) AC_ARG_ENABLE(tests, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4cbaeb914d..c97b1e797d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,12 +88,24 @@ if(SECP256K1_BUILD_TESTS) add_executable(noverify_tests tests.c) target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm) add_test(NAME noverify_tests COMMAND noverify_tests) - if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage") - add_executable(tests tests.c) - target_compile_definitions(tests PRIVATE VERIFY) - target_link_libraries(tests secp256k1_precomputed secp256k1_asm) - add_test(NAME tests COMMAND tests) + + add_executable(tests tests.c) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19) + set_target_properties(tests PROPERTIES EXCLUDE_FROM_ALL $) + else() + get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(is_multi_config) + set(SECP256K1_print_coverage_notice YES CACHE INTERNAL "") + endif() + endif() + target_compile_definitions(tests PRIVATE VERIFY) + target_link_libraries(tests secp256k1_precomputed secp256k1_asm) + set(configs ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES}) + list(REMOVE_ITEM configs Coverage) + if(configs) + add_test(NAME tests COMMAND tests CONFIGURATIONS ${configs}) endif() + unset(configs) endif() if(SECP256K1_BUILD_EXHAUSTIVE_TESTS)