View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0013946CMakeCMakepublic2013-02-23 01:202016-06-10 14:31
ReporterDave Abrahams 
Assigned ToKitware Robot 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
PlatformMacOSOS XOS Version10.8
Product VersionCMake 2.8.10 
Target VersionFixed in Version 
Summary0013946: custom command escaping of shell parentheses
DescriptionA left parenthesis in the COMMAND of add_custom_target is always passed to the shell in double quotation marks. That prevents COMMANDs like

"(" A "||" B ")" "&&" C

from working.
Steps To Reproducejust try it :-)
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0032365)
Dave Abrahams (reporter)
2013-02-23 01:42

Here's an example that didn't work for me:
https://github.com/ryppl/Boost2Git/blob/fc0fe838a1ae806e2ff9d7492d50d29bb02047c1/CMakeLists.txt#L73 [^]
The left paren was quoted to the shell, but the right paren was not!
(0032370)
Brad King (manager)
2013-02-25 08:34

The open paren is being treated as the argv[0] of a single command line.

Without the VERBATIM option quoting of special characters is not done consistently (here 'verbatim' means that we quote the value to get it through to the actual command's argv array as CMake sees it). Adding the option I get

 "(" A || B ")" && C

which at least is consistent with left and right parens. The shell operators are not quoted as they are treated as special cases already by VERBATIM due to previous such requests.

These kinds of shell expressions are not portable AFAIK. I suggest writing

 VERBATIM COMMAND sh -c "( A || B ) && C"

in the custom command instead, at least to work around this.

The list of special exceptions for shell operators is here:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmLocalGenerator.cxx;hb=v2.8.10.2#l2948 [^]

Try adding "(" and ")" to that list.
(0032375)
Dave Abrahams (reporter)
2013-02-25 09:42

1. Is that kind of shell expression any less portable than the availability of sh?

2. Not sure to whom the "Try adding…" advice is directed, but I don't plan to rebuild cmake for this one

3. Aside: I noticed that multiple COMMANDs get joined up by cmake with &&, at least on *nix. This can result in line lengths that would surely blow up CMD.EXE. The lack of parens around each clause means the user has to be aware of how cmake will construct the full command.
(0032376)
Brad King (manager)
2013-02-25 10:02

Re 0013946:0032375:

(1) No, but sh should be available anywhere you can use shell expressions and you don't need a new CMake to use it. I've seen projects go as far as using find_program to get sh, or just hard-code /bin/sh.

(2) The advice was directed to you to see if the fix is sufficient. Perhaps this fix will uncover another problem your project exposes which could then be reported too.

(3) Multiple commands are handled differently by different generators. If you don't put in your own shell expressions then you don't need to know how CMake combines them. Using "sh -c" will hide the operators inside a string argument and CMake will escape the command after -c so sh sees it cleanly (with VERBATIM).
(0032383)
Dave Abrahams (reporter)
2013-02-26 10:20

I appreciate your efforts, Brad, but we found a different approach.
(0032384)
Brad King (manager)
2013-02-26 10:42

Okay, sending to backlog for now and updating summary text.
(0042234)
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
2013-02-23 01:20 Dave Abrahams New Issue
2013-02-23 01:42 Dave Abrahams Note Added: 0032365
2013-02-25 08:34 Brad King Note Added: 0032370
2013-02-25 09:42 Dave Abrahams Note Added: 0032375
2013-02-25 10:02 Brad King Note Added: 0032376
2013-02-26 10:20 Dave Abrahams Note Added: 0032383
2013-02-26 10:42 Brad King Note Added: 0032384
2013-02-26 10:42 Brad King Severity major => minor
2013-02-26 10:42 Brad King Status new => backlog
2013-02-26 10:42 Brad King Summary add_custom_target COMMANDs have problems with left parens => custom command escaping of shell parentheses
2016-06-10 14:28 Kitware Robot Note Added: 0042234
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