cmake, refactor: Deduplicate test-related code
What changed, and why it matters
This commit is a straightforward cleanup of the project's build instructions. It replaces two nearly identical blocks of CMake code with a single reusable function that creates test programs. There is no change to the actual cryptographic code, no change to what tests are run, and no indication of any security issue being fixed.
No security action needed. This is a benign build-system refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors src/CMakeLists.txt by introducing an add_executable_and_tests() CMake function and calling it for noverify_tests and tests. The generated build targets, linked libraries, compile definitions, and registered CTest tests remain functionally identical to the previous code. No source files or logic were modified.
Changed components
src/CMakeLists.txtInspect captured patch +9 / −8
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ecbbbbe..10f96c3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -144,15 +144,16 @@ if(SECP256K1_BUILD_TESTS)
list(APPEND TEST_DEFINITIONS SUPPORTS_CONCURRENCY=1)
endif()
- add_executable(noverify_tests tests.c)
- target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm)
- target_compile_definitions(noverify_tests PRIVATE ${TEST_DEFINITIONS})
- add_test(NAME secp256k1_noverify_tests COMMAND noverify_tests)
+ function(add_executable_and_tests exe_name verify_definition)
+ add_executable(${exe_name} tests.c)
+ target_link_libraries(${exe_name} secp256k1_precomputed secp256k1_asm)
+ target_compile_definitions(${exe_name} PRIVATE ${verify_definition} ${TEST_DEFINITIONS})
+ add_test(NAME secp256k1_${exe_name} COMMAND ${exe_name})
+ endfunction()
+
+ add_executable_and_tests(noverify_tests "")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
- add_executable(tests tests.c)
- target_compile_definitions(tests PRIVATE VERIFY ${TEST_DEFINITIONS})
- target_link_libraries(tests secp256k1_precomputed secp256k1_asm)
- add_test(NAME secp256k1_tests COMMAND tests)
+ add_executable_and_tests(tests VERIFY)
endif()
unset(TEST_DEFINITIONS)
endif()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.