After much investigation and debugging CMake source code I decided that it’s a bug in CMake. The patch
diff --git a/Source/cmRuntimeDependencyArchive.cxx b/Source/cmRuntimeDependencyArchive.cxx
index 2fbf2fa04c..a8f9e05840 100644
--- a/Source/cmRuntimeDependencyArchive.cxx
+++ b/Source/cmRuntimeDependencyArchive.cxx
@@ -187,10 +187,18 @@ bool cmRuntimeDependencyArchive::GetRuntimeDependencies(
return false;
}
}
- return std::all_of(
+ if(!std::all_of(
modules.begin(), modules.end(), [this](std::string const& mod) -> bool {
return this->Linker->ScanDependencies(mod, cmStateEnums::MODULE_LIBRARY);
- });
+ }))
+ {
+ return false;
+ }
+ for (auto const & resolved : ResolvedPaths)
+ {
+ UnresolvedPaths.erase(resolved.first);
+ }
+ return true;
}
void cmRuntimeDependencyArchive::SetError(const std::string& e)
fixed it for me, but it seems that the issue was recently resolved in CMake 3.31 in a different way. Although I think my solution is shorter and more logical and general, it would require additional testing on non-LinuxELF platforms. Alternatively, the unresolved path clean-up step could be put into a cmBinUtilsLinker virtual function if something different needs to be done on different platforms.
For now upgrading CMake should solve my problem.