Search code examples
c++macoscmakemacports

Why does cmake ignore ADD(SYSTEM) header files when CXX is defined?


I've bumped into the following annoying issue. I installed g++ via macports on OSX, everything works fine. However, cmake still detects clang++ as the cpp compiler. Therefore, I end up putting

export CXX=/opt/local/bin/g++

in my profile. Now, cmake correctly detects g++ as the compiler. The problem is that all the system headers that I include with

INCLUDE_DIRECTORIES(SYSTEM "/path/to/system/header)

are included as regular headers. In other words, I am getting a whole bunch of warnings (-Wall) which I'd very much like to suppress, since I don't care about warnings in system headers like Boost or Eigen.

Any idea how to address this issue? It's driving me crazy, and I am completely puzzled why adding CXX in the profile results in this behaviour. If I remove the export CXX from my profile and manually set CMAKE_CXX_COMPILER to g++ in the CMakeLists.txt then everything is fine, no more warnings for system files.


Solution

  • I finally figured out a solution, from a somehow randomly found post: http://www.cmake.org/pipermail/cmake/2011-June/044769.html. For some reason, the SYSTEM directive was ignored. Setting

    SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
    

    solves it, no more warnings generated for system files.

    This is a very peculiar issue that appears only on OS X. On all other systems I tested, INCLUDE_DIRECTORIES(SYSTEM "/path/to/system/header") adds the headers as system headers, without any need to use the SET above.