Skip to content

Commit

Permalink
add variants for build modes
Browse files Browse the repository at this point in the history
  • Loading branch information
victoria-cherkas committed Sep 16, 2024
1 parent ed8f9de commit fb631d4
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion repos/c2sm/packages/flexpart-cosmo/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

#
from spack import *
import spack.error as error

from llnl.util.filesystem import working_dir, install_tree

def validate_mode(mode):
if 'none' in mode and any([x in mode for x in ('omp', 'opt', 'ncdfout', 'debug')]):
raise error.SpecError(
'Cannot have mode none in addition to other modes (omp, opt, ncdfout, debug) in the same build'
)

class FlexpartCosmo(MakefilePackage):
"""flexpart is a Lagrangian dispersion model"""
Expand All @@ -27,6 +34,24 @@ class FlexpartCosmo(MakefilePackage):
conflicts('%pgi')
conflicts('%cce')

# Make mode/Compile time options of Flexpart as defined in:
# https://github.com/C2SM-RCM/flexpart/blob/main/documentation/installation.md#compile-time-options
variant('none',
default=False,
description='Enable default flags only (do not combine with other variants); serial model.')
variant('omp',
default=False,
description='Specify OpenMP parallelism explicitly in mode.')
variant('opt',
default=False,
description='Specify code optimization explicitly in mode.')
variant('ncdfout',
default=False,
description='Specify netcdf output explicitly in mode.')
variant('debug',
default=False,
description='Specify netcdf output explicitly in mode.')

build_directory = 'src'

makefile_file = "Makefile.spack"
Expand All @@ -41,9 +66,24 @@ def setup_build_environment(self, env):

def build(self, spec, prefix):

mode = ''

for x in [
'none',
'omp',
'opt',
'ncdfout',
'debug']:
if f'+{x}' in self.spec:
mode += x

with working_dir(self.build_directory):
make.jobs = 1
make('-f', self.makefile_file)
if mode:
validate_mode(mode)
make('-f', self.makefile_file, f"mode={mode}")
else:
make('-f', self.makefile_file)

def install(self, spec, prefix):
mkdir(prefix.bin)
Expand Down

0 comments on commit fb631d4

Please sign in to comment.