[CMake] Using gcov/lcov and valgrind with cmake

Bill Lorensen bill.lorensen at gmail.com
Fri Nov 5 16:31:27 EDT 2010


It should be done in the CMakeCache.txt file. In most projects, with
multiple developers and multiple platforms, you would not want to
perform coverage on every build. Look at VTK:
http://www.cdash.org/CDash/index.php?project=VTK or ITK:
http://www.cdash.org/CDash/index.php?project=Insight
These toolkits try to build on many different platforms with many
different combinations of builds (debug, release, coverage,
valgrind...).

I suppose, if you have a small development community, with a small
number of supported platforms, then including in the CMakeLists.txt is
an option. But that means you cannot build an efficient release build.
Still, I would recommend doing this in the CMakeCache.txt (which can
be done with a ctest script).


On Fri, Nov 5, 2010 at 9:42 AM, Gerhard Gappmeier
<gerhard.gappmeier at ascolab.com> wrote:
> Hi David and Cole,
>
> I don't understand how it should help to add this to CMakeCache.txt.
> This file is only temp file and is not checked in the repo.
> Can the MEMORY_CHECK options also be set in the CMakeLists.txt?
>
> I have the coverage test working at the moment using this construct in
> the CMakeLists.txt:
> # enable coverage analysis using GCC and GCOV
> IF (CMAKE_COMPILER_IS_GNUCC)
>    SET(CMAKE_C_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage")
>    SET(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage")
>    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs
> -ftest-coverage -lgcov")
> ENDIF()
> It works, but I'm not sure if this is the right Cmake way to do that.
>
> You can checkout the complete example using
> git clone git://github.com/gergap/helloworld.git
>
> Any help is appreciated to complete this helloworld cmake tutorial.
>
> Am 05.11.2010 13:39, schrieb David Cole:
>> Bill means your CMakeCache.txt file, not your CMakeLists.txt file.
>> (Pretty sure...) :-)
>>
>>
>> On Fri, Nov 5, 2010 at 8:30 AM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
>>> Try adding these (with proper paths) to your CMakeLists.txt file:
>>> CMAKE_BUILD_TYPE:STRING=Debug
>>> COVERAGE_COMMAND:FILEPATH=/usr/bin/gcov
>>> CMAKE_C_FLAGS:STRING=-g -O0  -fprofile-arcs -ftest-coverage
>>> CMAKE_CXX_FLAGS:STRING=-g -O0  -fprofile-arcs -ftest-coverage
>>>
>>> CTEST_MEMORYCHECK_COMMAND:FILEPATH=/usr/bin/valgrind)
>>> CTEST_MEMORYCHECK_COMMAND_OPTIONS:STRING=--trace-children=yes --quiet
>>> --tool=memcheck --leak-check=yes --show-reachable=yes
>>> --num-callers=100 --verbose --demangle=yes
>>>
>>>
>>> On Wed, Nov 3, 2010 at 9:11 AM, Gerhard Gappmeier
>>> <gerhard.gappmeier at ascolab.com> wrote:
>>>> Hi all,
>>>>
>>>> I'm trying to figure out how to use gcov and maybe also lcov with cmake.
>>>> I know it works using ctest, I've seen that in several wiki entries,
>>>> but I could not find one single example on how to use it.
>>>> The wiki only shows the commandline args for GCC, but no cmake examples.
>>>>
>>>> I attached a simple hello world project with two tests (ADD_TEST) which work.
>>>> I tried to add the "ctest_coverage" and "ctest_memcheck" commands but I can't
>>>> get them working.
>>>>
>>>> Maybe somebody can complete this example.
>>>>
>>>> IMO a new section about gcov and valgrind should be added to
>>>> http://www.cmake.org/cmake/help/cmake_tutorial.html
>>>> This would help a lot of people.
>>>>
>>>> --
>>>> mit freundlichen Grüßen / best regards
>>>>
>>>> *Gerhard Gappmeier*
>>>> ascolab GmbH - automation systems communication laboratory
>>>> Tel.: +49 9131 691 123
>>>> Fax: +49 9131 691 128
>>>> Web: http://www.ascolab.com
>>>> GPG Key Id: 5AAC50C4
>>>> GPG Fingerprint: 967A 15F1 2788 164D CCA3 6C46 07CD 6F82 5AAC 50C4
>>>>
>>>> --
>>>> *ascolab GmbH*
>>>> Geschäftsführer: Gerhard Gappmeier, Matthias Damm, Uwe Steinkrauß
>>>> Sitz der Gesellschaft: Am Weichselgarten 7 . 91058 Erlangen . Germany
>>>> Registernummer: HRB 9360
>>>> Registergericht: Amtsgericht Fürth
>>>>
>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.cmake.org/mailman/listinfo/cmake
>>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.cmake.org/mailman/listinfo/cmake
>>>
>>
>
>
> --
> mit freundlichen Grüßen / best regards
>
> *Gerhard Gappmeier*
> ascolab GmbH - automation systems communication laboratory
> Tel.: +49 9131 691 123
> Fax: +49 9131 691 128
> Web: http://www.ascolab.com
> GPG-Key: http://www.ascolab.com/gpg/gg.asc
>
> --
> *ascolab GmbH*
> Geschäftsführer: Gerhard Gappmeier, Matthias Damm, Uwe Steinkrauß
> Sitz der Gesellschaft: Am Weichselgarten 7 • 91058 Erlangen • Germany
> Registernummer: HRB 9360
> Registergericht: Amtsgericht Fürth
>
>


More information about the CMake mailing list