Carmellose
Carmellose

Reputation: 5088

Cmake: check if system include directory

Is it possible with cmake 2.6 (or higher, if not possible in this version) to check whether an include directory is marked as SYSTEM (e.g. compile with the isystem gcc flag, see 2.8 System Headers)?

For example, I get the include directories of the current target with:

GET_PROPERTY(_target_include_dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)

How do I know which ones are marked as isystem?

Thanks

Upvotes: 3

Views: 1292

Answers (1)

Thomas
Thomas

Reputation: 182000

Looking at the CMake source, whether an include directory added with include_directories is marked as SYSTEM seems to be tracked in CMake internals, and is not available for consumption inside your CMakeLists.txt¹.

However, for the target property INTERFACE_INCLUDE_DIRECTORIES (populated by target_include_directories with either PUBLIC or INTERFACE), there is another target property named INTERFACE_SYSTEM_INCLUDE_DIRECTORIES:

add_library(testlib test.cc)

target_include_directories(testlib SYSTEM INTERFACE /target_system)

get_property(_system_include_dirs TARGET testlib PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
message("System: ${_system_include_dirs}")

So maybe you can use that instead.

¹ There is mention of a SYSTEM_INCLUDE_DIRECTORIES property available through a generator expression, but I couldn't get it to work.

Upvotes: 1

Related Questions