Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Adding support for generating XML Cobertura report.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mats Kindahl committed Oct 6, 2016
1 parent d728a47 commit 87c31a8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# Editors & Tools
.idea/
*.sublime-*
*~

# Folders
.DS_Store
Expand Down
38 changes: 38 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,44 @@ has been installed:
You can then open the folder `doc/html/index.html` in your browser.


Coverage information
--------------------

To build so that coverage information is generated:

cmake <path-to-source> -DENABLE_COVERAGE=1

To get coverage information, just run the program or the unit tests
(do not forget to enable the unit tests if you want to run them). Once
you have collected coverage information, you can generate an HTML
report in `<build-dir>/coverage/html` using:

make coverage-html

There are three variables to control where the information is
collected and where the reports are written:

- `GCOV_BASE_DIR` is a cache variable with the full path to a base
directory for the coverage information.

It defaults to `${CMAKE_BUILD_DIR}/coverage`.

- `GCOV_INFO_FILE` is a cache varible with the full path to the info
file for the collected coverage information.

It defaults to `${GCOV_BASE_DIR}/coverage.info`.

- `GCOV_XML_FILE` is a cache varible with the full path to the XML
file for the collected coverage information.

It defaults to `${GCOV_BASE_DIR}/coverage.xml`.

- `GCOV_HTML_DIR` is a cache variable with the full path to the
directory where the HTML coverage report will be generated.

It defaults to `${GCOV_BASE_DIR}/html`.


License
-------

Expand Down
17 changes: 16 additions & 1 deletion cmake/Coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ set(GCOV_HTML_DIR ${GCOV_BASE_DIR}/html CACHE PATH
"GCov HTML report output directory")
set(GCOV_INFO_FILE ${GCOV_BASE_DIR}/coverage.info CACHE FILEPATH
"GCov information file name")
set(GCOV_XML_FILE ${GCOV_BASE_DIR}/coverage.xml CACHE FILEPATH
"GCov XML report file name")

set(LCOV_FLAGS -b ${CMAKE_BINARY_DIR} -d ${CMAKE_SOURCE_DIR} -q)
set(GCOVR_FLAGS -r ${CMAKE_SOURCE_DIR})

include(TextUtils)

Expand Down Expand Up @@ -58,13 +61,25 @@ if(ENABLE_COVERAGE)
COMMAND ${CMAKE_COMMAND} -E make_directory ${GCOV_BASE_DIR}
COMMAND ${LCOV} ${LCOV_FLAGS} -o ${GCOV_INFO_FILE} -c
COMMAND ${LCOV} ${LCOV_FLAGS} -o ${GCOV_INFO_FILE} -r ${GCOV_INFO_FILE}
'/usr/include/*' 'ext/gmock/*' 'ext/gtest/*' '*/tests/*'
'/usr/include/*' 'ext/*' '*/tests/*'
COMMENT "Generating coverage info file ${GCOV_INFO_FILE}")
add_custom_target(coverage-html
DEPENDS coverage-info
COMMAND ${CMAKE_COMMAND} -E make_directory ${GCOV_HTML_DIR}
COMMAND ${GENHTML} -o ${GCOV_HTML_DIR} ${GCOV_INFO_FILE}
COMMENT "Generating HTML report on coverage in ${GCOV_HTML_DIR}")

find_program(GCOVR gcovr)
if(GCOVR)
add_custom_target(coverage-xml
COMMAND ${CMAKE_COMMAND} -E make_directory ${GCOV_BASE_DIR}
COMMAND ${GCOVR} ${GCOVR_FLAGS} -o ${GCOV_XML_FILE} --xml
-e '/usr/include/.*' -e '.*/tests/.*' -e 'ext/.*'
${CMAKE_BINARY_DIR})
message(STATUS "Target coverage-xml added to generate XML report")
else()
message(STATUS "Target coverage-xml not built - gcovr not found")
endif()
else()
message(FATAL_ERROR "Coverage not supported for ${CMAKE_CXX_COMPILER}")
endif()
Expand Down

0 comments on commit 87c31a8

Please sign in to comment.