[CMake] CTest w/ Coverage

Daniel Stonier d.stonier at gmail.com
Sun Apr 12 21:51:45 EDT 2009


I'm having a few troubles understanding how to get CTest setup. The
wiki is a bit piecemeal and just need a pointer in the right
direction.

Currently, the ctest results are passing for a simple hello world
project, but I can't get coverage working. When I run , it will

make all test                      OK
make Experimental            "Cannot find any coverage files"

Looking through the build tree, there is no gcov files anywhere. So
wondering what I have to add to instantiate them. The following is
what I'm currently using.

Thanks,
Daniel Stonier.


**************************************************************************
CMakeLists.txt

PROJECT (HELLOWORLD)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_BUILD_TYPE Debug)

INCLUDE (CTest)
ADD_SUBDIRECTORY (${CMAKE_SOURCE_DIR}/tests)

**************************************************************************
tests/hello.cpp

#include <iostream>

int main() {
    std::cout << "Hello Dude" << std::endl;
    std::cout << "Passed" << std::endl;
    return 0;
}

**************************************************************************
tests/CMakeLists.txt

ADD_EXECUTABLE(test_hello hello.cpp)

TARGET_LINK_LIBRARIES(test_hello ${LIBRARIES})
SET_TARGET_PROPERTIES(test_hello PROPERTIES COMPILE_FLAGS "-O0 -W
-Wshadow -Wunused-variable -Wunused-parameter -Wunused-function
-Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual
-Wwrite-strings -fprofile-arcs -ftest-coverage")
SET_TARGET_PROPERTIES(test_hello PROPERTIES LINK_FLAGS_DEBUG
"-fprofile-arcs -ftest-coverage")

ENABLE_TESTING()

ADD_TEST(hello test_hello)

# Regular expression to find. If found, test passes, otherwise fails.
SET_TESTS_PROPERTIES(hello PROPERTIES PASS_REGULAR_EXPRESSION "Passed")

**************************************************************************

I then run the system with the commands:

> cd builds
> cmake ../
> make all test
> make Experimental


More information about the CMake mailing list