1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-20 21:40:15 +08:00

CMAKE_FIND_USE_INSTALL_PREFIX considers CMAKE_STAGING_PREFIX

Fixes #23900
This commit is contained in:
Robert Maynard
2022-08-30 15:27:30 -04:00
parent 43d31c5198
commit 0fc10bb19b
12 changed files with 118 additions and 12 deletions

View File

@@ -166,7 +166,8 @@ If ``NO_DEFAULT_PATH`` is not specified, the search process is as follows:
* |SYSTEM_ENVIRONMENT_PATH_WINDOWS_XXX| * |SYSTEM_ENVIRONMENT_PATH_WINDOWS_XXX|
6. Search cmake variables defined in the Platform files 6. Search cmake variables defined in the Platform files
for the current system. The searching of ``CMAKE_INSTALL_PREFIX`` can be for the current system. The searching of ``CMAKE_INSTALL_PREFIX`` and
``CMAKE_STAGING_PREFIX`` can be
skipped if ``NO_CMAKE_INSTALL_PREFIX`` is passed or by setting the skipped if ``NO_CMAKE_INSTALL_PREFIX`` is passed or by setting the
:variable:`CMAKE_FIND_USE_INSTALL_PREFIX` to ``FALSE``. All these locations :variable:`CMAKE_FIND_USE_INSTALL_PREFIX` to ``FALSE``. All these locations
can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is passed or by setting the can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is passed or by setting the

View File

@@ -412,7 +412,8 @@ enabled.
package registry. package registry.
7. Search cmake variables defined in the Platform files for the 7. Search cmake variables defined in the Platform files for the
current system. The searching of :variable:`CMAKE_INSTALL_PREFIX` can be current system. The searching of :variable:`CMAKE_INSTALL_PREFIX` and
:variable:`CMAKE_STAGING_PREFIX` can be
skipped if ``NO_CMAKE_INSTALL_PREFIX`` is passed or by setting the skipped if ``NO_CMAKE_INSTALL_PREFIX`` is passed or by setting the
:variable:`CMAKE_FIND_USE_INSTALL_PREFIX` to ``FALSE``. All these locations :variable:`CMAKE_FIND_USE_INSTALL_PREFIX` to ``FALSE``. All these locations
can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is passed or by setting the can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is passed or by setting the

View File

@@ -4,7 +4,8 @@ CMAKE_FIND_USE_INSTALL_PREFIX
.. versionadded:: 3.24 .. versionadded:: 3.24
Controls the default behavior of the following commands for whether or not to Controls the default behavior of the following commands for whether or not to
search the install location: search the locations in the :variable:`CMAKE_INSTALL_PREFIX` and
:variable:`CMAKE_STAGING_PREFIX` variables.
* :command:`find_program` * :command:`find_program`
* :command:`find_library` * :command:`find_library`

View File

@@ -19,13 +19,19 @@ set(WIN32 )
function(_cmake_record_install_prefix ) function(_cmake_record_install_prefix )
set(_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_VALUE "${CMAKE_INSTALL_PREFIX}" PARENT_SCOPE) set(_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_VALUE "${CMAKE_INSTALL_PREFIX}" PARENT_SCOPE)
set(count 0) set(_CMAKE_SYSTEM_PREFIX_PATH_STAGING_PREFIX_VALUE "${CMAKE_STAGING_PREFIX}" PARENT_SCOPE)
set(icount 0)
set(scount 0)
foreach(value IN LISTS CMAKE_SYSTEM_PREFIX_PATH) foreach(value IN LISTS CMAKE_SYSTEM_PREFIX_PATH)
if(value STREQUAL CMAKE_INSTALL_PREFIX) if(value STREQUAL CMAKE_INSTALL_PREFIX)
math(EXPR count "${count}+1") math(EXPR icount "${icount}+1")
endif()
if(value STREQUAL CMAKE_STAGING_PREFIX)
math(EXPR scount "${scount}+1")
endif() endif()
endforeach() endforeach()
set(_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_COUNT "${count}" PARENT_SCOPE) set(_CMAKE_SYSTEM_PREFIX_PATH_INSTALL_PREFIX_COUNT "${icount}" PARENT_SCOPE)
set(_CMAKE_SYSTEM_PREFIX_PATH_STAGING_PREFIX_COUNT "${scount}" PARENT_SCOPE)
endfunction() endfunction()
# include Generic system information # include Generic system information

View File

