diff --git a/CMakeLists.txt b/CMakeLists.txt index fe716c8bde..dd8d76851d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,6 +134,8 @@ endif() option(SECP256K1_BUILD_BENCHMARK "Build benchmarks." ON) option(SECP256K1_BUILD_TESTS "Build tests." ON) +option(SECP256K1_BUILD_VERIFY_TESTS "Build tests with -DVERIFY." ${SECP256K1_BUILD_TESTS}) +mark_as_advanced(SECP256K1_BUILD_VERIFY_TESTS) option(SECP256K1_BUILD_EXHAUSTIVE_TESTS "Build exhaustive tests." ON) option(SECP256K1_BUILD_CTIME_TESTS "Build constant-time tests." ${SECP256K1_VALGRIND}) option(SECP256K1_BUILD_EXAMPLES "Build examples." OFF) @@ -258,11 +260,7 @@ endif() 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) -endif() -message(" tests ............................... ${tests_status}") +message(" tests ............................... ${SECP256K1_BUILD_VERIFY_TESTS}") message(" exhaustive tests .................... ${SECP256K1_BUILD_EXHAUSTIVE_TESTS}") message(" ctime_tests ......................... ${SECP256K1_BUILD_CTIME_TESTS}") message(" examples ............................ ${SECP256K1_BUILD_EXAMPLES}") diff --git a/CMakePresets.json b/CMakePresets.json index b35cd80579..b551e222e2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,5 +1,5 @@ { - "cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0}, + "cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0}, "version": 3, "configurePresets": [ { @@ -14,6 +14,17 @@ "dev": true, "uninitialized": true } + }, + { + "name": "coverage", + "displayName": "Build for coverage analysis", + "generator": "Unix Makefiles", + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_C_FLAGS": "-DCOVERAGE=1 -g -O0 --coverage", + "CMAKE_BUILD_TYPE": "None", + "SECP256K1_BUILD_VERIFY_TESTS": "OFF" + } } ] } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24eb0d3011..4da37a8505 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,8 +52,8 @@ if(SECP256K1_BUILD_TESTS) add_executable(noverify_tests tests.c) target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm) add_test(noverify_tests noverify_tests) - if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage") - add_executable(tests tests.c) + if(SECP256K1_BUILD_VERIFY_TESTS) + add_executable(tests tests.c ${internal_obj}) target_compile_definitions(tests PRIVATE VERIFY) target_link_libraries(tests secp256k1_precomputed secp256k1_asm) add_test(tests tests) @@ -62,9 +62,9 @@ endif() if(SECP256K1_BUILD_EXHAUSTIVE_TESTS) # Note: do not include secp256k1_precomputed in exhaustive_tests (it uses runtime-generated tables). - add_executable(exhaustive_tests tests_exhaustive.c) - target_link_libraries(exhaustive_tests secp256k1_asm) - target_compile_definitions(exhaustive_tests PRIVATE $<$>:VERIFY>) + add_executable(exhaustive_tests tests_exhaustive.c ${common_obj}) + target_compile_definitions(exhaustive_tests PRIVATE $<$>:VERIFY>) + target_link_libraries(exhaustive_tests binary_interface) add_test(exhaustive_tests exhaustive_tests) endif()