我构建了许多源代码,然后运行 gcovr 并输出JSON:
foreach(COMPONENT IN LISTS BLAHDIBLAH)
...
add_custom_command(TARGET ${COMPONENT}_coverage
COMMAND gcovr --exclude-unreachable-branches -k -r ${CMAKE_CURRENT_SOURCE_DIR} --json -o ${COMPONENT}_coverage_lines.json ${CMAKE_BINARY_DIR}/CMakeFiles/${COMPONENT}_test.dir/${UNIT_PATH_${COMPONENT}}
COMMAND gcovr --exclude-unreachable-branches -k -r ${CMAKE_CURRENT_SOURCE_DIR} --json -b -o ${COMPONENT}_coverage_branches.json ${CMAKE_BINARY_DIR}/CMakeFiles/${COMPONENT}_test.dir/${UNIT_PATH_${COMPONENT}}
)
list(APPEND COV_DEPS ${COMPONENT}_coverage)
...
endforeach()
稍后,我添加了一个coverage
目标来合并 gcovr 输出:
add_custom_target(coverage
COMMAND gcovr --exclude-unreachable-branches -k -r .. --add-tracefile coverage/*.json --html-details coverage/coverage.html
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
如果我运行make coverage
,gcovr 只拾取第一个源文件,但如果我手动运行命令:
gcovr --exclude-unreachable-branches -k -r .. --add-tracefile coverage/*.json --html-details coverage/coverage.html
......那么所有的信号源都会被接收。
为什么该命令在终端中有效,而在CMake中无效?
1条答案
按热度按时间qnzebej01#
答案在自定义目标中。
--add-tracefile
的参数需要用speech-marks括起来,而speech-marks本身需要转义:第一个