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

Campbell Barton ideasman42 at gmail.com
Wed Jun 8 01:26:45 EDT 2011


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++.

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.

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

-- 
- Campbell


More information about the CMake mailing list