MantisBT - CMake
View Issue Details
0014759CMake(No Category)public2014-02-17 07:552016-06-10 14:31
Mathieu Malaterre 
Kitware Robot 
normalminorhave not tried
closedmoved 
 
 
0014759: add_definitions and -std=c++11
I recently discovered a new behavior for add_definitions as explained at:

http://stackoverflow.com/questions/10851247/how-to-activate-c-11-in-cmake#16393486 [^]

For some reason, cmake seems to cope with something like this:

ADD_DEFINITIONS(
    -std=c++11 # Or -std=c++0x
    # Other flags
)

I doubt this is pure luck, so I would suggest that it either be documented as:
1. Undefined behavior
2. Properly defined behavior, in which case `cmake --help-command add_definitions` should be updated.

thanks
No tags attached.
Issue History
2014-02-17 07:55Mathieu MalaterreNew Issue
2014-02-17 08:11Nils GladitzNote Added: 0035118
2014-02-17 08:14Mathieu MalaterreNote Added: 0035119
2014-02-17 09:00Brad KingNote Added: 0035123
2016-06-10 14:29Kitware RobotNote Added: 0042489
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0035118)
Nils Gladitz   
2014-02-17 08:11   
You mean the fact that it is being used for something other than definitions?

The command help currently does state:

"This command can be used to add any flags, but it was originally intended to add preprocessor definitions."

I would vote for having this behaviour deprecated by policy.
Maybe some time after target specific compiler features have been implemented since it would make this specific (and apparently common) "hack" superfluous.
(0035119)
Mathieu Malaterre   
2014-02-17 08:14   
Depending on how you read it:

"Adds -D define flags to the compilation of source files."

I thought that flags refered to the defined string, eg FOO or BAR as in the example:

add_definitions(-DFOO -DBAR ...)


However as you pointed out, there is way to read the documentation and understand that flag means -DFOO, in which case indeed this is -sort of- documented.
(0035123)
Brad King   
2014-02-17 09:00   
The command has accepted arbitrary flags since day one. That is why the syntax is "-D" for definition flags. Nowadays we parse out the -D flags and treat them like COMPILE_DEFINITIONS and pass through the rest of the flags for compatibility.

Now that we have add_compile_options the value of this old add_definitions behavior is only in compatibility rather than in functionality. We could consider adding a policy to disallow non-definition flags but I'd like to wait until versions of CMake that understand add_compile_options have been out for longer (2.8.12).
(0042489)
Kitware Robot   
2016-06-10 14:29   
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.