forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -179,6 +179,14 @@ QVector<FolderNode::LocationInfo> extractBacktraceInformation(const BacktraceInf
|
|||||||
return info;
|
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,
|
QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
|
||||||
const FilePath &sourceDirectory,
|
const FilePath &sourceDirectory,
|
||||||
const FilePath &buildDirectory)
|
const FilePath &buildDirectory)
|
||||||
@@ -269,16 +277,28 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
|
|||||||
if (f.role == "libraries")
|
if (f.role == "libraries")
|
||||||
tmp = tmp.parentDir();
|
tmp = tmp.parentDir();
|
||||||
|
|
||||||
if (!tmp.isEmpty()
|
if (!tmp.isEmpty() && tmp.isDir()) {
|
||||||
&& tmp.isDir()) { // f.role is libraryPath or frameworkPath
|
// f.role is libraryPath or frameworkPath
|
||||||
librarySeachPaths.append(tmp);
|
// On Linux, exclude sub-paths from "/lib(64)", "/usr/lib(64)" and
|
||||||
// Libraries often have their import libs in ../lib and the
|
// "/usr/local/lib" since these are usually in the standard search
|
||||||
// actual dll files in ../bin on windows. Qt is one example of that.
|
// paths. There probably are more, but the naming schemes are arbitrary
|
||||||
if (tmp.fileName() == "lib" && HostOsInfo::isWindowsHost()) {
|
// so we'd need to ask the linker ("ld --verbose | grep SEARCH_DIR").
|
||||||
const FilePath path = tmp.parentDir().pathAppended("bin");
|
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())
|
if (path.isDir())
|
||||||
librarySeachPaths.append(path);
|
librarySeachPaths.append(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user