From d2bd95fd7e8bae264ba4248e960924e78c750a6c Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 10 Aug 2025 18:09:25 +0100 Subject: [PATCH 1/5] cmake: Move `is_multi_config` to unconditional flow This change ensures the correct evaluation of `is_multi_config` when printing the configure summary. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11dc3f6e53..61747f66b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,8 +174,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 From 8923d470f2c06b4cb7e7d26b9652d3790409a11a Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 10 Aug 2025 18:17:33 +0100 Subject: [PATCH 2/5] cmake: Do not hard-code `CMAKE_CONFIGURATION_TYPES` The initial idea was to place the desired default build configuration first in `CMAKE_CONFIGURATION_TYPES`. The "Ninja Multi-Config" generator treats the first configuration as the default, but this is not the case for other generators. This change uses the dedicated `CMAKE_DEFAULT_BUILD_TYPE` variable for the same purpose, avoiding hard-coding `CMAKE_CONFIGURATION_TYPES` and preserving users' settings, if any. --- CMakeLists.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61747f66b8..677e6f6898 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,12 +177,10 @@ mark_as_advanced( get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(PROJECT_IS_TOP_LEVEL) 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 +192,7 @@ if(PROJECT_IS_TOP_LEVEL) ) endif() endif() + unset(default_build_type) endif() include(TryAppendCFlags) From 78ef6a73f900d27e5a2872ca7a068deac861fb92 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 10 Aug 2025 18:20:30 +0100 Subject: [PATCH 3/5] cmake: Allow user to override "Coverage" build type flags --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 677e6f6898..f3a1662869 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,15 +158,12 @@ 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 From b2119a790f980abc84f50e207769d113dd8f7bf2 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 10 Aug 2025 18:24:34 +0100 Subject: [PATCH 4/5] cmake: Explicitly specify generators that support Coverage functionality Only the "Ninja Multi-Config" generator supports an `EXCLUDE_FROM_ALL` target property value that varies by configuration. --- CMakeLists.txt | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f3a1662869..6bc8a34ac5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,20 +156,27 @@ 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." -) -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." -) -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) From 7d5a19ca8877b7534c06efac94f71a668d7fabe7 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 10 Aug 2025 18:28:00 +0100 Subject: [PATCH 5/5] cmake: Rework `tests` target for Coverage and multi-config generators --- CMakeLists.txt | 9 +++++++-- src/CMakeLists.txt | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bc8a34ac5..804be1e528 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,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)