install(EXPORT): Use UNWIND_INCLUDE in exported find_dependency()

This commit is contained in:
Vito Gamberini
2025-07-24 14:10:31 -04:00
parent bba78d656e
commit 92b403fc62
9 changed files with 78 additions and 27 deletions
+14 -3
View File
@@ -451,16 +451,27 @@ void cmExportCMakeConfigGenerator::GenerateFindDependencyCalls(
return lhs.second.FindPackageIndex < rhs.second.FindPackageIndex;
});
// Unwinding is only valid in a find_package() context
os << "if(DEFINED CMAKE_FIND_PACKAGE_NAME)\n"
<< " set(_cmake_unwind_arg UNWIND_INCLUDE)\n"
<< "endif()\n\n";
for (auto const& it : packageDependenciesSorted) {
if (it.second.Enabled == cmExportSet::PackageDependencyExportEnabled::On) {
os << "find_dependency(" << it.first;
os << "__find_dependency_no_return(" << it.first;
for (auto const& arg : it.second.ExtraArguments) {
os << ' ' << cmOutputConverter::EscapeForCMake(arg);
}
os << ")\n";
os << " ${_cmake_unwind_arg})\n";
os << "if(NOT " << it.first << "_FOUND)\n"
<< " unset(_cmake_unwind_arg)\n"
<< " cmake_policy(POP)\n"
<< " return()\n"
<< "endif()\n\n";
}
}
os << "\n\n";
os << "unset(_cmake_unwind_arg)\n\n\n";
}
void cmExportCMakeConfigGenerator::GenerateMissingTargetsCheckCode(