Преглед изворни кода

Merge topic 'find_pkg_use_new_global_controls'

609fe39043 FindPackage:  Support `NO_[]_PATH` global call options
ff29c92df6 Tests: find_file restore PATH env variable after test runs

Acked-by: Kitware Robot <[email protected]>
Merge-request: !3590
Brad King пре 6 година
родитељ
комит
156f4c2f80

+ 10 - 5
Help/command/find_package.rst

@@ -293,13 +293,15 @@ enabled.
    The package root variables are maintained as a stack so if
    The package root variables are maintained as a stack so if
    called from within a find module, root paths from the parent's find
    called from within a find module, root paths from the parent's find
    module will also be searched after paths for the current package.
    module will also be searched after paths for the current package.
-   This can be skipped if ``NO_PACKAGE_ROOT_PATH`` is passed.
+   This can be skipped if ``NO_PACKAGE_ROOT_PATH`` is passed or by setting
+   the :variable:`CMAKE_FIND_USE_PACKAGE_ROOT_PATH` to ``FALSE``.
    See policy :policy:`CMP0074`.
    See policy :policy:`CMP0074`.
 
 
 2. Search paths specified in cmake-specific cache variables.  These
 2. Search paths specified in cmake-specific cache variables.  These
    are intended to be used on the command line with a ``-DVAR=value``.
    are intended to be used on the command line with a ``-DVAR=value``.
    The values are interpreted as :ref:`semicolon-separated lists <CMake Language Lists>`.
    The values are interpreted as :ref:`semicolon-separated lists <CMake Language Lists>`.
-   This can be skipped if ``NO_CMAKE_PATH`` is passed::
+   This can be skipped if ``NO_CMAKE_PATH`` is passed or by setting the
+   :variable:`CMAKE_FIND_USE_CMAKE_PATH` to ``FALSE``::
 
 
      CMAKE_PREFIX_PATH
      CMAKE_PREFIX_PATH
      CMAKE_FRAMEWORK_PATH
      CMAKE_FRAMEWORK_PATH
@@ -309,7 +311,8 @@ enabled.
    These are intended to be set in the user's shell configuration,
    These are intended to be set in the user's shell configuration,
    and therefore use the host's native path separator
    and therefore use the host's native path separator
    (``;`` on Windows and ``:`` on UNIX).
    (``;`` on Windows and ``:`` on UNIX).
-   This can be skipped if ``NO_CMAKE_ENVIRONMENT_PATH`` is passed::
+   This can be skipped if ``NO_CMAKE_ENVIRONMENT_PATH`` is passed or by setting
+   the :variable:`CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH` to ``FALSE``::
 
 
      <PackageName>_DIR
      <PackageName>_DIR
      CMAKE_PREFIX_PATH
      CMAKE_PREFIX_PATH
@@ -322,7 +325,8 @@ enabled.
    be specified with the ``PATHS`` option.
    be specified with the ``PATHS`` option.
 
 
 5. Search the standard system environment variables.  This can be
 5. Search the standard system environment variables.  This can be
-   skipped if ``NO_SYSTEM_ENVIRONMENT_PATH`` is passed.  Path entries
+   skipped if ``NO_SYSTEM_ENVIRONMENT_PATH`` is passed  or by setting the
+   :variable:`CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH` to ``FALSE``. Path entries
    ending in ``/bin`` or ``/sbin`` are automatically converted to their
    ending in ``/bin`` or ``/sbin`` are automatically converted to their
    parent directories::
    parent directories::
 
 
@@ -339,7 +343,8 @@ enabled.
 
 
 7. Search cmake variables defined in the Platform files for the
 7. Search cmake variables defined in the Platform files for the
    current system.  This can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is
    current system.  This can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is
-   passed::
+   passed or by setting the :variable:`CMAKE_FIND_USE_CMAKE_SYSTEM_PATH`
+   to ``FALSE``::
 
 
      CMAKE_SYSTEM_PREFIX_PATH
      CMAKE_SYSTEM_PREFIX_PATH
      CMAKE_SYSTEM_FRAMEWORK_PATH
      CMAKE_SYSTEM_FRAMEWORK_PATH

+ 2 - 2
Help/release/dev/global-controls-over-find-locations.rst

@@ -2,8 +2,8 @@ global-controls-over-find-locations
 -----------------------------------
 -----------------------------------
 
 
 * The :command:`find_file`, :command:`find_library`, :command:`find_path`,
 * The :command:`find_file`, :command:`find_library`, :command:`find_path`,
