set.rst 4.7 KB

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