diff --git a/CMakeLists.txt b/CMakeLists.txt index 11dc3f6e53..804be1e528 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,33 +156,35 @@ else() endif() # Define custom "Coverage" build type. -set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O0 -DCOVERAGE=1 --coverage" CACHE STRING - "Flags used by the C compiler during \"Coverage\" builds." - FORCE -) -set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING - "Flags used for linking binaries during \"Coverage\" builds." - FORCE -) -set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING - "Flags used by the shared libraries linker during \"Coverage\" builds." - FORCE -) -mark_as_advanced( - CMAKE_C_FLAGS_COVERAGE - CMAKE_EXE_LINKER_FLAGS_COVERAGE - CMAKE_SHARED_LINKER_FLAGS_COVERAGE -) +# The list of default build targets depends on whether they are being built for coverage. +# This functionality is limited to generators that support it. +if(CMAKE_GENERATOR MATCHES "Make|Ninja") + set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O0 -DCOVERAGE=1 --coverage" CACHE STRING + "Flags used by the C compiler during \"Coverage\" builds." + ) + set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING + "Flags used for linking binaries during \"Coverage\" builds." + ) + set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} --coverage" CACHE STRING + "Flags used by the shared libraries linker during \"Coverage\" builds." + ) + if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config") + list(APPEND CMAKE_CONFIGURATION_TYPES "Coverage") + endif() + mark_as_advanced( + CMAKE_C_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE + ) +endif() +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 - "Supported configuration types." - FORCE - ) - else() + if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config") + # Specify the configuration to use by default in the "Ninja Multi-Config" generator. + set(CMAKE_DEFAULT_BUILD_TYPE ${default_build_type} CACHE STRING "") + elseif(NOT is_multi_config) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" ) @@ -194,6 +196,7 @@ if(PROJECT_IS_TOP_LEVEL) ) endif() endif() + unset(default_build_type) endif() include(TryAppendCFlags) @@ -298,10 +301,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(CMAKE_GENERATOR STREQUAL "Ninja 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}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa3b2903eb..dc2292f920 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,12 +137,19 @@ if(SECP256K1_BUILD_TESTS) add_executable(noverify_tests tests.c) target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm) add_test(NAME secp256k1_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 secp256k1_tests COMMAND tests) + + add_executable(tests tests.c) + if(CMAKE_GENERATOR STREQUAL "Ninja Multi-Config") + set_target_properties(tests PROPERTIES EXCLUDE_FROM_ALL $) + 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 secp256k1_tests COMMAND tests CONFIGURATIONS ${configs}) endif() + unset(configs) endif() if(SECP256K1_BUILD_EXHAUSTIVE_TESTS)