[CMake] Problem measuring coverage in CTest scripts

Edoardo Pasca edo.paskino at gmail.com
Sat Oct 28 02:30:04 EDT 2017


Afaik, Ctest should be run in the build directory. From your command it
seems you run it in the source. I'm not surprised it doesn't work.

Edo

On Oct 28, 2017 6:59 AM, "Maarten Anonymous" <anonymous.maarten at gmail.com>
wrote:

> 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")
>
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171028/a653d133/attachment.html>


More information about the CMake mailing list