From a32295c53182b0c2018a618eea0b47dc4e9e5ab8 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 5 Apr 2024 16:24:14 +0200 Subject: [PATCH 1/3] Set CMake hints for Python if added as a dependency --- easybuild/easyblocks/generic/cmakemake.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/easybuild/easyblocks/generic/cmakemake.py b/easybuild/easyblocks/generic/cmakemake.py index eb0d582018..35a3c33d7a 100644 --- a/easybuild/easyblocks/generic/cmakemake.py +++ b/easybuild/easyblocks/generic/cmakemake.py @@ -302,6 +302,24 @@ def configure_step(self, srcdir=None, builddir=None): options['BOOST_ROOT'] = boost_root options['Boost_NO_SYSTEM_PATHS'] = 'ON' + # Make sure CMake finds our Python when it is a dependency + if any(dep['name'] == 'Python' for dep in self.cfg.dependencies()): + # CMake 3.12 introduced FindPython/FindPython2/FindPython3 + # Below only FindPythonInterp existed in core CMake which don't has such hints. + # However PYTHON_EXECUTABLE could be used. + if LooseVersion(self.cmake_version) >= '3.12': + python_root = get_software_root('Python') + python_version = LooseVersion(get_software_version('Python')) + # For find_package(Python) + options['Python_ROOT_DIR'] = python_root + if python_version >= '3': + # For find_package(Python3) + options['Python3_ROOT_DIR'] = python_root + else: + # For find_package(Python2) + options['Python2_ROOT_DIR'] = python_root + + if self.cfg.get('configure_cmd') == DEFAULT_CONFIGURE_CMD: self.prepend_config_opts(options) command = ' '.join([ From 72d224dea15c8067aed388c01f425b2fdb095a87 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 5 Apr 2024 16:26:43 +0200 Subject: [PATCH 2/3] Remove blank line --- easybuild/easyblocks/generic/cmakemake.py | 1 - 1 file changed, 1 deletion(-) diff --git a/easybuild/easyblocks/generic/cmakemake.py b/easybuild/easyblocks/generic/cmakemake.py index 35a3c33d7a..cd70746501 100644 --- a/easybuild/easyblocks/generic/cmakemake.py +++ b/easybuild/easyblocks/generic/cmakemake.py @@ -319,7 +319,6 @@ def configure_step(self, srcdir=None, builddir=None): # For find_package(Python2) options['Python2_ROOT_DIR'] = python_root - if self.cfg.get('configure_cmd') == DEFAULT_CONFIGURE_CMD: self.prepend_config_opts(options) command = ' '.join([ From b7efb0b6d4a50e26b4b95932eedd0d27c4cf3995 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Wed, 31 Jul 2024 09:28:32 +0200 Subject: [PATCH 3/3] Also handle indirect dependencies Sometimes Python is a dependency of a dependency and CMake still needs to find that. So check if Python is loaded and set the hints if it is. --- easybuild/easyblocks/generic/cmakemake.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/easybuild/easyblocks/generic/cmakemake.py b/easybuild/easyblocks/generic/cmakemake.py index cd70746501..486092ba01 100644 --- a/easybuild/easyblocks/generic/cmakemake.py +++ b/easybuild/easyblocks/generic/cmakemake.py @@ -302,13 +302,13 @@ def configure_step(self, srcdir=None, builddir=None): options['BOOST_ROOT'] = boost_root options['Boost_NO_SYSTEM_PATHS'] = 'ON' - # Make sure CMake finds our Python when it is a dependency - if any(dep['name'] == 'Python' for dep in self.cfg.dependencies()): + # Make sure CMake finds our Python when it is a direct or indirect dependency + python_root = get_software_root('Python') + if python_root: # CMake 3.12 introduced FindPython/FindPython2/FindPython3 # Below only FindPythonInterp existed in core CMake which don't has such hints. # However PYTHON_EXECUTABLE could be used. if LooseVersion(self.cmake_version) >= '3.12': - python_root = get_software_root('Python') python_version = LooseVersion(get_software_version('Python')) # For find_package(Python) options['Python_ROOT_DIR'] = python_root