MantisBT - CMake
View Issue Details
0012327CMakeCMakepublic2011-07-10 22:302016-06-10 14:31
Ryan H. Kawicki 
Kitware Robot 
normalmajoralways
closedmoved 
Microsoft WindowsWindows 7SP1 64-bit
CMake 2.8.5 
 
0012327: Appending Multiple COMPILE_FLAGS Produces Unexpected Results
When appending multiple compile flags to to a specific target, the final generated project file does not produce the correct information.

For Example:
###############################################
MACRO (ADD_COMPILER_FLAGS TargetProject Flags)
  SET_PROPERTY(TARGET ${TargetProject}
               APPEND PROPERTY
               COMPILE_FLAGS ${Flags})
ENDMACRO (ADD_COMPILER_FLAGS)

SET (SRC_FILES
Main.cpp
StdAfx.cpp
StdAfx.h)

ADD_EXECUTABLE(CMakeBugPrj WIN32 ${SRC_FILES})

ADD_COMPILER_FLAGS(CMakeBugPrj /wd4244)
ADD_COMPILER_FLAGS(CMakeBugPrj /wd4311)
ADD_COMPILER_FLAGS(CMakeBugPrj /wd4312)
###############################################

One would expect that the command line being passed to cl.exe would get /wd"4244" /wd"4311" /wd"4312", but instead it is getting /wd"4244" /wd"/wd4311" /wd"/wd4312".

To get around this issue, I was previously quoting the macro ${Flags} as " ${Flags}", but I came upon another issue that is now somewhat blocking me. I have another macro that also appends to the compiler flags list, but this time a semicolon is getting appended to the flag. This is causing the compiler to barf.
Sample code provided.
I've tracked the issue down to two locations:

cmProperty::Append - this function will append a semicolon if there is more than one option present.

cmSystemTools::ParseWindowsCommandLine - this function will jam all the arguments into one argument.

For example:
Project compile flags are set to "/Yu"StdAfx.h" /Yc"StdAfx.pch";/wd4244;/wd4311;/wd4312"

The project level compiler flags are separating the individual flags with a semicolon. When the generator begins generating the final output, it will take the project level compile flags and try to split out the arguments based on parsing the windows command line. According the the link, this is space separated, which means that the example above is actually two command line arguments.

I guess my recommendation, if I have one, is to determine a better solution for appending multiple compile flags. I would suggest a set of strings.
No tags attached.
related to 0012342closed Alex Neundorf Using set_property(...APPEND) for COMPILE_FLAGS result in semicolons in the build command line 
zip CMakeBug.zip (1,266) 2011-07-10 22:30
https://public.kitware.com/Bug/file/3968/CMakeBug.zip
Issue History
2011-07-10 22:30Ryan H. KawickiNew Issue
2011-07-10 22:30Ryan H. KawickiFile Added: CMakeBug.zip
2011-07-15 15:01Alex NeundorfRelationship addedrelated to 0012342
2012-08-11 11:38David ColeStatusnew => backlog
2012-08-11 11:38David ColeNote Added: 0030278
2016-06-10 14:28Kitware RobotNote Added: 0041860
2016-06-10 14:28Kitware RobotStatusbacklog => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0030278)
David Cole   
2012-08-11 11:38   
Sending old, never assigned issues to the backlog.

(The age of the bug, plus the fact that it's never been assigned to anyone means that nobody is actively working on it...)

If an issue you care about is sent to the backlog when you feel it should have been addressed in a different manner, please bring it up on the CMake mailing list for discussion. Sign up for the mailing list here, if you're not already on it: http://www.cmake.org/mailman/listinfo/cmake [^]

It's easy to re-activate a bug here if you can find a CMake developer who has the bandwidth to take it on, and ferry a fix through to our 'next' branch for dashboard testing.
(0041860)
Kitware Robot   
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.