From 0fa829ae77d1fd33ccaa8657bedcac45413b9655 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Tue, 1 Apr 2025 14:55:51 +0200 Subject: [PATCH] cmake: set CMAKE_POLICY_VERSION_MINIMUM (#49819) CMake 4.0.0 breaks compatibility with CMake projects requiring a CMake < 3.5. However, many projects that specify a minimum requirement for versions older than 3.5 are actually compatible with newer CMake and do not use CMake 3.4 or older features. This allows those projects to use a newer CMake Co-authored-by: John W. Parent <45471568+johnwparent@users.noreply.github.com> Signed-off-by: Massimiliano Culpo --- var/spack/repos/builtin/packages/cmake/package.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/var/spack/repos/builtin/packages/cmake/package.py b/var/spack/repos/builtin/packages/cmake/package.py index cb0c665e0c2..001f100b1fc 100644 --- a/var/spack/repos/builtin/packages/cmake/package.py +++ b/var/spack/repos/builtin/packages/cmake/package.py @@ -355,6 +355,15 @@ def install(self, spec, prefix): filter_file("mpc++_r)", "mpc++_r mpiFCC)", f, string=True) filter_file("mpifc)", "mpifc mpifrt)", f, string=True) + def setup_dependent_build_environment(self, env, dependent_spec): + # CMake 4.0.0 breaks compatibility with CMake projects requiring a CMake + # < 3.5. However, many projects that specify a minimum requirement for + # versions older than 3.5 are actually compatible with newer CMake + # and do not use CMake 3.4 or older features. This allows those + # projects to use a newer CMake + if self.spec.satisfies("@4:"): + env.set("CMAKE_POLICY_VERSION_MINIMUM", "3.5") + def setup_dependent_package(self, module, dependent_spec): """Called before cmake packages's install() methods."""