GNUInstallDirs.cmake 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. GNUInstallDirs
  5. --------------
  6. Define GNU standard installation directories
  7. Provides install directory variables as defined by the
  8. `GNU Coding Standards`_.
  9. .. _`GNU Coding Standards`: https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
  10. Result Variables
  11. ^^^^^^^^^^^^^^^^
  12. Inclusion of this module defines the following variables:
  13. ``CMAKE_INSTALL_<dir>``
  14. Destination for files of a given type. This value may be passed to
  15. the ``DESTINATION`` options of :command:`install` commands for the
  16. corresponding file type. It should be a path relative to the installation
  17. prefix so that it can be converted to an absolute path in a relocatable way.
  18. However, there are some `special cases`_ as documented below.
  19. While absolute paths are allowed, they are not recommended as they
  20. do not work with the ``cmake --install`` command's
  21. :option:`--prefix <cmake--install --prefix>` option, or with the
  22. :manual:`cpack <cpack(1)>` installer generators. In particular, there is no
  23. need to make paths absolute by prepending :variable:`CMAKE_INSTALL_PREFIX`;
  24. this prefix is used by default if the DESTINATION is a relative path.
  25. ``CMAKE_INSTALL_FULL_<dir>``
  26. The absolute path generated from the corresponding ``CMAKE_INSTALL_<dir>``
  27. value. If the value is not already an absolute path, an absolute path
  28. is constructed typically by prepending the value of the
  29. :variable:`CMAKE_INSTALL_PREFIX` variable, except in `special cases`_
  30. as documented below.
  31. These variables shouldn't be used in :command:`install` commands
  32. as they do not work with the ``cmake --install`` command's
  33. :option:`--prefix <cmake--install --prefix>` option, or with the
  34. :manual:`cpack <cpack(1)>` installer generators.
  35. where ``<dir>`` is one of:
  36. ``BINDIR``
  37. user executables (``bin``)
  38. ``SBINDIR``
  39. system admin executables (``sbin``)
  40. ``LIBEXECDIR``
  41. program executables (``libexec``)
  42. ``SYSCONFDIR``
  43. read-only single-machine data (``etc``)
  44. .. versionchanged:: 4.1
  45. If the :variable:`CMAKE_INSTALL_PREFIX` falls into the
  46. `special cases`_, the default paths for are the absolute
  47. path variants as described there. See policy :policy:`CMP0192`.
  48. ``SHAREDSTATEDIR``
  49. modifiable architecture-independent data (``com``)
  50. ``LOCALSTATEDIR``
  51. modifiable single-machine data (``var``)
  52. .. versionchanged:: 4.1
  53. If the :variable:`CMAKE_INSTALL_PREFIX` falls into the
  54. `special cases`_, the default paths for are the absolute
  55. path variants as described there. See policy :policy:`CMP0192`.
  56. ``RUNSTATEDIR``
  57. run-time variable data (``LOCALSTATEDIR/run``)
  58. .. versionadded:: 3.9
  59. .. versionchanged:: 4.1
  60. If the :variable:`CMAKE_INSTALL_PREFIX` falls into the
  61. `special cases`_, the default paths for are the absolute
  62. path variants as described there. See policy :policy:`CMP0192`.
  63. ``LIBDIR``
  64. object code libraries (``lib`` or ``lib64``)
  65. On Debian, this may be ``lib/<multiarch-tuple>`` when
  66. :variable:`CMAKE_INSTALL_PREFIX` is ``/usr``.
  67. ``INCLUDEDIR``
  68. C header files (``include``)
  69. ``OLDINCLUDEDIR``
  70. C header files for non-gcc (``/usr/include``)
  71. ``DATAROOTDIR``
  72. read-only architecture-independent data root (``share``)
  73. ``DATADIR``
  74. read-only architecture-independent data (``DATAROOTDIR``)
  75. ``INFODIR``
  76. info documentation (``DATAROOTDIR/info``)
  77. ``LOCALEDIR``
  78. locale-dependent data (``DATAROOTDIR/locale``)
  79. ``MANDIR``
  80. man documentation (``DATAROOTDIR/man``)
  81. ``DOCDIR``
  82. documentation root (``DATAROOTDIR/doc/PROJECT_NAME``)
  83. If the includer does not define a value the above-shown default will be
  84. used and the value will appear in the cache for editing by the user.
  85. If a default value for the ``CMAKE_INSTALL_<dir>`` is used and the
  86. :variable:`CMAKE_INSTALL_PREFIX` is changed, the new default value will
  87. be used calculated on the new :variable:`CMAKE_INSTALL_PREFIX` value.
  88. Using :option:`--prefix <cmake--install --prefix>` in ``cmake --install``
  89. will not alter these values.
  90. .. _`GNUInstallDirs special cases`:
  91. Special Cases
  92. ^^^^^^^^^^^^^
  93. .. versionadded:: 3.4
  94. The following values of :variable:`CMAKE_INSTALL_PREFIX` are special:
  95. ``/``
  96. For ``<dir>`` other than the ``SYSCONFDIR``, ``LOCALSTATEDIR`` and
  97. ``RUNSTATEDIR``, the value of ``CMAKE_INSTALL_<dir>`` is prefixed
  98. with ``usr/`` if it is not user-specified as an absolute path.
  99. For example, the ``INCLUDEDIR`` value ``include`` becomes ``usr/include``.
  100. This is required by the `GNU Coding Standards`_, which state:
  101. When building the complete GNU system, the prefix will be empty
  102. and ``/usr`` will be a symbolic link to ``/``.
  103. ``/usr``
  104. For ``<dir>`` equal to ``SYSCONFDIR``, ``LOCALSTATEDIR`` or
  105. ``RUNSTATEDIR``, the ``CMAKE_INSTALL_FULL_<dir>`` is computed by
  106. prepending just ``/`` to the value of ``CMAKE_INSTALL_<dir>``
  107. if it is not already an absolute path.
  108. For example, the ``SYSCONFDIR`` value ``etc`` becomes ``/etc``.
  109. This is required by the `GNU Coding Standards`_.
  110. .. versionchanged:: 4.1
  111. The default values of ``CMAKE_INSTALL_<dir>`` for ``<dir>`` equal
  112. to ``SYSCONFDIR``, ``LOCALSTATEDIR`` and ``RUNSTATEDIR`` are the
  113. absolute paths ``/etc``, ``/var`` and ``/var/run`` respectively.
  114. See policy :policy:`CMP0192`.
  115. ``/opt/...``
  116. For ``<dir>`` equal to ``SYSCONFDIR``, ``LOCALSTATEDIR`` or
  117. ``RUNSTATEDIR``, the ``CMAKE_INSTALL_FULL_<dir>`` is computed by
  118. *appending* the prefix to the value of ``CMAKE_INSTALL_<dir>``
  119. if it is not already an absolute path.
  120. For example, the ``SYSCONFDIR`` value ``etc`` becomes ``/etc/opt/...``.
  121. This is defined by the `Filesystem Hierarchy Standard`_.
  122. This behavior does not apply to paths under ``/opt/homebrew/...``.
  123. .. versionchanged:: 4.1
  124. The default values of ``CMAKE_INSTALL_<dir>`` for ``<dir>`` equal
  125. to ``SYSCONFDIR``, ``LOCALSTATEDIR`` and ``RUNSTATEDIR`` are the
  126. absolute paths ``/etc/opt/...``, ``/var/opt/...`` and
  127. ``/var/run/opt/...`` respectively. See policy :policy:`CMP0192`.
  128. .. _`Filesystem Hierarchy Standard`: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
  129. Macros
  130. ^^^^^^
  131. .. command:: GNUInstallDirs_get_absolute_install_dir
  132. .. code-block:: cmake
  133. GNUInstallDirs_get_absolute_install_dir(absvar var dirname)
  134. .. versionadded:: 3.7
  135. Set the given variable ``absvar`` to the absolute path contained
  136. within the variable ``var``. This is to allow the computation of an
  137. absolute path, accounting for all the special cases documented
  138. above. While this macro is used to compute the various
  139. ``CMAKE_INSTALL_FULL_<dir>`` variables, it is exposed publicly to
  140. allow users who create additional path variables to also compute
  141. absolute paths where necessary, using the same logic. ``dirname`` is
  142. the directory name to get, e.g. ``BINDIR``.
  143. .. versionchanged:: 3.20
  144. Added the ``<dirname>`` parameter. Previous versions of CMake passed
  145. this value through the variable ``${dir}``.
  146. #]=======================================================================]
  147. cmake_policy(SET CMP0140 NEW)
  148. # Note that even though we read the policy every time this file is `include`
  149. # only the first occurrence has effect because it is used for the initialization
  150. # of cache variables
  151. cmake_policy(GET CMP0192 _GNUInstallDirs_CMP0192)
  152. # Convert a cache variable to PATH type
  153. function(_GNUInstallDirs_cache_convert_to_path var description)
  154. get_property(cache_type CACHE ${var} PROPERTY TYPE)
  155. if(cache_type STREQUAL "UNINITIALIZED")
  156. file(TO_CMAKE_PATH "${${var}}" cmakepath)
  157. set_property(CACHE ${var} PROPERTY TYPE PATH)
  158. set_property(CACHE ${var} PROPERTY VALUE "${cmakepath}")
  159. set_property(CACHE ${var} PROPERTY HELPSTRING "${description}")
  160. endif()
  161. endfunction()
  162. # Create a cache variable with default for a path.
  163. function(_GNUInstallDirs_cache_path var description)
  164. set(cmake_install_var "CMAKE_INSTALL_${var}")
  165. set(default "${_GNUInstallDirs_${var}_DEFAULT}")
  166. # Check if we have a special way to calculate the defaults
  167. if(COMMAND _GNUInstallDirs_${var}_get_default)
  168. # Check if the current CMAKE_INSTALL_PREFIX is the same as before
  169. set(install_prefix_is_same TRUE)
  170. set(last_default "${default}")
  171. if(NOT DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
  172. OR NOT _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX)
  173. set(install_prefix_is_same FALSE)
  174. # Recalculate what the last default would have been
  175. cmake_language(CALL _GNUInstallDirs_${var}_get_default
  176. last_default
  177. "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}")
  178. endif()
  179. if(DEFINED CACHE{${cmake_install_var}} AND install_prefix_is_same)
  180. # If the cache variable was already set from a previous run and the
  181. # install prefix has not changed, we don't need to do anything
  182. return()
  183. else()
  184. # Otherwise get the new default
  185. cmake_language(CALL _GNUInstallDirs_${var}_get_default
  186. default
  187. "${CMAKE_INSTALL_PREFIX}")
  188. # if the current value is the same as the cache value and the same as
  189. # the old default, reset the value to the new default
  190. if(${cmake_install_var} STREQUAL "$CACHE{${cmake_install_var}}"
  191. AND ${cmake_install_var} STREQUAL last_default)
  192. set(${cmake_install_var} "${default}" CACHE PATH "${full_description}" FORCE)
  193. endif()
  194. # Continue to normal flow
  195. endif()
  196. endif()
  197. # Normal flow
  198. set(full_description "${description} (${default})")
  199. if(NOT DEFINED ${cmake_install_var})
  200. set(${cmake_install_var} "${default}" CACHE PATH "${full_description}")
  201. endif()
  202. _GNUInstallDirs_cache_convert_to_path("${cmake_install_var}" "${full_description}")
  203. endfunction()
  204. # Create a cache variable with not default for a path, with a fallback
  205. # when unset; used for entries slaved to other entries such as
  206. # DATAROOTDIR.
  207. function(_GNUInstallDirs_cache_path_fallback var description)
  208. set(cmake_install_var "CMAKE_INSTALL_${var}")
  209. set(default "${_GNUInstallDirs_${var}_DEFAULT}")
  210. # Check if there is a more special way to handle the default
  211. if(COMMAND _GNUInstallDirs_${var}_get_default)
  212. cmake_language(CALL _GNUInstallDirs_${var}_get_default
  213. default
  214. "${CMAKE_INSTALL_PREFIX}")
  215. endif()
  216. if(NOT ${cmake_install_var})
  217. set(${cmake_install_var} "" CACHE PATH "${description}")
  218. set(${cmake_install_var} "${default}")
  219. endif()
  220. _GNUInstallDirs_cache_convert_to_path("${cmake_install_var}" "${description}")
  221. return(PROPAGATE ${cmake_install_var})
  222. endfunction()
  223. # Other helpers
  224. # Check what system we are on for LIBDIR formatting
  225. function(_GNUInstallDirs_get_system_type_for_install out_var)
  226. unset(${out_var})
  227. # Check if we are building for conda
  228. if(DEFINED ENV{CONDA_BUILD} AND DEFINED ENV{PREFIX})
  229. set(conda_prefix "$ENV{PREFIX}")
  230. cmake_path(ABSOLUTE_PATH conda_prefix NORMALIZE)
  231. if("${CMAKE_INSTALL_PREFIX}" STREQUAL conda_prefix)
  232. set(${out_var} "conda")
  233. endif()
  234. elseif(DEFINED ENV{CONDA_PREFIX})
  235. set(conda_prefix "$ENV{CONDA_PREFIX}")
  236. cmake_path(ABSOLUTE_PATH conda_prefix NORMALIZE)
  237. if("${CMAKE_INSTALL_PREFIX}" STREQUAL conda_prefix AND
  238. NOT ("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$" OR
  239. "${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/local/?$"))
  240. set(${out_var} "conda")
  241. endif()
  242. endif()
  243. # If we didn't detect conda from the previous step, check
  244. # for the linux variant
  245. if(NOT ${out_var})
  246. if (EXISTS "/etc/alpine-release")
  247. set(${out_var} "alpine")
  248. elseif (EXISTS "/etc/arch-release")
  249. set(${out_var} "arch linux")
  250. elseif (EXISTS "/etc/debian_version")
  251. set(${out_var} "debian")
  252. endif()
  253. endif()
  254. return(PROPAGATE ${out_var})
  255. endfunction()
  256. # Special handler for `/`, `/usr`, `/opt/...` install prefixes
  257. # Used for SYSCONFDIR, LOCALSTATEDIR and RUNSTATEDIR paths
  258. function(_GNUInstallDirs_special_absolute out_var original_path install_prefix)
  259. set(${out_var} "${original_path}")
  260. if(install_prefix MATCHES "^/usr/?$")
  261. set(${out_var} "/${original_path}")
  262. elseif(install_prefix MATCHES "^/opt/" AND NOT install_prefix MATCHES "^/opt/homebrew/")
  263. set(${out_var} "/${original_path}/${install_prefix}")
  264. endif()
  265. return(PROPAGATE ${out_var})
  266. endfunction()
  267. # Common handler for defaults that should be in /<dir>
  268. # i.e. SYSCONFDIR and LOCALSTATEDIR
  269. function(__GNUInstallDirs_default_in_root out_var original_path install_prefix)
  270. if(_GNUInstallDirs_CMP0192 STREQUAL "NEW")
  271. _GNUInstallDirs_special_absolute(${out_var}
  272. "${original_path}" "${install_prefix}")
  273. endif()
  274. cmake_path(NORMAL_PATH ${out_var})
  275. return(PROPAGATE ${out_var})
  276. endfunction()
  277. # Installation directories
  278. #
  279. # Set the standard default values before any special handling
  280. set(_GNUInstallDirs_BINDIR_DEFAULT "bin")
  281. set(_GNUInstallDirs_SBINDIR_DEFAULT "sbin")
  282. set(_GNUInstallDirs_LIBEXECDIR_DEFAULT "libexec")
  283. set(_GNUInstallDirs_SYSCONFDIR_DEFAULT "etc")
  284. set(_GNUInstallDirs_SHAREDSTATEDIR_DEFAULT "com")
  285. set(_GNUInstallDirs_LOCALSTATEDIR_DEFAULT "var")
  286. set(_GNUInstallDirs_LIBDIR_DEFAULT "lib")
  287. set(_GNUInstallDirs_INCLUDEDIR_DEFAULT "include")
  288. set(_GNUInstallDirs_OLDINCLUDEDIR_DEFAULT "/usr/include")
  289. set(_GNUInstallDirs_DATAROOTDIR_DEFAULT "share")
  290. # Define the special defaults handling
  291. # Signature
  292. # _GNUInstallDirs_<Dir>_get_default(out_var install_prefix)
  293. #
  294. # ``out_var``
  295. # Output variable with the calculated default
  296. #
  297. # ``install_prefix``
  298. # The CMAKE_INSTALL_PREFIX used to calculate the default
  299. function(_GNUInstallDirs_LIBDIR_get_default out_var install_prefix)
  300. set(${out_var} "${_GNUInstallDirs_LIBDIR_DEFAULT}")
  301. # Override this default 'lib' with 'lib64' iff:
  302. # - we are on Linux system but NOT cross-compiling
  303. # - we are NOT on debian
  304. # - we are NOT building for conda
  305. # - we are on a 64 bits system
  306. # reason is: amd64 ABI: https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI
  307. # For Debian with multiarch, use 'lib/${CMAKE_LIBRARY_ARCHITECTURE}' if
  308. # CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu"
  309. # and CMAKE_INSTALL_PREFIX is "/usr"
  310. # See http://wiki.debian.org/Multiarch
  311. if (NOT DEFINED CMAKE_SYSTEM_NAME OR NOT DEFINED CMAKE_SIZEOF_VOID_P)
  312. message(AUTHOR_WARNING
  313. "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. "
  314. "Please enable at least one language before including GNUInstallDirs.")
  315. endif()
  316. if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|GNU)$" AND NOT CMAKE_CROSSCOMPILING)
  317. _GNUInstallDirs_get_system_type_for_install(system_type)
  318. if(system_type STREQUAL "debian")
  319. if(CMAKE_LIBRARY_ARCHITECTURE)
  320. if("${install_prefix}" MATCHES "^/usr/?$")
  321. set(${out_var} "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
  322. endif()
  323. endif()
  324. elseif(NOT DEFINED system_type)
  325. # not debian, alpine, arch, or conda so rely on CMAKE_SIZEOF_VOID_P:
  326. if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  327. set(${out_var} "lib64")
  328. endif()
  329. endif()
  330. endif()
  331. return(PROPAGATE ${out_var})
  332. endfunction()
  333. foreach(dir IN ITEMS
  334. SYSCONFDIR
  335. LOCALSTATEDIR
  336. )
  337. # Cannot call function() directly because `dir` would not be accessible inside the function
  338. # Using cmake_language(EVAL) to call a short wrapper function instead
  339. cmake_language(EVAL CODE "
  340. function(_GNUInstallDirs_${dir}_get_default out_var install_prefix)
  341. set(\${out_var} \"\${_GNUInstallDirs_${dir}_DEFAULT}\")
  342. __GNUInstallDirs_default_in_root(\${out_var} \"\${\${out_var}}\" \"\${install_prefix}\")
  343. return(PROPAGATE \${out_var})
  344. endfunction()
  345. "
  346. )
  347. endforeach()
  348. # Depends on current CMAKE_INSTALL_LOCALSTATEDIR value
  349. function(_GNUInstallDirs_RUNSTATEDIR_get_default out_var install_prefix)
  350. set(${out_var} "${_GNUInstallDirs_RUNSTATEDIR_DEFAULT}")
  351. if(_GNUInstallDirs_CMP0192 STREQUAL "NEW")
  352. # In the /opt/ case we want the install_prefix to be appended as
  353. # LOCALSTATEDIR/run/PREFIX
  354. if(install_prefix MATCHES "^/opt/" AND NOT install_prefix MATCHES "^/opt/homebrew/")
  355. string(REPLACE "${install_prefix}" "/run${install_prefix}"
  356. ${out_var} "${CMAKE_INSTALL_LOCALSTATEDIR}"
  357. )
  358. endif()
  359. endif()
  360. return(PROPAGATE ${out_var})
  361. endfunction()
  362. _GNUInstallDirs_cache_path(BINDIR
  363. "User executables")
  364. _GNUInstallDirs_cache_path(SBINDIR
  365. "System admin executables")
  366. _GNUInstallDirs_cache_path(LIBEXECDIR
  367. "Program executables")
  368. _GNUInstallDirs_cache_path(SYSCONFDIR
  369. "Read-only single-machine data")
  370. _GNUInstallDirs_cache_path(SHAREDSTATEDIR
  371. "Modifiable architecture-independent data")
  372. _GNUInstallDirs_cache_path(LOCALSTATEDIR
  373. "Modifiable single-machine data")
  374. _GNUInstallDirs_cache_path(LIBDIR
  375. "Object code libraries")
  376. _GNUInstallDirs_cache_path(INCLUDEDIR
  377. "C header files")
  378. _GNUInstallDirs_cache_path(OLDINCLUDEDIR
  379. "C header files for non-gcc")
  380. _GNUInstallDirs_cache_path(DATAROOTDIR
  381. "Read-only architecture-independent data root")
  382. #-----------------------------------------------------------------------------
  383. # Values whose defaults are relative to DATAROOTDIR. Store empty values in
  384. # the cache and store the defaults in local variables if the cache values are
  385. # not set explicitly. This auto-updates the defaults as DATAROOTDIR changes.
  386. if(CMAKE_SYSTEM_NAME MATCHES "^(([^kF].*)?BSD|DragonFly)$")
  387. set(_GNUInstallDirs_INFODIR_DEFAULT "info")
  388. _GNUInstallDirs_cache_path(INFODIR
  389. "Info documentation")
  390. else()
  391. set(_GNUInstallDirs_INFODIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}/info")
  392. _GNUInstallDirs_cache_path_fallback(INFODIR
  393. "Info documentation (DATAROOTDIR/info)")
  394. endif()
  395. if(CMAKE_SYSTEM_NAME MATCHES "^(([^k].*)?BSD|DragonFly)$" AND NOT CMAKE_SYSTEM_NAME MATCHES "^(FreeBSD)$")
  396. set(_GNUInstallDirs_MANDIR_DEFAULT "man")
  397. _GNUInstallDirs_cache_path(MANDIR
  398. "Man documentation")
  399. else()
  400. set(_GNUInstallDirs_MANDIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}/man")
  401. _GNUInstallDirs_cache_path_fallback(MANDIR
  402. "Man documentation (DATAROOTDIR/man)")
  403. endif()
  404. set(_GNUInstallDirs_DATADIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}")
  405. set(_GNUInstallDirs_LOCALEDIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}/locale")
  406. set(_GNUInstallDirs_DOCDIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}")
  407. set(_GNUInstallDirs_RUNSTATEDIR_DEFAULT "${CMAKE_INSTALL_LOCALSTATEDIR}/run")
  408. _GNUInstallDirs_cache_path_fallback(DATADIR
  409. "Read-only architecture-independent data (DATAROOTDIR)")
  410. _GNUInstallDirs_cache_path_fallback(LOCALEDIR
  411. "Locale-dependent data (DATAROOTDIR/locale)")
  412. _GNUInstallDirs_cache_path_fallback(DOCDIR
  413. "Documentation root (DATAROOTDIR/doc/PROJECT_NAME)")
  414. _GNUInstallDirs_cache_path_fallback(RUNSTATEDIR
  415. "Run-time variable data (LOCALSTATEDIR/run)")
  416. # Unset all the defaults used
  417. foreach(dir IN ITEMS
  418. BINDIR
  419. SBINDIR
  420. LIBEXECDIR
  421. SYSCONFDIR
  422. SHAREDSTATEDIR
  423. LOCALSTATEDIR
  424. LIBDIR
  425. INCLUDEDIR
  426. OLDINCLUDEDIR
  427. DATAROOTDIR
  428. DATADIR
  429. INFODIR
  430. MANDIR
  431. LOCALEDIR
  432. DOCDIR
  433. RUNSTATEDIR
  434. )
  435. unset(_GNUInstallDirs_${dir}_DEFAULT)
  436. endforeach()
  437. # Save for next run
  438. set(_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "CMAKE_INSTALL_PREFIX during last run")
  439. #-----------------------------------------------------------------------------
  440. mark_as_advanced(
  441. CMAKE_INSTALL_BINDIR
  442. CMAKE_INSTALL_SBINDIR
  443. CMAKE_INSTALL_LIBEXECDIR
  444. CMAKE_INSTALL_SYSCONFDIR
  445. CMAKE_INSTALL_SHAREDSTATEDIR
  446. CMAKE_INSTALL_LOCALSTATEDIR
  447. CMAKE_INSTALL_RUNSTATEDIR
  448. CMAKE_INSTALL_LIBDIR
  449. CMAKE_INSTALL_INCLUDEDIR
  450. CMAKE_INSTALL_OLDINCLUDEDIR
  451. CMAKE_INSTALL_DATAROOTDIR
  452. CMAKE_INSTALL_DATADIR
  453. CMAKE_INSTALL_INFODIR
  454. CMAKE_INSTALL_LOCALEDIR
  455. CMAKE_INSTALL_MANDIR
  456. CMAKE_INSTALL_DOCDIR
  457. )
  458. macro(GNUInstallDirs_get_absolute_install_dir absvar var)
  459. set(GGAID_extra_args ${ARGN})
  460. list(LENGTH GGAID_extra_args GGAID_extra_arg_count)
  461. if(GGAID_extra_arg_count GREATER "0")
  462. list(GET GGAID_extra_args 0 GGAID_dir)
  463. else()
  464. # Historical behavior: use ${dir} from caller's scope
  465. set(GGAID_dir "${dir}")
  466. message(AUTHOR_WARNING
  467. "GNUInstallDirs_get_absolute_install_dir called without third argument. "
  468. "Using \${dir} from the caller's scope for compatibility with CMake 3.19 and below.")
  469. endif()
  470. if(NOT IS_ABSOLUTE "${${var}}")
  471. # Handle special cases:
  472. # - CMAKE_INSTALL_PREFIX == /
  473. # - CMAKE_INSTALL_PREFIX == /usr
  474. # - CMAKE_INSTALL_PREFIX == /opt/...
  475. if("${GGAID_dir}" STREQUAL "SYSCONFDIR" OR "${GGAID_dir}" STREQUAL "LOCALSTATEDIR" OR "${GGAID_dir}" STREQUAL "RUNSTATEDIR")
  476. _GNUInstallDirs_special_absolute(${absvar} "${${var}}" "${CMAKE_INSTALL_PREFIX}")
  477. # If the CMAKE_INSTALL_PREFIX was not special, the output
  478. # is still not absolute, so use the default logic.
  479. if(NOT IS_ABSOLUTE "${${absvar}}")
  480. # Make sure we account for any trailing `/`
  481. if(CMAKE_INSTALL_PREFIX MATCHES "/$")
  482. set(${absvar} "${CMAKE_INSTALL_PREFIX}${${var}}")
  483. else()
  484. set(${absvar} "${CMAKE_INSTALL_PREFIX}/${${var}}")
  485. endif()
  486. endif()
  487. elseif("${CMAKE_INSTALL_PREFIX}" STREQUAL "/")
  488. if (NOT "${${var}}" MATCHES "^usr/")
  489. set(${var} "usr/${${var}}")
  490. endif()
  491. set(${absvar} "/${${var}}")
  492. else()
  493. set(${absvar} "${CMAKE_INSTALL_PREFIX}/${${var}}")
  494. endif()
  495. else()
  496. set(${absvar} "${${var}}")
  497. endif()
  498. unset(GGAID_dir)
  499. unset(GGAID_extra_arg_count)
  500. unset(GGAID_extra_args)
  501. endmacro()
  502. # Result directories
  503. #
  504. foreach(dir
  505. BINDIR
  506. SBINDIR
  507. LIBEXECDIR
  508. SYSCONFDIR
  509. SHAREDSTATEDIR
  510. LOCALSTATEDIR
  511. RUNSTATEDIR
  512. LIBDIR
  513. INCLUDEDIR
  514. OLDINCLUDEDIR
  515. DATAROOTDIR
  516. DATADIR
  517. INFODIR
  518. LOCALEDIR
  519. MANDIR
  520. DOCDIR
  521. )
  522. GNUInstallDirs_get_absolute_install_dir(CMAKE_INSTALL_FULL_${dir} CMAKE_INSTALL_${dir} ${dir})
  523. endforeach()
  524. unset(_GNUInstallDirs_CMP0192)