cmake and code coverage:
file coverage.sh:
!/bin/bash
lcov --capture --directory . --output-file coverage.info
lcov --directory . --output-file coverage.info \
--remove coverage.info "/usr/" ".moc" "test/*"
genhtml -o coverage coverage.info
minimal CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(bitboard)
include(CTest)
option(MAKE_COVERAGE "add coverage into tests" OFF)
add_executable(test1 test1.c)
if (${MAKE_COVERAGE})
target_compile_options(test1 PUBLIC "--coverage")
target_link_libraries(test1 gcov)
endif()
add_test(test1)
if (${MAKE_COVERAGE})
add_custom_target (coverage
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/coverage.sh
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
Commands to test this:
mkdir build
cd build
cmake -DMAKE_COVERAGE=ON ..
make
make test
make coverage
Coverage analysis can be found in build/coverage/index.html