GNUInstallDirs: Add macro to expose internal logic publicly

This commit is contained in:
Roger Leigh 2016-08-28 18:19:02 +01:00 committed by Brad King
parent 8317ea01aa
commit 17a24dc3b9
2 changed files with 58 additions and 32 deletions

View File

@ -0,0 +1,5 @@
GNUInstallDirs-function
-----------------------
* The :module:`GNUInstallDirs` module gained a new
:command:`GNUInstallDirs_get_absolute_install_dir` command.

View File

@ -99,6 +99,23 @@
# `Filesystem Hierarchy Standard`_. # `Filesystem Hierarchy Standard`_.
# #
# .. _`Filesystem Hierarchy Standard`: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html # .. _`Filesystem Hierarchy Standard`: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
#
# Macros
# ^^^^^^
#
# .. command:: GNUInstallDirs_get_absolute_install_dir
#
# ::
#
# GNUInstallDirs_get_absolute_install_dir(absvar var)
#
# Set the given variable ``absvar`` to the absolute path contained
# within the variable ``var``. This is to allow the computation of an
# absolute path, accounting for all the special cases documented
# above. While this macro is used to compute the various
# ``CMAKE_INSTALL_FULL_<dir>`` variables, it is exposed publicly to
# allow users who create additional path variables to also compute
# absolute paths where necessary, using the same logic.
#============================================================================= #=============================================================================
# Copyright 2015 Alex Turbov <i.zaufi@gmail.com> # Copyright 2015 Alex Turbov <i.zaufi@gmail.com>
@ -300,6 +317,41 @@ mark_as_advanced(
CMAKE_INSTALL_DOCDIR CMAKE_INSTALL_DOCDIR
) )
macro(GNUInstallDirs_get_absolute_install_dir absvar var)
if(NOT IS_ABSOLUTE "${${var}}")
# 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(${absvar} "/${${var}}")
else()
if (NOT "${${var}}" MATCHES "^usr/")
set(${var} "usr/${${var}}")
endif()
set(${absvar} "/${${var}}")
endif()
elseif("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
if("${dir}" STREQUAL "SYSCONFDIR" OR "${dir}" STREQUAL "LOCALSTATEDIR")
set(${absvar} "/${${var}}")
else()
set(${absvar} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
elseif("${CMAKE_INSTALL_PREFIX}" MATCHES "^/opt/.*")
if("${dir}" STREQUAL "SYSCONFDIR" OR "${dir}" STREQUAL "LOCALSTATEDIR")
set(${absvar} "/${${var}}${CMAKE_INSTALL_PREFIX}")
else()
set(${absvar} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
else()
set(${absvar} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
else()
set(${absvar} "${${var}}")
endif()
endmacro()
# Result directories # Result directories
# #
foreach(dir foreach(dir
@ -319,36 +371,5 @@ foreach(dir
MANDIR MANDIR
DOCDIR DOCDIR
) )
if(NOT IS_ABSOLUTE "${CMAKE_INSTALL_${dir}}") GNUInstallDirs_get_absolute_install_dir(CMAKE_INSTALL_FULL_${dir} 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()
endforeach() endforeach()