I have a project with source files and unit test files. cmake version 3.16.3. my CMakeLists.txt has two targets/executables: one for the app and one for ut.
I want coverage turned on ONLY for the ut target. But it get s turned on for both targets.
cmake_minimum_required(VERSION 3.16)
project(devcpp-lib-template)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "-O2")
# === src related
include_directories(${CMAKE_SOURCE_DIR}/lib)
set(SOURCE_FILES
lib/library_name.h lib/library_name.cpp
<snip other files here>
)
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})
# === Unit Tests
project(ut)
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})
# these turn on coverage
set(CMAKE_CXX_FLAGS "-g -fprofile-arcs -ftest-coverage")
set(UT_FILES
lib/version.h lib/library_name.h
<snip ... other files here>
ut/ut_test1.cpp
)
add_executable(ut ${UT_FILES})
target_link_libraries(${CMAKE_PROJECT_NAME}
${GTEST_LIBRARIES}
pthread
gcov
)
当我用目标“设计-校准”(即不“全”)来补充上述内容时, cm-build-debug/.../lib/有*.gcno文档(生成的覆盖面文件)。 这是错误的。
当我设定目标“ut”时,.号档案正确显示。 dir 树。
当我尝试将CMAKE_CXX_FLAGS变量与BUILD_TESING(以其他SO员额为基础)混为一谈时,无论是开发-lib-template还是ut目标,都无法获得免疫文件。
if (BUILD_TESTING)
set(CMAKE_CXX_FLAGS "-g -fprofile-arcs -ftest-coverage")
endif ()
我如何只获得“定点”目标,以悬挂简介国旗和检测国旗?