Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding Boost without CMake find module (CMP0167)

I use CMake version 3.30.5. My Boost projects now issue this warning when invoking CMake:

CMake Warning (dev) at euler16_power_digit_sum/CMakeLists.txt:3 (find_package): Policy CMP0167 is not set: The FindBoost module is removed. Run "cmake --help-policy CMP0167" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

At first I did as suggested and set the CMake policy, both on the command line (older CMake versions don't recognize the policy CMP0167), and in my CMakeLists.txt files.

CMake implemented the CMP0167 policy in version 3.30.

I believe the root cause of the problem is the Boost package uses some deprecated CMake commands, so Kitware implemented the policy in CMake.

I also discovered adding "NO_MODULE" to my find_package command also suppressed the warning:

find_package(Boost REQUIRED NO_MODULE)

It seems to be working fine now, but what is the NO_MODULE actually doing, and what are the drawbacks of me using it?

like image 839
Glen Dayton Avatar asked Dec 16 '25 18:12

Glen Dayton


1 Answers

TL;DR
If you are using Boost 1.70 or newer, you are most certainly fine. Add the following code to get rid of the warning and check if still everything works as expected:

if(POLICY CMP0167)
  cmake_policy(SET CMP0167 NEW)
endif()

Full detailed answer
CMake came with a FindBoost.cmake module to find Boost. For every release of Boost, CMake added code to detect new Boost libraries and their dependencies. You always needed a more recent version of CMake for the Boost version used.

With Boost 1.70 came BoostConfig.cmake which could be used instead of CMake's find module. It was only used, if finding Boost was explicitly called in config mode find(Boost CONFIG) or no module mode find(Boost NO_MODULE). As most users do not care about such details, most projects kept relying on CMake's find module.

The CMake release 3.30 disables the use of the find module and thus uses Boost's config file. To allow projects to stay compatible with the old behavior, CMake policy CMP0167 was introduced. If it is set to OLD, the find module remains to be used (also the case when the minimum required CMake version is below 3.30). Otherwise CMake tries to find Boost with the config file provided by Boost.

The code snipped above sets CMP0167 to NEW to get rid of the warning and to use the new behavior. It assumes that Boost 1.70 is old enough that nobody is using it anymore.

If you still rely on using older Boost versions, plan to update to Boost 1.70. Future versions of CMake will break your setup: either by removing FindBoost.cmake or by Boost becoming incompatible to the now unmaintained find module.

like image 170
usr1234567 Avatar answered Dec 19 '25 13:12

usr1234567



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!