是否可以使用CMake构建Boost? [英] Is it possible to build Boost with CMake?

查看:95
本文介绍了是否可以使用CMake构建Boost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是将静态库包含在交叉编译的项目中的源代码树中,而是想将boost直接添加到cmake中并进行构建.这可以吗?

Rather than include static libraries in my source tree in a cross-compiled project I'd like to add boost directly into cmake and build it. Is this available?

推荐答案

在我的工作场所中,我们也为此付出了很多努力.虽然我当然不能声称知道最佳"方法,但是我可以根据自己的经验提出以下想法.

We've struggled with this a fair bit too at my workplace. While I certainly can't claim to know the "best" way, I can offer the following thoughts on my experiences.

我们最初只是要求开发人员单独安装Boost,并让CMake以

We initially just required devs to install boost separately and had CMake do its normal checks in the form of a find_package(Boost...) call. This was easy, but not automated, and caused problems for devs with older versions of boost already installed.

然后,我们改变了策略,并添加了一个增强源的副本,这些副本是从您上面提到的一个项目中克隆的.我不记得具体细节,但我认为它是Ryppl项目目前正在研究的细节的先驱.重点是它已经支持CMake. boost库是通过add_library调用添加的实际CMake目标,这使它们更易于在CMake代码中使用.

We then changed tack and added a copy of the boost sources which we cloned from one of the projects you mentioned above. I can't recall the specifics, but I think it was a precursor to the one currently being worked on in the Ryppl project. The main point was that it already had support for CMake; the boost libraries were actual CMake targets added via add_library calls, which made them easier to work with in the CMake code.

尽管这通过自动化在我们的项目中使用boost解决了以前的问题,但最终成为维护的噩梦.我们从中克隆的boost项目从根本上进行了更改,现在非常依赖Ryppl特定的CMake函数.我们不想将Ryppl添加为依赖项,因此我们再次更改了方法!

While this solved the previous problems by automating the use of boost in our project, it ultimately became a maintenance nightmare. The boost project we had cloned from changed radically and is now very dependent on Ryppl-specific CMake functions. We didn't want to add Ryppl as a dependency, so we changed tack again!

我们查看了您在问题中提到的项目,同样发现它们都不可用.

We looked at the projects you mentioned in your question, and likewise found none of them to be usable.

我们当前的设置使用CMake的 ExternalProject 模块.这样,我们就可以下载并构建Boost到我们的构建树中.

Our current setup makes use of CMake's ExternalProject module. This allows us to download and build boost to our build tree.

优势:

  • 维护成本低
  • 自动完成,因此所有开发人员都使用带有相同标志构建的相同版本
  • 使我们自己的源代码树免受第三方代码的侵害
  • boost的多个副本可以愉快地共存(因此,没有机会无意中链接到使用不同的编译器/stdlib组合构建的副本)

缺点

  • 删除构建树意味着必须从头开始下载并构建boost.这可以通过例如改善.下载到固定位置(例如,系统temp dir),因此如果找到现有的Boost源副本,则可以跳过下载/解压缩步骤.
  • boost库不是正确的CMake目标(即尚未通过add_library调用添加)
  • Deleting your build tree means having to download and build boost from scratch. This could be ameliorated by e.g. downloading to a fixed location (say, system temp dir), so the download/unzip step could be skipped if an existing copy of the boost sources is found.
  • The boost libraries are not proper CMake targets (i.e. they haven't been added via add_library calls)

这是我们的CMake代码的链接.有几种方法可以改善此需求,但目前对我们来说效果不错.

Here's a link to our CMake code. There are a few ways in which this needs improved, but it currently works reasonably well for us.

我希望这个答案很快就会过时,并且可以得到一个体面的,模块化的,与CMake兼容的解决方案.

I hope that soon this answer becomes out of date and a decent, modularised, CMake-compatible solution becomes available.

这篇关于是否可以使用CMake构建Boost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