diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2015-06-15 18:16:57 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-06-18 12:59:34 (GMT) |
commit | c8bd37ec685c02736618af83ac894e96fc1e6ab8 (patch) | |
tree | 49f6721e20ea3baa778f0649cdb3f30430819e06 /Modules/GNUInstallDirs.cmake | |
parent | 5f30f1754ac9a701cbd311bab86250dd237d86fd (diff) | |
download | CMake-c8bd37ec685c02736618af83ac894e96fc1e6ab8.zip CMake-c8bd37ec685c02736618af83ac894e96fc1e6ab8.tar.gz CMake-c8bd37ec685c02736618af83ac894e96fc1e6ab8.tar.bz2 |
GNUInstallDirs: Add special cases for certain prefixes
Teach the module to handle SYSCONFDIR and LOCALSTATEDIR properly if
CMAKE_INSTALL_PREFIX is set to `/` or `/usr` -- i.e. as expected by GNU
Coding Standard (i.e. set SYSCONFDIR to `/etc` and `LOCALSTATEDIR` to
`/var`). Also if CMAKE_INSTALL_PREFIX is set to /opt/pkg, `SYSCONFDIR`
must be set to `/etc/opt/pkg` and `LOCALSTATEDIR` to `/var/opt/pkg`
according to FHS.
Diffstat (limited to 'Modules/GNUInstallDirs.cmake')
-rw-r--r-- | Modules/GNUInstallDirs.cmake | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake index 82258d1..b42084e 100644 --- a/Modules/GNUInstallDirs.cmake +++ b/Modules/GNUInstallDirs.cmake @@ -9,6 +9,9 @@ # # .. _`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>`` @@ -22,7 +25,8 @@ # 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. +# :variable:`CMAKE_INSTALL_PREFIX` variable. However, there are some +# `special cases`_ as documented below. # # where ``<dir>`` is one of: # @@ -60,8 +64,44 @@ # # 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`` +# +# 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. # @@ -279,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() |