From a37ba3fb89362e7eee32ef7a3179b4da940548b8 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Thu, 30 Jul 2026 02:08:25 -0400 Subject: [PATCH] Namespace the coverage target when embedded Follows a87cbfb: a sibling dependency may ship a `coverage` target of its own, so a non-top-level build gets `akstdlib_coverage` instead. The top-level name is unchanged, and so is every documented command. Verified: cmake --build build-coverage --target coverage still runs the suite (14/14) and reports 99.0% of lines; the mutation target still resolves. Co-Authored-By: Claude Opus 5 (1M context) --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c7ec61..3d64b93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -274,6 +274,14 @@ if(AKSL_COVERAGE AND Python3_FOUND) # 30s the test binaries get. set_tests_properties(coverage_reset coverage_report PROPERTIES TIMEOUT 300) + # Namespaced when embedded in another project, for the same reason the mutation + # target below is: a sibling dependency may well ship a `coverage` target too. + if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(AKSL_COVERAGE_TARGET coverage) + else() + set(AKSL_COVERAGE_TARGET akstdlib_coverage) + endif() + # Convenience entry point that also builds the test binaries first. It runs # the suite rather than the script directly, because the two fixture tests # above already reset the counters and produce the report -- and CTest pulls a @@ -281,14 +289,14 @@ if(AKSL_COVERAGE AND Python3_FOUND) # run the tests without them. The second command re-reads the same counters to # print the report that CTest suppressed for the passing coverage_report test # (it only spawns gcov again, it does not re-run anything). - add_custom_target(coverage + add_custom_target(${AKSL_COVERAGE_TARGET} COMMAND ctest --test-dir ${CMAKE_CURRENT_BINARY_DIR} --output-on-failure COMMAND ${AKSL_COVERAGE_ARGS} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} USES_TERMINAL COMMENT "Running the test suite under gcov and reporting coverage" ) - add_dependencies(coverage ${AKSL_TEST_TARGETS}) + add_dependencies(${AKSL_COVERAGE_TARGET} ${AKSL_TEST_TARGETS}) elseif(AKSL_COVERAGE) message(WARNING "AKSL_COVERAGE=ON but Python3 was not found: " "instrumenting the build, but the coverage report "