View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014429CMakeCMakepublic2013-09-20 16:172014-03-05 09:58
ReporterRob Stewart 
Assigned ToBrad King 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product VersionCMake 2.8.11 
Target VersionFixed in Version 
Summary0014429: SET_TARGET_PROPERTIES() Broken for COMPILE_DEFINITIONS?
DescriptionAccording 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).
Steps To ReproduceSET_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.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0033856)
Brad King (manager)
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 (manager)
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 (reporter)
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 (manager)
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 (manager)
2014-03-05 09:58

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

 Issue History
Date Modified Username Field Change
2013-09-20 16:17 Rob Stewart New Issue
2013-09-20 16:42 Brad King Note Added: 0033856
2013-09-20 16:45 Brad King Note Added: 0033857
2013-09-20 16:45 Brad King Status new => resolved
2013-09-20 16:45 Brad King Resolution open => no change required
2013-09-20 16:51 Rob Stewart Note Added: 0033858
2013-09-20 16:51 Rob Stewart Status resolved => feedback
2013-09-20 16:51 Rob Stewart Resolution no change required => reopened
2013-09-22 20:15 Brad King Status feedback => resolved
2013-09-22 20:15 Brad King Resolution reopened => no change required
2013-09-22 20:15 Brad King Assigned To => Brad King
2013-09-22 20:24 Brad King Note Added: 0033861
2014-03-05 09:58 Robert Maynard Note Added: 0035263
2014-03-05 09:58 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team