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 "