diff options
author | Harmen Stoppels <harmenstoppels@gmail.com> | 2021-11-19 14:10:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 14:10:00 +0100 |
commit | c5aee4d9b4840bc23041fa5d3339012598619cca (patch) | |
tree | 385c3ceabf3b3800750abb29a5c6171bc51a91fb /lib/spack/docs/build_systems | |
parent | 3db918b1cdfb720df22d6571804259ede8dc40f7 (diff) | |
download | spack-c5aee4d9b4840bc23041fa5d3339012598619cca.tar.gz spack-c5aee4d9b4840bc23041fa5d3339012598619cca.tar.bz2 spack-c5aee4d9b4840bc23041fa5d3339012598619cca.tar.xz spack-c5aee4d9b4840bc23041fa5d3339012598619cca.zip |
define_from_variant: return an empty string for non-existing variants (#27503)
This permits to use conditional variants without a lot of boilerplate.
Diffstat (limited to 'lib/spack/docs/build_systems')
-rw-r--r-- | lib/spack/docs/build_systems/cmakepackage.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/spack/docs/build_systems/cmakepackage.rst b/lib/spack/docs/build_systems/cmakepackage.rst index 3c3c96f92c..7ebac48734 100644 --- a/lib/spack/docs/build_systems/cmakepackage.rst +++ b/lib/spack/docs/build_systems/cmakepackage.rst @@ -145,6 +145,20 @@ and without the :meth:`~spack.build_systems.cmake.CMakePackage.define` and return args +Spack supports CMake defines from conditional variants too. Whenever the condition on +the variant is not met, ``define_from_variant()`` will simply return an empty string, +and CMake simply ignores the empty command line argument. For example the following + +.. code-block:: python + + variant('example', default=True, when='@2.0:') + + def cmake_args(self): + return [self.define_from_variant('EXAMPLE', 'example')] + +will generate ``'cmake' '-DEXAMPLE=ON' ...`` when `@2.0: +example` is met, but will +result in ``'cmake' '' ...`` when the spec version is below ``2.0``. + ^^^^^^^^^^ Generators |