MantisBT - CMake
View Issue Details
0015200CMakeCMakepublic2014-10-09 08:242015-04-06 09:07
Ray Donnelly 
 
normalmajoralways
closedno change required 
MicrosoftWindows7 64bit
CMake 3.0.2 
 
0015200: Odd quoting issue when mixing single, double and escaped quotes to COMMAND
Using the following CMakeList.txt:

add_executable (blender blender.c)

set(TARGETDIR_VER "C:/Program Files (x86)/Blender/share/blender/2.72")

add_custom_command(
  TARGET blender POST_BUILD MAIN_DEPENDENCY blender
  COMMAND ${CMAKE_COMMAND} -E echo 'now run: \"make install\" to copy runtime files and scripts to ${TARGETDIR_VER}'
)

Using any old blender.c (hello world will do)
And either "MSYS Makefiles" or "MinGW Makefiles" generators (actually I suspect any Makefile generator at all), we get badly quoted strings in CMakeFiles/blender.dir/build.make:

/C/cmake-3.0.2-win32-x86/bin/cmake.exe -E echo 'now run: "make install" to copy runtime files and scripts to "C:/Program Files (x86)/Blender/share/blender/2.72'"

It seems that the final ' and " have been swapped, which causes:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
unzip quote-problem.7z, and from the MSYS2 shell enter:

/c/cmake-3.0.2-win32-x86/bin/cmake.exe -G'MSYS Makefiles'
make

and observe the error message above.
This happens on the officially release 3.0.2 Windows binary and also on MSYS2's cmake.
No tags attached.
7z quote-problem.7z (489) 2014-10-09 08:24
https://public.kitware.com/Bug/file/5271/quote-problem.7z
Issue History
2014-10-09 08:24Ray DonnellyNew Issue
2014-10-09 08:24Ray DonnellyFile Added: quote-problem.7z
2014-10-09 08:36Ray DonnellyNote Added: 0037011
2014-10-09 08:40Brad KingNote Added: 0037013
2014-10-09 08:40Ray DonnellyNote Added: 0037014
2014-10-09 08:44Ray DonnellyNote Added: 0037015
2014-10-09 08:44Brad KingNote Added: 0037016
2014-10-09 08:47Brad KingNote Added: 0037017
2014-10-09 08:56Ray DonnellyNote Added: 0037018
2014-10-09 09:05Brad KingStatusnew => resolved
2014-10-09 09:05Brad KingResolutionopen => no change required
2015-04-06 09:07Robert MaynardNote Added: 0038421
2015-04-06 09:07Robert MaynardStatusresolved => closed

Notes
(0037011)
Ray Donnelly   
2014-10-09 08:36   
Testing on Linux, we get:

now run: "make install" to copy runtime files and scripts to C:/Program\ Files\ (x86)/Blender/share/blender/2.72
(0037013)
Brad King   
2014-10-09 08:40   
Try using the VERBATIM option to add_custom_command. It causes CMake to add proper escapes to send each argument through the build system shell correctly.
(0037014)
Ray Donnelly   
2014-10-09 08:40   
FWIW, I don't think 'MSYS Makefiles' should apply the Windows-y quoting logic, and should instead behave like Linux, but for 'MinGW Makefiles' the quoting does of course need to be applied, just not incorrectly.
(0037015)
Ray Donnelly   
2014-10-09 08:44   
VERBATIM does work around this bug, but is there any reason not to fix it?
(0037016)
Brad King   
2014-10-09 08:44   
Try something like this:

add_custom_command(
  TARGET blender POST_BUILD MAIN_DEPENDENCY blender
  VERBATIM COMMAND ${CMAKE_COMMAND} -E echo "now run: \"make install\" to copy runtime files and scripts to ${TARGETDIR_VER}"
  )
(0037017)
Brad King   
2014-10-09 08:47   
Re 0015200:0037015: The documentation of add_custom_command recommends VERBATIM because it enables correct behavior. However, LOTS of project code was written with hacks to work around the pre-VERBATIM behavior and "fixing" it would break that code by escaping the hacks. We do have the policy mechanism that could be used to fix it in a compatible way but feel that it would still be too disruptive now.
(0037018)
Ray Donnelly   
2014-10-09 08:56   
Ok, thanks Brad, that's fine then.

Could the policy mechanism allow the fix to happen around CMake 4 time? (whenever that is), if so, can I request this?
(0038421)
Robert Maynard   
2015-04-06 09:07   
Closing resolved issues that have not been updated in more than 4 months.