Skip to content

Commit

Permalink
cmake: Rework tests target for Coverage and multi-config generators
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Aug 18, 2024
1 parent b307614 commit 87534e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
19 changes: 16 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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"
Expand Down
22 changes: 17 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<CONFIG:Coverage>)
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)
Expand Down

0 comments on commit 87534e7

Please sign in to comment.