Problem
While doing a depends build with CMake 4.0.1, I got the following error:
 0Extracting freetype...
 1/root/bitcoin/depends/sources/freetype-2.11.0.tar.xz: OK
 2Preprocessing freetype...
 3Configuring freetype...
 4CMake Error at CMakeLists.txt:100 (cmake_minimum_required):
 5  Compatibility with CMake < 3.5 has been removed from CMake.
 6
 7  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
 8  to tell CMake that the project requires at least <min> but has been updated
 9  to work with policies introduced by <max> or earlier.
10
11  Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
12
13
14-- Configuring incomplete, errors occurred!
15make: *** [funcs.mk:343: /root/bitcoin/depends/x86_64-pc-linux-gnu/.freetype_stamp_configured] Error 1
16make: Leaving directory '/root/bitcoin/depends'
.. which led me to https://cmake.org/cmake/help/latest/release/4.0.html#deprecated-and-removed-features, which states compatibility with CMake versions less than 3.5 has been removed in 4.0.
Fix
Based on the suggestion from the error message (and from reading the CMake docs), I added -DCMAKE_POLICY_VERSION_MINIMUM=3.22. I picked 3.22 (as opposed to 3.5) since that is the minimum version of CMake we specify in doc/dependencies.md. Would be nice if there was a way to pipe the min version in as a variable (since presumably we’d want to update this to be in lock step with the minimum CMake version of the whole project), but I couldn’t think of a simple way to do this. Open to suggestions on a more robust way to do this if this is deemed too brittle.