[CMake] escaping spaces in paths with cmake -E commands?

Zachary Pincus zpincus at stanford.edu
Sat May 6 02:05:30 EDT 2006


Hi folks,

I'm using CMake 2.2-3, and have recently run into some problems with  
a stanza of CMake code that looks like this:

SET(src "${IN_DIR}/foo.bar")
SET(tgt "${OUT_DIR}/foo.bar")
EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E copy_if_different ${src} ${tgt})

The problem comes when src or tgt have spaces in the paths -- the  
exec fails (obviously). Slightly less obviously, this also fails:
EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E copy_if_different "${src}" "$ 
{tgt}")

This seems to work, but I'm not sure if it is portable:
EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E copy_if_different "'${src}'" "'$ 
{tgt}'")

Is there a better option?

Now, when I had set this all up in the context of an  
ADD_CUSTOM_COMMAND instead of an EXEC_PROGRAM, things seemed to work  
-- is there automatic path escaping for args to custom commands, but  
not exec'd programs, in this version of CMake? (For some reason, we  
had to move to EXEC_PROGRAM instead of using a custom command...)

Thanks,
Zach


More information about the CMake mailing list