mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-30 18:29:37 -06:00
GNUInstallDirs: Fix regression on -DCMAKE_INSTALL_<dir>=<default> in /usr
Fix commit 9789f7d05e (GNUInstallDirs: Add internal helper to compute
specific defaults, 2025-03-28, v4.1.0-rc1~384^2~3) to avoid updating
explicitly-specified cache entries on the first run. Do not reset the
default value until at least the second run, during which we have
`_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX` already defined.
Fixes: #27211
This commit is contained in:
@@ -257,15 +257,16 @@ function(_GNUInstallDirs_cache_path var description)
|
||||
if(COMMAND _GNUInstallDirs_${var}_get_default)
|
||||
# Check if the current CMAKE_INSTALL_PREFIX is the same as before
|
||||
set(install_prefix_is_same TRUE)
|
||||
set(last_default "${default}")
|
||||
if(NOT DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
|
||||
OR NOT _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX)
|
||||
unset(last_default)
|
||||
if(DEFINED _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX
|
||||
AND NOT _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX)
|
||||
set(install_prefix_is_same FALSE)
|
||||
# Recalculate what the last default would have been
|
||||
cmake_language(CALL _GNUInstallDirs_${var}_get_default
|
||||
last_default
|
||||
"${_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX}")
|
||||
endif()
|
||||
|
||||
if(DEFINED CACHE{${cmake_install_var}} AND install_prefix_is_same)
|
||||
# If the cache variable was already set from a previous run and the
|
||||
# install prefix has not changed, we don't need to do anything
|
||||
@@ -278,6 +279,7 @@ function(_GNUInstallDirs_cache_path var description)
|
||||
# if the current value is the same as the cache value and the same as
|
||||
# the old default, reset the value to the new default
|
||||
if(${cmake_install_var} STREQUAL "$CACHE{${cmake_install_var}}"
|
||||
AND DEFINED last_default
|
||||
AND ${cmake_install_var} STREQUAL last_default)
|
||||
set(full_description "${description} (${default})")
|
||||
set_property(CACHE ${cmake_install_var} PROPERTY TYPE PATH)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
set(CMAKE_SIZEOF_VOID_P 8)
|
||||
set(CMAKE_LIBRARY_ARCHITECTURE "arch")
|
||||
set(CMAKE_INSTALL_PREFIX "/usr/local")
|
||||
include(GNUInstallDirs)
|
||||
set(dirs
|
||||
BINDIR
|
||||
@@ -0,0 +1,6 @@
|
||||
-- CMAKE_INSTALL_BINDIR='bin'
|
||||
-- CMAKE_INSTALL_INCLUDEDIR='include'
|
||||
-- CMAKE_INSTALL_LIBDIR='lib'
|
||||
-- CMAKE_INSTALL_FULL_BINDIR='/opt/bin'
|
||||
-- CMAKE_INSTALL_FULL_INCLUDEDIR='/opt/include'
|
||||
-- CMAKE_INSTALL_FULL_LIBDIR='/opt/lib'
|
||||
2
Tests/RunCMake/GNUInstallDirs/ExplicitDefaults-Opt.cmake
Normal file
2
Tests/RunCMake/GNUInstallDirs/ExplicitDefaults-Opt.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(CMAKE_INSTALL_PREFIX "/opt")
|
||||
include(ExplicitDefaults-Common.cmake)
|
||||
@@ -0,0 +1,6 @@
|
||||
-- CMAKE_INSTALL_BINDIR='bin'
|
||||
-- CMAKE_INSTALL_INCLUDEDIR='include'
|
||||
-- CMAKE_INSTALL_LIBDIR='lib'
|
||||
-- CMAKE_INSTALL_FULL_BINDIR='/usr/bin'
|
||||
-- CMAKE_INSTALL_FULL_INCLUDEDIR='/usr/include'
|
||||
-- CMAKE_INSTALL_FULL_LIBDIR='/usr/lib'
|
||||
@@ -0,0 +1,2 @@
|
||||
set(CMAKE_INSTALL_PREFIX "/")
|
||||
include(ExplicitDefaults-Common.cmake)
|
||||
@@ -0,0 +1,6 @@
|
||||
-- CMAKE_INSTALL_BINDIR='bin'
|
||||
-- CMAKE_INSTALL_INCLUDEDIR='include'
|
||||
-- CMAKE_INSTALL_LIBDIR='lib'
|
||||
-- CMAKE_INSTALL_FULL_BINDIR='/usr/bin'
|
||||
-- CMAKE_INSTALL_FULL_INCLUDEDIR='/usr/include'
|
||||
-- CMAKE_INSTALL_FULL_LIBDIR='/usr/lib'
|
||||
2
Tests/RunCMake/GNUInstallDirs/ExplicitDefaults-Usr.cmake
Normal file
2
Tests/RunCMake/GNUInstallDirs/ExplicitDefaults-Usr.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(CMAKE_INSTALL_PREFIX "/usr")
|
||||
include(ExplicitDefaults-Common.cmake)
|
||||
@@ -0,0 +1,2 @@
|
||||
set(CMAKE_INSTALL_PREFIX "/usr/local")
|
||||
include(ExplicitDefaults-Common.cmake)
|
||||
@@ -40,8 +40,15 @@ endblock()
|
||||
run_cmake(GetAbs)
|
||||
run_cmake(NoSystem)
|
||||
|
||||
run_cmake_with_options(ExplicitDefaults
|
||||
-DCMAKE_INSTALL_BINDIR=bin
|
||||
-DCMAKE_INSTALL_INCLUDEDIR=include
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
)
|
||||
foreach(case
|
||||
Opt
|
||||
Root
|
||||
Usr
|
||||
UsrLocal
|
||||
)
|
||||
run_cmake_with_options(ExplicitDefaults-${case}
|
||||
-DCMAKE_INSTALL_BINDIR=bin
|
||||
-DCMAKE_INSTALL_INCLUDEDIR=include
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
)
|
||||
endforeach()
|
||||
|
||||
Reference in New Issue
Block a user