From c968213d2e43945e69ebe4ad12ca933b8f4c4e6f Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Tue, 6 Dec 2016 20:44:45 +0000 Subject: 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 --- Modules/GNUInstallDirs.cmake | 117 +++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 66 deletions(-) diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake index 059a2fc..b8b95bc 100644 --- a/Modules/GNUInstallDirs.cmake +++ b/Modules/GNUInstallDirs.cmake @@ -120,31 +120,38 @@ # allow users who create additional path variables to also compute # absolute paths where necessary, using the same logic. -# 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() +# 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() -if(NOT DEFINED CMAKE_INSTALL_SYSCONFDIR) - set(CMAKE_INSTALL_SYSCONFDIR "etc" CACHE PATH "read-only single-machine data (etc)") -endif() +# 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() -if(NOT DEFINED CMAKE_INSTALL_SHAREDSTATEDIR) - set(CMAKE_INSTALL_SHAREDSTATEDIR "com" CACHE PATH "modifiable architecture-independent data (com)") -endif() +# Installation directories +# -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() -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") + _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_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)") #----------------------------------------------------------------------------- -- cgit v0.12 From 53b5d6345dd9216e5110a9645a0aa194926d5688 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Fri, 9 Dec 2016 21:36:55 +0000 Subject: GNUInstallDirs: Set UNINITALIZED cache properties to type PATH Also convert the path to a cmake path --- Modules/GNUInstallDirs.cmake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake index b8b95bc..9599f27 100644 --- a/Modules/GNUInstallDirs.cmake +++ b/Modules/GNUInstallDirs.cmake @@ -120,11 +120,26 @@ # allow users who create additional path variables to also compute # absolute paths where necessary, using the same logic. +# Convert a cache variable to PATH type + +macro(_GNUInstallDirs_cache_convert_to_path var description) + get_property(_GNUInstallDirs_cache_type CACHE ${var} PROPERTY TYPE) + if(_GNUInstallDirs_cache_type STREQUAL "UNINITIALIZED") + file(TO_CMAKE_PATH "${${var}}" _GNUInstallDirs_cmakepath) + set_property(CACHE ${var} PROPERTY TYPE PATH) + set_property(CACHE ${var} PROPERTY VALUE "${_GNUInstallDirs_cmakepath}") + set_property(CACHE ${var} PROPERTY HELPSTRING "${description}") + unset(_GNUInstallDirs_cmakepath) + endif() + unset(_GNUInstallDirs_cache_type) +endmacro() + # 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() + _GNUInstallDirs_cache_convert_to_path("${var}" "${description}") endmacro() # Create a cache variable with not default for a path, with a fallback @@ -135,6 +150,7 @@ macro(_GNUInstallDirs_cache_path_fallback var default description) set(${var} "" CACHE PATH "${description}") set(${var} "${default}") endif() + _GNUInstallDirs_cache_convert_to_path("${var}" "${description}") endmacro() # Installation directories @@ -232,6 +248,7 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set set_property(CACHE CMAKE_INSTALL_LIBDIR PROPERTY VALUE "${_LIBDIR_DEFAULT}") endif() endif() +_GNUInstallDirs_cache_convert_to_path(CMAKE_INSTALL_LIBDIR "Object code libraries (lib)") # Save for next run set(_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE INTERNAL "CMAKE_INSTALL_PREFIX during last run") -- cgit v0.12