我正在尝试制作一个非常简单的回归模型(除其他外),构建和编译 GCC 目标以进行覆盖,执行,然后发布标准的 Cobertura 覆盖率报告(全部在 Jenkins 内)。Jenkins 部分在这里有些无关紧要,我现在只关心 CMake 语法。到目前为止,这是我的 CMake 文件:
cmake_minimum_required( VERSION 3.15 )
# Project's name
project( my_project )
# Set the output folder where your program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/test/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set( CMAKE_VERBOSE_MAKEFILE on )
# Generate coverage on GCC.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(LDFLAGS "${LDFLAGS} -lgcov -fprofile-arcs")
endif()
# Includes and Sources
include_directories(${PROJECT_SOURCE_DIR}/inc)
file(GLOB APP_SRC "./src/*.c")
file(GLOB TEST_DEPENDS_SRC "./test/src/*.c")
# Add executable to list.
add_executable( ${PROJECT_NAME}_Test ${APP_SRC} ${TEST_DEPENDS_SRC} )
这会在 /test/build/gcc/CMakeFiles/my_project.dir/* 目录中生成我的 *.gcno 和 *.gcda 文件,但为了便于后处理,我想我希望将这些文件放在它们的源代码旁边。那可能吗?如果是这样,怎么做?这是最佳做法吗?当谈到 CMake 时,我仍然很年轻。