GNUInstallDirs.cmake 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. #.rst:
  2. # GNUInstallDirs
  3. # --------------
  4. #
  5. # Define GNU standard installation directories
  6. #
  7. # Provides install directory variables as defined by the
  8. # `GNU Coding Standards`_.
  9. #
  10. # .. _`GNU Coding Standards`: https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
  11. #
  12. # Result Variables
  13. # ^^^^^^^^^^^^^^^^
  14. #
  15. # Inclusion of this module defines the following variables:
  16. #
  17. # ``CMAKE_INSTALL_<dir>``
  18. #
  19. # Destination for files of a given type. This value may be passed to
  20. # the ``DESTINATION`` options of :command:`install` commands for the
  21. # corresponding file type.
  22. #
  23. # ``CMAKE_INSTALL_FULL_<dir>``
  24. #
  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. #
  31. # where ``<dir>`` is one of:
  32. #
  33. # ``BINDIR``
  34. # user executables (``bin``)
  35. # ``SBINDIR``
  36. # system admin executables (``sbin``)
  37. # ``LIBEXECDIR``
  38. # program executables (``libexec``)
  39. # ``SYSCONFDIR``
  40. # read-only single-machine data (``etc``)
  41. # ``SHAREDSTATEDIR``
  42. # modifiable architecture-independent data (``com``)
  43. # ``LOCALSTATEDIR``
  44. # modifiable single-machine data (``var``)
  45. # ``LIBDIR``
  46. # object code libraries (``lib`` or ``lib64``
  47. # or ``lib/<multiarch-tuple>`` on Debian)
  48. # ``INCLUDEDIR``
  49. # C header files (``include``)
  50. # ``OLDINCLUDEDIR``
  51. # C header files for non-gcc (``/usr/include``)
  52. # ``DATAROOTDIR``
  53. # read-only architecture-independent data root (``share``)
  54. # ``DATADIR``
  55. # read-only architecture-independent data (``DATAROOTDIR``)
  56. # ``INFODIR``
  57. # info documentation (``DATAROOTDIR/info``)
  58. # ``LOCALEDIR``
  59. # locale-dependent data (``DATAROOTDIR/locale``)
  60. # ``MANDIR``
  61. # man documentation (``DATAROOTDIR/man``)
  62. # ``DOCDIR``
  63. # documentation root (``DATAROOTDIR/doc/PROJECT_NAME``)
  64. #
  65. # If the includer does not define a value the above-shown default will be
  66. # used and the value will appear in the cache for editing by the user.
  67. #
  68. # Special Cases
  69. # ^^^^^^^^^^^^^
  70. #
  71. # The following values of :variable:`CMAKE_INSTALL_PREFIX` are special:
  72. #
  73. # ``/``
  74. #
  75. # For ``<dir>`` other than the ``SYSCONFDIR`` and ``LOCALSTATEDIR``,
  76. # the value of ``CMAKE_INSTALL_<dir>`` is prefixed with ``usr/`` if
  77. # it is not user-specified as an absolute path. For example, the
  78. # ``INCLUDEDIR`` value ``include`` becomes ``usr/include``.
  79. # This is required by the `GNU Coding Standards`_, which state:
  80. #
  81. # When building the complete GNU system, the prefix will be empty
  82. # and ``/usr`` will be a symbolic link to ``/``.
  83. #
  84. # ``/usr``
  85. #
  86. # For ``<dir>`` equal to ``SYSCONFDIR`` or ``LOCALSTATEDIR``, the
  87. # ``CMAKE_INSTALL_FULL_<dir>`` is computed by prepending just ``/``
  88. # to the value of ``CMAKE_INSTALL_<dir>`` if it is not user-specified
  89. # as an absolute path. For example, the ``SYSCONFDIR`` value ``etc``
  90. # becomes ``/etc``. This is required by the `GNU Coding Standards`_.
  91. #
  92. # ``/opt/...``
  93. #
  94. # For ``<dir>`` equal to ``SYSCONFDIR`` or ``LOCALSTATEDIR``, the
  95. # ``CMAKE_INSTALL_FULL_<dir>`` is computed by *appending* the prefix
  96. # to the value of ``CMAKE_INSTALL_<dir>`` if it is not user-specified
  97. # as an absolute path. For example, the ``SYSCONFDIR`` value ``etc``
  98. # becomes ``/etc/opt/...``. This is defined by the
  99. # `Filesystem Hierarchy Standard`_.
  100. #
  101. # .. _`Filesystem Hierarchy Standard`: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
  102. #=============================================================================
  103. # Copyright 2015 Alex Turbov <i.zaufi@gmail.com>
  104. # Copyright 2011 Nikita Krupen'ko <krnekit@gmail.com>
  105. # Copyright 2011 Kitware, Inc.
  106. #
  107. # Distributed under the OSI-approved BSD License (the "License");
  108. # see accompanying file Copyright.txt for details.
  109. #
  110. # This software is distributed WITHOUT ANY WARRANTY; without even the
  111. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  112. # See the License for more information.
  113. #=============================================================================
  114. # (To distribute this file outside of CMake, substitute the full
  115. # License text for the above reference.)
  116. # Installation directories
  117. #
  118. if(NOT DEFINED CMAKE_INSTALL_BINDIR)
  119. set(CMAKE_INSTALL_BINDIR "bin" CACHE PATH "user executables (bin)")
  120. endif()
  121. if(NOT DEFINED CMAKE_INSTALL_SBINDIR)
  122. set(CMAKE_INSTALL_SBINDIR "sbin" CACHE PATH "system admin executables (sbin)")
  123. endif()
  124. if(NOT DEFINED CMAKE_INSTALL_LIBEXECDIR)
  125. set(CMAKE_INSTALL_LIBEXECDIR "libexec" CACHE PATH "program executables (libexec)")
  126. endif()
  127. if(NOT DEFINED CMAKE_INSTALL_SYSCONFDIR)
  128. set(CMAKE_INSTALL_SYSCONFDIR "etc" CACHE PATH "read-only single-machine data (etc)")
  129. endif()
  130. if(NOT DEFINED CMAKE_INSTALL_SHAREDSTATEDIR)
  131. set(CMAKE_INSTALL_SHAREDSTATEDIR "com" CACHE PATH "modifiable architecture-independent data (com)")
  132. endif()
  133. if(NOT DEFINED CMAKE_INSTALL_LOCALSTATEDIR)
  134. set(CMAKE_INSTALL_LOCALSTATEDIR "var" CACHE PATH "modifiable single-machine data (var)")
  135. endif()
  136. # We check if the variable was manually set and not cached, in order to
  137. # allow projects to set the values as normal variables before including
  138. # GNUInstallDirs to avoid having the entries cached or user-editable. It
  139. # replaces the "if(NOT DEFINED CMAKE_INSTALL_XXX)" checks in all the
  140. # other cases.
  141. # If CMAKE_INSTALL_LIBDIR is defined, if _libdir_set is false, then the
  142. # variable is a normal one, otherwise it is a cache one.
  143. get_property(_libdir_set CACHE CMAKE_INSTALL_LIBDIR PROPERTY TYPE SET)
  144. if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set
  145. AND DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
  146. AND NOT "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}"))
  147. # If CMAKE_INSTALL_LIBDIR is not defined, it is always executed.
  148. # Otherwise:
  149. # * if _libdir_set is false it is not executed (meaning that it is
  150. # not a cache variable)
  151. # * if _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX is not defined it is
  152. # not executed
  153. # * if _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX and
  154. # CMAKE_INSTALL_PREFIX are the same string it is not executed.
  155. # _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX is updated after the
  156. # execution, of this part of code, therefore at the next inclusion
  157. # of the file, CMAKE_INSTALL_LIBDIR is defined, and the 2 strings
  158. # are equal, meaning that the if is not executed the code the
  159. # second time.
  160. set(_LIBDIR_DEFAULT "lib")
  161. # Override this default 'lib' with 'lib64' iff:
  162. # - we are on Linux system but NOT cross-compiling
  163. # - we are NOT on debian
  164. # - we are on a 64 bits system
  165. # reason is: amd64 ABI: http://www.x86-64.org/documentation/abi.pdf
  166. # For Debian with multiarch, use 'lib/${CMAKE_LIBRARY_ARCHITECTURE}' if
  167. # CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu"
  168. # and CMAKE_INSTALL_PREFIX is "/usr"
  169. # See http://wiki.debian.org/Multiarch
  170. if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX)
  171. set(__LAST_LIBDIR_DEFAULT "lib")
  172. # __LAST_LIBDIR_DEFAULT is the default value that we compute from
  173. # _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX, not a cache entry for
  174. # the value that was last used as the default.
  175. # This value is used to figure out whether the user changed the
  176. # CMAKE_INSTALL_LIBDIR value manually, or if the value was the
  177. # default one. When CMAKE_INSTALL_PREFIX changes, the value is
  178. # updated to the new default, unless the user explicitly changed it.
  179. endif()
  180. if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|kFreeBSD|GNU)$"
  181. AND NOT CMAKE_CROSSCOMPILING)
  182. if (EXISTS "/etc/debian_version") # is this a debian system ?
  183. if(CMAKE_LIBRARY_ARCHITECTURE)
  184. if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
  185. set(_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
  186. endif()
  187. if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
  188. AND "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
  189. set(__LAST_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
  190. endif()
  191. endif()
  192. else() # not debian, rely on CMAKE_SIZEOF_VOID_P:
  193. if(NOT DEFINED CMAKE_SIZEOF_VOID_P)
  194. message(AUTHOR_WARNING
  195. "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. "
  196. "Please enable at least one language before including GNUInstallDirs.")
  197. else()
  198. if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  199. set(_LIBDIR_DEFAULT "lib64")
  200. if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX)
  201. set(__LAST_LIBDIR_DEFAULT "lib64")
  202. endif()
  203. endif()
  204. endif()
  205. endif()
  206. endif()
  207. if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
  208. set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "object code libraries (${_LIBDIR_DEFAULT})")
  209. elseif(DEFINED __LAST_LIBDIR_DEFAULT
  210. AND "${__LAST_LIBDIR_DEFAULT}" STREQUAL "${CMAKE_INSTALL_LIBDIR}")
  211. set_property(CACHE CMAKE_INSTALL_LIBDIR PROPERTY VALUE "${_LIBDIR_DEFAULT}")
  212. endif()
  213. endif()
  214. # Save for next run
  215. set(_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "CMAKE_INSTALL_PREFIX during last run")
  216. unset(_libdir_set)
  217. unset(__LAST_LIBDIR_DEFAULT)
  218. if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
  219. set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE PATH "C header files (include)")
  220. endif()
  221. if(NOT DEFINED CMAKE_INSTALL_OLDINCLUDEDIR)
  222. set(CMAKE_INSTALL_OLDINCLUDEDIR "/usr/include" CACHE PATH "C header files for non-gcc (/usr/include)")
  223. endif()
  224. if(NOT DEFINED CMAKE_INSTALL_DATAROOTDIR)
  225. set(CMAKE_INSTALL_DATAROOTDIR "share" CACHE PATH "read-only architecture-independent data root (share)")
  226. endif()
  227. #-----------------------------------------------------------------------------
  228. # Values whose defaults are relative to DATAROOTDIR. Store empty values in
  229. # the cache and store the defaults in local variables if the cache values are
  230. # not set explicitly. This auto-updates the defaults as DATAROOTDIR changes.
  231. if(NOT CMAKE_INSTALL_DATADIR)
  232. set(CMAKE_INSTALL_DATADIR "" CACHE PATH "read-only architecture-independent data (DATAROOTDIR)")
  233. set(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATAROOTDIR}")
  234. endif()
  235. if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  236. if(NOT CMAKE_INSTALL_INFODIR)
  237. set(CMAKE_INSTALL_INFODIR "" CACHE PATH "info documentation (info)")
  238. set(CMAKE_INSTALL_INFODIR "info")
  239. endif()
  240. if(NOT CMAKE_INSTALL_MANDIR)
  241. set(CMAKE_INSTALL_MANDIR "" CACHE PATH "man documentation (man)")
  242. set(CMAKE_INSTALL_MANDIR "man")
  243. endif()
  244. else()
  245. if(NOT CMAKE_INSTALL_INFODIR)
  246. set(CMAKE_INSTALL_INFODIR "" CACHE PATH "info documentation (DATAROOTDIR/info)")
  247. set(CMAKE_INSTALL_INFODIR "${CMAKE_INSTALL_DATAROOTDIR}/info")
  248. endif()
  249. if(NOT CMAKE_INSTALL_MANDIR)
  250. set(CMAKE_INSTALL_MANDIR "" CACHE PATH "man documentation (DATAROOTDIR/man)")
  251. set(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_DATAROOTDIR}/man")
  252. endif()
  253. endif()
  254. if(NOT CMAKE_INSTALL_LOCALEDIR)
  255. set(CMAKE_INSTALL_LOCALEDIR "" CACHE PATH "locale-dependent data (DATAROOTDIR/locale)")
  256. set(CMAKE_INSTALL_LOCALEDIR "${CMAKE_INSTALL_DATAROOTDIR}/locale")
  257. endif()
  258. if(NOT CMAKE_INSTALL_DOCDIR)
  259. set(CMAKE_INSTALL_DOCDIR "" CACHE PATH "documentation root (DATAROOTDIR/doc/PROJECT_NAME)")
  260. set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}")
  261. endif()
  262. #-----------------------------------------------------------------------------
  263. mark_as_advanced(
  264. CMAKE_INSTALL_BINDIR
  265. CMAKE_INSTALL_SBINDIR
  266. CMAKE_INSTALL_LIBEXECDIR
  267. CMAKE_INSTALL_SYSCONFDIR
  268. CMAKE_INSTALL_SHAREDSTATEDIR
  269. CMAKE_INSTALL_LOCALSTATEDIR
  270. CMAKE_INSTALL_LIBDIR
  271. CMAKE_INSTALL_INCLUDEDIR
  272. CMAKE_INSTALL_OLDINCLUDEDIR
  273. CMAKE_INSTALL_DATAROOTDIR
  274. CMAKE_INSTALL_DATADIR
  275. CMAKE_INSTALL_INFODIR
  276. CMAKE_INSTALL_LOCALEDIR
  277. CMAKE_INSTALL_MANDIR
  278. CMAKE_INSTALL_DOCDIR
  279. )
  280. # Result directories
  281. #
  282. foreach(dir
  283. BINDIR
  284. SBINDIR
  285. LIBEXECDIR
  286. SYSCONFDIR
  287. SHAREDSTATEDIR
  288. LOCALSTATEDIR
  289. LIBDIR
  290. INCLUDEDIR
  291. OLDINCLUDEDIR
  292. DATAROOTDIR
  293. DATADIR
  294. INFODIR
  295. LOCALEDIR
  296. MANDIR
  297. DOCDIR
  298. )
  299. if(NOT IS_ABSOLUTE "${CMAKE_INSTALL_${dir}}")
  300. # Handle special cases:
  301. # - CMAKE_INSTALL_PREFIX == /
  302. # - CMAKE_INSTALL_PREFIX == /usr
  303. # - CMAKE_INSTALL_PREFIX == /opt/...
  304. if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/")
  305. if("${dir}" STREQUAL "SYSCONFDIR" OR "${dir}" STREQUAL "LOCALSTATEDIR")
  306. set(CMAKE_INSTALL_FULL_${dir} "/${CMAKE_INSTALL_${dir}}")
  307. else()
  308. if (NOT "${CMAKE_INSTALL_${dir}}" MATCHES "^usr/")
  309. set(CMAKE_INSTALL_${dir} "usr/${CMAKE_INSTALL_${dir}}")
  310. endif()
  311. set(CMAKE_INSTALL_FULL_${dir} "/${CMAKE_INSTALL_${dir}}")
  312. endif()
  313. elseif("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
  314. if("${dir}" STREQUAL "SYSCONFDIR" OR "${dir}" STREQUAL "LOCALSTATEDIR")
  315. set(CMAKE_INSTALL_FULL_${dir} "/${CMAKE_INSTALL_${dir}}")
  316. else()
  317. set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}")
  318. endif()
  319. elseif("${CMAKE_INSTALL_PREFIX}" MATCHES "^/opt/.*")
  320. if("${dir}" STREQUAL "SYSCONFDIR" OR "${dir}" STREQUAL "LOCALSTATEDIR")
  321. set(CMAKE_INSTALL_FULL_${dir} "/${CMAKE_INSTALL_${dir}}${CMAKE_INSTALL_PREFIX}")
  322. else()
  323. set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}")
  324. endif()
  325. else()
  326. set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}")
  327. endif()
  328. else()
  329. set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_${dir}}")
  330. endif()
  331. endforeach()