Discussion:
[CMake] using gcov with cmake
Ioan Calin Borcoman
17 years ago
Permalink
Hi,

I am trying to use gcov with cmake (I'm new to both gcov and cmake).

My first attempt was like this:

add_executable(hello main.cpp)
set(CMAKE_CXX_FLAGS -fprofile-arcs -ftest-coverage)
target_link_libraries(hello -fprofile-arcs)

As recommended, I've created a build dir and did the compilation from there:

$ cmake ..
$ make
$ ./hello

The problem is that no coverage data was produced.

Then I've changed the CMakeLists.txt to this:

include(CTest)
add_executable(hello main.cpp)
add_test(hello_test ${EXECUTABLE_OUTPUT_PATH}/hello)
add_definitions(-fprofile-arcs -ftest-coverage)
target_link_libraries(hello -fprofile-arcs)

Then run this from the build dir:

$ cmake ..
$ make
$ make test
$ make ExperimentalCoverage

Now coverage worked and I've got the coverage output under
build/Testing/CoverageInfo.

If I run "make Experimental" all the above steps are run, but I don't
understand very well if the results are really uploaded and if yes,
where can I view them. On the console I get something like

Drop site: http://public.kitware.com/cgi-bin/HTTPUploadDartFile.cgi
Uploaded: ...
Using HTTP trigger method
Trigger site:
http://public.kitware.com/cgi-bin/Submit-Random-TestingResults.cgi
Dart server triggered...
Submission successful

Now my questions:

1. is this the way to do a code coverage? why no coverage is produced
when I run the hello app?
2. is there a way to store and convert all the test/coverage/etc
results normally uploaded to a dart server into a local directory for
local browsing?
3. is there a better way to test/do coverage?

Thanx,

Ionutz
Mathieu Malaterre
17 years ago
Permalink
Post by Ioan Calin Borcoman
Hi,
I am trying to use gcov with cmake (I'm new to both gcov and cmake).
add_executable(hello main.cpp)
set(CMAKE_CXX_FLAGS -fprofile-arcs -ftest-coverage)
target_link_libraries(hello -fprofile-arcs)
No that's not the correct way to pass flags to the linker:

http://www.cmake.org/Wiki/CTest:Coverage

2cts
--
Mathieu
Continue reading on narkive:
Search results for '[CMake] using gcov with cmake' (Questions and Answers)
6
replies
Where to learn to code?
started 11 years ago
programming & design
Loading...