Skip to content

Commit

Permalink
Make cmake and meson follow noopt/debug toolchainopts
Browse files Browse the repository at this point in the history
  • Loading branch information
Micket committed Sep 20, 2024
1 parent 633264a commit da1cd3d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 8 additions & 2 deletions easybuild/easyblocks/generic/cmakemake.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def extra_options(extra_vars=None):
'build_shared_libs': [None, "Build shared library (instead of static library)"
"None can be used to add no flag (usually results in static library)", CUSTOM],
'build_type': [None, "Build type for CMake, e.g. Release."
"Defaults to 'Release' or 'Debug' depending on toolchainopts[debug]", CUSTOM],
"Defaults to 'Release', 'RelWithDebInfo' or 'Debug' depending on "
"toolchainopts[debug,noopt]", CUSTOM],
'configure_cmd': [DEFAULT_CONFIGURE_CMD, "Configure command to use", CUSTOM],
'generator': [None, "Build file generator to use. None to use CMakes default", CUSTOM],
'install_target_subdir': [None, "Subdirectory to use as installation target", CUSTOM],
Expand Down Expand Up @@ -148,7 +149,12 @@ def build_type(self):
"""Build type set in the EasyConfig with default determined by toolchainopts"""
build_type = self.cfg.get('build_type')
if build_type is None:
build_type = 'Debug' if self.toolchain.options.get('debug', None) else 'Release'
if self.toolchain.options.get('noopt', None): # also implies debug but is the closest match
target = 'Debug'
elif self.toolchain.options.get('debug', None):
target = 'RelWithDebInfo'
else:
build_type = 'Release'
return build_type

def prepend_config_opts(self, config_opts):
Expand Down
20 changes: 19 additions & 1 deletion easybuild/easyblocks/generic/mesonninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,28 @@ def extra_options(extra_vars=None):
extra_vars.update({
'build_dir': [None, "build_dir to pass to meson", CUSTOM],
'build_cmd': [DEFAULT_BUILD_CMD, "Build command to use", CUSTOM],
'build_type': [None, "Build type for meson, e.g. release."
"Defaults to 'release', 'debugoptimized' or 'debug' depending on "
"toolchainopts[debug,noopt]", CUSTOM],
'configure_cmd': [DEFAULT_CONFIGURE_CMD, "Configure command to use", CUSTOM],
'install_cmd': [DEFAULT_INSTALL_CMD, "Install command to use", CUSTOM],
'separate_build_dir': [True, "Perform build in a separate directory", CUSTOM],
})
return extra_vars

@property
def build_type(self):
"""Build type set in the EasyConfig with default determined by toolchainopts"""
build_type = self.cfg.get('build_type')
if build_type is None:
if self.toolchain.options.get('noopt', None): # also implies debug but is the closest match
target = 'debug'
elif self.toolchain.options.get('debug', None):
target = 'debugoptimized'
else:
build_type = 'release'
return build_type

def configure_step(self, cmd_prefix=''):
"""
Configure with Meson.
Expand Down Expand Up @@ -92,13 +108,15 @@ def configure_step(self, cmd_prefix=''):

build_dir = self.cfg.get('build_dir') or self.start_dir

cmd = "%(preconfigopts)s %(configure_cmd)s --prefix %(installdir)s %(configopts)s %(source_dir)s" % {
cmd = "%(preconfigopts)s %(configure_cmd)s --prefix %(installdir)s --buildtype %(buildtype)s %(configopts)s %(source_dir)s" % {
'configopts': self.cfg['configopts'],
'configure_cmd': configure_cmd,
'installdir': self.installdir,
'preconfigopts': self.cfg['preconfigopts'],
'source_dir': build_dir,
'buildtype': self.build_type(),
}

res = run_shell_cmd(cmd)
return res.output

Expand Down

0 comments on commit da1cd3d

Please sign in to comment.