CMake Gcov c++ creating wrong .gcno files

It is generating the report files in: project_root/build/CMakeFiles/project.dir/

This is directory where all additional files are built for 'project' executable.

BUT the files it generates have extentions '.cpp.gcno', '.cpp.gcda' and '.cpp.o'

This is because CMake creates .cpp.o object file from .cpp source (you may see that running make VERBOSE=1. In accordance to -fprofile-arcs option's description, data file has suffix .cpp.gcno.

Also, they are not in the same folder as the src files

Data files are created in the same directory with object file.


Actually, created files are still work, if you call

gcov main.cpp.gcno

from the directory with .gcno files.


Apparently the standard CMake behavior to add an extension to give .cpp.o can be changed to replace an extension to give .o by using:

set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)

Tags:

C++

Cmake

Gcov