From 8ffffde67de37817cae22f8275f7894532179a0f Mon Sep 17 00:00:00 2001 From: crivella Date: Fri, 4 Oct 2024 13:14:30 +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 3e2bf0385a..e6b8ce4ea7 100644 --- a/easybuild/easyblocks/generic/cmakemake.py +++ b/easybuild/easyblocks/generic/cmakemake.py @@ -337,6 +337,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