From 5e1f40a3afbaf829a48bb6fbef342cb9b0615663 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 5 Mar 2021 13:25:32 +0100 Subject: [PATCH] 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 --- .../fileapidataextractor.cpp | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp index 80ea50c6d0c..1474a8da4da 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp @@ -179,6 +179,14 @@ QVector 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 generateBuildTargets(const PreprocessedData &input, const FilePath &sourceDirectory, const FilePath &buildDirectory) @@ -269,16 +277,28 @@ QList 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 (!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); + if (path.isDir()) + librarySeachPaths.append(path); + } } } }