View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015070CMakeCMakepublic2014-08-07 15:022015-05-04 09:05
ReporterVitali 
Assigned ToBrad King 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformApple MacOSOS XOS Version10.4.10
Product VersionCMake 3.0 
Target VersionCMake 3.1Fixed in VersionCMake 3.1 
Summary0015070: CMake doesn't escape # properly in add_compile_options with Makefile generator
Descriptionadd_compile_options appears to generate the wrong escape sequence for:
add_compile_options("-Wno-error=#warnings")

when used in conjuction with the Makefile generator
Steps To Reproduceadd_compile_options("-Wno-error=#warnings")

Use makefile generator

Look at flags.make:
CXX_FLAGS = ... "-Wno-error=#warnings" ...
It should be:
CXX_FLAGS = "-Wno-error=\#warnings"
due to shell-expansion (otherwise # gets treated as a comment).
Additional InformationNo amount of escaping in CMake fixes this.
It looks like CMake is already aware of \ escaping for the Makefile generator but not for #:

add_compile_options("-Wno-error=\#warnings")
CXX_FLAGS = ... "-Wno-error=#warnings" ...

add_compile_options("-Wno-error=\\#warnings")
CXX_FLAGS = ... "-Wno-error=\\#warnings" ...

add_compile_options("-Wno-error=\\\#warnings")
CXX_FLAGS = ... "-Wno-error=\\#warnings" ...
TagsNo tags attached.
Attached Files

 Relationships
related to 0014547closedKitware Robot Unix Makefile generator won't escape '#' 
related to 0013562closedKitware Robot Incorrect Makefiles generated for paths containing '#' 
has duplicate 0015285closed Cannot escape "#" in add_compile_options 
related to 0015322closed Double backslash to escape '#' in CMAKE_CXX_FLAGS no longer works 

  Notes
(0036577)
Brad King (manager)
2014-08-07 16:01

The _FLAGS variables are written here:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmMakefileTargetGenerator.cxx;hb=v3.0.0#l359 [^]

The flags that come from COMPILE_OPTIONS are computed by cmLocalGenerator::AddCompileOptions here:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmLocalGenerator.cxx;hb=v3.0.0#l1447 [^]

which uses cmLocalGenerator::AppendFlagEscape:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmLocalGenerator.cxx;hb=v3.0.0#l2347 [^]

which uses cmLocalGenerator::EscapeForShell.

That is meant for escaping things directly in the shell command part of a make rule. However, in this case it needs to escape for Make syntax in a variable assignment. That does not care about quoting so an extra layer of escaping is needed.
(0036604)
Brad King (manager)
2014-08-12 14:01

I've drafted a commit to fix this:

 Makefile: Handle '#' in COMPILE_OPTIONS
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=fbf7a929 [^]
(0038704)
Robert Maynard (manager)
2015-05-04 09:05

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2014-08-07 15:02 Vitali New Issue
2014-08-07 16:01 Brad King Note Added: 0036577
2014-08-12 14:01 Brad King Note Added: 0036604
2014-12-04 14:46 Brad King Relationship added related to 0015285
2014-12-04 14:47 Brad King Relationship replaced has duplicate 0015285
2014-12-04 14:48 Brad King Relationship added related to 0014547
2014-12-04 14:48 Brad King Relationship added related to 0013562
2014-12-04 14:51 Brad King Assigned To => Brad King
2014-12-04 14:51 Brad King Status new => resolved
2014-12-04 14:51 Brad King Resolution open => fixed
2014-12-04 14:51 Brad King Fixed in Version => CMake 3.1
2014-12-04 14:51 Brad King Target Version => CMake 3.1
2014-12-22 13:21 Brad King Relationship added related to 0015322
2015-05-04 09:05 Robert Maynard Note Added: 0038704
2015-05-04 09:05 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team