CMake finds Boost but the imported targets not available for Boost version

BoostCmake

Boost Problem Overview


I use CMake to find Boost. Boost is found, but CMake errors out with

> Imported targets not available for Boost version

See the complete error (from macOS) below. What am I doing wrong?

CMake Warning at /Applications/CMake.app/Contents/share/cmake-3.6/Modules/FindBoost.cmake:743 (message):
  Imported targets not available for Boost version 106300
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.6/Modules/FindBoost.cmake:842 (_Boost_COMPONENT_DEPENDENCIES)
/Applications/CMake.app/Contents/share/cmake-3.6/Modules/FindBoost.cmake:1395 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:6 (find_package)

Boost version: 1.63.0
Found the following Boost libraries:
  thread
CMake Warning at /Applications/CMake.app/Contents/share/cmake-3.6/Modules/FindBoost.cmake:743 (message):
  Imported targets not available for Boost version 106300
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.6/Modules/FindBoost.cmake:842 (_Boost_COMPONENT_DEPENDENCIES)
  /Applications/CMake.app/Contents/share/cmake-3.6/Modules/FindBoost.cmake:1395 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:7 (find_package)

Boost Solutions


Solution 1 - Boost

Your CMake version is too old. Update CMake and it will work.

CMake cannot detect the dependencies between the different Boost libraries. They have explicitly implemented in FindBoost.
For every Boost release this information is added by the CMake maintainers and it gets part of the next CMake release. So you have to make sure, that your CMake version was released after the Boost version you try to find.

Boost 1.63 requires CMake 3.7 or newer.
Boost 1.64 requires CMake 3.8 or newer.
Boost 1.65 and 1.65.1 require CMake 3.9.3 or newer.
Boost 1.66 requires CMake 3.11 or newer.
Boost 1.67 requires CMake 3.12 or newer.
Boost 1.68, 1.69 require CMake 3.13 or newer.
Boost 1.70 requires CMake 3.14 or newer.
Boost 1.71 requires CMake 3.15.3 or newer.
Boost 1.72 requires CMake 3.16.2 or newer.
Boost 1.73 requires CMake 3.17.2 or newer.
Boost 1.74 requires CMake 3.19 or newer.
Boost 1.75 requires CMake 3.19.5 or newer.
Boost 1.76 requires CMake 3.20.3 or newer.
Boost 1.77 requires CMake 3.21.3 or newer.
Boost 1.78 requires CMake 3.22.2 or newer.

Without FindBoost

Starting with version 1.77, Boost provides a BoostConfig.cmake that obsoletes FindBoost and the required changes. Using

find_package(Boost CONFIG)

does exclude the FindBoost file and searches only for the config file.
For compatibility CMake will remain providing FindBoost.

Solution 2 - Boost

I just wanted to post the following work around, as it's far easier than upgrading CMake on the systems I'm working on where I do not have root/sudo access. Set BOOST_INCLUDEDIR and BOOST_LIBRARYDIR directly when invoking CMake.

cmake  -DBOOST_INCLUDEDIR=... -DBOOST_LIBRARYDIR=... ...

This may not work if Boost changed dependencies between the list hard coded in the module that ships with CMake and the boost version that you are using. It will take you 30 sec to try vs 30 min to install cmake from source.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSounakView Question on Stackoverflow
Solution 1 - Boostusr1234567View Answer on Stackoverflow
Solution 2 - Boostuser2267882View Answer on Stackoverflow