如果 CMake 构建无法到达依赖项回购协议,则会失败

CMake build fails if it can't reach dependency repo

我有一个依赖于另一个 CMake 项目(集成器)的 CMake 项目 (myapp)。集成器项目是通过 ExternalProject_Add 声明的,我使用 GIT_TAG 参数来指示要构建的集成器代码版本。在线时效果很好。但是,如果我曾经离线,我 运行 会遇到构建失败的问题。如果它无法到达 git 存储库,它总是会导致构建失败,即使它之前已经下载了该存储库的副本。我可以让 CMake 停止访问 GIT_TAG 存储库,而只使用我上次在线时下载的代码构建吗?

根据 ExternalProject 的文档,有一个名为 UPDATE_DISCONNECTED 的选项。

If UPDATE_DISCONNECTED is set, the update step is not executed automatically when building the main target. The update step can still be added as a step target and called manually. This is useful if you want to allow to build the project when you are disconnected from the network (you might still need the network for the download step). This is disabled by default.

因此,您应该添加选项设置

UPDATE_DISCONNECTED 1

到您的 ExternalProject_Add 声明以便能够离线工作。