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
This commit is contained in:
Brad King
2024-12-18 09:37:59 -05:00
parent 1c6cecdce9
commit adfb0623cb
3 changed files with 15 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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()

View File

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