MantisBT - CMake
View Issue Details
0010837CMakeModulespublic2010-06-16 10:112016-02-07 15:35
Francois Kritzinger 
Gregor Jasny 
normaltextalways
closedduplicate 
CMake-2-8 
CMake 3.6 
0010837: GCC flag -isystem not applied on OS X
I've seen it mentioned in places (e.g. http://public.kitware.com/Bug/view.php?id=4462 [^]) that GCC on OS X doesn't support -isystem, but I can confirm that GCC 4.2.1 on OS X 2.6.4 does indeed support it.

For this reason I recommend that the following code at the bottom of Modules/Compiler/GNU.cmake

  if(NOT APPLE)
      set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
  endif(NOT APPLE)

be changed to

  set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")

(the reverse of the patch attached to the above-mentioned bug report).

No tags attached.
related to 0004462closed Brad King Do not use -isystem on Mac OS X 
related to 0015687closed Gregor Jasny target_include_directories(): SYSTEM option does not seem to work when targeting Xcode. 
related to 0015953closed Gregor Jasny CMake Does Not Use -isystem with GCC on OS X 
Issue History
2010-06-16 10:11Francois KritzingerNew Issue
2011-01-06 16:14Bill HoffmanNote Added: 0024481
2011-01-06 16:15Bill HoffmanAssigned To => Bill Hoffman
2011-01-06 16:15Bill HoffmanStatusnew => assigned
2011-01-07 13:41Francois KritzingerNote Added: 0024508
2011-01-07 16:49Brad KingRelationship addedrelated to 0004462
2011-01-07 16:53Brad KingNote Added: 0024519
2011-08-15 19:12Grant LimbergNote Added: 0027206
2012-03-01 22:57Andrew HillNote Added: 0028781
2012-07-05 00:36Strahinja Markovic Note Added: 0029911
2012-07-05 00:38Strahinja Markovic Note Edited: 0029911bug_revision_view_page.php?bugnote_id=29911#r727
2012-07-05 00:43Strahinja Markovic Note Edited: 0029911bug_revision_view_page.php?bugnote_id=29911#r728
2013-01-13 09:18valentinNote Added: 0032099
2013-01-13 09:19valentinNote Edited: 0032099bug_revision_view_page.php?bugnote_id=32099#r993
2013-01-13 09:21valentinNote Edited: 0032099bug_revision_view_page.php?bugnote_id=32099#r994
2013-01-16 19:13valentinNote Edited: 0032099bug_revision_view_page.php?bugnote_id=32099#r997
2015-08-07 04:41Gregor JasnyRelationship addedrelated to 0015687
2016-02-07 07:47Gregor JasnyAssigned ToBill Hoffman => Gregor Jasny
2016-02-07 07:47Gregor JasnyRelationship addedrelated to 0015953
2016-02-07 15:34Gregor JasnyNote Added: 0040443
2016-02-07 15:35Gregor JasnyStatusassigned => closed
2016-02-07 15:35Gregor JasnyResolutionopen => duplicate
2016-02-07 15:35Gregor JasnyFixed in Version => CMake 3.6

Notes
(0024481)
Bill Hoffman   
2011-01-06 16:14   
Is this still an issue?
(0024508)
Francois Kritzinger   
2011-01-07 13:41   
I think it is indeed still an issue, as the change I suggested has not been made in HEAD. Unless I am missing something?

One obvious thing I left out above was a check for the version of GCC and OS X. I couldn't say when -isystem support was first added, but, as I said above, I can confirm that it is supported on GCC 4.2.1 on OS X 10.6, which I am quite certain is the version of GCC it ships with.
(0024519)
Brad King   
2011-01-07 16:53   
I see -isystem documented in a very old Apple GCC:

  gcc version 3.3 20030304 (Apple Computer, Inc. build 1666)
  ProductName: Mac OS X
  ProductVersion: 10.3.9
  BuildVersion: 7W98

I think reverting the change from 0004462 is reasonable. If the original problem in that bug is really an issue then it needs to be investigated in more detail to show why -isystem is broken.
(0027206)
Grant Limberg   
2011-08-15 19:12   
isystem definitely works on Apple GCC and Clang compilers today.

If i recall correctly, it didn't work correctly with g++ on Tiger, though. I ran into a situation at a previous employer where attempting to compile a C++ project that used -isystem flags on OS X 10.4. g++ on Tiger implicitly added an an extern "C" around all includes that were found in the -isystem path. This was fixed as of Leopard, though.
(0028781)
Andrew Hill   
2012-03-01 22:57   
I've tried removing the "if(NOT APPLE)" guards but this doesn't seem to help (Xcode 4.3)

Xcode 4.3 uses llvm/clang, but as far as I can tell CMake still treats this as GNU?
Have also modded Modules/Platform/Darwin.cmake (which currently clears CMAKE_INCLUDE_SYSTEM_FLAG_C and CMAKE_INCLUDE_SYSTEM_FLAG_CXX) but this also had no effect on the commands being called by Xcode.

clang and gcc that come with Xcode 4.3 both support -isystem, but I can't seem to get cmake/xcode to put it in the command line that it builds with, and can't seem to see which is at fault
(0029911)
Strahinja Markovic    
2012-07-05 00:36   
(edited on: 2012-07-05 00:43)
I am experiencing this issue as well, even in the latest version (CMake 2.8.8). This problem basically kills the "SYSTEM" option to include_directories(). So if I use include_directories(SYSTEM <some path to header>) on Mac OS X, the SYSTEM option is completely ignored and cmake uses -I flags instead of -isystem (verified by looking at the generated flags.make file). With -Werror, this breaks my builds on Macs (because of warnings coming from irrelevant headers).

As noted, using set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ") before the include_directories(SYSTEM ...) call is a good workaround that resolves the problem.

Clang accepts -isystem just fine as does the Apple flavor of GCC.

This seems easily fixable: removing the if(NOT APPLE) condition should suffice. Any chance of seeing this change in trunk soon?

Note: I'm using the Unix Makefiles generator, Mac OS X Lion and "Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)"

(0032099)
valentin   
2013-01-13 09:18   
(edited on: 2013-01-16 19:13)
I currently need to use the -isystem flag to turn off some warnings in 3rd party headers, and I confirm that Xcode support -isystem flag too.

Is it possible, in addition to the proposed patch which make -isystem flag understandable by Unix Makefiles generator, to replace

IF(XCODE)
  SET(CMAKE_INCLUDE_SYSTEM_FLAG_C)
  SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
ENDIF(XCODE)

by something like

IF(XCODE)
  set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
ENDIF(XCODE)

in Modules/Platform/Darwin.cmake and Modules/Platform/Darwin-icc.cmake too?
(and maybe in QNX.cmake if it support this flag too)

EDIT : QNX seems to support it too ==> http://www.qnx.com/developers/docs/6.4.1/neutrino/utilities/g/gcc.html [^]

EDIT2 : I don't know the internal use for the 3 last .cmake files, but maybe it is better to completely remove this condition if GNU.cmake is included before them.

(0040443)
Gregor Jasny   
2016-02-07 15:34   
CMake will turn on -isystem for GCC >= 4 on Apple systems. See 0015953 for follow-ups.