在 CMake 中使用

编程入门 行业动态 更新时间:2024-10-20 20:57:10
本文介绍了在 CMake 中使用 -isystem 而不是 -I的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 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/onlinedocs/gcc/Directory-Options.html#Directory-Options 有关 -I 和 -isystem 的详细信息.

See http://gcc.gnu/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/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 to foo 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/cmake/help/v2.8.12/cmake.html#command:target_include_directories

这篇关于在 CMake 中使用 -isystem 而不是 -I的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 04:52:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/795975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CMake

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!