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?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
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.
I found Fraser's answer above to be a good starting point, but ran into some issues using Boost 1.55.0 on our system.
First we wanted to have a self-contained source code package for our applications, so preferred not to use the CMake ExternalProject. We were only using the thread and date_time libraries from Boost, so we used bcp to create a subset of Boost with the build tools, thread and other dependent libraries:
and checked this into our svn repository.
Next, I was able to adapt Fraser's CMake file to build on Linux, but ran into problems running the
bootstrap.bat
file on Windows with CMake's execute_process command. To run bootstrap.bat we first needed to run the relevant Visual Studiovcvarsall.bat
script to set environment variables (we could probably figure out which individual variables need to be set, but it was easier to run the whole script). To run two .bat files in the same shell using execult_process, we usedcmd /c
and listed the files separated by a&
as the argument.Also
bootstrap.bat
did not set the exit code to non-zero in case of failure, so using the execute_process RESULT_VARIABLE to check for success didn't work. Instead we checked that the b2.exe executable had been created after the command was run.One last issue:
bootstrap.sh
supports the--prefix=
option, whichbootstrap.bat
does not. I also found that specifying the--prefix
option forb2.exe
on windows worked, but using the--prefix
option forb2
on Linux, without specifying it forbootstrap.sh
gave errors. (I haven't understood why yet).So the relevant part of our CMake file looks like:
In the above
APT_BOOST_SRC
is the location of the Boost subdirectory in our source directory,APT_BOOST_BIN
is the location we use to store the libraries in our CMake build directory, andAPT_BOOST_COMPONENTS
is a list of the Boost libraries we are using.