summaryrefslogtreecommitdiff
path: root/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2021-03-05 13:25:32 +0100
committerEike Ziller <eike.ziller@qt.io>2021-03-05 14:53:41 +0000
commit5e1f40a3afbaf829a48bb6fbef342cb9b0615663 (patch)
treeb35a000418d869aea449c735391b0ea0117ba226 /src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
parentfab090907d094d459fda0d4ed0618644584cb9ff (diff)
downloadqt-creator-5e1f40a3afbaf829a48bb6fbef342cb9b0615663.tar.gz
CMake: Don't add standard Linux paths to LD_LIBRARY_PATH
If a project specifically links to a library in a standard path (like /usr/lib/...), we do not need to add that path to LD_LIBRARY_PATH. Actually adding it can be harmful if the build needs to link against some other library in a different version than is available in the system path. Common case is linking the application against a Qt version from the online installer. If /usr/lib/... ends up in the LD_LIBRARY_PATH before the path to the Qt from the online installer, the system Qt is picked up at runtime instead of the Qt from the online installer. Fixes: QTCREATORBUG-25292 Change-Id: Ib080e41f5893fb68e9d65cc9c9f11d1a9a60f485 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Diffstat (limited to 'src/plugins/cmakeprojectmanager/fileapidataextractor.cpp')
-rw-r--r--src/plugins/cmakeprojectmanager/fileapidataextractor.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
index 80ea50c6d0..1474a8da4d 100644
--- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
+++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp
@@ -179,6 +179,14 @@ QVector<FolderNode::LocationInfo> extractBacktraceInformation(const BacktraceInf
return info;
}
+static bool isChildOf(const FilePath &path, const QStringList &prefixes)
+{
+ for (const QString &prefix : prefixes)
+ if (path.isChildOf(FilePath::fromString(prefix)))
+ return true;
+ return false;
+}
+
QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
const FilePath &sourceDirectory,
const FilePath &buildDirectory)
@@ -269,16 +277,28 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
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);
+ if (!tmp.isEmpty() && tmp.isDir()) {
+ // f.role is libraryPath or frameworkPath
+ // On Linux, exclude sub-paths from "/lib(64)", "/usr/lib(64)" and
+ // "/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 (!HostOsInfo::isLinuxHost()
+ || !isChildOf(tmp,
+ {"/lib",
+ "/lib64",
+ "/usr/lib",
+ "/usr/lib64",
+ "/usr/local/lib"})) {
+ 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);
+ }
}
}
}