Reputation:
When using CMake's include_directories
command, there is a way to specify whether a given directory is a system include directory.
For various reasons, though, I have to resort to using set_target_properties
to specify different include paths for different targets in the same scope, by setting INCLUDE_DIRECTORIES
property of the target.
The problem is, however, that I could not figure out how to tell CMake that a directory is a system directory so it uses -isystem
instead of -I
when possible. Mainly because the property is simply a list of directory paths and does not have any flags.
I thought there could be SYSTEM_INCLUDE_DIRECTORIES
, but I could not find any mention of that.
Any thoughts on how to go about this?
Upvotes: 2
Views: 8951
Reputation: 11074
In CMake 2.8.12, the target_include_directories() command learned the SYSTEM keyword:
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1925cffa083b
CMake 3.0.0 (the next release) will treat all directories listed in dependent IMPORTED targets as SYSTEM by default.
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a63fcbcb9f6c
Upvotes: 5
Reputation: 65801
The correct way to add system directories is to use the SYSTEM
option of the include_directories
command:
include_directories(SYSTEM "/foo/bar")
If include_directories
is not an option, you can specify a system include directory by directly modifying the target's COMPILE_FLAGS
property:
set_target_properties(main PROPERTIES APPEND_STRING PROPERTY
COMPILE_FLAGS " ${CMAKE_INCLUDE_SYSTEM_FLAG_CXX} /foo/bar")
The variable CMAKE_INCLUDE_SYSTEM_FLAG_CXX
usually resolves to -isystem
on UNIX systems.
Upvotes: 10