-  and :command:`find_program` commands have learned to check the following
-  variables to control searching
+  :command:`find_package`, and :command:`find_program` commands have learned to
+  check the following variables to control searching
 
 
   * :variable:`CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH` - Controls the searching
   * :variable:`CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH` - Controls the searching
     the cmake-specific environment variables.
     the cmake-specific environment variables.

+ 1 - 1
Help/variable/CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH.rst

@@ -3,7 +3,7 @@ CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH
 
 
 Controls the searching the cmake-specific environment variables by the
 Controls the searching the cmake-specific environment variables by the
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
-and :command:`find_path` commands.
+:command:`find_path`, and command:`find_package` commands.
 This is useful in cross-compiling environments.
 This is useful in cross-compiling environments.
 
 
 By default this variable is not set, which is equivalent to it having
 By default this variable is not set, which is equivalent to it having

+ 1 - 1
Help/variable/CMAKE_FIND_USE_CMAKE_PATH.rst

@@ -3,7 +3,7 @@ CMAKE_FIND_USE_CMAKE_PATH
 
 
 Controls the searching the cmake-specific cache variables by the
 Controls the searching the cmake-specific cache variables by the
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
-and :command:`find_path` commands.
+:command:`find_path`, and command:`find_package` commands.
 This is useful in cross-compiling environments.
 This is useful in cross-compiling environments.
 
 
 By default this variable is not set, which is equivalent to it having
 By default this variable is not set, which is equivalent to it having

+ 1 - 1
Help/variable/CMAKE_FIND_USE_CMAKE_SYSTEM_PATH.rst

@@ -3,7 +3,7 @@ CMAKE_FIND_USE_CMAKE_SYSTEM_PATH
 
 
 Controls the searching cmake platform specific variables by the
 Controls the searching cmake platform specific variables by the
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
-and :command:`find_path` commands.
+:command:`find_path`, and command:`find_package` commands.
 This is useful in cross-compiling environments.
 This is useful in cross-compiling environments.
 
 
 By default this variable is not set, which is equivalent to it having
 By default this variable is not set, which is equivalent to it having

+ 1 - 1
Help/variable/CMAKE_FIND_USE_PACKAGE_ROOT_PATH.rst

@@ -3,7 +3,7 @@ CMAKE_FIND_USE_PACKAGE_ROOT_PATH
 
 
 Controls the searching of :variable:`<PackageName>_ROOT` variables by the
 Controls the searching of :variable:`<PackageName>_ROOT` variables by the
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
-and :command:`find_path` commands.
+:command:`find_path`, and command:`find_package` commands.
 This is useful in cross-compiling environments.
 This is useful in cross-compiling environments.
 
 
 By default this variable is not set, which is equivalent to it having
 By default this variable is not set, which is equivalent to it having

+ 1 - 1
Help/variable/CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH.rst

@@ -3,7 +3,7 @@ CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH
 
 
 Controls the searching the standard system environment variables by the
 Controls the searching the standard system environment variables by the
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
 :command:`find_program`, :command:`find_library`, :command:`find_file`,
-and :command:`find_path` commands.
+:command:`find_path`, and command:`find_package` commands.
 This is useful in cross-compiling environments.
 This is useful in cross-compiling environments.
 
 
 By default this variable is not set, which is equivalent to it having
 By default this variable is not set, which is equivalent to it having

+ 3 - 0
Source/cmFindPackageCommand.cxx

@@ -225,6 +225,9 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
     this->SortDirection = strcmp(sd, "ASC") == 0 ? Asc : Dec;
     this->SortDirection = strcmp(sd, "ASC") == 0 ? Asc : Dec;
   }
   }
 
 
+  // Find what search path locations have been enabled/disable
+  this->SelectDefaultSearchModes();
+
   // Find the current root path mode.
   // Find the current root path mode.
   this->SelectDefaultRootPathMode();
   this->SelectDefaultRootPathMode();
 
 

+ 2 - 0
Tests/RunCMake/find_file/FromPrefixPath.cmake

@@ -1,3 +1,4 @@
+set(ENV_PATH "$ENV{PATH}")
 set(ENV{PATH} "")
 set(ENV{PATH} "")
 foreach(path "/does_not_exist" "/include" "")
 foreach(path "/does_not_exist" "/include" "")
   unset(PrefixInPATH_File CACHE)
   unset(PrefixInPATH_File CACHE)
