[CMake] Problem measuring coverage in CTest scripts
Maarten Anonymous
anonymous.maarten at gmail.com
Sat Oct 28 01:59:06 EDT 2017
Hey,
I have a question about using CMake+CTest+CTest scripts for coverage tests.
If I manually build the project and run "make ExperimantalCoverage" in a
build folder,
the coverage succeeds.
If I run the coverage from within a CTest script,
it fails.
Am I forgetting something?
A minimum example that exhibits my problem can be found at
https://gist.github.com/madebr/07ebd0de59e789cd819643b58db25df9.
This works:
mkdir build && cd build && cmake .. && make && make test && make
ExperimentalCoverage && cd ..
This fails:
ctest -S test.ctest
Source listing:
###################
#CMakeLists.txt:
###################
cmake_minimum_required(VERSION 3.9)
project(cmake_coverage)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/main.c" "int main() {return 0;}")
add_executable(main
main.c
)
target_compile_options(main
PUBLIC
"-O0"
"-fprofile-arcs"
"-ftest-coverage"
)
target_link_libraries(main
gcov
)
include(CTest)
enable_testing()
add_test(NAME test
COMMAND main
)
##############
# test.ctest:
##############
set(CTEST_SOURCE_DIRECTORY "${CTEST_SCRIPT_DIRECTORY}")
set(CTEST_BINARY_DIRECTORY "${CTEST_SCRIPT_DIRECTORY}/build/ctest")
ctest_empty_binary_directory("${CTEST_BINARY_DIRECTORY}")
set(CTEST_SITE "${CMAKE_SYSTEM_NAME}")
set(CTEST_BUILD_NAME "experimental build")
set(CTEST_CMAKE_GENERATOR "Ninja")
set(CTEST_COVERAGE_COMMAND "gcov")
ctest_start("Experimental")
ctest_configure()
ctest_build()
ctest_test()
ctest_coverage()
##############
# CTestConfig.cmake:
##############
set(CTEST_PROJECT_NAME "Simple ctest_coverage project")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171028/c796bbec/attachment.html>
More information about the CMake
mailing list