Getting ready

We will extend the source code of the previous recipe with a minor change in src/sum_integers.cpp, where we will add a function - sum_integers_unused:

#include "sum_integers.hpp"#include <vector>int sum_integers(const std::vector<int> integers) {  auto sum = 0;  for (auto i : integers) {    sum += i;  }  return sum;}int sum_integers_unused(const std::vector<int> integers) {  auto sum = 0;  for (auto i : integers) {    sum += i;  }  return sum;}

Our goal is to detect this unused code with a test coverage analysis, by using gcov (https://gcc.gnu.org/onlinedocs/gcc/Gcov.html). Apart from the preceding modification, we will use the unmodified sources of the previous recipe.

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.