Skip to content
10 changes: 9 additions & 1 deletion cmake/script/CoverageInclude.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ separate_arguments(LCOV_OPTS)
set(LCOV_COMMAND ${LCOV_EXECUTABLE} --gcov-tool ${CMAKE_CURRENT_LIST_DIR}/cov_tool_wrapper.sh ${LCOV_OPTS})

find_program(GENHTML_EXECUTABLE genhtml REQUIRED)
set(GENHTML_COMMAND ${GENHTML_EXECUTABLE} --show-details ${LCOV_OPTS})

# HTML_OPTS is optionally passed via -D flag.
# Default: inherit LCOV_OPTS. If HTML_OPTS is provided (even if empty), use it instead.
set(GENHTML_OPTS ${LCOV_OPTS})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we can't be consistent with the naming, either GENHTML_OPTS or HTML_OPTS

if(DEFINED HTML_OPTS)
separate_arguments(HTML_OPTS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if LCOV_OPTS is not defined? Does cmake create an empty variable or error?

set(GENHTML_OPTS ${HTML_OPTS})
endif()
set(GENHTML_COMMAND ${GENHTML_EXECUTABLE} --show-details ${GENHTML_OPTS})

find_program(GREP_EXECUTABLE grep REQUIRED)
find_program(AWK_EXECUTABLE awk REQUIRED)
Expand Down
11 changes: 11 additions & 0 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,17 @@ enabled by setting `LCOV_OPTS="--rc branch_coverage=1"`:
cmake -DLCOV_OPTS="--rc branch_coverage=1" -P build/Coverage.cmake
```

HTML_OPTS can override the genhtml options (which default to LCOV_OPTS). If HTML_OPTS is omitted, LCOV_OPTS are implicitly passed to genhtml. If HTML_OPTS is provided but empty (e.g. -DHTML_OPTS=""), no options are passed to genhtml and LCOV_OPTS are not inherited.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to add an example showing combined use of both LCOV_OPTS and HTML_OPTS to clarify precedence.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if LCOV_OPTS is also not set? Does it default to empty?


Examples:
```
# Override genhtml options explicitly
cmake -DHTML_OPTS="--title 'Knots Coverage'" -P build/Coverage.cmake

# Provide an empty override: pass nothing to genhtml (do not inherit LCOV_OPTS)
cmake -DHTML_OPTS="" -P build/Coverage.cmake
```

To enable test parallelism:
```
cmake -DJOBS=$(nproc) -P build/Coverage.cmake
Expand Down