Why is cmake ignoring ADD (SYSTEM) headers when defining CXX?

I came across the following annoying question. I installed g ++ via macports on OSX everything works fine. However, cmake still detects clang ++ as a cpp compiler. So I end up saying

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

      

in my profile. Cmake now 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)

      

included as normal headers. In other words, I am getting a whole bunch of warnings ( -Wall

) that I would really like to suppress since I don't care about warnings in the headers of systems like Boost or Eigen.

Any idea how to fix this problem? It drives me crazy, and I am totally baffled why adding CXX

to a profile leads to this behavior. If I remove export CXX

from my profile and manually install CMAKE_CXX_COMPILER

in g ++ CMakeLists.txt

then everything is fine, no more warnings for system files.

+3


source to share


2 answers


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

was ignored. Setting up

SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")

      



solves it, no more warnings generated for system files.

This is a very strange problem that only appears on OS X. On all other tested systems, it INCLUDE_DIRECTORIES(SYSTEM "/path/to/system/header")

adds headers as system headers, without having to use the SET

above.

+4


source


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

with a few other system variables not adapted seems a little unorthodox, so the strange behavior is perhaps not surprising.

I suggest you set up from scratch (= from the clean build directory) your project from cmake-gui, the menu allows you to specify the path to the compiler (s) you want to use. You can also use your own toolchain file. I suggest you use cmake-gui, it offers a couple of options that might solve your problem.



Once you fix that, you can document the equivalent command line command for other people building your project.

+1


source







All Articles