GNUInstallDirs.cmake 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. While absolute paths are allowed, they are not recommended as they
  19. do not work with the ``cmake --install`` command's
  20. :option:`--prefix <cmake--install --prefix>` option, or with the
  21. :manual:`cpack <cpack(1)>` installer generators. In particular, there is no
  22. need to make paths absolute by prepending :variable:`CMAKE_INSTALL_PREFIX`;
  23. this prefix is used by default if the DESTINATION is a relative path.
  24. ``CMAKE_INSTALL_FULL_<dir>``
  25. The absolute path generated from the corresponding ``CMAKE_INSTALL_<dir>``
  26. value. If the value is not already an absolute path, an absolute path
  27. is constructed typically by prepending the value of the
  28. :variable:`CMAKE_INSTALL_PREFIX` variable. However, there are some
  29. `special cases`_ as documented below.
  30. These variables shouldn't be used in :command:`install` commands
  31. as they do not work with the ``cmake --install`` command's
  32. :option:`--prefix <cmake--install --prefix>` option, or with the
  33. :manual:`cpack <cpack(1)>` installer generators.
  34. where ``<dir>`` is one of:
  35. ``BINDIR``
  36. user executables (``bin``)
  37. ``SBINDIR``
  38. system admin executables (``sbin``)
  39. ``LIBEXECDIR``
  40. program executables (``libexec``)
  41. ``SYSCONFDIR``
  42. read-only single-machine data (``etc``)
  43. ``SHAREDSTATEDIR``
  44. modifiable architecture-independent data (``com``)
  45. ``LOCALSTATEDIR``
  46. modifiable single-machine data (``var``)
  47. ``RUNSTATEDIR``
  48. .. versionadded:: 3.9
  49. run-time variable data (``LOCALSTATEDIR/run``)
  50. ``LIBDIR``
  51. object code libraries (``lib`` or ``lib64``)
  52. On Debian, this may be ``lib/<multiarch-tuple>`` when
  53. :variable:`CMAKE_INSTALL_PREFIX` is ``/usr``.
  54. ``INCLUDEDIR``
  55. C header files (``include``)
  56. ``OLDINCLUDEDIR``
  57. C header files for non-gcc (``/usr/include``)
  58. ``DATAROOTDIR``
  59. read-only architecture-independent data root (``share``)
  60. ``DATADIR``
  61. read-only architecture-independent data (``DATAROOTDIR``)
  62. ``INFODIR``
  63. info documentation (``DATAROOTDIR/info``)
  64. ``LOCALEDIR``
  65. locale-dependent data (``DATAROOTDIR/locale``)
  66. ``MANDIR``
  67. man documentation (``DATAROOTDIR/man``)
  68. ``DOCDIR``
  69. documentation root (``DATAROOTDIR/doc/PROJECT_NAME``)
  70. If the includer does not define a value the above-shown default will be
  71. used and the value will appear in the cache for editing by the user.
  72. Special Cases
  73. ^^^^^^^^^^^^^
  74. .. versionadded:: 3.4
  75. The following values of :variable:`CMAKE_INSTALL_PREFIX` are special:
  76. ``/``
  77. For ``<dir>`` other than the ``SYSCONFDIR``, ``LOCALSTATEDIR`` and
  78. ``RUNSTATEDIR``, the value of ``CMAKE_INSTALL_<dir>`` is prefixed
  79. with ``usr/`` if it is not user-specified as an absolute path.
  80. For example, the ``INCLUDEDIR`` value ``include`` becomes ``usr/include``.
  81. This is required by the `GNU Coding Standards`_, which state:
  82. When building the complete GNU system, the prefix will be empty
  83. and ``/usr`` will be a symbolic link to ``/``.
  84. ``/usr``
  85. For ``<dir>`` equal to ``SYSCONFDIR``, ``LOCALSTATEDIR`` or
  86. ``RUNSTATEDIR``, the ``CMAKE_INSTALL_FULL_<dir>`` is computed by
  87. prepending just ``/`` to the value of ``CMAKE_INSTALL_<dir>``
  88. if it is not user-specified as an absolute path.
  89. For example, the ``SYSCONFDIR`` value ``etc`` becomes ``/etc``.
  90. This is required by the `GNU Coding Standards`_.
  91. ``/opt/...``
  92. For ``<dir>`` equal to ``SYSCONFDIR``, ``LOCALSTATEDIR`` or
  93. ``RUNSTATEDIR``, the ``CMAKE_INSTALL_FULL_<dir>`` is computed by
  94. *appending* the prefix to the value of ``CMAKE_INSTALL_<dir>``
  95. if it is not user-specified as an absolute path.
  96. For example, the ``SYSCONFDIR`` value ``etc`` becomes ``/etc/opt/...``.
  97. This is defined by the `Filesystem Hierarchy Standard`_.
  98. This behavior does not apply to paths under ``/opt/homebrew/...``.
  99. .. _`Filesystem Hierarchy Standard`: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
  100. Macros
  101. ^^^^^^
  102. .. command:: GNUInstallDirs_get_absolute_install_dir
  103. .. code-block:: cmake
  104. GNUInstallDirs_get_absolute_install_dir(absvar var dirname)
  105. .. versionadded:: 3.7
  106. Set the given variable ``absvar`` to the absolute path contained
  107. within the variable ``var``. This is to allow the computation of an
  108. absolute path, accounting for all the special cases documented
  109. above. While this macro is used to compute the various
  110. ``CMAKE_INSTALL_FULL_<dir>`` variables, it is exposed publicly to
  111. allow users who create additional path variables to also compute
  112. absolute paths where necessary, using the same logic. ``dirname`` is
  113. the directory name to get, e.g. ``BINDIR``.
  114. .. versionchanged:: 3.20
  115. Added the ``<dirname>`` parameter. Previous versions of CMake passed
  116. this value through the variable ``${dir}``.
  117. #]=======================================================================]
  118. cmake_policy(SET CMP0140 NEW)
  119. # Convert a cache variable to PATH type
  120. function(_GNUInstallDirs_cache_convert_to_path var description)
  121. get_property(cache_type CACHE ${var} PROPERTY TYPE)
  122. if(cache_type STREQUAL "UNINITIALIZED")
  123. file(TO_CMAKE_PATH "${${var}}" cmakepath)
  124. set_property(CACHE ${var} PROPERTY TYPE PATH)
  125. set_property(CACHE ${var} PROPERTY VALUE "${cmakepath}")
  126. set_property(CACHE ${var} PROPERTY HELPSTRING "${description}")
  127. endif()
  128. endfunction()
  129. # Create a cache variable with default for a path.
  130. function(_GNUInstallDirs_cache_path var description)
  131. set(cmake_install_var "CMAKE_INSTALL_${var}")
  132. set(default "${_GNUInstallDirs_${var}_DEFAULT}")
  133. set(full_description "${description} (${default})")
  134. if(NOT DEFINED ${cmake_install_var})
  135. set(${cmake_install_var} "${default}" CACHE PATH "${full_description}")
  136. endif()
  137. _GNUInstallDirs_cache_convert_to_path("${cmake_install_var}" "${full_description}")
  138. endfunction()
  139. # Create a cache variable with not default for a path, with a fallback
  140. # when unset; used for entries slaved to other entries such as
  141. # DATAROOTDIR.
  142. function(_GNUInstallDirs_cache_path_fallback var description)
  143. set(cmake_install_var "CMAKE_INSTALL_${var}")
  144. set(default "${_GNUInstallDirs_${var}_DEFAULT}")
  145. if(NOT ${cmake_install_var})
  146. set(${cmake_install_var} "" CACHE PATH "${description}")
  147. set(${cmake_install_var} "${default}")
  148. endif()
  149. _GNUInstallDirs_cache_convert_to_path("${cmake_install_var}" "${description}")
  150. return(PROPAGATE ${cmake_install_var})
  151. endfunction()
  152. # Other helpers
  153. # Check what system we are on for LIBDIR formatting
  154. function(_GNUInstallDirs_get_system_type_for_install out_var)
  155. unset(${out_var})
  156. # Check if we are building for conda
  157. if(DEFINED ENV{CONDA_BUILD} AND DEFINED ENV{PREFIX})
  158. set(conda_prefix "$ENV{PREFIX}")
  159. cmake_path(ABSOLUTE_PATH conda_prefix NORMALIZE)
  160. if("${CMAKE_INSTALL_PREFIX}" STREQUAL conda_prefix)
  161. set(${out_var} "conda")
  162. endif()
  163. elseif(DEFINED ENV{CONDA_PREFIX})
  164. set(conda_prefix "$ENV{CONDA_PREFIX}")
  165. cmake_path(ABSOLUTE_PATH conda_prefix NORMALIZE)
  166. if("${CMAKE_INSTALL_PREFIX}" STREQUAL conda_prefix AND
  167. NOT ("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$" OR
  168. "${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/local/?$"))
  169. set(${out_var} "conda")
  170. endif()
  171. endif()
  172. # If we didn't detect conda from the previous step, check
  173. # for the linux variant
  174. if(NOT ${out_var})
  175. if (EXISTS "/etc/alpine-release")
  176. set(${out_var} "alpine")
  177. elseif (EXISTS "/etc/arch-release")
  178. set(${out_var} "arch linux")
  179. elseif (EXISTS "/etc/debian_version")
  180. set(${out_var} "debian")
  181. endif()
  182. endif()
  183. return(PROPAGATE ${out_var})
  184. endfunction()
  185. # Installation directories
  186. #
  187. # Set the standard default values before any special handling
  188. set(_GNUInstallDirs_BINDIR_DEFAULT "bin")
  189. set(_GNUInstallDirs_SBINDIR_DEFAULT "sbin")
  190. set(_GNUInstallDirs_LIBEXECDIR_DEFAULT "libexec")
  191. set(_GNUInstallDirs_SYSCONFDIR_DEFAULT "etc")
  192. set(_GNUInstallDirs_SHAREDSTATEDIR_DEFAULT "com")
  193. set(_GNUInstallDirs_LOCALSTATEDIR_DEFAULT "var")
  194. set(_GNUInstallDirs_LIBDIR_DEFAULT "lib")
  195. set(_GNUInstallDirs_INCLUDEDIR_DEFAULT "include")
  196. set(_GNUInstallDirs_OLDINCLUDEDIR_DEFAULT "/usr/include")
  197. set(_GNUInstallDirs_DATAROOTDIR_DEFAULT "share")
  198. # We check if the variable was manually set and not cached, in order to
  199. # allow projects to set the values as normal variables before including
  200. # GNUInstallDirs to avoid having the entries cached or user-editable. It
  201. # replaces the "if(NOT DEFINED CMAKE_INSTALL_XXX)" checks in all the
  202. # other cases.
  203. # If CMAKE_INSTALL_LIBDIR is defined, if _libdir_set is false, then the
  204. # variable is a normal one, otherwise it is a cache one.
  205. get_property(_libdir_set CACHE CMAKE_INSTALL_LIBDIR PROPERTY TYPE SET)
  206. if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set
  207. AND DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
  208. AND NOT "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}"))
  209. # If CMAKE_INSTALL_LIBDIR is not defined, it is always executed.
  210. # Otherwise:
  211. # * if _libdir_set is false it is not executed (meaning that it is
  212. # not a cache variable)
  213. # * if _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX is not defined it is
  214. # not executed
  215. # * if _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX and
  216. # CMAKE_INSTALL_PREFIX are the same string it is not executed.
  217. # _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX is updated after the
  218. # execution, of this part of code, therefore at the next inclusion
  219. # of the file, CMAKE_INSTALL_LIBDIR is defined, and the 2 strings
  220. # are equal, meaning that the if is not executed the code the
  221. # second time.
  222. set(_LIBDIR_DEFAULT "lib")
  223. # Override this default 'lib' with 'lib64' iff:
  224. # - we are on Linux system but NOT cross-compiling
  225. # - we are NOT on debian
  226. # - we are NOT building for conda
  227. # - we are on a 64 bits system
  228. # reason is: amd64 ABI: https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI
  229. # For Debian with multiarch, use 'lib/${CMAKE_LIBRARY_ARCHITECTURE}' if
  230. # CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu"
  231. # and CMAKE_INSTALL_PREFIX is "/usr"
  232. # See http://wiki.debian.org/Multiarch
  233. if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX)
  234. set(__LAST_LIBDIR_DEFAULT "lib")
  235. # __LAST_LIBDIR_DEFAULT is the default value that we compute from
  236. # _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX, not a cache entry for
  237. # the value that was last used as the default.
  238. # This value is used to figure out whether the user changed the
  239. # CMAKE_INSTALL_LIBDIR value manually, or if the value was the
  240. # default one. When CMAKE_INSTALL_PREFIX changes, the value is
  241. # updated to the new default, unless the user explicitly changed it.
  242. endif()
  243. if (NOT DEFINED CMAKE_SYSTEM_NAME OR NOT DEFINED CMAKE_SIZEOF_VOID_P)
  244. message(AUTHOR_WARNING
  245. "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. "
  246. "Please enable at least one language before including GNUInstallDirs.")
  247. endif()
  248. if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|GNU)$"
  249. AND NOT CMAKE_CROSSCOMPILING)
  250. _GNUInstallDirs_get_system_type_for_install(__system_type_for_install)
  251. if(__system_type_for_install STREQUAL "debian")
  252. if(CMAKE_LIBRARY_ARCHITECTURE)
  253. if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
  254. set(_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
  255. endif()
  256. if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
  257. AND "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
  258. set(__LAST_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
  259. endif()
  260. endif()
  261. elseif(NOT DEFINED __system_type_for_install)
  262. # not debian, alpine, arch, or conda so rely on CMAKE_SIZEOF_VOID_P:
  263. if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  264. set(_LIBDIR_DEFAULT "lib64")
  265. if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX)
  266. set(__LAST_LIBDIR_DEFAULT "lib64")
  267. endif()
  268. endif()
  269. endif()
  270. endif()
  271. unset(__system_type_for_install)
  272. if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
  273. set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "Object code libraries (${_LIBDIR_DEFAULT})")
  274. elseif(DEFINED __LAST_LIBDIR_DEFAULT
  275. AND "${__LAST_LIBDIR_DEFAULT}" STREQUAL "${CMAKE_INSTALL_LIBDIR}")
  276. set_property(CACHE CMAKE_INSTALL_LIBDIR PROPERTY VALUE "${_LIBDIR_DEFAULT}")
  277. endif()
  278. endif()
  279. _GNUInstallDirs_cache_convert_to_path(CMAKE_INSTALL_LIBDIR "Object code libraries (lib)")
  280. # Save for next run
  281. set(_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "CMAKE_INSTALL_PREFIX during last run")
  282. unset(_libdir_set)
  283. unset(__LAST_LIBDIR_DEFAULT)
  284. _GNUInstallDirs_cache_path(BINDIR
  285. "User executables")
  286. _GNUInstallDirs_cache_path(SBINDIR
  287. "System admin executables")
  288. _GNUInstallDirs_cache_path(LIBEXECDIR
  289. "Program executables")
  290. _GNUInstallDirs_cache_path(SYSCONFDIR
  291. "Read-only single-machine data")
  292. _GNUInstallDirs_cache_path(SHAREDSTATEDIR
  293. "Modifiable architecture-independent data")
  294. _GNUInstallDirs_cache_path(LOCALSTATEDIR
  295. "Modifiable single-machine data")
  296. _GNUInstallDirs_cache_path(INCLUDEDIR
  297. "C header files")
  298. _GNUInstallDirs_cache_path(OLDINCLUDEDIR
  299. "C header files for non-gcc")
  300. _GNUInstallDirs_cache_path(DATAROOTDIR
  301. "Read-only architecture-independent data root")
  302. #-----------------------------------------------------------------------------
  303. # Values whose defaults are relative to DATAROOTDIR. Store empty values in
  304. # the cache and store the defaults in local variables if the cache values are
  305. # not set explicitly. This auto-updates the defaults as DATAROOTDIR changes.
  306. if(CMAKE_SYSTEM_NAME MATCHES "^(([^kF].*)?BSD|DragonFly)$")
  307. set(_GNUInstallDirs_INFODIR_DEFAULT "info")
  308. _GNUInstallDirs_cache_path(INFODIR
  309. "Info documentation")
  310. else()
  311. set(_GNUInstallDirs_INFODIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}/info")
  312. _GNUInstallDirs_cache_path_fallback(INFODIR
  313. "Info documentation (DATAROOTDIR/info)")
  314. endif()
  315. if(CMAKE_SYSTEM_NAME MATCHES "^(([^k].*)?BSD|DragonFly)$" AND NOT CMAKE_SYSTEM_NAME MATCHES "^(FreeBSD)$")
  316. set(_GNUInstallDirs_MANDIR_DEFAULT "man")
  317. _GNUInstallDirs_cache_path(MANDIR
  318. "Man documentation")
  319. else()
  320. set(_GNUInstallDirs_MANDIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}/man")
  321. _GNUInstallDirs_cache_path_fallback(MANDIR
  322. "Man documentation (DATAROOTDIR/man)")
  323. endif()
  324. set(_GNUInstallDirs_DATADIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}")
  325. set(_GNUInstallDirs_LOCALEDIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}/locale")
  326. set(_GNUInstallDirs_DOCDIR_DEFAULT "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}")
  327. set(_GNUInstallDirs_RUNSTATEDIR_DEFAULT "${CMAKE_INSTALL_LOCALSTATEDIR}/run")
  328. _GNUInstallDirs_cache_path_fallback(DATADIR
  329. "Read-only architecture-independent data (DATAROOTDIR)")
  330. _GNUInstallDirs_cache_path_fallback(LOCALEDIR
  331. "Locale-dependent data (DATAROOTDIR/locale)")
  332. _GNUInstallDirs_cache_path_fallback(DOCDIR
  333. "Documentation root (DATAROOTDIR/doc/PROJECT_NAME)")
  334. _GNUInstallDirs_cache_path_fallback(RUNSTATEDIR
  335. "Run-time variable data (LOCALSTATEDIR/run)")
  336. # Unset all the defaults used
  337. foreach(dir IN ITEMS
  338. BINDIR
  339. SBINDIR
  340. LIBEXECDIR
  341. SYSCONFDIR
  342. SHAREDSTATEDIR
  343. LOCALSTATEDIR
  344. LIBDIR
  345. INCLUDEDIR
  346. OLDINCLUDEDIR
  347. DATAROOTDIR
  348. DATADIR
  349. INFODIR
  350. MANDIR
  351. LOCALEDIR
  352. DOCDIR
  353. RUNSTATEDIR
  354. )
  355. unset(_GNUInstallDirs_${dir}_DEFAULT)
  356. endforeach()
  357. #-----------------------------------------------------------------------------
  358. mark_as_advanced(
  359. CMAKE_INSTALL_BINDIR
  360. CMAKE_INSTALL_SBINDIR
  361. CMAKE_INSTALL_LIBEXECDIR
  362. CMAKE_INSTALL_SYSCONFDIR
  363. CMAKE_INSTALL_SHAREDSTATEDIR
  364. CMAKE_INSTALL_LOCALSTATEDIR
  365. CMAKE_INSTALL_RUNSTATEDIR
  366. CMAKE_INSTALL_LIBDIR
  367. CMAKE_INSTALL_INCLUDEDIR
  368. CMAKE_INSTALL_OLDINCLUDEDIR
  369. CMAKE_INSTALL_DATAROOTDIR
  370. CMAKE_INSTALL_DATADIR
  371. CMAKE_INSTALL_INFODIR
  372. CMAKE_INSTALL_LOCALEDIR
  373. CMAKE_INSTALL_MANDIR
  374. CMAKE_INSTALL_DOCDIR
  375. )
  376. macro(GNUInstallDirs_get_absolute_install_dir absvar var)
  377. set(GGAID_extra_args ${ARGN})
  378. list(LENGTH GGAID_extra_args GGAID_extra_arg_count)
  379. if(GGAID_extra_arg_count GREATER "0")
  380. list(GET GGAID_extra_args 0 GGAID_dir)
  381. else()
  382. # Historical behavior: use ${dir} from caller's scope
  383. set(GGAID_dir "${dir}")
  384. message(AUTHOR_WARNING
  385. "GNUInstallDirs_get_absolute_install_dir called without third argument. "
  386. "Using \${dir} from the caller's scope for compatibility with CMake 3.19 and below.")
  387. endif()
  388. if(NOT IS_ABSOLUTE "${${var}}")
  389. # Handle special cases:
  390. # - CMAKE_INSTALL_PREFIX == /
  391. # - CMAKE_INSTALL_PREFIX == /usr
  392. # - CMAKE_INSTALL_PREFIX == /opt/...
  393. if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/")
  394. if("${GGAID_dir}" STREQUAL "SYSCONFDIR" OR "${GGAID_dir}" STREQUAL "LOCALSTATEDIR" OR "${GGAID_dir}" STREQUAL "RUNSTATEDIR")
  395. set(${absvar} "/${${var}}")
  396. else()
  397. if (NOT "${${var}}" MATCHES "^usr/")
  398. set(${var} "usr/${${var}}")
  399. endif()
  400. set(${absvar} "/${${var}}")
  401. endif()
  402. elseif("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
  403. if("${GGAID_dir}" STREQUAL "SYSCONFDIR" OR "${GGAID_dir}" STREQUAL "LOCALSTATEDIR" OR "${GGAID_dir}" STREQUAL "RUNSTATEDIR")
  404. set(${absvar} "/${${var}}")
  405. else()
  406. set(${absvar} "${CMAKE_INSTALL_PREFIX}/${${var}}")
  407. endif()
  408. elseif("${CMAKE_INSTALL_PREFIX}" MATCHES "^/opt/" AND NOT "${CMAKE_INSTALL_PREFIX}" MATCHES "^/opt/homebrew/")
  409. if("${GGAID_dir}" STREQUAL "SYSCONFDIR" OR "${GGAID_dir}" STREQUAL "LOCALSTATEDIR" OR "${GGAID_dir}" STREQUAL "RUNSTATEDIR")
  410. set(${absvar} "/${${var}}${CMAKE_INSTALL_PREFIX}")
  411. else()
  412. set(${absvar} "${CMAKE_INSTALL_PREFIX}/${${var}}")
  413. endif()
  414. else()
  415. set(${absvar} "${CMAKE_INSTALL_PREFIX}/${${var}}")
  416. endif()
  417. else()
  418. set(${absvar} "${${var}}")
  419. endif()
  420. unset(GGAID_dir)
  421. unset(GGAID_extra_arg_count)
  422. unset(GGAID_extra_args)
  423. endmacro()
  424. # Result directories
  425. #
  426. foreach(dir
  427. BINDIR
  428. SBINDIR
  429. LIBEXECDIR
  430. SYSCONFDIR
  431. SHAREDSTATEDIR
  432. LOCALSTATEDIR
  433. RUNSTATEDIR
  434. LIBDIR
  435. INCLUDEDIR
  436. OLDINCLUDEDIR
  437. DATAROOTDIR
  438. DATADIR
  439. INFODIR
  440. LOCALEDIR
  441. MANDIR
  442. DOCDIR
  443. )
  444. GNUInstallDirs_get_absolute_install_dir(CMAKE_INSTALL_FULL_${dir} CMAKE_INSTALL_${dir} ${dir})
  445. endforeach()