MantisBT - CMake
View Issue Details
0014429CMakeCMakepublic2013-09-20 16:172014-03-05 09:58
Rob Stewart 
Brad King 
normalmajoralways
closedno change required 
CMake 2.8.11 
 
0014429: SET_TARGET_PROPERTIES() Broken for COMPILE_DEFINITIONS?
According to my efforts, SET_TARGET_PROPERTIES() fails for COMPILE_DEFINITIONS. On the one hand, one might suppose that none of the values should be prefixed by "-D", thinking that the contents of that property will be enumerated and that "-D" or "/D" will be inserted ahead of each value on the command line. That doesn't work. The values appear as set by SET_TARGET_PROPERTIES(). So, one decides to ensure that all values are prefixed by "-D". That doesn't work either, according to what I'm seeing. The problem is that the first one is prefixed by "-D" and none of the rest are. IOW, it seems like SET_TARGET_PROPERTIES(), for COMPILE_DEFINITIONS, expects only one definition, but since one must, in general, use GET_TARGET_PROPERTY() first, to get the current values, then add new definitions, one is very likely to set multiple definitions.

Either SET_TARGET_PROPERTIES() should require "-D" prefixed to each definition, when setting COMPILE_DEFINITIONS, or it should expect that no value is prefixed. I think that SET_TARGET_PROPERTIES() should accept a quoted list (with semicolons), not just a space separated list of values, so I suggest that SET_TARGET_PROPERTIES(target PROPERTIES COMPILE_DEFINITIONS "value") iterate value and prepend "-D", as needed. Since that property is actually used after it is set, I'm really suggesting that the using code do the iteration (SET_TARGET_PROPERTIES() should really just save the values it's given).
SET_TARGET_PROPERTIES(target PROPERTIES COMPILE_DEFINITIONS "a b c")

Observe "-Da b c" in the compilation command.

SET_TARGET_PROPERTIES(target PROPERTIES COMPILE_DEFINITIONS "-Da -Db -Dc")

Observe "-D-Da -Db -Dc" in the compilation command.
No tags attached.
Issue History
2013-09-20 16:17Rob StewartNew Issue
2013-09-20 16:42Brad KingNote Added: 0033856
2013-09-20 16:45Brad KingNote Added: 0033857
2013-09-20 16:45Brad KingStatusnew => resolved
2013-09-20 16:45Brad KingResolutionopen => no change required
2013-09-20 16:51Rob StewartNote Added: 0033858
2013-09-20 16:51Rob StewartStatusresolved => feedback
2013-09-20 16:51Rob StewartResolutionno change required => reopened
2013-09-22 20:15Brad KingStatusfeedback => resolved
2013-09-22 20:15Brad KingResolutionreopened => no change required
2013-09-22 20:15Brad KingAssigned To => Brad King
2013-09-22 20:24Brad KingNote Added: 0033861
2014-03-05 09:58Robert MaynardNote Added: 0035263
2014-03-05 09:58Robert MaynardStatusresolved => closed

Notes
(0033856)
Brad King   
2013-09-20 16:42   
The COMPILE_DEFINITIONS property is documented as a ;-list:

 http://www.cmake.org/cmake/help/v2.8.11/cmake.html#prop_tgt:COMPILE_DEFINITIONS [^]
 "The COMPILE_DEFINITIONS property may be set to a semicolon-separated
  list of preprocessor definitions using the syntax VAR or VAR=value."

Any of

 set_target_properties(target PROPERTIES COMPILE_DEFINITIONS "a;b;c")

or

 set_property(TARGET target PROPERTY COMPILE_DEFINITIONS "a;b;c")

or

 set_property(TARGET target PROPERTY COMPILE_DEFINITIONS a b c)

will work. The latter works because set_property combines multiple args as a ;-list:

 http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:set_property [^]
 "arguments are used to compose the property value in the form of a semicolon-separated list"
(0033857)
Brad King   
2013-09-20 16:45   
Please bring questions like this to the mailing list at

 http://www.cmake.org/mailman/listinfo/cmake [^]

first. The issue tracker is for tracking issues. It is not a help and discussion forum.
(0033858)
Rob Stewart   
2013-09-20 16:51   
COMPILE_FLAGS does not accept a list. COMPILE_DEFINITIONS expects a list. Inconsistencies like these and the varying output argument position for the different commands, are driving me mad!

I was using a common function to manage getting the current values for a target's property, updating it, then using SET_TARGET_PROPERTIES() to save the updated value. I see that using SET_PROPERTY() will give me the consistency needed.
(0033861)
Brad King   
2013-09-22 20:24   
FYI, the inconsistency between COMPILE_FLAGS and COMPILE_DEFINITIONS is historical. COMPILE_FLAGS was created first to give raw access to place literal content on the command line. Later COMPILE_DEFINITIONS was introduced with a cleaner interface that automatically escapes values as necessary. Of course COMPILE_FLAGS cannot be changed and still be compatible with old code. Incidentally, CMake 2.8.12 will have a new COMPILE_OPTIONS target property that is ;-separated and escapes flags properly, like COMPILE_DEFINITIONS but for arbitrary flags.
(0035263)
Robert Maynard   
2014-03-05 09:58   
Closing resolved issues that have not been updated in more than 4 months