gpt4 book ai didi

c++ - 如果 include_directories 中的路径之一不存在,为什么 CMakeLists 不抛出警告/错误(在编译期间)?

转载 作者:行者123 更新时间:2023-11-28 04:08:59 24 4
gpt4 key购买 nike

在我的 CMakeLists.txt 中,我在 include_directories() 下有很多路径。我希望在遇到不存在的路径时看到错误或警告。这样我就可以清理我的 CMakeLists.txt。我想清理多个 CMakeLists.txt。我的 include_directories 看起来像这样:

include_directories(
"inc"
"../../../../../../a/b/c/d/e/f/inc"
"../../../../../../a/b/c/d/l/p/inc"
"../../../../../../a/b/c/d/l/o/inc"
.
.
.
.
.
.
.
.

)

CMakeLists.txt 的当前分支中不存在路径“inc”,但不会引发错误。

我认为 CMakeLists.txt 会忽略 include_directories() 中的空字符串。

最佳答案

CMake passes 包括进一步构建系统的目录,并且不太关心它们的存在。

但是,您可以使用一些代码自行完成。函数include_directories将列表放入变量 INCLUDE_DIRECTORIES你可以迭代:

get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
FOREACH(dir ${dirs})
IF(NOT EXISTS ${dir})
message(SEND_ERROR "directory '" ${dir} "' does not exist.")
ENDIF(NOT EXISTS ${dir})
ENDFOREACH(dir)

Live demo .

关于c++ - 如果 include_directories 中的路径之一不存在,为什么 CMakeLists 不抛出警告/错误(在编译期间)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58214882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com