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?
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.
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.
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.
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.
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:
Disadvantages
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With