Skip to content

Instantly share code, notes, and snippets.

@sleepdefic1t
Last active January 13, 2021 19:19
Show Gist options
  • Save sleepdefic1t/6cbe2e64a52a83dc3e7753799a929e36 to your computer and use it in GitHub Desktop.
Save sleepdefic1t/6cbe2e64a52a83dc3e7753799a929e36 to your computer and use it in GitHub Desktop.
# /project_dir/CMakeLists.txt

# ------------------------------------------------------------------------------
# Coverage 1:2
# ------------------------------------------------------------------------------

if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
    add_definitions(-Wno-unused-command-line-argument)
endif() #CMAKE_BUILD_TYPE STREQUAL "Coverage"

# ------------------------------------------------------------------------------
# /project_dir/test_dir/CMakeLists.txt

# ------------------------------------------------------------------------------
# Coverage 2:2
# ------------------------------------------------------------------------------

include("${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake")

setup_target_for_coverage(${PROJECT_NAME}_coverage ${PROJECT_NAME} coverage)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")

# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Run Coverage
# ------------------------------------------------------------------------------

mkdir build && cd build
cmake -DUNIT_TEST=ON -DCMAKE_BUILD_TYPE=Coverage ..
make
make ${PROJECT_NAME}_coverage

# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Create Report
# ------------------------------------------------------------------------------

# rm extern and applications folders
lcov --remove coverage.info '*/extern/*' '*/Applications/*' '*/src/lib/*' -o coverage.trimmed.info
genhtml coverage.trimmed.info --output-directory ./coverage   

# ------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment