GNUInstallDirs.cmake 10 KB

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