我有以下项目结构:
├── app
│ ├── CMakeLists.txt
│ └── tcpstream
│ ├── CMakeLists.txt
│ ├── include
│ │ └── TCPAcceptor.h
│ └── src
│ └── TCPAcceptor.cpp
├── cmake
│ └── CodeCoverage.cmake
├── CMakeLists.txt
└── test
├── CMakeLists.txt
└── TestTCPAcceptor.cpp
主 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()
...
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
)
还会生成代码覆盖率报告。但它报告了TestTCPAcceptor.cpp
我不想要的测试文件。我想要覆盖源文件(TCPAcceptor.cpp
)。我应该在哪里更改以生成源文件而不是测试文件的报告。任何帮助,将不胜感激。