问题描述
在使用 gcc 构建时,CMake 中是否有任何方法可以强制通过 include_directories(或可能通过不同的函数)指定的路径使用 -isystem 标志而不是 -I 标志?
Is there any way in CMake to force a path specified via include_directories (or perhaps through a different function) to use the -isystem flag instead of the -I flag when building with gcc?
参见 http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#Directory-Options 有关 -I 和 -isystem 的详细信息.
See http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#Directory-Options for details on -I and -isystem.
推荐答案
是的,您通过使用可选的 SYSTEM 标志强制路径成为系统包含
Yes you force a path to be a system include by using the optional SYSTEM flag
include_directories(SYSTEM path)
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories
从 CMake 2.8.12 开始,您可以使用新的 target_include_directories 在目标级别包含系统目录包含,同时利用 cmake 的新使用要求功能:
Starting with CMake 2.8.12 you can use the new target_include_directories to include system directory includes at the target level, while leveraging the new usage requirement features of cmake:
target_include_directories(foo SYSTEM PUBLIC path)
现在目标 foo 将使用路径作为系统包含,以及任何链接到foo 也会像系统包含一样自动使用路径.您可以通过将 PUBLIC 关键字更改为 PRIVATE 或 INTERFACE 来控制这些使用要求的传播.
Now target foo will use path as a system include, and anything that links tofoo will also use path as automatically as a system include. You can control the propagation of these usage requirements by changing the PUBLIC keyword to PRIVATE or INTERFACE.
http://cmake.org/cmake/help/v2.8.12/cmake.html#command:target_include_directories
这篇关于在 CMake 中使用 -isystem 而不是 -I的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!