cmake code coverage (ExperimentalCoverage)

Want to add code coverage and integrate that to the target ExperimentalCoverage. It fails to the find the source code, searching under ${CMAKE_BINARY_DIR}/Testing instead of under ${CMAKE_SOURCE_DIR}. Tried to set CTEST_SOURCE_DIRECTORY from cmake file but its not picked up.

Coverage is…weird :frowning: . There are probably flags you want to pass to the coverage gathering tool to output absolute paths. For example, gcov works much better with the --long-file-names --hash-filenames options.

Yeah coverage in cmake is a bit weird. At least I cannot get to work properly. But is cmake actually using the variables? E.g. tried to set CTEST_COVERAGE_COMMAND before including Ctest, but it is not picked up by ctest. Same goes for CTEST_SOURCE_DIRECTORY.

How about CTEST_COVERAGE_EXTRA_FLAGS?

Variables like CTEST_COVERAGE_COMMAND and CTEST_SOURCE_DIRECTORY are meant to be set in a ctest dashboard script, not in your project’s CMakeLists.txt file.

1 Like

Will putting it in CTestConfig.cmake make it be picked up by cmake/ctest?

I don’t know, try it and see? :wink: