57

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)
usr1234567
  • 21,601
  • 16
  • 108
  • 128
Sounak
  • 4,803
  • 7
  • 30
  • 48

2 Answers2

130

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.
Boost 1.79 requires CMake 3.23.2 or newer.
Boost 1.80 requires CMake 3.24.2 or newer.
Boost 1.81 requires CMake 3.25.2 or newer.
Boost 1.82 requires CMake 3.27.0 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.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
  • 3
    Thank you very much. CLion's 2016.3 bundled CMake 3.6.3 fails with this command. Now I use system CMake 3.7.2 from `/usr/bin/cmake` – kyb Mar 25 '17 at 02:30
  • 1
    You may get lucky sometimes. I got the "imported targets not available" warnings but could build my project nevertheless (CMake 3.6.2, Boost 1.64.0). I suspect because the dependencies have not changed for the libraries I use (filesystem,system,python,unit_test_framework) since 1.62 which is the highest Boost version CMake 3.6 knows about. – András Aszódi Jun 02 '17 at 09:12
  • 11
    I have boost 1.64 and cmake 3.8 and still get the message – Stepan Yakovenko Aug 12 '17 at 07:38
  • @StepanYakovenko Probably you have to delete your build directory and start from scratch. – usr1234567 Aug 12 '17 at 08:05
  • cmake=3.5.1 boost =? – Stepan Yakovenko Mar 28 '18 at 19:01
  • 2
    1.68 works with 3.12 for me. Also this is a really retarded system. – Timmmm Aug 30 '18 at 10:31
  • @Timmmm This might be the case for you, but you have not tested all combinations of Boost libraries. If there was a single change in the dependencies it will fail. The problem is Boost, they don't export the dependencies in a way CMake can process. They want to switch to CMake, but it is unclear when this will happen. – usr1234567 Aug 30 '18 at 11:43
  • My solution is to copy `FindBoost.cmake` from the latest CMake into my project and point `CMAKE_MODULE_PATH` at it. – Timmmm Aug 30 '18 at 14:05
  • 2
    boost 1.67 does not work for me with cmake 3.12, and it IS a retarded system, espcieally if there is no error like "you need a newer version of cmake for your version of boost" – hoijui Dec 01 '18 at 21:55
  • 2
    I still get this message with boost 1.70 despite using cmake 3.14 – Jaap Versteegh May 15 '19 at 10:58
  • who came up with this BS system. `cmake` 3.18.4, boost 1.74.0.3, same error. – Martin Braun Sep 02 '23 at 13:20
1

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.

user2267882
  • 79
  • 1
  • 7
  • 2
    Good for you, that it worked out. But it is not a general solution. If new libraries were added or existing ones dropped, it does not work. – usr1234567 Oct 21 '17 at 16:43