Search code examples
makefilecmakecode-coverageninja

CMake ninja with coverage puts gcno files in root binary directory


I am building a project over cmake with a ninja generator and build my project for coverage with add_compile_options("$<$<CONFIG:COVERAGE>:-g;-O0;-ftest-coverage;-fprofile-arcs;-fno-builtin>"). What happens is that my gcno files are put in the ${CMAKE_BINARY_DIR} and not in the corresponding target directory like ${CMAKE_BINARY_DIR}/CMakeFiles/Project.dir.

The implication of this difference is that I now cannot have source files with the same name.

When I build the same project with makefiles, the gcno files do end up in those folders. I checked the different calls it does in the command line and the difference is the following. It is most definitely the change of working directory.

How can I tell ninja to also put the gcno files in the corresponding project directories?

make

cd C:/my_project/MASTER/build/EXTERNAL_3RDPARTY/blake2 && C:/qnx700/host/win64/x86_64/usr/bin/qcc.exe -Vgcc_ntox86_64  -IC:/C:/my_project/3RDPARTY/blake2/src  -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wconversion -Wall -Wextra -pedantic -Wmissing-declarations -Wunused -Wpedantic -Wlogical-op -Wdouble-promotion -Wformat=2 -fmessage-length=0 -fno-exceptions -march=broadwell -g -O0 -ftest-coverage -fprofile-arcs -fno-builtin -std=c11 -o CMakeFiles/libblake2.dir/src/blake2/blake2b.c.o -c C:/my_project/3RDPARTY/blake2/src/blake2/blake2b.c

ninja:

C:\qnx700\host\win64\x86_64\usr\bin\qcc.exe -Vgcc_ntox86_64 -IC:/C:/my_project/3RDPARTY/blake2/src -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wconversion -Wall -Wextra -pedantic -Wmissing-declarations -Wunused -Wpedantic -Wlogical-op -Wdouble-promotion -Wformat=2 -fmessage-length=0 -fno-exceptions -march=broadwell -g -O0 -ftest-coverage -fprofile-arcs -fno-builtin -std=c11 -Wp,-MD,EXTERNAL_3RDPARTY\blake2\CMakeFiles\libblake2.dir\src\blake2\blake2b.c.o.d -Wp,-MT,EXTERNAL_3RDPARTY/blake2/CMakeFiles/libblake2.dir/src/blake2/blake2b.c.o -Wp,-MF,EXTERNAL_3RDPARTY\blake2\CMakeFiles\libblake2.dir\src\blake2\blake2b.c.o.d -o EXTERNAL_3RDPARTY/blake2/CMakeFiles/libblake2.dir/src/blake2/blake2b.c.o -c C:/my_project/3RDPARTY/blake2/src/blake2/blake2b.c

Solution

  • We did some more research and came to the conclusion that the qcc.exe wrapper is the actual problem. Using gcc.exe directly resolves the issue.