Tutorial: Fix potentially misleading guidance on -D flags in script mode

This commit is contained in:
Vito Gamberini
2026-05-19 17:23:23 -04:00
parent c6c57360f1
commit 788364b927

View File

@@ -84,17 +84,18 @@ change a variable which has already been created.
.. code-block:: console
$ cmake -P StickyCacheVariable.cmake
$ cmake -B build
...
StickyCacheVariable: I will not change
Because :option:`-D <cmake -D>` flags are processed before any other commands,
Because :option:`-D <cmake -D>` flags are processed before any project commands,
they take precedence for setting the value of a cache variable.
.. code-block:: console
$ cmake \
-DStickyCacheVariable="Commandline always wins" \
-P StickyCacheVariable.cmake
$ cmake -B build \
-DStickyCacheVariable="Commandline always wins"
...
StickyCacheVariable: Commandline always wins
While cache variables cannot ordinarily be changed, they can be *shadowed* by
@@ -113,10 +114,16 @@ the normal variable.
.. code-block:: console
$ cmake -P ShadowVariable.cmake
$ cmake -B build
...
ShadowVariable: Hiding the cache variable
ShadowVariable: In the shadows
.. note::
:ref:`Script mode <Script Processing Mode>` operates slightly differently,
only :option:`-D <cmake -D>` flags provided before the :option:`-P <cmake -P>`
flag in the command are evaluated and available in the running script.
Exercise 1 - Using Options
^^^^^^^^^^^^^^^^^^^^^^^^^^