Bläddra i källkod

find_package: Fix assertion failure on empty sysroots

Previously we crashed if at least one root variable was set to empty and
at least one to non-empty.

Fixes: #26538
Brad King 11 månader sedan
förälder
incheckning
adfb0623cb

+ 4 - 4
Source/cmFindCommon.cxx

@@ -248,19 +248,19 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths,
   // Construct the list of path roots with no trailing slashes.
   cmList roots;
   debugRoot("CMAKE_FIND_ROOT_PATH", rootPath);
-  if (rootPath) {
+  if (cmNonempty(rootPath)) {
     roots.assign(*rootPath);
   }
   debugRoot("CMAKE_SYSROOT_COMPILE", sysrootCompile);
-  if (sysrootCompile) {
+  if (cmNonempty(sysrootCompile)) {
     roots.emplace_back(*sysrootCompile);
   }
   debugRoot("CMAKE_SYSROOT_LINK", sysrootLink);
-  if (sysrootLink) {
+  if (cmNonempty(sysrootLink)) {
     roots.emplace_back(*sysrootLink);
   }
   debugRoot("CMAKE_SYSROOT", sysroot);
-  if (sysroot) {
+  if (cmNonempty(sysroot)) {
     roots.emplace_back(*sysroot);
   }
   for (auto& r : roots) {

+ 10 - 0
Tests/RunCMake/find_package/EmptyRoots.cmake

@@ -0,0 +1,10 @@
+set(vars CMAKE_SYSROOT CMAKE_SYSROOT_COMPILE CMAKE_SYSROOT_LINK CMAKE_FIND_ROOT_PATH)
+foreach(v IN LISTS vars)
+  set("${v}" "")
+endforeach()
+foreach(v IN LISTS vars)
+  block()
+    set("${v}" "/dummy")
+    find_package(dummy CONFIG NO_DEFAULT_PATH PATHS "/")
+  endblock()
+endforeach()

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

@@ -3,6 +3,7 @@ include(RunCMake)
 run_cmake(CMP0074-WARN)
 run_cmake(CMP0074-OLD)
 run_cmake(ComponentRequiredAndOptional)
+run_cmake(EmptyRoots)
 run_cmake(FromPATHEnv)
 run_cmake_with_options(FromPATHEnvDebugPkg --debug-find-pkg=Resolved)
 run_cmake(FromPrefixPath)