CMake

FAQ

  1. Can I build Boost libraries using the tool CMake and what documentation resources are available to help with this?

    Yes, CMake is a popular tool to use in conjunction with the Boost libraries.

    In this User Guide, refer to the examples in Getting Started and in Building with CMake.

    The Boost CMake support infrastructure has a lot of good information in it too.

  2. Am I right that the alternative to using CMake to build Boost is the B2 tool?

    Correct. Refer to Getting Started for examples, and B2 for a full specification.

  3. Do I need to set BOOST_ROOT?

    Usually not — CMake can often find Boost automatically. However, if Boost is installed in a non-standard location, call cmake -DBOOST_ROOT=/<PATH-TO-BOOST> or add set(BOOST_ROOT "/PATH-TO-BOOST") in your CMake file. This is especially useful when working with custom-built Boost versions.

  4. Any good advice if CMake fails to find Boost components?

    Set the flag -DBoost_DEBUG=ON to print detailed search diagnostics.

  5. If I want to install and build all of Boost using CMake, what would the command be?

    Try:

    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=<target-dir> -DBOOST_INCLUDE_LIBRARIES=serialization <path-to-boost-root-folder> && cmake --build . --target install  --config Release
  6. If I include a single library I want to use in my CMake build file, will dependent libraries automatically be built too, or do I have to include them explicitly?

    You do not usually have to include dependent libraries in your CMake file if you use the target_link_libraries command. For example, if you just wanted to build Boost.Filesystem, then add the following to your file:

    find_package(Boost REQUIRED COMPONENTS filesystem)
    target_link_libraries(my_app PRIVATE Boost::filesystem)

    However, if you use the add_subdirectory option in CMake, you will need to specify individual dependent libraries. Use the Boostdep tool to provide a list of all dependencies. Refer to Boost CMake support infrastructure for details.