[CMake] include_directories(SYSTEM, GNU.cmake and -isystem for C (not CXX)

Michael Hertling mhertling at online.de
Thu Jun 9 18:59:56 EDT 2011


On 06/08/2011 07:26 AM, Campbell Barton wrote:
> There were some system headers giving warnings compiling on linux,
> since I like to have warnings as errors, and not edit system headers,
> I used:
>  include_directories(SYSTEM dir1 dir2 ...)
> ... for system directories only.
> 
> However this does not result in -isystem being used in C because
> GNU.cmake does not set:
>  set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
> ... as it does for C++.

On my system, I can confirm that. AFAICS, it's caused by the macro
"__compiler_gnu" in ${CMAKE_ROOT}/Modules/Compiler/GNU.cmake; this
macro is parameterized with the argument "lang" for the language,
but for the "-isystem" option, it reads

set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")

i.e., the "-isystem" option is enabled statically for C++ only,
regardless of the "lang" argument. Shouldn't this line read

set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")

instead, i.e. "-isystem" for each "lang"?

> I tried adding this directly after the project(), call (beforehand it
> fails to have any effect):
> 
> 	if(CMAKE_COMPILER_IS_GNUCC)
> 		if(NOT APPLE)
> 			set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
> 		endif()
> 	endif()
> 
> 
> So now it almost works, but I've noticed that If
> "include_directories(SYSTEM" is called after a non system include, ALL
> includes then use -isystem.
> 
> Putting "include_directories(SYSTEM" first mostly works out OK, but I
> found a few cases where the order isn't so easy to set in our own
> CMakeLists.txt and still incorrectly uses -isystem where it shouldn't.
> Also found using the BEFORE / AFTER arguments to include_directories(
> doesn't make any difference to the use of -isystem.

This, however, I can't confirm. Could you provide an example?

> Is this a known problem or is there a way to get this working?

If you tweak the above-noted line in GNU.cmake, i.e. replace CXX with
${lang}, things work as expected at the first glance. This issue does
not seem to be correct, so I think your bug report is justified.

Regards,

Michael


More information about the CMake mailing list