Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 569225a

Browse files
committed
Update docs and add Enum
1 parent 1b22dea commit 569225a

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/setprogramoptions/SetProgramOptionsCMake.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
When using the BASH generator to generate command line arguments, CMake
2424
uses the syntax ``-D<VARNAME>[:<TYPE>]=<VALUE>``. The ``TYPE`` field is optional
2525
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
2727
``-D`` operation should be considered a FORCE operation too. For example,
2828
``-DFOO:STRING=BAR`` is roughly equivalent to the CMake command:
2929
``set(FOO CACHE STRING "docstring" FORCE)``.
@@ -32,7 +32,11 @@
3232
will instruct CMake to make that variable non-cache. Care should be taken when
3333
using ``PARENT_SCOPE`` as combining it with the usual CACHE operations results
3434
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`.
3640
3741
See CMake documentation on the `set() <https://cmake.org/cmake/help/latest/command/set.html>`_
3842
command for more information on how fragment file entries are generated.
@@ -42,8 +46,10 @@
4246
4347
:Authors:
4448
- William C. McLendon III <wcmclen@sandia.gov>
49+
- Evan Harvey <eharvey@sandia.gov>
4550
"""
4651
from __future__ import print_function
52+
from enum import Enum
4753

4854
#import inspect
4955
#from pathlib import Path
@@ -130,7 +136,10 @@ def _fieldhandler_CMAKE_FRAGMENT_CMAKE(self, field):
130136
# M A I N C L A S S
131137
# ===============================
132138

133-
139+
class VarType(Enum):
140+
"""Enumeration used to check for CMake variable types in SPOC."""
141+
CACHE = 1
142+
NON_CACHE = 2
134143

135144
class SetProgramOptionsCMake(SetProgramOptions):
136145
"""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
224233

225234
# Type-1 (non-cached / PARENT_SCOPE / non-typed) entries should not be
226235
# written to the set of Bash parameters.
227-
if param_opts['VARIANT'] == 1:
236+
if param_opts['VARIANT'] == VarType.NON_CACHE:
228237
msg = f"bash generator - `{varname}={value}` skipped because"
229238
msg += f" it is a non-cached (type-1) operation."
230239
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):
422431
# PARENT_SCOPE forces Type-1 (i.e., non-cache var)
423432
# - This will override CACHE, at least as of CMake 3.21.x
424433
if output['PARENT_SCOPE']:
425-
output['VARIANT'] = 1
434+
output['VARIANT'] = VarType.NON_CACHE
426435

427436
# FORCE implies CACHE. If type wasn't provided then it's a STRING
428437
elif output['FORCE']:
429-
output['VARIANT'] = 2
438+
output['VARIANT'] = VarType.CACHE
430439

431440
# If a TYPE is provided then it's a type-2 (CACHE) assignment.
432441
elif output['TYPE'] is not None:
433-
output['VARIANT'] = 2
442+
output['VARIANT'] = VarType.CACHE
434443

435444
# Otherwise, a simple set is a type-1
436445
else:
437-
output['VARIANT'] = 1
446+
output['VARIANT'] = VarType.NON_CACHE
438447

439448
return output

0 commit comments

Comments
 (0)