1
0

CMAKE_INSTALL_MODE.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. CMAKE_INSTALL_MODE
  2. ------------------
  3. .. versionadded:: 3.22
  4. .. include:: include/ENV_VAR.rst
  5. The ``CMAKE_INSTALL_MODE`` environment variable allows users to operate
  6. CMake in an alternate mode of :command:`file(INSTALL)` and :command:`install()`.
  7. The default behavior for an installation is to copy a source file from a
  8. source directory into a destination directory. This environment variable
  9. however allows the user to override this behavior, causing CMake to create
  10. symbolic links instead.
  11. Usage Scenarios
  12. ^^^^^^^^^^^^^^^
  13. Installing symbolic links rather than copying files can help in the following
  14. ways:
  15. * Conserving storage space because files do not have to be duplicated on disk.
  16. * Changes to the source of the symbolic link are seen at the install
  17. destination without having to re-run the install step.
  18. * Editing through the link at the install destination will modify the source
  19. of the link. This may be useful when dealing with CMake project hierarchies,
  20. i.e. using :module:`ExternalProject` and consistent source navigation and
  21. refactoring is desired across projects.
  22. Allowed Values
  23. ^^^^^^^^^^^^^^
  24. The following values are allowed for ``CMAKE_INSTALL_MODE``:
  25. ``COPY``, empty or unset
  26. Duplicate the file at its destination. This is the default behavior.
  27. ``ABS_SYMLINK``
  28. Create an *absolute* symbolic link to the source file at the destination.
  29. Halt with an error if the link cannot be created.
  30. ``ABS_SYMLINK_OR_COPY``
  31. Like ``ABS_SYMLINK`` but fall back to silently copying if the symlink
  32. couldn't be created.
  33. ``REL_SYMLINK``
  34. Create a *relative* symbolic link to the source file at the destination.
  35. Halt with an error if the link cannot be created.
  36. ``REL_SYMLINK_OR_COPY``
  37. Like ``REL_SYMLINK`` but fall back to silently copying if the symlink
  38. couldn't be created.
  39. ``SYMLINK``
  40. Try as if through ``REL_SYMLINK`` and fall back to ``ABS_SYMLINK`` if the
  41. referenced file cannot be expressed using a relative path.
  42. Halt with an error if the link cannot be created.
  43. ``SYMLINK_OR_COPY``
  44. Like ``SYMLINK`` but fall back to silently copying if the symlink couldn't
  45. be created.
  46. .. note::
  47. A symbolic link consists of a reference file path rather than contents of its
  48. own, hence there are two ways to express the relation, either by a *relative*
  49. or an *absolute* path.
  50. When To Set The Environment Variable
  51. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  52. For the environment variable to take effect, it must be set during the correct
  53. build phase(s).
  54. * If the project calls :command:`file(INSTALL)` directly, the environment
  55. variable must be set during the configuration phase.
  56. * In order to apply to :command:`install()`, the environment variable must be
  57. set during installation. This could be during a build if using the
  58. ``install`` or ``package`` build targets, or separate from the build when
  59. invoking an install or running :manual:`cpack <cpack(1)>` from the command
  60. line.
  61. * When using :module:`ExternalProject`, it might be required during the build
  62. phase, since the external project's own configure, build and install steps
  63. will execute during the main project's build phase.
  64. Given the above, it is recommended to set the environment variable consistently
  65. across all phases (configure, build and install).
  66. Caveats
  67. ^^^^^^^
  68. Use this environment variable with caution. The following highlights some
  69. points to be considered:
  70. * ``CMAKE_INSTALL_MODE`` only affects files, not directories.
  71. * Symbolic links are not available on all platforms.
  72. * The way this environment variable interacts with the install step of
  73. :module:`ExternalProject` is more complex. For further details, see that
  74. module's documentation.
  75. * A symbolic link ties the destination to the source in a persistent way.
  76. Writing to either of the two affects both file system objects.
  77. This is in contrast to normal install behavior which only copies files as
  78. they were at the time the install was performed, with no enduring
  79. relationship between the source and destination of the install.
  80. * Combining ``CMAKE_INSTALL_MODE`` with :prop_tgt:`IOS_INSTALL_COMBINED` is
  81. not supported.
  82. * Changing ``CMAKE_INSTALL_MODE`` from what it was on a previous run can lead
  83. to unexpected results. Moving from a non-symlinking mode to a symlinking
  84. mode will discard any previous file at the destination, but the reverse is
  85. not true. Once a symlink exists at the destination, even if you switch to a
  86. non-symlink mode, the symlink will continue to exist at the destination and
  87. will not be replaced by an actual file.