|
3 | 3 | You can adapt this file completely to your liking, but it should at least
|
4 | 4 | contain the root `toctree` directive.
|
5 | 5 |
|
6 |
| -Welcome to SetProgramOptions documentation! |
7 |
| -=========================================== |
| 6 | +SetProgramOptions Python Module |
| 7 | +=============================== |
8 | 8 |
|
9 | 9 | .. toctree::
|
10 |
| - :maxdepth: 2 |
11 |
| - :caption: Contents: |
| 10 | + :maxdepth: 1 |
| 11 | + :caption: Table of Contents: |
12 | 12 |
|
13 | 13 | SetProgramOptions
|
14 | 14 | SetProgramOptionsCMake
|
15 | 15 | License <License>
|
16 | 16 |
|
17 | 17 |
|
18 | 18 |
|
19 |
| -Indices and tables |
20 |
| -================== |
| 19 | +Indices and Tables |
| 20 | +------------------ |
21 | 21 |
|
22 | 22 | * :ref:`genindex`
|
23 | 23 | * :ref:`modindex`
|
24 | 24 | * :ref:`search`
|
25 | 25 |
|
26 | 26 |
|
| 27 | +Overview |
| 28 | +======== |
| 29 | +TODO: This needs to be expanded for RTD. |
| 30 | + |
| 31 | + |
| 32 | +Examples |
| 33 | +======== |
| 34 | +Here we show a few examples of how ``SetProgramOptions`` and |
| 35 | +``SetProgramOptionsCMake`` can be used. |
| 36 | + |
| 37 | +Example 1 |
| 38 | +--------- |
| 39 | +In example-01 we have a fairly simple .ini file that demostrates utilization |
| 40 | +of the ``use`` operation that comes built in with |
| 41 | +`ConfigParserEnhanced <https://pypi.org/project/configparserenhanced/>`_. |
| 42 | +In this example we are going to demonstrate how the ``opt-set`` operations |
| 43 | +in our .ini file can be used to generate a custom bash command with |
| 44 | +customizable argument sets added. |
| 45 | + |
| 46 | +In this case, we will process the ``[MY_LS_COMMAND]`` section to generate |
| 47 | +a bash command that would generate a directory listing in list form by |
| 48 | +reverse time order of last modified with a custom timestamp format. |
| 49 | + |
| 50 | +While this example is quite simple we can see how a complex environment |
| 51 | +in a DevOps setting might use this to bundle "common" operations to reduce |
| 52 | +the amount of copying and pasting that is used. |
| 53 | + |
| 54 | +example-01.ini |
| 55 | +++++++++++++++ |
| 56 | +.. literalinclude:: ../../examples/example-01.ini |
| 57 | + :language: ini |
| 58 | + :linenos: |
| 59 | + |
| 60 | +example-01.py |
| 61 | ++++++++++++++ |
| 62 | +.. literalinclude:: ../../examples/example-01.py |
| 63 | + :language: python |
| 64 | + :linenos: |
| 65 | + |
| 66 | +Console Output |
| 67 | +++++++++++++++ |
| 68 | +.. literalinclude:: ../../examples/example-01.log |
| 69 | + :language: text |
| 70 | + :linenos: |
| 71 | + |
| 72 | +Example 2 |
| 73 | +--------- |
| 74 | +Example 2 demonstrates the use of ``SetProgramOptionsCMake`` |
| 75 | +which is a *subclass* of ``SetProgramOptions`` and implements |
| 76 | +*operations* for handling *CMake* variables in a .ini file. |
| 77 | +SetProgramOptionsCMake also introduces a new "CMake fragment" |
| 78 | +generator and implements logic to maintain consistency of |
| 79 | +behavior between generated BASH scripts and CMake fragments |
| 80 | +with knoweldge of how CMake treats ``-D`` operations at the |
| 81 | +command line versus ``set()`` operations inside a CMake script. |
| 82 | + |
| 83 | +Here we show the new operation ``opt-set-cmake-var`` which |
| 84 | +has the form ``opt-set-cmake-var VARNAME <OPTIONAL PARAMS> : VALUE``. |
| 85 | +Details and a comprehensive list of the optional parameters can |
| 86 | +be found in the ``SetProgramOptionsCMake`` Class Reference page. |
| 87 | + |
| 88 | +The main elements this example will demonstrate is how to use |
| 89 | +``opt-set-cmake-var`` operations and how they can be used. |
| 90 | + |
| 91 | +This example is fairly straightforward since the .ini file |
| 92 | +options being defined will generate the same output for both |
| 93 | +generator types. |
| 94 | + |
| 95 | +example-02.ini |
| 96 | +++++++++++++++ |
| 97 | +.. literalinclude:: ../../examples/example-02.ini |
| 98 | + :language: ini |
| 99 | + :linenos: |
| 100 | + |
| 101 | +example-02.py |
| 102 | ++++++++++++++ |
| 103 | +.. literalinclude:: ../../examples/example-02.py |
| 104 | + :language: python |
| 105 | + :linenos: |
| 106 | + |
| 107 | +Console Output |
| 108 | +++++++++++++++ |
| 109 | +.. literalinclude:: ../../examples/example-02.log |
| 110 | + :language: text |
| 111 | + :linenos: |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +Example 3 |
| 116 | +--------- |
| 117 | +The last example we show here is a bit more complicated and gets into |
| 118 | +some of the differences in how CMake treats a *command line* variable |
| 119 | +being set via a ``-D`` option versus a ``set()`` operation within a |
| 120 | +CMakeLists.txt file. |
| 121 | + |
| 122 | +The script prints out a notice explaining the nuance but the general |
| 123 | +idea is that CMake treats options provided by a ``-D`` option at the |
| 124 | +command line as though they are ``CACHE`` variables with the ``FORCE`` |
| 125 | +option enabled. This is designed to allow command-line parameters to |
| 126 | +generally take precedence over what a CMakeLists.txt file might set |
| 127 | +as though it's a user-override. The added ``FORCE`` option also ensures |
| 128 | +that if there are multiple ``-D`` options setting the same variable the |
| 129 | +*last* one will win. |
| 130 | + |
| 131 | +This can have a subtle yet profound effect on how we must process our |
| 132 | +``opt-set-cmake-var`` operations within a .ini file if our goal is to |
| 133 | +ensure that the resulting ``CMakeCache.txt`` file generated by a CMake |
| 134 | +run would be the same for both *bash* and *cmake fragment* generators. |
| 135 | + |
| 136 | +In this case, in order to have a variable be set by the *bash* generator |
| 137 | +it must be a ``CACHE`` variable -- which can be accomplished by either |
| 138 | +adding a *TYPE* or a *FORCE* option. |
| 139 | +We will note here that if ``FORCE`` is given without a *TYPE* then we |
| 140 | +use the default type of *STRING*. |
| 141 | + |
| 142 | +If the *same* CMake variable is being assigned, such as in a case where |
| 143 | +we have a section that is updating a flag, then the `FORCE` option must |
| 144 | +be present on the second and all subsequent occurrences of ``opt-set-cmake-var`` |
| 145 | +or the *bash* generator will skip over that assignment since a non-forced |
| 146 | +``set()`` operation in CMake would not overwrite an existing cache var. |
| 147 | +This situation can occur frequently if our .ini file(s) are structured to |
| 148 | +have some *common* configuration option set and then a specialization which |
| 149 | +updates one of the arguments. One example of this kind of situation might |
| 150 | +be where we have a specialization that adds OpenMP and we would want to add |
| 151 | +the ``-fopenmp`` flags to our linker flags. |
| 152 | + |
| 153 | +example-03.ini |
| 154 | +++++++++++++++ |
| 155 | +.. literalinclude:: ../../examples/example-03.ini |
| 156 | + :language: ini |
| 157 | + :linenos: |
| 158 | + |
| 159 | +example-03.py |
| 160 | ++++++++++++++ |
| 161 | +.. literalinclude:: ../../examples/example-03.py |
| 162 | + :language: python |
| 163 | + :linenos: |
| 164 | + |
| 165 | +Console Output |
| 166 | +++++++++++++++ |
| 167 | +.. literalinclude:: ../../examples/example-03.log |
| 168 | + :language: text |
| 169 | + :linenos: |
| 170 | + |
| 171 | +We will note here that the *CMake* fragment generator will still generate |
| 172 | +all of the commands. In this case the second ``set()`` command would be ignored |
| 173 | +by CMake since it's not FORCEd but the main take-away here is that the |
| 174 | +*bash* generator omitted the second ``-D`` operation since that would be |
| 175 | +a ``FORCE`` operation by default which is not representative of what was |
| 176 | +specified in the .ini file. |
| 177 | + |
| 178 | + |
| 179 | + |
0 commit comments