GNUInstallDirs: Unify path logic into helper macros

- Unify path handling: Rather than repeat the same logic for each
  individual path create two macros which can be used throughout
  the module.
- Capitalise helpstrings to match the conventions used by the
  standard CMake properties
This commit is contained in:
Roger Leigh 2016-12-06 20:44:45 +00:00 committed by Roger Leigh
parent 0f37cd228e
commit c968213d2e

View File

@ -120,31 +120,38 @@
# allow users who create additional path variables to also compute
# absolute paths where necessary, using the same logic.
# Create a cache variable with default for a path.
macro(_GNUInstallDirs_cache_path var default description)
if(NOT DEFINED ${var})
set(${var} "${default}" CACHE PATH "${description}")
endif()
endmacro()
# Create a cache variable with not default for a path, with a fallback
# when unset; used for entries slaved to other entries such as
# DATAROOTDIR.
macro(_GNUInstallDirs_cache_path_fallback var default description)
if(NOT ${var})
set(${var} "" CACHE PATH "${description}")
set(${var} "${default}")
endif()
endmacro()
# Installation directories
#
if(NOT DEFINED CMAKE_INSTALL_BINDIR)
set(CMAKE_INSTALL_BINDIR "bin" CACHE PATH "user executables (bin)")
endif()
if(NOT DEFINED CMAKE_INSTALL_SBINDIR)
set(CMAKE_INSTALL_SBINDIR "sbin" CACHE PATH "system admin executables (sbin)")
endif()
if(NOT DEFINED CMAKE_INSTALL_LIBEXECDIR)
set(CMAKE_INSTALL_LIBEXECDIR "libexec" CACHE PATH "program executables (libexec)")
endif()
if(NOT DEFINED CMAKE_INSTALL_SYSCONFDIR)
set(CMAKE_INSTALL_SYSCONFDIR "etc" CACHE PATH "read-only single-machine data (etc)")
endif()
if(NOT DEFINED CMAKE_INSTALL_SHAREDSTATEDIR)
set(CMAKE_INSTALL_SHAREDSTATEDIR "com" CACHE PATH "modifiable architecture-independent data (com)")
endif()
if(NOT DEFINED CMAKE_INSTALL_LOCALSTATEDIR)
set(CMAKE_INSTALL_LOCALSTATEDIR "var" CACHE PATH "modifiable single-machine data (var)")
endif()
_GNUInstallDirs_cache_path(CMAKE_INSTALL_BINDIR "bin"
"User executables (bin)")
_GNUInstallDirs_cache_path(CMAKE_INSTALL_SBINDIR "sbin"
"System admin executables (sbin)")
_GNUInstallDirs_cache_path(CMAKE_INSTALL_LIBEXECDIR "libexec"
"Program executables (libexec)")
_GNUInstallDirs_cache_path(CMAKE_INSTALL_SYSCONFDIR "etc"
"Read-only single-machine data (etc)")
_GNUInstallDirs_cache_path(CMAKE_INSTALL_SHAREDSTATEDIR "com"
"Modifiable architecture-independent data (com)")
_GNUInstallDirs_cache_path(CMAKE_INSTALL_LOCALSTATEDIR "var"
"Modifiable single-machine data (var)")
# We check if the variable was manually set and not cached, in order to
# allow projects to set the values as normal variables before including
@ -219,71 +226,49 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set
endif()
endif()
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "object code libraries (${_LIBDIR_DEFAULT})")
set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "Object code libraries (${_LIBDIR_DEFAULT})")
elseif(DEFINED __LAST_LIBDIR_DEFAULT
AND "${__LAST_LIBDIR_DEFAULT}" STREQUAL "${CMAKE_INSTALL_LIBDIR}")
set_property(CACHE CMAKE_INSTALL_LIBDIR PROPERTY VALUE "${_LIBDIR_DEFAULT}")
endif()
endif()
# Save for next run
set(_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "CMAKE_INSTALL_PREFIX during last run")
unset(_libdir_set)
unset(__LAST_LIBDIR_DEFAULT)
if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE PATH "C header files (include)")
endif()
if(NOT DEFINED CMAKE_INSTALL_OLDINCLUDEDIR)
set(CMAKE_INSTALL_OLDINCLUDEDIR "/usr/include" CACHE PATH "C header files for non-gcc (/usr/include)")
endif()
if(NOT DEFINED CMAKE_INSTALL_DATAROOTDIR)
set(CMAKE_INSTALL_DATAROOTDIR "share" CACHE PATH "read-only architecture-independent data root (share)")
endif()
_GNUInstallDirs_cache_path(CMAKE_INSTALL_INCLUDEDIR "include"
"C header files (include)")
_GNUInstallDirs_cache_path(CMAKE_INSTALL_OLDINCLUDEDIR "/usr/include"
"C header files for non-gcc (/usr/include)")
_GNUInstallDirs_cache_path(CMAKE_INSTALL_DATAROOTDIR "share"
"Read-only architecture-independent data root (share)")
#-----------------------------------------------------------------------------
# Values whose defaults are relative to DATAROOTDIR. Store empty values in
# the cache and store the defaults in local variables if the cache values are
# not set explicitly. This auto-updates the defaults as DATAROOTDIR changes.
if(NOT CMAKE_INSTALL_DATADIR)
set(CMAKE_INSTALL_DATADIR "" CACHE PATH "read-only architecture-independent data (DATAROOTDIR)")
set(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATAROOTDIR}")
endif()
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATAROOTDIR}"
"Read-only architecture-independent data (DATAROOTDIR)")
if(CMAKE_SYSTEM_NAME MATCHES "^(.*BSD|DragonFly)$")
if(NOT CMAKE_INSTALL_INFODIR)
set(CMAKE_INSTALL_INFODIR "" CACHE PATH "info documentation (info)")
set(CMAKE_INSTALL_INFODIR "info")
endif()
if(NOT CMAKE_INSTALL_MANDIR)
set(CMAKE_INSTALL_MANDIR "" CACHE PATH "man documentation (man)")
set(CMAKE_INSTALL_MANDIR "man")
endif()
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_INFODIR "info"
"Info documentation (info)")
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_MANDIR "man"
"Man documentation (man)")
else()
if(NOT CMAKE_INSTALL_INFODIR)
set(CMAKE_INSTALL_INFODIR "" CACHE PATH "info documentation (DATAROOTDIR/info)")
set(CMAKE_INSTALL_INFODIR "${CMAKE_INSTALL_DATAROOTDIR}/info")
endif()
if(NOT CMAKE_INSTALL_MANDIR)
set(CMAKE_INSTALL_MANDIR "" CACHE PATH "man documentation (DATAROOTDIR/man)")
set(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_DATAROOTDIR}/man")
endif()
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_INFODIR "${CMAKE_INSTALL_DATAROOTDIR}/info"
"Info documentation (DATAROOTDIR/info)")
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_DATAROOTDIR}/man"
"Man documentation (DATAROOTDIR/man)")
endif()
if(NOT CMAKE_INSTALL_LOCALEDIR)
set(CMAKE_INSTALL_LOCALEDIR "" CACHE PATH "locale-dependent data (DATAROOTDIR/locale)")
set(CMAKE_INSTALL_LOCALEDIR "${CMAKE_INSTALL_DATAROOTDIR}/locale")
endif()
if(NOT CMAKE_INSTALL_DOCDIR)
set(CMAKE_INSTALL_DOCDIR "" CACHE PATH "documentation root (DATAROOTDIR/doc/PROJECT_NAME)")
set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}")
endif()
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_LOCALEDIR "${CMAKE_INSTALL_DATAROOTDIR}/locale"
"Locale-dependent data (DATAROOTDIR/locale)")
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}"
"Documentation root (DATAROOTDIR/doc/PROJECT_NAME)")
#-----------------------------------------------------------------------------