Skip to content

Commit 50b167e

Browse files
authored
Merge pull request #1880 from DLR-AMR/improve-codecov-for-templated-code
Improvement: Change location of CodeCoverage include in cmake
2 parents ba04e21 + f5563cf commit 50b167e

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
9191
"Debug" "Release" "RelWithDebInfo")
9292
endif()
9393

94+
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
95+
# Option to generate code coverage target.
96+
option( T8CODE_CODE_COVERAGE "Enable code coverage reporting" OFF)
97+
if(T8CODE_CODE_COVERAGE)
98+
include(./cmake/CodeCoverage.cmake)
99+
endif()
100+
endif()
101+
94102
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
95103

96104
if( T8CODE_BUILD_FORTRAN_INTERFACE )

cmake/CodeCoverage.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# Adds compiler flags necessary to be able to collect coverage information.
1414
#
1515
function(append_coverage_compiler_flags)
16-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --coverage" PARENT_SCOPE)
17-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g --coverage" PARENT_SCOPE)
16+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --coverage -O0" PARENT_SCOPE)
17+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g --coverage -O0" PARENT_SCOPE)
1818
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage" PARENT_SCOPE)
1919
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage" PARENT_SCOPE)
2020
endfunction() # append_coverage_compiler_flags
@@ -79,8 +79,6 @@ function(setup_target_for_coverage)
7979

8080
# Generate HTML file using genhtml.
8181
COMMAND ${GENHTML_PATH} -o ${Coverage_NAME} ${Coverage_NAME}.info
82-
# Show result in terminal.
83-
COMMAND ${LCOV_PATH} --list ${Coverage_NAME}.info
8482

8583
BYPRODUCTS
8684
${Coverage_NAME}.base
@@ -95,9 +93,11 @@ function(setup_target_for_coverage)
9593
endfunction() # setup_target_for_coverage
9694

9795
# Call functions defined above with customized arguments.
96+
# Attention: For some gcov versions, you have to add --ignore-errors mismatch to the LCOV_ARGS.
97+
# This seems to be a common gcov problem.
9898
append_coverage_compiler_flags()
9999
setup_target_for_coverage(
100100
NAME coverage
101-
EXCLUDE "${CMAKE_SOURCE_DIR}/sc*"
102-
LCOV_ARGS "--no-external"
101+
EXCLUDE "${CMAKE_SOURCE_DIR}/sc*" "${CMAKE_SOURCE_DIR}/p4est*" "${CMAKE_SOURCE_DIR}/test*" "${CMAKE_SOURCE_DIR}/thirdparty*" "${CMAKE_SOURCE_DIR}/tutorials*" "${CMAKE_SOURCE_DIR}/example*" "${CMAKE_SOURCE_DIR}/benchmarks*"
102+
LCOV_ARGS --no-external --ignore-errors gcov
103103
)

src/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ if( CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
4141
endif()
4242

4343
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
44-
# Option to generate code coverage target.
45-
option( T8CODE_CODE_COVERAGE "Enable code coverage reporting" OFF)
46-
if(T8CODE_CODE_COVERAGE)
47-
include(CodeCoverage)
48-
endif()
49-
5044
set (T8_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
5145
set (T8_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
5246

0 commit comments

Comments
 (0)