Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: Automatic Boost download and build if not found

Tags:

c++

boost

cmake

I would like to have a failsafe setup in my project. I don't really want to mess around with installing boost and the other libs every time we are setting stuff up.

So it would be awesome, that if a required Boost version is not found, cmake downloads and compiles boost and uses that version for the project.

Is there an easy possibility?

I found this in the maid-safe project. But I am not that experienced with cmake and have no clue how to use it.

like image 726
thi gg Avatar asked Feb 05 '15 14:02

thi gg


People also ask

Can I build boost with Cmake?

One of my current projects relies on Boost. Python, which requires a more recent version of Boost (1.64) than the one (1.54) provided by my Linux distribution (Ubuntu 14.04).

How do I add boosts to Cmakelist?

If you are using custome boost path, set CMAKE_PREFIX_PATH firstly. So, cmake can find your custome boost. By the way, if you run above code in sub cmake file, should set CMAKE_PREFIX_PATH back to parent scope. If you want find all components of boost, using below code.

Where do I put boost?

Install Boost (Windows) Download the source code from http://www.boost.org/users/download/. Extract in a Boost folder located at C:\ or C:\Program files so that CMake find-modules can detect it. Invoke the command line and navigate to the extracted folder (e.g. cd C:\Boost\boost_1_63_0 ).


1 Answers

You could use this find module I created.

  1. Download the FindBoost.cmake file.
  2. Save it somewhere within your project; for example, in a directory named cmake.
  3. Add the aforementioned directory to CMAKE_MODULE_PATH. Here's one way of accomplishing this: list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake).
  4. Set BOOST_REQUESTED_VERSION. For example, set(BOOST_REQUESTED_VERSION 1.61).
  5. Use the module like you would do with any other find module. For instance: find_package(Boost COMPONENTS system program_options)

If Boost is not installed in your system it will be downloaded and compiled on-the-fly, at build time (i.e., when you run make). If it is installed in your system, nothing will be downloaded.

(Optional) You can change BOOST_ROOT_DIR to the root directory of the location where boost is installed in your system. This is useful if it is installed in a non-standard location.

like image 157
thiagowfx Avatar answered Sep 22 '22 12:09

thiagowfx