title: How can I get CMake to create an xcode project where warnings are suppressed in system headers?
body: <p>I have a CMake project with 3rd party library dependencies. The headers for the 3rd party libraries generate warnings that I care about for our source code.</p>
  
  <p>The CMake-generated Ninja project (using clang) does not generate warnings for 3rd party library headers.</p>
  
  <p>The Xcode project generated by CMake produces warnings for 3rd party library headers. I've tried including the 3rd party library paths with the CMake command</p>
  
  <p><code>include_directories(SYSTEM dirname1 dirname2)</code></p>
  
  <p>but Xcode does not seem to do do anything with this information.</p>
  
  <p>How can I generate an Xcode project from CMake that does not produce warnings for system headers?</p>
  
  <p>The Xcode command line just appends -I onto the header include paths regardless of whether I add <code>SYSTEM</code> to CMake.</p>
  
  <p>The following section from Darwin.cmake is less than encouraging:</p>
  
  <pre><code># Xcode does not support -isystem yet.
  if(XCODE)
    set(CMAKE_INCLUDE_SYSTEM_FLAG_C)
    set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
  endif()
  </code></pre>
  
  <h1>Extra info added</h1>
  
  <p>I've put together a small reproduction of the issue outlined:</p>
  
  <pre><code>== CMakeLists.txt ==
  include_directories(local_headers)
  include_directories(SYSTEM system_headers)
  
  set(CMAKE_CXX_FLAGS "-Werror=unused-variable")
  
  add_executable(main main.cpp)
  
  == main.cpp ==
  #include &lt;system_header.h&gt;
  #include "local_header.h"
  
  int main(int, const char**)
  {
  }
  
  == system_headers/system_header.h ==
  int f()
  {
    int x;
    return 5;
  }
  
  == local_headers/local_header.h ==
  int g()
  {
    int x = 5;
    return x;
  }
  </code></pre>
  
  <p>Running <code>cmake -GNinja &amp;&amp; cmake --build .</code> builds without errors.</p>
  
  <p>Running <code>cmake -GXcode &amp;&amp; cmake --build .</code> gives the following error:
  <code>
      system_headers/system_header.h:3:7: error: unused variable 'x' [-Werror,-Wunused-variable]
        int x;
  </code></p>
  
  <p>The full Xcode compile path is:
  <code>/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR=\"Debug\" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.11 -g -Wno-sign-conversion -I/Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/xcode_build/Debug/include -I/Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/local_headers -I/Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/system_headers -I/Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/xcode_build/Project.build/Debug/main.build/DerivedSources/x86_64 -I/Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/xcode_build/Project.build/Debug/main.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/xcode_build/Debug -Werror=unused-variable -MMD -MT dependencies -MF /Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/xcode_build/Project.build/Debug/main.build/Objects-normal/x86_64/main.d --serialize-diagnostics /Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/xcode_build/Project.build/Debug/main.build/Objects-normal/x86_64/main.dia -c /Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/main.cpp -o /Users/jon/DEV/CMakeSandbox/XcodeSystemIncludes/xcode_build/Project.build/Debug/main.build/Objects-normal/x86_64/main.o
  </code></p>
  
  <p>Running the Xcode compile command directly on the command line gives the same errors. </p>