I have the following project structure:
├── app
│ ├── CMakeLists.txt
│ └── tcpstream
│ ├── CMakeLists.txt
│ ├── include
│ │ └── TCPAcceptor.h
│ └── src
│ └── TCPAcceptor.cpp
├── cmake
│ └── CodeCoverage.cmake
├── CMakeLists.txt
└── test
├── CMakeLists.txt
└── TestTCPAcceptor.cpp
Contents of main CMakeLists.txt:
...
if(BUILD_TESTING)
find_package(GTest 1.8.0 EXACT REQUIRED COMPONENTS gtest gmock gtest_main)
if(NOT GTest_FOUND)
message(FATAL_ERROR "Couldn't find gtest")
endif()
enable_testing()
include(CodeCoverage)
append_coverage_compiler_flags()
set(COVERAGE_LCOV_EXCLUDES "${CMAKE_CURRENT_LIST_DIR}/test/*")
add_subdirectory(${CMAKE_SOURCE_DIR}/test)
endif()
...
Contents of test/CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
add_executable(TestTCPAcceptor
TestTCPAcceptor.cpp
$<TARGET_PROPERTY:tcpstream,SOURCE_DIR>/include/TCPAcceptor.h
)
target_include_directories(TestTCPAcceptor
PRIVATE
$<TARGET_PROPERTY:tcpstream,SOURCE_DIR>/include
)
target_link_libraries(TestTCPAcceptor
PUBLIC
tcpstream
GTest::gtest_main
GTest::gtest
GTest::gmock
)
add_test(NAME TestTCPAcceptor COMMAND TestTCPAcceptor)
# Set up coverage for test executables
setup_target_for_coverage_gcovr_html(
NAME coverage
EXECUTABLE TestTCPAcceptor
DEPENDENCIES
TestTCPAcceptor
)
Code coverage report is also generated. But it reports for test file TestTCPAcceptor.cpp
which is I don't want. I want coverage for source file (TCPAcceptor.cpp
) instead. Where should I change to generate the report for source file and not for the test files. Any help would be appreciated.