cmopts_setup_coverage#

This function is intended as a convenience for adding a target for generating HTML-formatted coverage report using gcovr utility. It aims to provide sensible defaults so that projects can generally just use this method without any arguments.

cmopts_setup_coverage([target]
                      [BASE_DIRECTORY dir]
                      [COMMAND executable]
                      [DEPENDS [depends...]]
                      [EXCLUDE [patterns...]])

The function defines a target for running and collecting code coverage information, builds dependencies, runs the given executable and outputs the HTML-formatted report.

Note

The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the gcovr command.

Arguments#

By default, generated target will have coverage name. The target argument can be used to specify other name for the generated target.

The options are:

BASE_DIRECTORY

The base directory of your source files. Defaults to CMAKE_SOURCE_DIR. File names are reported relative to this root.

COMMAND

Specify the command-line to generate gcov output files. Defaults to ctest -j${PROCESSOR_COUNT}.

Caution

Specified command-line is always executed in CMAKE_BINARY_DIR directory.

DEPENDS

(Acts the same way as DEPENDS option of add_custom_target command)

Reference files and outputs of custom commands created with add_custom_command command calls in the same directory (CMakeLists.txt file). They will be brought up to date when the target is built.

EXCLUDE

Exclude source files that match the given filter(s).

Requirements#

Note

The executable should always have a ZERO as exit code otherwise the coverage generation will not complete.

Warning

gcovr utility must be installed before using this function.

Output#

Generated HTML-formatted coverage report will reside by this the following path

  • ${PROJECT_BINARY_DIR}/<target>.