View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0012427CMakeCMakepublic2011-08-28 10:412016-06-10 14:31
ReporterMathnerd314 
Assigned ToKitware Robot 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionmoved 
PlatformWindowsOS7OS Version64-bit
Product VersionCMake 2.8.5 
Target VersionFixed in Version 
Summary0012427: ADD_CUSTOM_COMMAND escapes quotes incorrectly under MSVC
DescriptionADD_CUSTOM_COMMAND maps to a batch file, and in batch files the proper way to escape quotes is by doubling them. (i.e., "") However, the generated file doesn't do this, instead escaping them using a backslash (i.e., \"), which cmd.exe does not support.
Steps To Reproduce1. Generate project files for attached CMakeLists.txt
2. Examine test.vcproj, and note that the applicable rule has a CommandLine containing "\""
3. Build the project in Visual Studio, and note how a #define statement is output
4. Examine version.h, and note how the contents is not a valid header file
Additional InformationThere appear to be no workarounds, so a speedy fix would be helpful.
TagsNo tags attached.
Attached Filestxt file icon CMakeLists.txt [^] (1,025 bytes) 2011-08-28 10:41 [Show Content]

 Relationships

  Notes
(0027280)
Brad King (manager)
2011-08-29 10:02

Windows command line parsing is not done by cmd.exe or in bat files when it comes to executing a native program. The whole command line is passed to the CreateProcess API internally as a single string. It is up to the process startup code to actually do the parsing. The standard MS runtime library parses using a documented approach to define argv for main. CMake constructs escapes correctly according to this standard.

Escaping in custom commands is fairly well tested:

http://cmake.org/gitweb?p=cmake.git;a=blob;f=Tests/CustomCommand/CMakeLists.txt;hb=v2.8.5#l221 [^]

Which VS version/generator are you using?
(0027293)
Mathnerd314 (reporter)
2011-08-29 15:19

VS 9 2008 (Express Edition), and I'm generating for that version.
(0027295)
Brad King (manager)
2011-08-29 15:44

Okay, I can reproduce that. It looks like the shell fails to correctly handle the escapes while pulling out the shell redirection operator. You can work around this by moving the operator before the arguments:

ADD_CUSTOM_TARGET(test ALL
  ${CMAKE_COMMAND} -E echo "#ifndef VERSION_H" > "${CMAKE_BINARY_DIR}/version.h.tmp"
  COMMAND ${CMAKE_COMMAND} -E echo "#define VERSION_H" >> "${CMAKE_BINARY_DIR}/version.h.tmp"
  COMMAND ${CMAKE_COMMAND} >> "${CMAKE_BINARY_DIR}/version.h.tmp" -E echo_append "#define PACKAGE_VERSION \"0.0.0 r" # ***
  COMMAND ${SVNVERSION_EXECUTABLE} -n ${CMAKE_CURRENT_SOURCE_DIR} >> "${CMAKE_BINARY_DIR}/version.h.tmp"
  COMMAND ${CMAKE_COMMAND} >> "${CMAKE_BINARY_DIR}/version.h.tmp" -E echo "\"" # ***
  COMMAND ${CMAKE_COMMAND} -E echo "#endif" >> "${CMAKE_BINARY_DIR}/version.h.tmp"
  COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_BINARY_DIR}/version.h.tmp" "${CMAKE_BINARY_DIR}/version.h"
  COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/version.h.tmp"
  WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  COMMENT "Updating ${CMAKE_BINARY_DIR}/version.h..."
  VERBATIM
  )
(0027296)
Brad King (manager)
2011-08-29 15:46

Moving to backlog as it is unclear whether CMake can do anything about this. We already bend over backwards to accommodate crazy escaping patterns on Windows. I can find no way to get an unmatched double quote in an argument before ">>", though I haven't tried too hard.
(0027301)
Mathnerd314 (reporter)
2011-08-29 20:32

A quick workaround is all I needed. Thanks! :-)
(0041895)
Kitware Robot (administrator)
2016-06-10 14:28

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2011-08-28 10:41 Mathnerd314 New Issue
2011-08-28 10:41 Mathnerd314 File Added: CMakeLists.txt
2011-08-29 10:02 Brad King Note Added: 0027280
2011-08-29 15:19 Mathnerd314 Note Added: 0027293
2011-08-29 15:44 Brad King Note Added: 0027295
2011-08-29 15:46 Brad King Note Added: 0027296
2011-08-29 15:46 Brad King Status new => backlog
2011-08-29 20:32 Mathnerd314 Note Added: 0027301
2016-06-10 14:28 Kitware Robot Note Added: 0041895
2016-06-10 14:28 Kitware Robot Status backlog => resolved
2016-06-10 14:28 Kitware Robot Resolution open => moved
2016-06-10 14:28 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team