问题描述
有什么办法在CMake强制通过include_directories(或可能通过不同的函数)指定的路径使用-isystem标志而不是使用gcc构建时的-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?
请参阅了解有关-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)
从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)
b $ b
现在目标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.
这篇关于对CMake使用-isystem而不是-I的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!