CMakePM: Only add paths with dlls to PATH

Skip adding object libraries paths to runtime PATH.
Also add only the paths that contain the dll files.

Fixes: QTCREATORBUG-29662
Change-Id: I58cd9b24c6c079b99ed51ae2ebd315a1aa195f04
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2024-02-28 19:02:26 +01:00
parent 4ca8ad8293
commit 0d8a542b4f

View File

@@ -301,8 +301,24 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t,
continue; continue;
const FilePath buildDir = relativeLibs ? buildDirectory : currentBuildDir; const FilePath buildDir = relativeLibs ? buildDirectory : currentBuildDir;
FilePath tmp = buildDir.resolvePath(part); std::optional<QString> dllName;
if (buildDir.osType() == OsTypeWindows && (f.role == "libraries")) {
// Skip object libraries on Windows. This case can happen with static qml plugins
if (part.endsWith(".obj") || part.endsWith(".o"))
continue;
// Only consider dlls, not static libraries
for (const QString &suffix :
{QString(".lib"), QString(".dll.a"), QString(".a")}) {
if (part.endsWith(suffix) && !dllName)
dllName = FilePath::fromUserInput(
part.chopped(suffix.length()).append(".dll"))
.fileName();
}
}
FilePath tmp = buildDir.resolvePath(part);
if (f.role == "libraries") if (f.role == "libraries")
tmp = tmp.parentDir(); tmp = tmp.parentDir();
@@ -312,19 +328,20 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t,
// "/usr/local/lib" since these are usually in the standard search // "/usr/local/lib" since these are usually in the standard search
// paths. There probably are more, but the naming schemes are arbitrary // paths. There probably are more, but the naming schemes are arbitrary
// so we'd need to ask the linker ("ld --verbose | grep SEARCH_DIR"). // so we'd need to ask the linker ("ld --verbose | grep SEARCH_DIR").
if (buildDir.osType() == OsTypeWindows if (buildDir.osType() != OsTypeWindows
|| !isChildOf(tmp, && !isChildOf(tmp,
{"/lib", {"/lib", "/lib64", "/usr/lib", "/usr/lib64", "/usr/local/lib"}))
"/lib64",
"/usr/lib",
"/usr/lib64",
"/usr/local/lib"})) {
librarySeachPaths.append(tmp); librarySeachPaths.append(tmp);
if (buildDir.osType() == OsTypeWindows && dllName) {
if (tmp.pathAppended(*dllName).exists())
librarySeachPaths.append(tmp);
// Libraries often have their import libs in ../lib and the // Libraries often have their import libs in ../lib and the
// actual dll files in ../bin on windows. Qt is one example of that. // actual dll files in ../bin on windows. Qt is one example of that.
if (tmp.fileName() == "lib" && buildDir.osType() == OsTypeWindows) { if (tmp.fileName() == "lib" && buildDir.osType() == OsTypeWindows) {
const FilePath path = tmp.parentDir().pathAppended("bin"); const FilePath path = tmp.parentDir().pathAppended("bin");
if (path.isDir()) if (path.isDir() && path.pathAppended(*dllName).exists())
librarySeachPaths.append(path); librarySeachPaths.append(path);
} }
} }