How to make code coverage in cmake

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

I want to create a custom target called "test_coverage", which, when called to run, should run all the tests, collect their coverage data and generate html (using genhtml) in the "code_coverage" directory.

Is there a way to get a list of all the tests in my project and their path to the directories, so that in the custom target "test_coverage" I can run each test individually and collect data about its scope?

+7
cmake ctest
source share
1 answer

You can execute 'ctest -VV' from the command line, and if all the tests were created using add_test, everything will be executed.

If you want the custom build target to do the same, you can use this code:

add_custom_target(run_tests COMMAND "ctest -VV" ) 

I have a LOT of cmake code for code coverage and unit testing to show, but there is no point in copying / pasting, as it seems like you are just starting.

0
source share