如何将外部依赖引入跨平台CMake项目?
How to bring external dependencies into cross-platform CMake project?
将外部依赖项引入跨平台 CMake 项目的最佳方法是什么?请参阅下面我看到的问题范围和解决方案。
问题范围
假设我们有一个具有以下约束的 C/C++ 项目:
- CMake 是构建系统;
- 必须为不同的平台构建(桌面,Android NDK/Yocto SDK,iOS);
- 具有使用 CMake 构建的外部依赖项(例如 Google 测试);
- 具有外部非基于 CMake 的依赖项(例如 SQLite 合并、Boost);
- 并非所有依赖项都有 Git 上游(例如,SQLite 保存在 fossil 中)。
很高兴有东西:
- 自动下载依赖项,让新开发者开始编码的步骤更少;
- 依赖项的配置方式 IDE(如 CLion)可以自动完成(无需完成额外的配置步骤)。
可能的解决方案
- Git 子模块(不清楚如何处理基于非 Cmake 且未保留在 Git 依赖项中);
- Google Repo 工具(与之前相同的问题);
- CMake ExternalProject(下载、解压并可能在生成阶段使用 CMakeLists.txt 进行修补,并包含到使用 add_subdirectory 的项目中)。
我根据 Craig Scott 在 [3] 中的 [2] 回答创建了一个 PoC[1]。
参考资料
- [1] https://github.com/tegoo/cmake-dfetch
- [2] https://whosebug.com/users/1938798/craig-scott
- [3] CMake + GoogleTest
您的 PoC 可能有效,但 CMake 内置了 solution for fetching external projects during the configure step. If this does not satisfy your requirements like non CMake based dependencies, you may have a look at Conan。
https://blog.conan.io/2018/06/11/Transparent-CMake-Integration.html
将外部依赖项引入跨平台 CMake 项目的最佳方法是什么?请参阅下面我看到的问题范围和解决方案。
问题范围
假设我们有一个具有以下约束的 C/C++ 项目:
- CMake 是构建系统;
- 必须为不同的平台构建(桌面,Android NDK/Yocto SDK,iOS);
- 具有使用 CMake 构建的外部依赖项(例如 Google 测试);
- 具有外部非基于 CMake 的依赖项(例如 SQLite 合并、Boost);
- 并非所有依赖项都有 Git 上游(例如,SQLite 保存在 fossil 中)。
很高兴有东西:
- 自动下载依赖项,让新开发者开始编码的步骤更少;
- 依赖项的配置方式 IDE(如 CLion)可以自动完成(无需完成额外的配置步骤)。
可能的解决方案
- Git 子模块(不清楚如何处理基于非 Cmake 且未保留在 Git 依赖项中);
- Google Repo 工具(与之前相同的问题);
- CMake ExternalProject(下载、解压并可能在生成阶段使用 CMakeLists.txt 进行修补,并包含到使用 add_subdirectory 的项目中)。 我根据 Craig Scott 在 [3] 中的 [2] 回答创建了一个 PoC[1]。
参考资料
- [1] https://github.com/tegoo/cmake-dfetch
- [2] https://whosebug.com/users/1938798/craig-scott
- [3] CMake + GoogleTest
您的 PoC 可能有效,但 CMake 内置了 solution for fetching external projects during the configure step. If this does not satisfy your requirements like non CMake based dependencies, you may have a look at Conan。
https://blog.conan.io/2018/06/11/Transparent-CMake-Integration.html