27
votes

I am trying to figure out what components to Find in CMakeList.txt for boost libraries.

I looked at this directory /usr/local/include/boost. And I randomly pick some of the folders and try to use FIND_PACKAGE. These following all works well.

FIND_PACKAGE(Boost COMPONENTS thread system log log_setup
                    signals graph memory_order program_options REQUIRED)

The particular one that I am using is property_tree. It is not working and produces the following error message:

CMake Error at /Applications/CMake.app/Contents/share/cmake-3.1/Modules/FindBoost.cmake:1182 (message):

Unable to find the requested Boost libraries.

Boost version: 1.55.0

Boost include path: /usr/local/include

Could not find the following static Boost libraries:

    boost_property_tree

Could anyone explain how or where I can find the proper library names for boost?

2

2 Answers

27
votes

The COMPONENTS part of FIND_PACKAGE only searches for compiled libraries. It is not able to check for the header-only libraries that comprise a major part of Boost. There are only a few libraries that require linking (mostly those that perform platform-specific things).

From your examples, only thread, signals (in contrast to signals2 which is header-only), system and program_options need to be build beforehand and then linked with your program. For the rest, it is sufficient to include the relevant header files .

Thus, it is sufficient to add ${Boost_INCLUDE_DIRS} to the include directories of your target.

See here for a list of libraries of these libraries Which boost libraries are header-only?

2
votes

If boost library is compiled, then component name is basically lowercase name of library without prefixes and suffixes (for example for boost_system-vc141-mt-x64-1_66.lib it would be 'system')

Also see here: https://cmake.org/cmake/help/v3.10/module/FindBoost.html