| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 1 | set |
| 2 | --- |
| 3 | |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 4 | Set a normal, cache, or environment variable to a given value. |
| 5 | See the :ref:`cmake-language(7) variables <CMake Language Variables>` |
| 6 | documentation for the scopes and interaction of normal variables |
| 7 | and cache entries. |
| 8 | |
| 9 | Signatures of this command that specify a ``<value>...`` placeholder |
| 10 | expect zero or more arguments. Multiple arguments will be joined as |
| Brad King | 512f642 | 2023-03-24 14:39:48 -0400 | [diff] [blame] | 11 | a :ref:`semicolon-separated list <CMake Language Lists>` to form the |
| 12 | actual variable value to be set. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 13 | |
| 14 | Set Normal Variable |
| 15 | ^^^^^^^^^^^^^^^^^^^ |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 16 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 17 | .. signature:: |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 18 | set(<variable> <value>... [PARENT_SCOPE]) |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 19 | :target: normal |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 20 | |
| Brad King | 512f642 | 2023-03-24 14:39:48 -0400 | [diff] [blame] | 21 | Set or unset ``<variable>`` in the current function or directory scope: |
| 22 | |
| 23 | * If at least one ``<value>...`` is given, set the variable to that value. |
| 24 | * If no value is given, unset the variable. This is equivalent to |
| 25 | :command:`unset(<variable>) <unset>`. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 26 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 27 | If the ``PARENT_SCOPE`` option is given the variable will be set in |
| 28 | the scope above the current scope. Each new directory or :command:`function` |
| 29 | command creates a new scope. A scope can also be created with the |
| FeRD (Frank Dana) | 2f319c6 | 2023-08-30 14:35:04 -0400 | [diff] [blame] | 30 | :command:`block` command. ``set(PARENT_SCOPE)`` will set the value |
| 31 | of a variable into the parent directory, calling function, or |
| 32 | encompassing scope (whichever is applicable to the case at hand). |
| 33 | The previous state of the variable's value stays the same in the |
| 34 | current scope (e.g., if it was undefined before, it is still undefined |
| 35 | and if it had a value, it is still that value). |
| Marc Chevrier | 44a2f3f | 2022-08-05 10:55:32 +0200 | [diff] [blame] | 36 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 37 | The :command:`block(PROPAGATE)` and :command:`return(PROPAGATE)` commands |
| 38 | can be used as an alternate method to the :command:`set(PARENT_SCOPE)` |
| 39 | and :command:`unset(PARENT_SCOPE)` commands to update the parent scope. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 40 | |
| Brad King | 512f642 | 2023-03-24 14:39:48 -0400 | [diff] [blame] | 41 | .. include:: UNSET_NOTE.txt |
| 42 | |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 43 | Set Cache Entry |
| 44 | ^^^^^^^^^^^^^^^ |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 45 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 46 | .. signature:: |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 47 | set(<variable> <value>... CACHE <type> <docstring> [FORCE]) |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 48 | :target: CACHE |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 49 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 50 | Sets the given cache ``<variable>`` (cache entry). Since cache entries |
| 51 | are meant to provide user-settable values this does not overwrite |
| 52 | existing cache entries by default. Use the ``FORCE`` option to |
| 53 | overwrite existing entries. |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 54 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 55 | The ``<type>`` must be specified as one of: |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 56 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 57 | ``BOOL`` |
| 58 | Boolean ``ON/OFF`` value. |
| 59 | :manual:`cmake-gui(1)` offers a checkbox. |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 60 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 61 | ``FILEPATH`` |
| 62 | Path to a file on disk. |
| 63 | :manual:`cmake-gui(1)` offers a file dialog. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 64 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 65 | ``PATH`` |
| 66 | Path to a directory on disk. |
| 67 | :manual:`cmake-gui(1)` offers a file dialog. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 68 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 69 | ``STRING`` |
| 70 | A line of text. |
| 71 | :manual:`cmake-gui(1)` offers a text field or a drop-down selection |
| 72 | if the :prop_cache:`STRINGS` cache entry property is set. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 73 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 74 | ``INTERNAL`` |
| 75 | A line of text. |
| 76 | :manual:`cmake-gui(1)` does not show internal entries. |
| 77 | They may be used to store variables persistently across runs. |
| 78 | Use of this type implies ``FORCE``. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 79 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 80 | The ``<docstring>`` must be specified as a line of text |
| 81 | providing a quick summary of the option |
| 82 | for presentation to :manual:`cmake-gui(1)` users. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 83 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 84 | If the cache entry does not exist prior to the call or the ``FORCE`` |
| 85 | option is given then the cache entry will be set to the given value. |
| Marc Chevrier | d96eb55 | 2021-05-20 15:14:30 +0200 | [diff] [blame] | 86 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 87 | .. note:: |
| Marc Chevrier | d96eb55 | 2021-05-20 15:14:30 +0200 | [diff] [blame] | 88 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 89 | The content of the cache variable will not be directly accessible |
| 90 | if a normal variable of the same name already exists |
| 91 | (see :ref:`rules of variable evaluation <CMake Language Variables>`). |
| 92 | If policy :policy:`CMP0126` is set to ``OLD``, any normal variable |
| 93 | binding in the current scope will be removed. |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 94 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 95 | It is possible for the cache entry to exist prior to the call but |
| 96 | have no type set if it was created on the :manual:`cmake(1)` command |
| 97 | line by a user through the :option:`-D\<var\>=\<value\> <cmake -D>` option |
| 98 | without specifying a type. In this case the ``set`` command will add the |
| 99 | type. Furthermore, if the ``<type>`` is ``PATH`` or ``FILEPATH`` |
| 100 | and the ``<value>`` provided on the command line is a relative path, |
| 101 | then the ``set`` command will treat the path as relative to the |
| 102 | current working directory and convert it to an absolute path. |
| Brad King | 77d466e | 2015-04-01 16:25:42 -0400 | [diff] [blame] | 103 | |
| Brad King | 91eb736 | 2015-04-01 16:24:39 -0400 | [diff] [blame] | 104 | Set Environment Variable |
| 105 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 106 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 107 | .. signature:: |
| Taylor Holberton | cb01b8c | 2019-01-31 19:26:14 -0500 | [diff] [blame] | 108 | set(ENV{<variable>} [<value>]) |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 109 | :target: ENV |
| Kitware Robot | f051814 | 2013-10-15 11:17:36 -0400 | [diff] [blame] | 110 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 111 | Sets an :manual:`Environment Variable <cmake-env-variables(7)>` |
| 112 | to the given value. |
| 113 | Subsequent calls of ``$ENV{<variable>}`` will return this new value. |
| Joachim Wuttke (h) | 3de551c | 2018-10-27 15:08:43 +0200 | [diff] [blame] | 114 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 115 | This command affects only the current CMake process, not the process |
| 116 | from which CMake was called, nor the system environment at large, |
| 117 | nor the environment of subsequent build or test processes. |
| Taylor Holberton | cb01b8c | 2019-01-31 19:26:14 -0500 | [diff] [blame] | 118 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 119 | If no argument is given after ``ENV{<variable>}`` or if ``<value>`` is |
| 120 | an empty string, then this command will clear any existing value of the |
| 121 | environment variable. |
| Taylor Holberton | cb01b8c | 2019-01-31 19:26:14 -0500 | [diff] [blame] | 122 | |
| Matthew Woehlke | a239a2a | 2023-03-10 11:49:40 -0500 | [diff] [blame] | 123 | Arguments after ``<value>`` are ignored. If extra arguments are found, |
| 124 | then an author warning is issued. |
| Alex Turbov | 65457e4 | 2022-11-06 23:55:33 +0400 | [diff] [blame] | 125 | |
| 126 | See Also |
| 127 | ^^^^^^^^ |
| 128 | |
| 129 | * :command:`unset` |