Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to build Boost with CMake? [closed]

Tags:

c++

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?

like image 844
dzada Avatar asked Aug 21 '13 10:08

dzada


People also ask

Can I build Boost with CMake?

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

Does Boost need to be compiled?

Most Boost libraries are header-only: they consist entirely of header files containing templates and inline functions, and require no separately-compiled library binaries or special treatment when linking. The only Boost libraries that must be built separately are: Boost.

How do I add boosts to Cmakelist?

You can use find_package to search for available boost libraries. It defers searching for Boost to FindBoost. cmake, which is default installed with CMake. Upon finding Boost, the find_package() call will have filled many variables (check the reference for FindBoost.

Is C++ Boost still used?

After 20 years of active Boost development, it's now recognized as a very powerful C++ library, for each major version many C++ libraries from the community were added. The Boost reviewers have an advanced C++ skills and their contributions guarantee a high quality for many years.


1 Answers

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.

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.

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.

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.

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

Advantages:

  • Low maintenance
  • Automated, so all devs use the same version built with the same flags
  • Keeps our own source tree free from third-party code
  • Multiple copies of boost can happily co-exist (so no chance of accidentally linking to a copy built with a different compiler/stdlib combination)

Disadvantages

  • 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)

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.

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

like image 77
Fraser Avatar answered Sep 21 '22 09:09

Fraser