用于构建和管理第三方库的框架

发布于 2024-09-13 11:12:36 字数 682 浏览 8 评论 0原文

我正在开发一个跨平台项目,该项目使用大量第三方库(目前有 22 个并且还在增加,我预计这个数字会显着增加)。我的项目是基于 CMake 的,并保持 ThirdParty/ 目录的组织方式如下:

ThirdParty/$libname/include/
ThirdParty/$libname/lib/$platform/$buildtype/

我的 CMakeLists.txt 具有确定 $platform(mac-i386、mac-ia64、win32-i386 等)和 $buildtype(debug/发布)。

使这些库针对每个平台保持最新是很困难的。目前我正在手动执行此操作 - 当我更新一个库时,我会为每个平台重建它。但这是一场噩梦,添加一个新平台只需要两天的时间。

如果第三方库本身是基于 CMake 的,那么这将很容易实现自动化,但它们使用从 CMake 到 autoconf 到自定义解决方案到手动生成文件的所有内容。它们之间没有一致性,并且都需要在构建平台方面跳过各种障碍(特别是在 32 位与 64 位构建方面)。

是否有任何工具(或 CMake 扩展)可以使其更易于管理?例如,CMake 和 autoconf 之间是否存在任何合理的共同点?

理想的解决方案将给我一个单一的命令来构建给定平台需要重建的所有内容(交叉编译不是必需的,因为我可以访问所有必要的平台),但是任何能够逐渐使我的生活变得更轻松的东西都会受到赞赏。

I am working on a cross-platform project which uses a large number of third party libraries (currently 22 and counting, and I expect this number to increase significantly). My project is CMake-based, and keeps the ThirdParty/ directory organized like so:

ThirdParty/$libname/include/
ThirdParty/$libname/lib/$platform/$buildtype/

My CMakeLists.txt has logic to determine the appropriate values for $platform (mac-i386, mac-ia64, win32-i386, and so on) and $buildtype (debug/release).

The difficulty arises in keeping these libraries up-to-date for each platform. Currently I am doing this manually - when I update one library, I go and rebuild it for each platform. But this is a nightmare, and adding a new platform is a two day affair.

This would be easy to automate if the third party libraries were themselves CMake-based, but they use everything from CMake to autoconf to custom solutions to hand-rolled Makefiles. There is no consistency between them, and all require various hoops to be jumped through with regards to build platform (especially with regards to 32- vs. 64-bit builds).

Are there any tools (or CMake extensions) which would make this easier to manage? Is there even any reasonable common ground that can be reached between CMake and autoconf, for example?

The ideal solution would give me a single command to build everything that needs rebuilding for a given platform (cross-compilation is not necessary, as I have access to all necessary platforms), but anything that incrementally makes my life easier would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺渁∝ 2024-09-20 11:12:36

您可能可以使用 ExternalProject这。

创建自定义目标以在外部树中构建项目。
“ExternalProject_Add”函数创建一个自定义目标来驱动外部项目的下载、更新/修补、配置、构建、安装和测试步骤。

如果您的项目文件层次结构中已经有源代码,那么您可以使用类似的内容(对于 zlib):

include(ExternalProject)
ExternalProject_Add(zlib URL ${CMAKE_CURRENT_SOURCE_DIR}/zlib-1.2.4/
    CONFIGURE_COMMAND cd <SOURCE_DIR> && ./configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/zlib-build
    BUILD_IN_SOURCE 1
    BUILD_COMMAND make)

这会将 zlib 源代码从源代码树复制到构建树中,运行配置步骤(在 cd'ing 到复制的目录),然后在配置的目录上运行 make。最后,zlib 的构建版本被安装到当前构建目录中名为 zlib-build 的子目录中。

您可以根据需要调整设置、配置和构建步骤 - 例如,zlib 1.2.4 不喜欢在源代码之外运行“配置”。

对于自定义设置,您可以跳过配置步骤并仅运行构建命令(例如)。这需要最新版本的 CMake 才能工作(2.8+)。

You can probably use ExternalProject for this.

Create custom targets to build projects in external trees.
The 'ExternalProject_Add' function creates a custom target to drive download, update/patch, configure, build, install and test steps of an external project.

If you already have the source in your project's file hierarchy, then you can use something like this (for zlib):

include(ExternalProject)
ExternalProject_Add(zlib URL ${CMAKE_CURRENT_SOURCE_DIR}/zlib-1.2.4/
    CONFIGURE_COMMAND cd <SOURCE_DIR> && ./configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/zlib-build
    BUILD_IN_SOURCE 1
    BUILD_COMMAND make)

That will copy the zlib source code from your source tree into the build tree, run the configure step (after cd'ing into the copied directory), then run make on the configured directory. Finally the built version of zlib is installed into the current build directory, in a sub-directory called zlib-build.

You can tweak the setup, configure, and build steps however you like - zlib 1.2.4 for example doesn't like to have "configure" run out-of-source.

For a custom setup, you can skip the CONFIGURE step and just run the build command (for example). This requires a recent version of CMake to work (2.8+).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文