set.rst 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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:`;-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. ::
  15. set(<variable> <value>... [PARENT_SCOPE])
  16. Set 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. ::
  27. set(<variable> <value>... CACHE <type> <docstring> [FORCE])
  28. Set 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. Furthermore, any normal variable binding in the current scope will
  53. be removed to expose the newly cached value to any immediately
  54. following evaluation.
  55. It is possible for the cache entry to exist prior to the call but
  56. have no type set if it was created on the :manual:`cmake(1)` command
  57. line by a user through the ``-D<var>=<value>`` option without
  58. specifying a type. In this case the ``set`` command will add the
  59. type. Furthermore, if the ``<type>`` is ``PATH`` or ``FILEPATH``
  60. and the ``<value>`` provided on the command line is a relative path,
  61. then the ``set`` command will treat the path as relative to the
  62. current working directory and convert it to an absolute path.
  63. Set Environment Variable
  64. ^^^^^^^^^^^^^^^^^^^^^^^^
  65. ::
  66. set(ENV{<variable>} <value>...)
  67. Set the current process environment ``<variable>`` to the given value.