Skip to content

Commit 35b87a7

Browse files
TST: add Coverage.cmake file
Co-authored-by: Chengyu HAN <[email protected]>
1 parent 02ed86b commit 35b87a7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/Coverage.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
2+
3+
# Enable coverage compilation option
4+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
6+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
7+
endif()
8+
if(MSVC)
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /coverage")
10+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /coverage")
11+
endif()
12+
13+
# Add custom targets for generating coverage reports
14+
add_custom_target(coverage
15+
COMMAND lcov --capture --directory . --output-file coverage.info
16+
COMMAND lcov --output-file coverage.info --extract coverage.info '*/include/xsf/*'
17+
COMMAND lcov --list coverage.info
18+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
19+
COMMENT "Generating coverage report"
20+
)
21+
22+
# Generate coverage reports in HTML format
23+
add_custom_target(coverage_html
24+
COMMAND genhtml --demangle-cpp --legend coverage.info --output-directory coverage_report
25+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
26+
COMMENT "Generating HTML coverage report"
27+
)
28+
add_dependencies(coverage_html coverage)
29+
30+
endif() # CMAKE_BUILD_TYPE=Coverage

0 commit comments

Comments
 (0)