Search code examples
c++cmakevalgrindctest

ctest does not find valgrind


Calling

ctest -j4 -DCTEST_MEMORYCHECK_COMMAND="/usr/bin/valgrind" -DMemoryCheckCommand="/usr/bin/valgrind" --output-on-failure -T MemCheck 

says

Memory checker (MemoryCheckCommand) not set, or cannot find the specified program.

Why doesn't it find valgrind automatically nor when specified manually?


Solution

  • As described on the CTest Wiki page, CTest reads the location of the memory check command (among other settings) from a file DartConfiguration.tcl in the build directory. One way to create the dart configuration file is to simply include the CTest CMake module in your CMakeLists.txt:

    include (CTest)
    

    The CTest module will find your valgrind installation in /usr/bin and put a variable MemoryCheckCommand pointing to it in the DartConfiguration.tcl file.