|
23 | 23 | When using the BASH generator to generate command line arguments, CMake |
24 | 24 | uses the syntax ``-D<VARNAME>[:<TYPE>]=<VALUE>``. The ``TYPE`` field is optional |
25 | 25 | and if left out CMake will default to a ``STRING`` type. Further, all CMake |
26 | | -varaibles set via the command line using ``-D`` will be CACHE variables and each |
| 26 | +variables set via the command line using ``-D`` will be CACHE variables and each |
27 | 27 | ``-D`` operation should be considered a FORCE operation too. For example, |
28 | 28 | ``-DFOO:STRING=BAR`` is roughly equivalent to the CMake command: |
29 | 29 | ``set(FOO CACHE STRING "docstring" FORCE)``. |
|
32 | 32 | will instruct CMake to make that variable non-cache. Care should be taken when |
33 | 33 | using ``PARENT_SCOPE`` as combining it with the usual CACHE operations results |
34 | 34 | in CMake creating a non-cached variable whose contents are the list containing |
35 | | -``<varname>;CACHE;<type>;doc string``. |
| 35 | +``<varname>;CACHE;<type>;doc string``. As a result, the BASH generator issues |
| 36 | +warnings with no generated command line arguments when either: |
| 37 | + 1. ``PARENT_SCOPE`` or; |
| 38 | + 2. solely a variable name AND variable value. |
| 39 | +are passed in to `opt-set-cmake-var`. |
36 | 40 |
|
37 | 41 | See CMake documentation on the `set() <https://cmake.org/cmake/help/latest/command/set.html>`_ |
38 | 42 | command for more information on how fragment file entries are generated. |
|
42 | 46 |
|
43 | 47 | :Authors: |
44 | 48 | - William C. McLendon III <wcmclen@sandia.gov> |
| 49 | + - Evan Harvey <eharvey@sandia.gov> |
45 | 50 | """ |
46 | 51 | from __future__ import print_function |
| 52 | +from enum import Enum |
47 | 53 |
|
48 | 54 | #import inspect |
49 | 55 | #from pathlib import Path |
@@ -130,7 +136,10 @@ def _fieldhandler_CMAKE_FRAGMENT_CMAKE(self, field): |
130 | 136 | # M A I N C L A S S |
131 | 137 | # =============================== |
132 | 138 |
|
133 | | - |
| 139 | +class VarType(Enum): |
| 140 | + """Enumeration used to check for CMake variable types in SPOC.""" |
| 141 | + CACHE = 1 |
| 142 | + NON_CACHE = 2 |
134 | 143 |
|
135 | 144 | class SetProgramOptionsCMake(SetProgramOptions): |
136 | 145 | """Extends SetProgramOptions to add in CMake option support. |
@@ -224,7 +233,7 @@ def _program_option_handler_opt_set_cmake_var_bash(self, params: list, value: st |
224 | 233 |
|
225 | 234 | # Type-1 (non-cached / PARENT_SCOPE / non-typed) entries should not be |
226 | 235 | # written to the set of Bash parameters. |
227 | | - if param_opts['VARIANT'] == 1: |
| 236 | + if param_opts['VARIANT'] == VarType.NON_CACHE: |
228 | 237 | msg = f"bash generator - `{varname}={value}` skipped because" |
229 | 238 | msg += f" it is a non-cached (type-1) operation." |
230 | 239 | msg += f" To generate a bash arg for this consider adding FORCE or a TYPE" |
@@ -422,18 +431,18 @@ def _helper_opt_set_cmake_var_parse_parameters(self, params: list): |
422 | 431 | # PARENT_SCOPE forces Type-1 (i.e., non-cache var) |
423 | 432 | # - This will override CACHE, at least as of CMake 3.21.x |
424 | 433 | if output['PARENT_SCOPE']: |
425 | | - output['VARIANT'] = 1 |
| 434 | + output['VARIANT'] = VarType.NON_CACHE |
426 | 435 |
|
427 | 436 | # FORCE implies CACHE. If type wasn't provided then it's a STRING |
428 | 437 | elif output['FORCE']: |
429 | | - output['VARIANT'] = 2 |
| 438 | + output['VARIANT'] = VarType.CACHE |
430 | 439 |
|
431 | 440 | # If a TYPE is provided then it's a type-2 (CACHE) assignment. |
432 | 441 | elif output['TYPE'] is not None: |
433 | | - output['VARIANT'] = 2 |
| 442 | + output['VARIANT'] = VarType.CACHE |
434 | 443 |
|
435 | 444 | # Otherwise, a simple set is a type-1 |
436 | 445 | else: |
437 | | - output['VARIANT'] = 1 |
| 446 | + output['VARIANT'] = VarType.NON_CACHE |
438 | 447 |
|
439 | 448 | return output |
0 commit comments