@@ -15,3 +16,4 @@ foreach(path "/does_not_exist" "/include" "")
   message(STATUS "PrefixInPATH_File='${PrefixInPATH_File}'")
   message(STATUS "PrefixInPATH_File='${PrefixInPATH_File}'")
 endforeach()
 endforeach()
 set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH ON)
 set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH ON)
+set(ENV{PATH} "${ENV_PATH}")

+ 9 - 0
Tests/RunCMake/find_package/FromPATHEnv-stdout.txt

@@ -0,0 +1,9 @@
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='1'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'

+ 27 - 0
Tests/RunCMake/find_package/FromPATHEnv.cmake

@@ -0,0 +1,27 @@
+set(ENV_PATH "$ENV{PATH}")
+foreach(path "/does_not_exist" "/PackageRoot" "")
+  unset(Resolved_FOUND CACHE)
+  set(Resolved_DIR "")
+  set(ENV{PATH} "${CMAKE_CURRENT_SOURCE_DIR}${path}")
+  find_package(Resolved QUIET)
+  message(STATUS "Resolved_FOUND='${Resolved_FOUND}'")
+endforeach()
+
+set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH OFF)
+foreach(path "/does_not_exist" "/PackageRoot" "")
+  unset(Resolved_FOUND CACHE)
+  set(Resolved_DIR "")
+  set(ENV{PATH} "${CMAKE_CURRENT_SOURCE_DIR}${path}")
+  find_package(Resolved QUIET)
+  message(STATUS "Resolved_FOUND='${Resolved_FOUND}'")
+endforeach()
+
+set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH ON)
+foreach(path "/does_not_exist" "/PackageRoot" "")
+  unset(Resolved_FOUND CACHE)
+  set(Resolved_DIR "")
+  set(ENV{PATH} "${CMAKE_CURRENT_SOURCE_DIR}${path}")
+  find_package(Resolved NO_SYSTEM_ENVIRONMENT_PATH QUIET)
+  message(STATUS "Resolved_FOUND='${Resolved_FOUND}'")
+endforeach()
+set(ENV{PATH} "${ENV_PATH}")

+ 9 - 0
Tests/RunCMake/find_package/FromPrefixPath-stdout.txt

@@ -0,0 +1,9 @@
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='1'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'
+-- Resolved_FOUND='0'

+ 29 - 0
Tests/RunCMake/find_package/FromPrefixPath.cmake

@@ -0,0 +1,29 @@
+set(ENV_PATH "$ENV{PATH}")
+set(ENV{PATH} "")
+foreach(path "/does_not_exist" "/PackageRoot" "")
+  unset(Resolved_FOUND CACHE)
+  set(Resolved_DIR "")
+  set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}${path}")
+  find_package(Resolved QUIET)
+  message(STATUS "Resolved_FOUND='${Resolved_FOUND}'")
+endforeach()
+
+set(CMAKE_FIND_USE_CMAKE_PATH OFF)
+set(CMAKE_PREFIX_PATH )
+foreach(path "/does_not_exist" "/PackageRoot" "")
+  unset(Resolved_FOUND CACHE)
+  set(Resolved_DIR "")
+  set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}${path}")
+  find_package(Resolved QUIET)
+  message(STATUS "Resolved_FOUND='${Resolved_FOUND}'")
+endforeach()
+
+set(CMAKE_FIND_USE_CMAKE_PATH ON)
+foreach(path "/does_not_exist" "/PackageRoot" "")
+  unset(Resolved_FOUND CACHE)
+  set(Resolved_DIR "")
+  set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}${path}")
+  find_package(Resolved NO_CMAKE_PATH QUIET)
+  message(STATUS "Resolved_FOUND='${Resolved_FOUND}'")
+endforeach()
+set(ENV{PATH} "${ENV_PATH}")

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

@@ -3,6 +3,8 @@ include(RunCMake)
 run_cmake(CMP0074-WARN)
 run_cmake(CMP0074-WARN)
 run_cmake(CMP0074-OLD)
 run_cmake(CMP0074-OLD)
 run_cmake(ComponentRequiredAndOptional)
 run_cmake(ComponentRequiredAndOptional)
+run_cmake(FromPATHEnv)
+run_cmake(FromPrefixPath)
 run_cmake(MissingNormal)
 run_cmake(MissingNormal)
 run_cmake(MissingNormalRequired)
 run_cmake(MissingNormalRequired)
 run_cmake(MissingNormalVersion)
 run_cmake(MissingNormalVersion)