From 0d8a542b4f7d8a7b4d27f42ff16d309fba6cbf22 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Wed, 28 Feb 2024 19:02:26 +0100 Subject: [PATCH] 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 --- .../fileapidataextractor.cpp | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp index d573fcf6a68..ad1e600124d 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp @@ -301,8 +301,24 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t, continue; const FilePath buildDir = relativeLibs ? buildDirectory : currentBuildDir; - FilePath tmp = buildDir.resolvePath(part); + std::optional 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") tmp = tmp.parentDir(); @@ -312,19 +328,20 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t, // "/usr/local/lib" since these are usually in the standard search // paths. There probably are more, but the naming schemes are arbitrary // so we'd need to ask the linker ("ld --verbose | grep SEARCH_DIR"). - if (buildDir.osType() == OsTypeWindows - || !isChildOf(tmp, - {"/lib", - "/lib64", - "/usr/lib", - "/usr/lib64", - "/usr/local/lib"})) { + if (buildDir.osType() != OsTypeWindows + && !isChildOf(tmp, + {"/lib", "/lib64", "/usr/lib", "/usr/lib64", "/usr/local/lib"})) 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 // actual dll files in ../bin on windows. Qt is one example of that. if (tmp.fileName() == "lib" && buildDir.osType() == OsTypeWindows) { const FilePath path = tmp.parentDir().pathAppended("bin"); - if (path.isDir()) + if (path.isDir() && path.pathAppended(*dllName).exists()) librarySeachPaths.append(path); } }