1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

GNUInstallDirs: Refactor LIBDIR default calculation

Implement via the `_GNUInstallDirs_<dir>_get_default` helper.

Signed-off-by: Cristian Le <git@lecris.dev>
This commit is contained in:
Cristian Le
2025-03-27 19:15:56 +01:00
committed by Brad King
parent 9789f7d05e
commit 42dfcbf1a5
2 changed files with 16 additions and 64 deletions

View File

@@ -288,32 +288,9 @@ set(_GNUInstallDirs_DATAROOTDIR_DEFAULT "share")
# ``install_prefix`` # ``install_prefix``
# The CMAKE_INSTALL_PREFIX used to calculate the default # The CMAKE_INSTALL_PREFIX used to calculate the default
# We check if the variable was manually set and not cached, in order to function(_GNUInstallDirs_LIBDIR_get_default out_var install_prefix)
# allow projects to set the values as normal variables before including set(${out_var} "${_GNUInstallDirs_LIBDIR_DEFAULT}")
# GNUInstallDirs to avoid having the entries cached or user-editable. It
# replaces the "if(NOT DEFINED CMAKE_INSTALL_XXX)" checks in all the
# other cases.
# If CMAKE_INSTALL_LIBDIR is defined, if _libdir_set is false, then the
# variable is a normal one, otherwise it is a cache one.
get_property(_libdir_set CACHE CMAKE_INSTALL_LIBDIR PROPERTY TYPE SET)
if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set
AND DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
AND NOT "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}" STREQUAL "${CMAKE_INSTALL_PREFIX}"))
# If CMAKE_INSTALL_LIBDIR is not defined, it is always executed.
# Otherwise:
# * if _libdir_set is false it is not executed (meaning that it is
# not a cache variable)
# * if _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX is not defined it is
# not executed
# * if _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX and
# CMAKE_INSTALL_PREFIX are the same string it is not executed.
# _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX is updated after the
# execution, of this part of code, therefore at the next inclusion
# of the file, CMAKE_INSTALL_LIBDIR is defined, and the 2 strings
# are equal, meaning that the if is not executed the code the
# second time.
set(_LIBDIR_DEFAULT "lib")
# Override this default 'lib' with 'lib64' iff: # Override this default 'lib' with 'lib64' iff:
# - we are on Linux system but NOT cross-compiling # - we are on Linux system but NOT cross-compiling
# - we are NOT on debian # - we are NOT on debian
@@ -324,58 +301,29 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set
# CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu" # CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu"
# and CMAKE_INSTALL_PREFIX is "/usr" # and CMAKE_INSTALL_PREFIX is "/usr"
# See http://wiki.debian.org/Multiarch # See http://wiki.debian.org/Multiarch
if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX)
set(__LAST_LIBDIR_DEFAULT "lib")
# __LAST_LIBDIR_DEFAULT is the default value that we compute from
# _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX, not a cache entry for
# the value that was last used as the default.
# This value is used to figure out whether the user changed the
# CMAKE_INSTALL_LIBDIR value manually, or if the value was the
# default one. When CMAKE_INSTALL_PREFIX changes, the value is
# updated to the new default, unless the user explicitly changed it.
endif()
if (NOT DEFINED CMAKE_SYSTEM_NAME OR NOT DEFINED CMAKE_SIZEOF_VOID_P) if (NOT DEFINED CMAKE_SYSTEM_NAME OR NOT DEFINED CMAKE_SIZEOF_VOID_P)
message(AUTHOR_WARNING message(AUTHOR_WARNING
"Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. " "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. "
"Please enable at least one language before including GNUInstallDirs.") "Please enable at least one language before including GNUInstallDirs.")
endif() endif()
if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|GNU)$" AND NOT CMAKE_CROSSCOMPILING)
if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|GNU)$" _GNUInstallDirs_get_system_type_for_install(system_type)
AND NOT CMAKE_CROSSCOMPILING) if(system_type STREQUAL "debian")
_GNUInstallDirs_get_system_type_for_install(__system_type_for_install)
if(__system_type_for_install STREQUAL "debian")
if(CMAKE_LIBRARY_ARCHITECTURE) if(CMAKE_LIBRARY_ARCHITECTURE)
if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$") if("${install_prefix}" MATCHES "^/usr/?$")
set(_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}") set(${out_var} "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
endif()
if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
AND "${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/?$")
set(__LAST_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
endif() endif()
endif() endif()
elseif(NOT DEFINED __system_type_for_install) elseif(NOT DEFINED system_type)
# not debian, alpine, arch, or conda so rely on CMAKE_SIZEOF_VOID_P: # not debian, alpine, arch, or conda so rely on CMAKE_SIZEOF_VOID_P:
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(_LIBDIR_DEFAULT "lib64") set(${out_var} "lib64")
if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX)
set(__LAST_LIBDIR_DEFAULT "lib64")
endif()
endif() endif()
endif() endif()
endif() endif()
unset(__system_type_for_install)
if(NOT DEFINED CMAKE_INSTALL_LIBDIR) return(PROPAGATE ${out_var})
set(CMAKE_INSTALL_LIBDIR "${_LIBDIR_DEFAULT}" CACHE PATH "Object code libraries (${_LIBDIR_DEFAULT})") endfunction()
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()
_GNUInstallDirs_cache_convert_to_path(CMAKE_INSTALL_LIBDIR "Object code libraries (lib)")
unset(_libdir_set)
unset(__LAST_LIBDIR_DEFAULT)
_GNUInstallDirs_cache_path(BINDIR _GNUInstallDirs_cache_path(BINDIR
"User executables") "User executables")
@@ -389,7 +337,8 @@ _GNUInstallDirs_cache_path(SHAREDSTATEDIR
"Modifiable architecture-independent data") "Modifiable architecture-independent data")
_GNUInstallDirs_cache_path(LOCALSTATEDIR _GNUInstallDirs_cache_path(LOCALSTATEDIR
"Modifiable single-machine data") "Modifiable single-machine data")
_GNUInstallDirs_cache_path(LIBDIR
"Object code libraries")
_GNUInstallDirs_cache_path(INCLUDEDIR _GNUInstallDirs_cache_path(INCLUDEDIR
"C header files") "C header files")
_GNUInstallDirs_cache_path(OLDINCLUDEDIR _GNUInstallDirs_cache_path(OLDINCLUDEDIR

View File

@@ -3,6 +3,9 @@
target architecture is known. Please enable at least one language before target architecture is known. Please enable at least one language before
including GNUInstallDirs. including GNUInstallDirs.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
.*GNUInstallDirs.cmake:[0-9]+ \(_GNUInstallDirs_LIBDIR_get_default\)
.*GNUInstallDirs.cmake:[0-9]+ \(cmake_language\)
.*GNUInstallDirs.cmake:[0-9]+ \(_GNUInstallDirs_cache_path\)
NoSystem.cmake:[0-9]+ \(include\) NoSystem.cmake:[0-9]+ \(include\)
CMakeLists.txt:[0-9]+ \(include\) CMakeLists.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$ This warning is for project developers. Use -Wno-dev to suppress it.$