Просмотр исходного кода

CMAKE_FIND_USE_INSTALL_PREFIX considers CMAKE_STAGING_PREFIX

Fixes #23900
Robert Maynard 3 лет назад
Родитель
Сommit
0fc10bb19b

+ 2 - 1
Help/command/FIND_XXX.txt

@@ -166,7 +166,8 @@ If ``NO_DEFAULT_PATH`` is not specified, the search process is as follows:
    * |SYSTEM_ENVIRONMENT_PATH_WINDOWS_XXX|
 
 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
    :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

+ 2 - 1
Help/command/find_package.rst

@@ -412,7 +412,8 @@ enabled.
    package registry.
 
 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
    :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

+ 2 - 1
Help/variable/CMAKE_FIND_USE_INSTALL_PREFIX.rst

@@ -4,7 +4,8 @@ CMAKE_FIND_USE_INSTALL_PREFIX
 .. versionadded:: 3.24
 
 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_library`

+ 9 - 3
Modules/CMakeSystemSpecificInformation.cmake

@@ -19,13 +19,19 @@ set(WIN32  )
 
 function(_cmake_record_install_prefix )
   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)
     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()
   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()
 
 # include Generic system information

+ 7 - 6
Source/cmFindBase.cxx

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

+ 43 - 0
Tests/RunCMake/find_library/IgnoreStagingAndInstallPrefix-stderr.txt

@@ -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.*

+ 3 - 0
Tests/RunCMake/find_library/IgnoreStagingAndInstallPrefix-stdout.txt

@@ -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'

+ 1 - 0
Tests/RunCMake/find_library/IgnoreStagingAndInstallPrefix.cmake

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

+ 43 - 0
Tests/RunCMake/find_library/IgnoreStagingPrefix-stderr.txt

@@ -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.*

+ 3 - 0
Tests/RunCMake/find_library/IgnoreStagingPrefix-stdout.txt

@@ -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'

+ 1 - 0
Tests/RunCMake/find_library/IgnoreStagingPrefix.cmake

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

+ 2 - 0
Tests/RunCMake/find_library/RunCMakeTest.cmake

@@ -4,6 +4,8 @@ run_cmake(Created)
 run_cmake(FromPrefixPath)
 run_cmake(FromPATHEnv)
 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)
   run_cmake(LibArchLink)
   run_cmake(LibSymLink)