I am creating boost unit test cases and I need to get the code coverage for the same. I am planning to use GCOV and LCOV for getting the code coverage. Can someone help me in getting the configuration in Jamfile for GCOV and LCOV integration with bjam?
2 Answers
A good way to do this is by defining a separate variant (similar to debug and release variants).
This creates a new "coverage" variant based on the "debug" variant with additional coverage options:
variant coverage : debug : <cxxflags>"-fprofile-arcs -ftest-coverage"
<linkflags>"-lgcov" ;
The advantage of the variant approach is that the coverage build will go to a separate directory structure. Otherwise, files compiled with and without coverage options will end up in the same directories, which will lead to link errors. Those typically have to be resolved with bjam -a
, which works but requires a full rebuild when switching between coverage and debug, which isn't necessary with the variant approach.
To trigger a coverage build, use:
bjam variant=coverage

- 6,989
- 4
- 40
- 60
-
How do I make those cxxflags and linkflags apply only when toolset is gcc or clang? msvc doesn't understand those options. – Vinnie Falco Jun 20 '17 at 21:30
-
@VinnieFalco: Use `
gcc: – Christian Aichinger Jun 21 '17 at 04:19"-fprofile-arcs -ftest-coverage"` and so on. See "conditional properties" on http://www.boost.org/build/tutorial.html.
Try this. Edit it according to your requirement.
unit-test MyTest : MyTest.cpp libraries : --std=gnu++0x --profile-arcs --test-coverage --coverage -lgcov shared : gcov ;

- 186
- 9