在使用 gcc 构建时,CMake 中是否有任何方法可以强制通过 include_directories(或者可能通过不同的函数)指定的路径使用 -isystem 标志而不是 -I 标志?
见 http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#Directory-Options有关 -I 和 -isystem 的详细信息。
最佳答案
是的,您通过使用可选的 SYSTEM 标志强制将路径作为系统包含
include_directories(SYSTEM path)
https://cmake.org/cmake/help/latest/command/include_directories.html
从 CMake 2.8.12 开始,您可以使用新的 target_include_directories 在目标级别包含系统目录,同时利用 cmake 的新使用要求功能:
target_include_directories(foo SYSTEM PUBLIC path)
现在目标 foo 将使用 path 作为系统包含,并且链接到 foo 的任何内容也将自动使用 path 作为系统包含。您可以通过将 PUBLIC 关键字更改为 PRIVATE 或 INTERFACE 来控制这些使用要求的传播。
https://cmake.org/cmake/help/latest/command/target_include_directories.html
https://stackoverflow.com/questions/3371127/