26

I want to use code coverage tools(lcov) in my cmake project. I read the example here https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake The tests are added in my project using the 'add_test()' cmake function.

I want to create a custom target, something called 'test_coverage', that when invoked for execution should run all the tests, collect their coverage data and generate the html(using genhtml) in a directory 'code_coverage'.

Is there a way I could get the list of all the tests in my project and their directory paths, so that in the custom target 'test_coverage' I could execute each test individually and collect its coverage data ?

David Doria
  • 9,873
  • 17
  • 85
  • 147
Monku
  • 2,440
  • 4
  • 33
  • 57
  • 1
    From your decription I assume you have already read [Detailed guide on using gcov with CMake/CDash?](http://stackoverflow.com/questions/13116488/detailed-guide-on-using-gcov-with-cmake-cdash). But did you see e.g. https://github.com/stepcode/stepcode/blob/master/lcov.cmake ? `CTest` knows/can extract the list of test in your CMake's binary output directory and with its script mode `ctest -S ...` you can automate the whole build, test and collect coverage data process. – Florian Jun 10 '15 at 19:00
  • 1
    Also useful could be [How to run ctest after building my project with cmake](http://stackoverflow.com/questions/15115075/how-to-run-ctest-after-building-my-project-with-cmake) – Florian Jun 10 '15 at 19:01
  • @Florian I don't see a ctest_coverage call in the lcov.cmake example? Also, are you saying you can perform the coverage analysis without a script (-S) at all? Can you point to an example of how to do that? I'm interested in coverage analysis of all of the test targets in aggregate. – David Doria Feb 02 '16 at 02:09
  • Maybe this module which we are using is useful for you: https://code.cor-lab.de/projects/rsc/repository/entry/cmake/Modules/EnableCoverageReport.cmake. It uses lcov and gcovr to generate the reports. It still doesn't help to automatically collect the test targets, but maybe it saves some time to write your coverage logic. – languitar Jun 14 '16 at 12:04
  • 1
    This is now answered here: https://stackoverflow.com/questions/13116488/detailed-guide-on-using-gcov-with-cmake-cdash/16536401#16536401 – Philipp Ludwig Feb 28 '18 at 09:12
  • 1
    Does this answer your question? [Detailed guide on using gcov with CMake/CDash?](https://stackoverflow.com/questions/13116488/detailed-guide-on-using-gcov-with-cmake-cdash) – starball Sep 08 '22 at 05:03

0 Answers0