From 606533b25a0557f8c93240c35e87ac448394683e Mon Sep 17 00:00:00 2001 From: crivella Date: Fri, 4 Oct 2024 13:28:51 +0200 Subject: [PATCH] Convenience function to set find_python HINTS --- easybuild/easyblocks/generic/cmakemake.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/easybuild/easyblocks/generic/cmakemake.py b/easybuild/easyblocks/generic/cmakemake.py index 5b7ec4d702..296c8ab039 100644 --- a/easybuild/easyblocks/generic/cmakemake.py +++ b/easybuild/easyblocks/generic/cmakemake.py @@ -336,6 +336,22 @@ def configure_step(self, srcdir=None, builddir=None): return out + def set_cmake_env_vars_python(self): + """Convenience function to set CMake hints for FindPython[_2/3] as environment variables. + Needed to avoid wrong Python being picked up by CMake when not called directly by EasyBuild but as step in a + build and no option is provided to set custom CMake variables. + """ + if LooseVersion(self.cmake_version) < '3.12': + raise EasyBuildError("Setting Python hints for CMake requires CMake version 3.12 or newer") + python_root = get_software_root('Python') + if python_root: + python_version = LooseVersion(get_software_version('Python')) + setvar('Python_ROOT_DIR', python_root) + if python_version >= "3": + setvar('Python3_ROOT_DIR', python_root) + else: + setvar('Python2_ROOT_DIR', python_root) + def test_step(self): """CMake specific test setup""" # When using ctest for tests (default) then show verbose output if a test fails