5

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

......

Community
  • 1
  • 1
Ad N
  • 7,930
  • 6
  • 36
  • 80
  • how is the compiler invoked? please paste the output of `make VERBOSE=1` (or Xcode equivalent) – m.s. Jul 30 '15 at 17:53
  • @m.s. Thank you for the suggestion. I posted a new edit containing the compiler invocation made by Xcode, is it the equivalent of `VERBOSE` in make ? – Ad N Aug 03 '15 at 08:48
  • Are you sure that the issue is of cmake and not of Xcode? Does Xcode support `-isystem`? I think not. There is also an issue open in the Apple bug tracker – Francesco Sep 19 '15 at 08:48
  • @Francesco Xcode (in reasonably recent versions [tested with Xcode 5.1.1]) does support it, as I can use it by hand. – Ad N Sep 21 '15 at 08:50
  • @AdN which is the variable you have to set? I'd like to give it a try – Francesco Sep 21 '15 at 08:53
  • @Francesco I manually added `-isystem ${my_boost_path}` to the **Other C++ Flags** target option, and it was forwarded to Clang that took it into account. – Ad N Sep 21 '15 at 09:41
  • @AdN now I understand the reason of the question. The solution on the cmake side will be a workaround, not a proper solution. The real issue is that Xcode really does not support `-isystem` while Clang yes. I've already opened the issue in the Apple bug tracker, some months ago, but it is still opened. – Francesco Sep 21 '15 at 11:38

1 Answers1

5

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.

RobertJMaynard
  • 2,183
  • 14
  • 13