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