diff options
Diffstat (limited to 'Modules/GNUInstallDirs.cmake')
-rw-r--r-- | Modules/GNUInstallDirs.cmake | 130 |
1 files changed, 101 insertions, 29 deletions
diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake index c61e7e9..b42084e 100644 --- a/Modules/GNUInstallDirs.cmake +++ b/Modules/GNUInstallDirs.cmake @@ -4,59 +4,104 @@ # # Define GNU standard installation directories # -# Provides install directory variables as defined for GNU software: +# Provides install directory variables as defined by the +# `GNU Coding Standards`_. # -# http://www.gnu.org/prep/standards/html_node/Directory-Variables.html +# .. _`GNU Coding Standards`: https://www.gnu.org/prep/standards/html_node/Directory-Variables.html +# +# Result Variables +# ^^^^^^^^^^^^^^^^ # # Inclusion of this module defines the following variables: # # ``CMAKE_INSTALL_<dir>`` -# destination for files of a given type +# +# Destination for files of a given type. This value may be passed to +# the ``DESTINATION`` options of :command:`install` commands for the +# corresponding file type. +# # ``CMAKE_INSTALL_FULL_<dir>`` -# corresponding absolute path # -# where <dir> is one of: +# The absolute path generated from the corresponding ``CMAKE_INSTALL_<dir>`` +# value. If the value is not already an absolute path, an absolute path +# is constructed typically by prepending the value of the +# :variable:`CMAKE_INSTALL_PREFIX` variable. However, there are some +# `special cases`_ as documented below. +# +# where ``<dir>`` is one of: # # ``BINDIR`` -# user executables (bin) +# user executables (``bin``) # ``SBINDIR`` -# system admin executables (sbin) +# system admin executables (``sbin``) # ``LIBEXECDIR`` -# program executables (libexec) +# program executables (``libexec``) # ``SYSCONFDIR`` -# read-only single-machine data (etc) +# read-only single-machine data (``etc``) # ``SHAREDSTATEDIR`` -# modifiable architecture-independent data (com) +# modifiable architecture-independent data (``com``) # ``LOCALSTATEDIR`` -# modifiable single-machine data (var) +# modifiable single-machine data (``var``) # ``LIBDIR`` -# object code libraries (lib or lib64 or lib/<multiarch-tuple> on Debian) +# object code libraries (``lib`` or ``lib64`` +# or ``lib/<multiarch-tuple>`` on Debian) # ``INCLUDEDIR`` -# C header files (include) +# C header files (``include``) # ``OLDINCLUDEDIR`` -# C header files for non-gcc (/usr/include) +# C header files for non-gcc (``/usr/include``) # ``DATAROOTDIR`` -# read-only architecture-independent data root (share) +# read-only architecture-independent data root (``share``) # ``DATADIR`` -# read-only architecture-independent data (DATAROOTDIR) +# read-only architecture-independent data (``DATAROOTDIR``) # ``INFODIR`` -# info documentation (DATAROOTDIR/info) +# info documentation (``DATAROOTDIR/info``) # ``LOCALEDIR`` -# locale-dependent data (DATAROOTDIR/locale) +# locale-dependent data (``DATAROOTDIR/locale``) # ``MANDIR`` -# man documentation (DATAROOTDIR/man) +# man documentation (``DATAROOTDIR/man``) # ``DOCDIR`` -# documentation root (DATAROOTDIR/doc/PROJECT_NAME) +# documentation root (``DATAROOTDIR/doc/PROJECT_NAME``) +# +# If the includer does not define a value the above-shown default will be +# used and the value will appear in the cache for editing by the user. +# +# Special Cases +# ^^^^^^^^^^^^^ +# +# The following values of :variable:`CMAKE_INSTALL_PREFIX` are special: +# +# ``/`` +# +# For ``<dir>`` other than the ``SYSCONFDIR`` and ``LOCALSTATEDIR``, +# the value of ``CMAKE_INSTALL_<dir>`` is prefixed with ``usr/`` if +# it is not user-specified as an absolute path. For example, the +# ``INCLUDEDIR`` value ``include`` becomes ``usr/include``. +# This is required by the `GNU Coding Standards`_, which state: +# +# When building the complete GNU system, the prefix will be empty +# and ``/usr`` will be a symbolic link to ``/``. +# +# ``/usr`` # -# Each CMAKE_INSTALL_<dir> value may be passed to the DESTINATION -# options of install() commands for the corresponding file type. If the -# includer does not define a value the above-shown default will be used -# and the value will appear in the cache for editing by the user. Each -# CMAKE_INSTALL_FULL_<dir> value contains an absolute path constructed -# from the corresponding destination by prepending (if necessary) the -# value of CMAKE_INSTALL_PREFIX. +# For ``<dir>`` equal to ``SYSCONFDIR`` or ``LOCALSTATEDIR``, the +# ``CMAKE_INSTALL_FULL_<dir>`` is computed by prepending just ``/`` +# to the value of ``CMAKE_INSTALL_<dir>`` if it is not user-specified +# as an absolute path. For example, the ``SYSCONFDIR`` value ``etc`` +# becomes ``/etc``. This is required by the `GNU Coding Standards`_. +# +# ``/opt/...`` +# +# For ``<dir>`` equal to ``SYSCONFDIR`` or ``LOCALSTATEDIR``, the +# ``CMAKE_INSTALL_FULL_<dir>`` is computed by *appending* the prefix +# to the value of ``CMAKE_INSTALL_<dir>`` if it is not user-specified +# as an absolute path. For example, the ``SYSCONFDIR`` value ``etc`` +# becomes ``/etc/opt/...``. This is defined by the +# `Filesystem Hierarchy Standard`_. +# +# .. _`Filesystem Hierarchy Standard`: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html #============================================================================= +# Copyright 2015 Alex Turbov <i.zaufi@gmail.com> # Copyright 2011 Nikita Krupen'ko <krnekit@gmail.com> # Copyright 2011 Kitware, Inc. # @@ -274,8 +319,35 @@ foreach(dir MANDIR DOCDIR ) - if(NOT IS_ABSOLUTE ${CMAKE_INSTALL_${dir}}) - set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}") + if(NOT IS_ABSOLUTE "${CMAKE_INSTALL_${dir}}") + # Handle special cases: + # - CMAKE_INSTALL_PREFIX == / + # - CMAKE_INSTALL_PREFIX == /usr + # - CMAKE_INSTALL_PREFIX == /opt/... + if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/") + if("${dir}" STREQUAL "SYSCONFDIR" OR "${dir}" STREQUAL "LOCALSTATEDIR") + set(CMAKE_INSTALL_FULL_${dir} "/${CMAKE_INSTALL_${dir}}") + else() + if (NOT "${CMAKE_INSTALL_${dir}}" MATCHES "^usr/") + set(CMAKE_INSTALL_${dir} "usr/${CMAKE_INSTALL_${dir}}") + endif() + set(CMAKE_INSTALL_FULL_${dir} "/${CMAKE_INSTALL_${dir}}") + endif() + elseif("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$") + if("${dir}" STREQUAL "SYSCONFDIR" OR "${dir}" STREQUAL "LOCALSTATEDIR") + set(CMAKE_INSTALL_FULL_${dir} "/${CMAKE_INSTALL_${dir}}") + else() + set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}") + endif() + elseif("${CMAKE_INSTALL_PREFIX}" MATCHES "^/opt/.*") + if("${dir}" STREQUAL "SYSCONFDIR" OR "${dir}" STREQUAL "LOCALSTATEDIR") + set(CMAKE_INSTALL_FULL_${dir} "/${CMAKE_INSTALL_${dir}}${CMAKE_INSTALL_PREFIX}") + else() + set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}") + endif() + else() + set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${dir}}") + endif() else() set(CMAKE_INSTALL_FULL_${dir} "${CMAKE_INSTALL_${dir}}") endif() |