简体   繁体   中英

CMake: Automatic Boost download and build if not found

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.

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 (ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM