Friday, November 07, 2008

cdart, cdart2 or cdash? no, cdash public!

Having a way to monitor the quality of your project is a nice thing. Uffe, my former boss from Motorola, will happily agree on this.

CMake comes with CTest and you can use it to run and collect the results of your unit-tests. Even more, you can use CTest to run gcov and valgrind.

Another nice feature of CTest is its ability to store in a central location these results, though this is also one of its problem: it's a bit more difficult (aka, not obvious) how to not publish your results and still get code coverage!

Also difficult is setting a server where to publish your data. Based on the CMake wiki, I have assumed (wrongly), that I need to set up a CDart server. Then I've found a tutorial about using a CDart2 server that looked even simpler. But just when I was going to start installing CDart2, I've come upon an e-mail from CDart2 mailing list that stated that both CDart and CDart2 are obsoleted and I should use CDash instead.

Lucky me I was too lazy to install any of the CDart of CDart2 servers.

Even better, you don't have to install CDash either: just register at and create a project (or more) there. Once your project is created, you can download an auto-generated CTestConfig.cmake file that can be dropped into your top source dir. Once that is done, you can run ctest and publish the results (from the build directory, of course) to CDashPublic.

Unfortunately, you still need a couple of tweaks:
  • none of the default CMake build types supports the flags needed by gcov. I've solved this by creating my own Maintainer mode:
    set(CMAKE_CXX_FLAGS_MAINTAINER "-g -O0 -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual -Wwrite-strings -fprofile-arcs -ftest-coverage" CACHE STRI
    "Flags used by the C++ compiler during maintainer builds."
    set(CMAKE_C_FLAGS_MAINTAINER "-g -O0 -Wall -pedantic -W -fprofile-arcs -ftest-coverage" CACHE STRING
    "Flags used by the C compiler during maintainer builds."
    "-Wl,--warn-unresolved-symbols,--warn-once -fprofile-arcs -ftest-coverage" CACHE STRING
    "Flags used for linking binaries during maintainer builds."
    "-Wl,--warn-unresolved-symbols,--warn-once -fprofile-arcs -ftest-coverage" CACHE STRING
    "Flags used by the shared libraries linker during maintainer builds."
  • activate the maintainer mode (without this, you'll not get gcov data):
    mkdir build
    cd build
    cmake -DCMAKE_BUILD_TYPE=Maintainer ..
  • publish the data (you need an explicit call to ExperimentalMemCheck to get valgrind)
    ctest -D Experimental -D ExperimentalMemCheck
Not perfect, but not that bad either and now I can publish and analyze my metrics :-)

1 comment:

  1. This comment has been removed by a blog administrator.