[CMake] using gcov with cmake

Ioan Calin Borcoman iborco at gmail.com
Thu Oct 2 08:33:10 EDT 2008


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


More information about the CMake mailing list