MantisBT - CMake
View Issue Details
0004756CMakeCMakepublic2007-04-02 16:542016-06-10 14:30
Sean McBride 
Kitware Robot 
normalfeaturealways
closedmoved 
 
 
0004756: CMake needs an Objective-C equivalent of CMAKE_CXX_FLAGS
CMake provides CMAKE_CXX_FLAGS and CMAKE_C_FLAGS to supply compiler flags that are only supported by C++ and C respectively.

It is however lacking an analogous feature for Objective-C. That is, we need a CMAKE_OBJC_FLAGS.

In many cases, gcc on Mac OS X actually gives a warning when a flag is passed when compiling for a language that does not support the flag. For example, the '-fobjc-gc' flag if passed when building C++ warns:

"cc1plus: warning: command line option "-fobjc-gc" is valid for ObjC/ObjC++ but not for C++"

Objective-C files can be recognised by the .m filename extension.

There is also Objective-C++, recognised by the .mm extension, that allows both C++ and Obj-C syntax in the same file. In this case, we could either have a CMAKE_OBJCXX_FLAGS or apply both CMAKE_CXX_FLAGS and CMAKE_OBJC_FLAGS to those files. I believe I prefer the latter, but I have not given it too much thought.
No tags attached.
Issue History
2007-11-21 11:11Sean McBrideNote Added: 0009718
2007-12-18 10:34Sean McBrideNote Added: 0009978
2010-07-05 15:34Sean McBrideNote Added: 0021244
2011-12-20 08:41Brad KingNote Added: 0028019
2011-12-20 12:17Eric WingNote Added: 0028022
2011-12-20 15:38Sean McBrideNote Added: 0028023
2012-01-03 13:43David ColeNote Added: 0028146
2012-01-03 14:23Brad KingNote Added: 0028147
2014-02-14 14:09Brad KingAssigned ToBill Hoffman => Steve Wilson
2014-02-14 14:09Brad KingTarget Version => CMake 3.1
2014-10-03 09:33Brad KingAssigned ToSteve Wilson =>
2014-10-03 09:33Brad KingStatusassigned => backlog
2014-10-03 09:33Brad KingTarget VersionCMake 3.1 =>
2016-06-10 14:27Kitware RobotNote Added: 0041351
2016-06-10 14:27Kitware RobotStatusbacklog => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:27Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0007072)
Eric Wing   
2007-04-02 17:09   
Actually, I think you would need both/separate CMAKE_OBJC_FLAGS and CMAKE_OBJCXX_FLAGS. The problem is that there are some Obj-C++ only flags such as -fobjc-call-cxx-cdtors (Run non-trivial default constructors and destructors on C++ instance variables of Objective-C classes). This one is critical if you have C++ ivars (not pointers to) contained in an Obj-C class. But it is meaningless to pure C/Obj-C and pure C++ code.


(0007909)
Sean McBride   
2007-06-19 13:48   
Eric, you are quite right, CMake does need both.
(0009718)
Sean McBride   
2007-11-21 11:11   
In VTK, if one enables Garbage Collection in Cocoa, one gets many warnings:

http://www.vtk.org/Testing/Sites/RogueResearch4/Mac10.5-VTKBS-dbg/20071121-0300-Nightly/BuildWarning.html [^]
(0009978)
Sean McBride   
2007-12-18 10:34   
Committed a workaround for the VTK case, to eliminate all the warnings when doing a GC build of VTK Cocoa:

/cvsroot/VTK/VTK/Rendering/CMakeLists.txt,v <-- CMakeLists.txt
new revision: 1.267; previous revision: 1.266
(0021244)
Sean McBride   
2010-07-05 15:34   
Just to ping this bug.... Nothing much has changed as of 2.8.2. I'd still like to see this supported.
(0028019)
Brad King   
2011-12-20 08:41   
Should all C flags be used for ObjC too, and C++ flags for ObjC++?

I think the real change needed here may be to split ObjC and ObjCXX out into their own languages that need to be enabled by the project() or enable_language() commands. Then they will be fully distinct and can have their own compiler flags and such. Achieving this with compatibility though will require a policy:

  http://www.cmake.org/Wiki/CMake/Policies [^]
(0028022)
Eric Wing   
2011-12-20 12:17   
Obj-C is a pure 100% superset of C. It seems reasonable that C flags be used for ObjC.
I think it is safe to extend that idea for C++ to ObjC++.

I am having trouble imagining a real world case where you would not want the flags passed on.
(0028023)
Sean McBride   
2011-12-20 15:38   
I concur with Eric here...
(0028146)
David Cole   
2012-01-03 13:43   
This seems like a large amount of work for a very small benefit. Is there anybody listening in on this issue who can supply a patch, including, but not limited to the following:

- adding new languages ObjC and ObjCXX
- adding new flags for the languages
- associating *.m and *.mm files with the languages
- creating a policy
- adding a test
- following up on the dashboard when things go wrong on various Mac submissions

Anybody have time to work on a patch?
(0028147)
Brad King   
2012-01-03 14:23   
Re 0004756:0028146: I think the discussion here has concluded that we do not need new languages ObjC and ObjCXX but can instead just add the extra flags for *.m and *.mm sources with a special case. The simplest generalization of the special case I can think of is to define "variants" of a language that get special flags.
(0041351)
Kitware Robot   
2016-06-10 14:27   
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.