summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2020-06-08 16:22:04 +0200
committerTobias Hunger <tobias.hunger@qt.io>2020-06-10 09:42:45 +0000
commit443f2bae50514124c444603418c6d8738e8b88ef (patch)
treefcf0a37ee8d118dc48bf1f1e4ff3427d8a94b0a7
parent91a98c133041227cebe8e1fc4afb4dfb13a387f2 (diff)
downloadqt-creator-443f2bae50514124c444603418c6d8738e8b88ef.tar.gz
CMake: Filter out non-directories from LD_LIBRARY_PATH/PATH
Task-number: QTCREATORBUG-23997 Change-Id: I4b92cd484305614b30c70bbdbd8815b0d85b7d98 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r--src/plugins/cmakeprojectmanager/fileapidataextractor.cpp69
1 files changed, 41 insertions, 28 deletions
diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
index 79891a8b5b..2cd3782e75 100644
--- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
+++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
@@ -260,39 +260,52 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
extractBacktraceInformation(t.backtraceGraph, sourceDir, id.backtrace, 500));
}
- // Is this a terminal application?
- Utils::FilePaths librarySeachPaths;
- if (ct.targetType == ExecutableType && t.link && t.link.value().language == "CXX") {
+ if (ct.targetType == ExecutableType) {
+ Utils::FilePaths librarySeachPaths;
+ // Is this a GUI application?
+ ct.linksToQtGui = Utils::contains(t.link.value().fragments,
+ [](const FragmentInfo &f) {
+ return f.role == "libraries"
+ && (f.fragment.contains("QtGui")
+ || f.fragment.contains("Qt5Gui")
+ || f.fragment.contains("Qt6Gui"));
+ });
+
+ // Extract library directories for executables:
for (const FragmentInfo &f : t.link.value().fragments) {
- FilePath tmp;
- // Some projects abuse linking to libraries to pass random flags to the linker!
- if (f.role != "flags"
- && !(f.fragment.startsWith("-") || f.fragment.contains(" -"))) {
- tmp = FilePath::fromString(currentBuildDir.absoluteFilePath(
- QDir::fromNativeSeparators(f.fragment)));
- }
-
- if (f.role == "libraries") {
- tmp = tmp.parentDir();
-
- if (f.fragment.contains("QtGui") || f.fragment.contains("Qt5Gui")
- || f.fragment.contains("Qt6Gui"))
- ct.linksToQtGui = true;
- }
-
- if (!tmp.isEmpty()) {
- 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" && HostOsInfo::isWindowsHost()) {
- const FilePath path = tmp.parentDir().pathAppended("bin");
-
- librarySeachPaths.append(path);
+ if (f.role == "flags") // ignore all flags fragments
+ continue;
+
+ // CMake sometimes mixes several shell-escaped pieces into one fragment. Disentangle that again:
+ const QStringList parts = QtcProcess::splitArgs(f.fragment);
+ for (const QString part : parts) {
+ // Some projects abuse linking to libraries to pass random flags to the linker, so ignore
+ // flags mixed into a fragment
+ if (part.startsWith("-"))
+ continue;
+
+ FilePath tmp = FilePath::fromString(
+ currentBuildDir.absoluteFilePath(QDir::fromNativeSeparators(part)));
+
+ if (f.role == "libraries")
+ tmp = tmp.parentDir();
+
+ if (!tmp.isEmpty()
+ && tmp.isDir()) { // f.role is libraryPath or frameworkPath
+ 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" && HostOsInfo::isWindowsHost()) {
+ const FilePath path = tmp.parentDir().pathAppended("bin");
+
+ if (path.isDir())
+ librarySeachPaths.append(path);
+ }
}
}
}
+ ct.libraryDirectories = filteredUnique(librarySeachPaths);
}
- ct.libraryDirectories = filteredUnique(librarySeachPaths);
return ct;
});