set.rst 4.7 KB

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