Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake Gcov c++ creating wrong .gcno files

Tags:

c++

cmake

gcov

I have a CMakeLists.txt file in which I added:

set(CMAKE_CXX_FLAGS "-fprofile-arcs -ftest-coverage -pthread -std=c++11 -O0 ${CMAKE_CXX_FLAGS}")

It is generating the report files in:

project_root/build/CMakeFiles/project.dir/

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

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

project_root/src/ 

When I move the report files to the src/ folder and execute

$ gcov main.cpp
main.gcno:cannot open notes file

But I get that error message. So I change the .cpp.gcno, .cpp.cdna and cpp.o to .gcno, .gcda and .o and finally I get the following:

gcov main.cpp
Lines executed:86.67% of 15
Creating 'main.cpp.gcov'

I have over 50 files and can't do this manually for each one.

I need to be able to run gcov once for all files and generate report for all files. I don't care where the files are generated.

like image 760
fedest Avatar asked Jun 22 '16 20:06

fedest


2 Answers

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.

like image 109
Tsyvarev Avatar answered Sep 29 '22 00:09

Tsyvarev


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)
like image 33
Mathijs Avatar answered Sep 28 '22 23:09

Mathijs