set.rst 4.0 KB

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