Skip to main content

How to use in a C/C++ project

If you need a good code coverage web reporting tool for a github-hosted project, may be your next best friend. I'm already using it on biology and rainbrurpg).

The present article is usable on a C/C++ project using cmake as build system and travis-ci as CI platform. screenshot screenshot

Handling coverage in cmake

You first need to install some package (at least on Debian GNU/Linux) :
sudo apt install gcov lcov gcovr

Then, copy the CodeCoverage.cmake in a cmake/ directory inside your project's repository and add this line to your CMakeLists.txt file:

Generate coverage reports and send them

Now, you need to modify your .travis.yml file and add this :
  # Creating report
  - lcov --version
  - lcov --directory . --capture --output-file
  - lcov --remove '/usr/*' --output-file
  - lcov --list #debug info
  # Uploading report to CodeCov
  - bash <(curl -s || echo "Codecov did not collect coverage reports"


Popular posts from this blog

How to make a map of variant in C++

This code is used by RainbruRPG to store any scalar types in a single class instance. It's already in use since revision 254 to save game states values when switching fullscreen or changing screen resolution.
The map class It's basically a map of boost::variant using std::string as map key. I decided to use function template setter and getter to have a standardized exception-based error handling, but you could have multiple parameter-based specialized getter/setter (void set(bool), void set(int)...).