CMake target_include_directories(SYSTEM …): SYSTEM

2019-02-25 04:47发布

We are building an application depending on Boost, and compilation generates a lot of warning "Class member cannot be redeclared" in a Boost header (tag_of.hpp).

To avoid spamming the build log, we decided to include Boost headers as system headers:

target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})

Our understanding is that this command should put Boost include directory behind a -isystemcompiler flags. Yet it does no such thing, instead putting it alongside 'normal' include directories in the header search path.

The environment is CMake 3.0.0, generating a project file for Xcode 5.1.1. This seems to be an issue with some others (see last two comments in this answer).

Is there a working way to include headers as system ?


EDIT: Just tested in the same environment, updating CMake to version 3.3.0, and the behaviour is the same.


EDIT: Here is a minimal example that is showing the issue on my environment

cmake_minimum_required(VERSION 3.0)

find_package(Boost 1.49 COMPONENTS)

project(system_dependencies)

add_executable(${PROJECT_NAME} main.cpp)

target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})

The Xcode project file generated from this script places the path to Boost in the build setting: Header search path, instead of appending it behind a -isystem compiler flag. Which is confirmed by the compilation command issued by the IDE:

/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.9.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -mmacosx-version-min=10.9 -g -Wno-sign-conversion -I/Users/.../system_dependencies/build/Debug/include

-I/Users/.../SDK/boost/include

......

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-02-25 05:22

This issue looks to only occur for the XCode generator, as CMake believes it doesn't support the isystem flag. I would think the best solution is to report this issue on CMake bug tracker.

查看更多
登录 后发表回答