@@ -278,13 +278,11 @@ void cmFindBase::FillSystemEnvironmentPath()
paths.AddSuffixes(this->SearchPathSuffixes); paths.AddSuffixes(this->SearchPathSuffixes);
} }
#include <iostream>
namespace { namespace {
struct entry_to_remove struct entry_to_remove
{ {
entry_to_remove(std::string name, cmMakefile* makefile) entry_to_remove(std::string const& name, cmMakefile* makefile)
: count(-1) : value()
, value()
{ {
if (cmValue to_skip = makefile->GetDefinition( if (cmValue to_skip = makefile->GetDefinition(
cmStrCat("_CMAKE_SYSTEM_PREFIX_PATH_", name, "_PREFIX_COUNT"))) { cmStrCat("_CMAKE_SYSTEM_PREFIX_PATH_", name, "_PREFIX_COUNT"))) {
@@ -312,7 +310,7 @@ struct entry_to_remove
} }
} }
long count; long count = -1;
std::string value; std::string value;
}; };
} }
@@ -339,20 +337,23 @@ void cmFindBase::FillCMakeSystemVariablePath()
// have removed `CMAKE_INSTALL_PREFIX` from the list, we don't remove // have removed `CMAKE_INSTALL_PREFIX` from the list, we don't remove
// some other entry by mistake ( likewise for `CMAKE_STAGING_PREFIX` ) // some other entry by mistake ( likewise for `CMAKE_STAGING_PREFIX` )
entry_to_remove install_entry("INSTALL", this->Makefile); entry_to_remove install_entry("INSTALL", this->Makefile);
entry_to_remove staging_entry("STAGING", this->Makefile);
if (remove_install_prefix && install_prefix_in_list && if (remove_install_prefix && install_prefix_in_list &&
install_entry.valid()) { (install_entry.valid() || staging_entry.valid())) {
cmValue prefix_paths = cmValue prefix_paths =
this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH"); this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH");
// remove entries from CMAKE_SYSTEM_PREFIX_PATH // remove entries from CMAKE_SYSTEM_PREFIX_PATH
std::vector<std::string> expanded = cmExpandedList(*prefix_paths); std::vector<std::string> expanded = cmExpandedList(*prefix_paths);
install_entry.remove_self(expanded); install_entry.remove_self(expanded);
staging_entry.remove_self(expanded);
paths.AddPrefixPaths(expanded, paths.AddPrefixPaths(expanded,
this->Makefile->GetCurrentSourceDirectory().c_str()); this->Makefile->GetCurrentSourceDirectory().c_str());
} else if (add_install_prefix && !install_prefix_in_list) { } else if (add_install_prefix && !install_prefix_in_list) {
paths.AddCMakePrefixPath("CMAKE_INSTALL_PREFIX"); paths.AddCMakePrefixPath("CMAKE_INSTALL_PREFIX");
paths.AddCMakePrefixPath("CMAKE_STAGING_PREFIX");
paths.AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH"); paths.AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
} else { } else {
// Otherwise the current setup of `CMAKE_SYSTEM_PREFIX_PATH` is correct // Otherwise the current setup of `CMAKE_SYSTEM_PREFIX_PATH` is correct

View File

@@ -0,0 +1,43 @@
find_library called with the following settings:.*
VAR: CREATED_LIBRARY
NAMES: \"created\"
Documentation.*
Framework.*
AppBundle.*
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
CMAKE_FIND_USE_INSTALL_PREFIX: 0
find_library considered the following locations:.*
The item was not found.*
find_library called with the following settings:.*
VAR: CREATED_LIBRARY
NAMES: \"created\"
Documentation.*
Framework.*
AppBundle.*
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
CMAKE_FIND_USE_INSTALL_PREFIX: 1
find_library considered the following locations:.*
The item was found at.*
.*IgnoreStagingAndInstallPrefix-build/lib.*
find_library called with the following settings:.*
VAR: CREATED_LIBRARY
NAMES: \"created\"
Documentation.*
Framework.*
AppBundle.*
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
CMAKE_FIND_USE_INSTALL_PREFIX: 0
find_library considered the following locations:.*
The item was not found.*

View File

@@ -0,0 +1,3 @@
-- CREATED_LIBRARY='CREATED_LIBRARY-NOTFOUND'
-- CREATED_LIBRARY='[^']*/Tests/RunCMake/find_library/IgnoreStagingAndInstallPrefix-build/lib/libcreated.a'
-- CREATED_LIBRARY='CREATED_LIBRARY-NOTFOUND'

View File

@@ -0,0 +1 @@
include(IgnoreInstallPrefix.cmake)

View File

@@ -0,0 +1,43 @@
find_library called with the following settings:.*
VAR: CREATED_LIBRARY
NAMES: \"created\"
Documentation.*
Framework.*
AppBundle.*
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
CMAKE_FIND_USE_INSTALL_PREFIX: 0
find_library considered the following locations:.*
The item was not found.*
find_library called with the following settings:.*
VAR: CREATED_LIBRARY
NAMES: \"created\"
Documentation.*
Framework.*
AppBundle.*
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
CMAKE_FIND_USE_INSTALL_PREFIX: 1
find_library considered the following locations:.*
The item was found at.*
.*IgnoreStagingPrefix-build/lib.*
find_library called with the following settings:.*
VAR: CREATED_LIBRARY
NAMES: \"created\"
Documentation.*
Framework.*
AppBundle.*
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
CMAKE_FIND_USE_INSTALL_PREFIX: 0
find_library considered the following locations:.*
The item was not found.*

View File

@@ -0,0 +1,3 @@
-- CREATED_LIBRARY='CREATED_LIBRARY-NOTFOUND'
-- CREATED_LIBRARY='[^']*/Tests/RunCMake/find_library/IgnoreStagingPrefix-build/lib/libcreated.a'
-- CREATED_LIBRARY='CREATED_LIBRARY-NOTFOUND'

View File

@@ -0,0 +1 @@
include(IgnoreInstallPrefix.cmake)

View File

@@ -4,6 +4,8 @@ run_cmake(Created)
run_cmake(FromPrefixPath) run_cmake(FromPrefixPath)
run_cmake(FromPATHEnv) run_cmake(FromPATHEnv)
run_cmake_with_options(IgnoreInstallPrefix "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/IgnoreInstallPrefix-build/") run_cmake_with_options(IgnoreInstallPrefix "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/IgnoreInstallPrefix-build/")
run_cmake_with_options(IgnoreStagingPrefix "-DCMAKE_STAGING_PREFIX=${RunCMake_BINARY_DIR}/IgnoreStagingPrefix-build/")
run_cmake_with_options(IgnoreStagingAndInstallPrefix "-DCMAKE_STAGING_PREFIX=${RunCMake_BINARY_DIR}/IgnoreStagingAndInstallPrefix-build/" "-DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/IgnoreStagingAndInstallPrefix-build/")
if(UNIX AND NOT CYGWIN) if(UNIX AND NOT CYGWIN)
run_cmake(LibArchLink) run_cmake(LibArchLink)
run_cmake(LibSymLink) run_cmake(LibSymLink)