From a8706cc89b49fadadc644cdbb7077743fcc58b4b Mon Sep 17 00:00:00 2001 From: "Seth R. Johnson" Date: Mon, 16 Mar 2020 14:41:19 -0400 Subject: 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). --- var/spack/repos/builtin.mock/packages/cmake-client/package.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'var') 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 -- cgit v1.2.3-70-g09d2