I'm having trouble getting cmake 4.1 to work with boost 1.88. I set the cmake BOOST_ROOT variable to C:\boost_1_88_0 and when my CMakeLists.txt file calls find_package(Boost REQUIRED) it successfully finds the file C:\boost_1_88_0\tools\cmake\config\BoostConfig.cmake, but when that file calls find_package(boost_headers ...) cmake fails, saying it can't find boost_headers-config.cmake, even though I can find that file deep under the C:\boost_1_88_0 directory. Is there an easy way to get boost to work with cmake 4.1?
I found the cause. I was trying to suppress the deprecation warnings from cmake, so I changed the cmake_minimum_required from VERSION 3.15.0 to VERSION 3.15.0...4.1.0. It seems that the boost cmake config files don't work with policy version 4.1.0. On Thu, Nov 20, 2025 at 1:57 PM Nigel Stewart <nigels.com@gmail.com> wrote:
Can you try some older versions of cmake, just to check if it's a cmake problem? Such as 3.28?
Is there an easy way to get boost to work with cmake 4.1?
What cmake warnings you've met? `cmake_minimum_required(VERSION 3.15...4.1.0)` is probably not you want to do, if you want to fix the warnings and still support 3.15. If I understand correctly, in this case (see https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html#poli...) policy version is set to 4.1.0, which means in 4.1.0 all policies introduced before will have `NEW` behaviour, but in 3.15 all policies will basically have `OLD` behaviour and users will get two types of cmake behaviour, without any warnings, so things may go out of control. For consistency it's better just to set policies with warnings to `OLD`, until min version in `cmake_minimum_required` will be able to support it. Or if you really need `NEW` behaviour, then you can set it for this particular policy.
A note that in cmake <3.30 https://cmake.org/cmake/help/latest/policy/CMP0167.htm might be set to `OLD` and `find_package(Boost REQUIRED)` will find `FindBoost.cmake` and behaviour could be different, since it will ignore `BoostConfig.cmake`.
Ah, sorry, broken url. The correct url is https://cmake.org/cmake/help/latest/policy/CMP0167.html
It's kind of odd that it's able to find `BoostConfig.cmake` in this scenario, since it shouldn't consider `\tools` folder to find `BoostConfig.cmake`, since `tools` is not the standard path that `find_package` would add to `C:\boost_1_88_0`. So there must be also `C:\boost_1_88_0\tools` somewhere on the PATH, allowing it to find `BoostConfig.cmake`. Either way, I believe it's not the correct way to provide boost config to cmake. The correct way is to set `Boost_ROOT` (or `BOOST_ROOT`) to the boost installation directory - typically `C:\boost_1_88_0\stage`, that would have `lib\cmake\Boost-1.86.0\BoostConfig.cmake` that cmake would be able to find. Note that you don't need to set `BOOST_ROOT` explicitly, it's just one of the options to add it to the path - you can also add `C:\boost_1_88_0\stage` to the general `CMAKE_PREFIX_PATH`. If you still have issues, please provide a minimal cmake file to reproduce this - it's very important to know what cmake version requirements are used in the file and what policies are set.
participants (5)
-
Andrej -
Andrej730 -
Nigel Stewart -
schoch+boost.org@starnet.com -
Steven Schoch