[CMake] spaces in path to MEMCHECK_COMMAND

Noah Roberts roberts.noah at gmail.com
Sat Aug 18 21:13:33 EDT 2012


A couple weeks back I sent in a question about passing the name of a
test to the memory program as an argument to --xml-file.  I didn't get
a response so I continued trying to solve the issue myself.  I managed
to for the most part except for one problem.

What I did is make a "valgrind.sh" script inside of the source
directory.  This script takes the first argument to find a place to
create logs and uses basename to find the name of the test in the
second argument.  I then set it to the memory check command in this
way:


        set(MEMORYCHECK_COMMAND ${CMAKE_SOURCE_DIR}/cmake/valgrind.sh)
        set(MEMORYCHECK_COMMAND_OPTIONS "${CMAKE_BINARY_DIR}")

This works fine so long as CMAKE_SOURCE_DIR does not contain spaces.
When it does I get the following output:


nroberts at ubuntu:~/test lib/debug$ make ExperimentalMemCheck
   Site: ubuntu
   Build name: Linux-c++
Memory check project /home/nroberts/test lib/debug
    Start 1: main
1/1 MemCheck #1: main .............................***Not Run   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.01 sec

The following tests FAILED:
          1 - main (BAD_COMMAND)
-- Processing memory checking output:
Memory checking results:
Errors while running CTest
make[3]: *** [CMakeFiles/ExperimentalMemCheck] Error 16
make[2]: *** [CMakeFiles/ExperimentalMemCheck.dir/all] Error 2
make[1]: *** [CMakeFiles/ExperimentalMemCheck.dir/rule] Error 2
make: *** [ExperimentalMemCheck] Error 2

Inside of Testing/Temporary/LastDynamicAnalysis... I see this:

1/1 Testing: main
1/1 Test: main
Command: "/home/nroberts/test\ lib/cmake/valgrind.sh"
"/home/nroberts/test lib/debug" "/home/nroberts/test
lib/debug/test/main" "--output_format=xml" "--log_leel=all"
"--report_level=no" "--log_sink=/home/nroberts/test
lib/debug/test/repots/main.xml"
Directory: /home/nroberts/test lib/debug/test

The problem seems to be that it's running the command within quotes
and having a \ to escape the space.  When I do this on the command
line myself it of course cannot find the program.

So far I've not been able to find a workaround except requiring that
the source directory to contain the project never have a space (or
probably any other character requiring escape).  I'd rather not force
this requirement.  Does anyone know a way around this?

Content of valgrind.sh:

#!/bin/bash
valgrind --xml=yes --xml-file="$1/test/valgrind_reports/`basename
$2`.xml" --leak-check=full --show-reachable=yes -q --error-exitcode=1
"$2"


-- 
http://crazycpp.wordpress.com
http://crazyeddiesbrain.wordpress.com


More information about the CMake mailing list