From 9ba06ad5518c5d2a06692ee7b56991c7bfd7b13a Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Thu, 9 Feb 2023 15:33:09 +0100 Subject: [PATCH] Fix CMake configopts when iterating (multiple builds) Partial revert of #2541: Do not modify `cfg['configopts']` but simply read them and pass the combined result to `run_cmd`. This fixes an issue with templating while iterating over e.g. multiple Pythons and also avoids keeping values in configopts over multiple iterations/builds. Fixes #2881 --- easybuild/easyblocks/generic/cmakemake.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/easybuild/easyblocks/generic/cmakemake.py b/easybuild/easyblocks/generic/cmakemake.py index f747702fc9f..f72d5a8ff9e 100644 --- a/easybuild/easyblocks/generic/cmakemake.py +++ b/easybuild/easyblocks/generic/cmakemake.py @@ -139,13 +139,20 @@ def build_type(self): build_type = 'Debug' if self.toolchain.options.get('debug', None) else 'Release' return build_type - def prepend_config_opts(self, config_opts): - """Prepends configure options (-Dkey=value) to configopts ignoring those already set""" + def combine_config_opts(self, config_opts_default): + """Combine configure options (-Dkey=value) from config_opts_default with those from the EC + + -- config_opts_default: Dictionary mapping keys (variable names) to values. + Those will be prepended to the ECs configopts if they are set by the EC, + i.e. if they would be overwritten/duplicated. + """ cfg_configopts = self.cfg['configopts'] # All options are of the form '-D=' - new_opts = ' '.join('-D%s=%s' % (key, value) for key, value in config_opts.items() + new_opts = ' '.join('-D%s=%s' % (key, value) for key, value in config_opts_default.items() if '-D%s=' % key not in cfg_configopts) - self.cfg['configopts'] = ' '.join([new_opts, cfg_configopts]) + if new_opts and cfg_configopts: + new_opts += ' ' + return new_opts + cfg_configopts def configure_step(self, srcdir=None, builddir=None): """Configure build using cmake""" @@ -286,12 +293,11 @@ def configure_step(self, srcdir=None, builddir=None): options['Boost_NO_SYSTEM_PATHS'] = 'ON' if self.cfg.get('configure_cmd') == DEFAULT_CONFIGURE_CMD: - self.prepend_config_opts(options) command = ' '.join([ self.cfg['preconfigopts'], DEFAULT_CONFIGURE_CMD, generator, - self.cfg['configopts'], + self.combine_config_opts(options), srcdir]) else: command = ' '.join([