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.
The CMake-generated Ninja project (using clang) does not generate warnings for 3rd party library headers.
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
include_directories(SYSTEM dirname1 dirname2)
but Xcode does not seem to do do anything with this information.
How can I generate an Xcode project from CMake that does not produce warnings for system headers?
The Xcode command line just appends -I onto the header include paths regardless of whether I add SYSTEM
to CMake.
The following section from Darwin.cmake is less than encouraging:
# Xcode does not support -isystem yet.
if(XCODE)
set(CMAKE_INCLUDE_SYSTEM_FLAG_C)
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
endif()
Extra info added
I've put together a small reproduction of the issue outlined:
== 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 <system_header.h>
#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;
}
Running cmake -GNinja && cmake --build .
builds without errors.
Running cmake -GXcode && cmake --build .
gives the following error:
system_headers/system_header.h:3:7: error: unused variable 'x' [-Werror,-Wunused-variable]
int x;
The full Xcode compile path is:
/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
Running the Xcode compile command directly on the command line gives the same errors.