CTest Coverage failing when building with Ninja in a subdirectory
I just stumbled over a working "CTest -T coverage" setup (with Ninja and gcov) failing after a quite innocent change:
- Before the change, the build dir was a sibling directory of the source directory. The coverage step worked as expected.
- After the change, the build dir was a (deep) subdirectory of the source directory. The coverage step fails. With a minimal test project, it reports "Cannot find any coverage files. Ignoring Coverage request."
In a verbose build, I noticed that the changed build dir has a side effect on Ninja builds but not Makefile builds:
- When the build dir is a sibling directory, gcc is called with the absolute path of the source file.
- When the build dir is a subdirectory, gcc is called with the relative path of the source file. This side effect is no issue for compilation (cmake --build .) or running the test stage (ctest -T Test --no-compress-output). But I suspect this the reason for the failing coverage step, given that in my original setup, a subsequent CI coverage task on Azure pipelines fails as well, reporting incorrect absolute paths for expected source files.)
The attached ZIP file contains a minimal reproducing example. For a build in a subdir and in a sibling dir, the setup is the same:
cmake -G Ninja /ABSOULTE/PATH/TO/SOURCE VERBOSE=1 cmake --build . ctest -T Test --no-compress-output ctest -T Coverage