[cmake-developers] [CMake 0012327]: Appending Multiple COMPILE_FLAGS Produces Unexpected Results

Mantis Bug Tracker mantis at public.kitware.com
Sun Jul 10 22:30:40 EDT 2011


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=12327 
====================================================================== 
Reported By:                Ryan H. Kawicki
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   12327
Category:                   CMake
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2011-07-10 22:30 EDT
Last Modified:              2011-07-10 22:30 EDT
====================================================================== 
Summary:                    Appending Multiple COMPILE_FLAGS Produces Unexpected
Results
Description: 
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.

Steps to Reproduce: 
Sample code provided.

Additional Information: 
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.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2011-07-10 22:30 Ryan H. KawickiNew Issue                                    
2011-07-10 22:30 Ryan H. KawickiFile Added: CMakeBug.zip                     
======================================================================




More information about the cmake-developers mailing list