blob: fa635c661cd8049d1b875868ac44a2f0371312cb [file] [log] [blame]
Kitware Robotf0518142013-10-15 11:17:36 -04001set
2---
3
Brad King91eb7362015-04-01 16:24:39 -04004Set a normal, cache, or environment variable to a given value.
5See the :ref:`cmake-language(7) variables <CMake Language Variables>`
6documentation for the scopes and interaction of normal variables
7and cache entries.
8
9Signatures of this command that specify a ``<value>...`` placeholder
10expect zero or more arguments. Multiple arguments will be joined as
Brad King512f6422023-03-24 14:39:48 -040011a :ref:`semicolon-separated list <CMake Language Lists>` to form the
12actual variable value to be set.
Brad King91eb7362015-04-01 16:24:39 -040013
14Set Normal Variable
15^^^^^^^^^^^^^^^^^^^
Kitware Robotf0518142013-10-15 11:17:36 -040016
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050017.. signature::
Brad King91eb7362015-04-01 16:24:39 -040018 set(<variable> <value>... [PARENT_SCOPE])
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050019 :target: normal
Kitware Robotf0518142013-10-15 11:17:36 -040020
Brad King512f6422023-03-24 14:39:48 -040021 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 King91eb7362015-04-01 16:24:39 -040026
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050027 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)2f319c62023-08-30 14:35:04 -040030 :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 Chevrier44a2f3f2022-08-05 10:55:32 +020036
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050037 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 King91eb7362015-04-01 16:24:39 -040040
Brad King512f6422023-03-24 14:39:48 -040041.. include:: UNSET_NOTE.txt
42
Brad King91eb7362015-04-01 16:24:39 -040043Set Cache Entry
44^^^^^^^^^^^^^^^
Kitware Robotf0518142013-10-15 11:17:36 -040045
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050046.. signature::
Brad King91eb7362015-04-01 16:24:39 -040047 set(<variable> <value>... CACHE <type> <docstring> [FORCE])
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050048 :target: CACHE
Kitware Robotf0518142013-10-15 11:17:36 -040049
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050050 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 Robotf0518142013-10-15 11:17:36 -040054
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050055 The ``<type>`` must be specified as one of:
Kitware Robotf0518142013-10-15 11:17:36 -040056
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050057 ``BOOL``
58 Boolean ``ON/OFF`` value.
59 :manual:`cmake-gui(1)` offers a checkbox.
Kitware Robotf0518142013-10-15 11:17:36 -040060
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050061 ``FILEPATH``
62 Path to a file on disk.
63 :manual:`cmake-gui(1)` offers a file dialog.
Brad King91eb7362015-04-01 16:24:39 -040064
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050065 ``PATH``
66 Path to a directory on disk.
67 :manual:`cmake-gui(1)` offers a file dialog.
Brad King91eb7362015-04-01 16:24:39 -040068
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050069 ``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 King91eb7362015-04-01 16:24:39 -040073
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050074 ``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 King91eb7362015-04-01 16:24:39 -040079
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050080 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 King91eb7362015-04-01 16:24:39 -040083
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050084 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 Chevrierd96eb552021-05-20 15:14:30 +020086
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050087 .. note::
Marc Chevrierd96eb552021-05-20 15:14:30 +020088
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050089 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 King91eb7362015-04-01 16:24:39 -040094
Matthew Woehlkea239a2a2023-03-10 11:49:40 -050095 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 King77d466e2015-04-01 16:25:42 -0400103
Brad King91eb7362015-04-01 16:24:39 -0400104Set Environment Variable
105^^^^^^^^^^^^^^^^^^^^^^^^
Kitware Robotf0518142013-10-15 11:17:36 -0400106
Matthew Woehlkea239a2a2023-03-10 11:49:40 -0500107.. signature::
Taylor Holbertoncb01b8c2019-01-31 19:26:14 -0500108 set(ENV{<variable>} [<value>])
Matthew Woehlkea239a2a2023-03-10 11:49:40 -0500109 :target: ENV
Kitware Robotf0518142013-10-15 11:17:36 -0400110
Matthew Woehlkea239a2a2023-03-10 11:49:40 -0500111 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)3de551c2018-10-27 15:08:43 +0200114
Matthew Woehlkea239a2a2023-03-10 11:49:40 -0500115 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 Holbertoncb01b8c2019-01-31 19:26:14 -0500118
Matthew Woehlkea239a2a2023-03-10 11:49:40 -0500119 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 Holbertoncb01b8c2019-01-31 19:26:14 -0500122
Matthew Woehlkea239a2a2023-03-10 11:49:40 -0500123 Arguments after ``<value>`` are ignored. If extra arguments are found,
124 then an author warning is issued.
Alex Turbov65457e42022-11-06 23:55:33 +0400125
126See Also
127^^^^^^^^
128
129* :command:`unset`