summaryrefslogtreecommitdiff
path: root/var
diff options
context:
space:
mode:
authorSeth R. Johnson <johnsonsr@ornl.gov>2020-03-16 14:41:19 -0400
committerGitHub <noreply@github.com>2020-03-16 11:41:19 -0700
commita8706cc89b49fadadc644cdbb7077743fcc58b4b (patch)
tree674d4644408b5cd38422ee207c0ea2cb7b200411 /var
parent55d5adfecfdaa097724ca75bdcb4b92251697e97 (diff)
downloadspack-a8706cc89b49fadadc644cdbb7077743fcc58b4b.tar.gz
spack-a8706cc89b49fadadc644cdbb7077743fcc58b4b.tar.bz2
spack-a8706cc89b49fadadc644cdbb7077743fcc58b4b.tar.xz
spack-a8706cc89b49fadadc644cdbb7077743fcc58b4b.zip
CMakePackage: convert variants to CMake arguments (#14376)
Add a 'define_from_variant` helper function to CMake-based Spack packages to convert package variants into CMake arguments. For example: args.append('-DFOO=%s' % ('ON' if '+foo' in self.spec else 'OFF')) can be replaced with: args.append(self.define_from_variant('foo')) The following conversions are handled automatically: * Flag variants will be converted to CMake booleans * Multivalued variants will be converted to semicolon-separated strings * Other variant values are converted to CMake string arguments This also adds a 'define' helper method to convert any variable to a CMake argument. It has the same conversion rules as 'define_from_variant' (but operates directly on values rather than requiring the user to supply the name of a package variant).
Diffstat (limited to 'var')
-rw-r--r--var/spack/repos/builtin.mock/packages/cmake-client/package.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/var/spack/repos/builtin.mock/packages/cmake-client/package.py b/var/spack/repos/builtin.mock/packages/cmake-client/package.py
index 286ee08086..2350259b22 100644
--- a/var/spack/repos/builtin.mock/packages/cmake-client/package.py
+++ b/var/spack/repos/builtin.mock/packages/cmake-client/package.py
@@ -21,6 +21,14 @@ class CmakeClient(CMakePackage):
version('1.0', '4cb3ff35b2472aae70f542116d616e63')
+ variant(
+ 'multi', description='',
+ values=any_combination_of('up', 'right', 'back').with_default('up')
+ )
+ variant('single', description='', default='blue',
+ values=('blue', 'red', 'green'), multi=False)
+ variant('truthy', description='', default=True)
+
callback_counter = 0
flipped = False