summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/find_package
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-10-20 11:26:25 (GMT)
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-10-20 16:50:41 (GMT)
commit91ec6eee58cdde3ad7994b5c7f96994427e65b68 (patch)
tree54da9829389349ecbf36a9fbb29e986334bce861 /Tests/RunCMake/find_package
parent9be4c7f0c426c1445e48165f13ae2d31fa1f2940 (diff)
downloadCMake-91ec6eee58cdde3ad7994b5c7f96994427e65b68.zip
CMake-91ec6eee58cdde3ad7994b5c7f96994427e65b68.tar.gz
CMake-91ec6eee58cdde3ad7994b5c7f96994427e65b68.tar.bz2
find_package: Don't reroot prefix that is equal to a root path
When both CMAKE_FIND_ROOT_PATH and CMAKE_PREFIX_PATH are set to /opt/my_device_sysroot, cmFindCommon::RerootPaths would only look for packages in /opt/my_device_sysroot/opt/my_device_sysroot but would not try to look in /opt/my_device_sysroot. Make sure to not reroot the prefix path in such a case. Fixes: #21937
Diffstat (limited to 'Tests/RunCMake/find_package')
-rw-r--r--Tests/RunCMake/find_package/FindRootPathAndPrefixPathAreEqual.cmake16
-rw-r--r--Tests/RunCMake/find_package/FindRootPathAndPrefixPathAreEqual/lib/cmake/Foo/FooConfig.cmake0
-rw-r--r--Tests/RunCMake/find_package/RunCMakeTest.cmake1
3 files changed, 17 insertions, 0 deletions
diff --git a/Tests/RunCMake/find_package/FindRootPathAndPrefixPathAreEqual.cmake b/Tests/RunCMake/find_package/FindRootPathAndPrefixPathAreEqual.cmake
new file mode 100644
index 0000000..2994fc2
--- /dev/null
+++ b/Tests/RunCMake/find_package/FindRootPathAndPrefixPathAreEqual.cmake
@@ -0,0 +1,16 @@
+set(root "${CMAKE_CURRENT_SOURCE_DIR}/FindRootPathAndPrefixPathAreEqual")
+set(CMAKE_FIND_ROOT_PATH "${root}")
+set(CMAKE_PREFIX_PATH "${root}")
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "ONLY")
+
+find_package(Foo
+ REQUIRED
+ CONFIG
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_SYSTEM_ENVIRONMENT_PATH
+ # Important because CMAKE_SYSTEM_PREFIX_PATH might contain "/" as a prefix
+ # And when "/" is rerooted onto the root above, the package is found even if
+ # CMAKE_PREFIX_PATH is empty. We want to ensure that we hit
+ # the CMAKE_FIND_ROOT_PATH == CMAKE_PREFIX_PATH code path.
+ NO_CMAKE_SYSTEM_PATH
+ )
diff --git a/Tests/RunCMake/find_package/FindRootPathAndPrefixPathAreEqual/lib/cmake/Foo/FooConfig.cmake b/Tests/RunCMake/find_package/FindRootPathAndPrefixPathAreEqual/lib/cmake/Foo/FooConfig.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/find_package/FindRootPathAndPrefixPathAreEqual/lib/cmake/Foo/FooConfig.cmake
diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake
index b20a889..ad9757d 100644
--- a/Tests/RunCMake/find_package/RunCMakeTest.cmake
+++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake
@@ -25,6 +25,7 @@ run_cmake(PackageRootNestedModule)
run_cmake(PolicyPush)
run_cmake(PolicyPop)
run_cmake(RequiredOptionValuesClash)
+run_cmake(FindRootPathAndPrefixPathAreEqual)
run_cmake(SetFoundFALSE)
run_cmake(WrongVersion)
run_cmake(WrongVersionConfig)