forked from qt-creator/qt-creator
CMakePM: Do not check the existence of dlls for PATH handling
In order to fix QTCREATORBUG-29662 the check of existence of an dll was a prerequisite to add the path to the PATH environment variable. As it turns out this is not an easy thing to do, since the ".lib" file name can be different than the ".dll" file name. Also for MinGW you can have ".dll.a" or ".a" as library filename extensions. You can also have a "lib" as prefix for the library filename. Amends0d8a542b4f
Amends8713919f31
Amendsac97ab1abf
Task-number: QTCREATORBUG-29662 Fixes: QTCREATORBUG-30827 Fixes: QTCREATORBUG-30932 Change-Id: I90afad825d43fd4f801c2aac20ed98f013861152 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -210,9 +210,11 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t,
|
|||||||
const FilePath &sourceDirectory,
|
const FilePath &sourceDirectory,
|
||||||
const FilePath &buildDirectory,
|
const FilePath &buildDirectory,
|
||||||
bool relativeLibs,
|
bool relativeLibs,
|
||||||
const QSet<FilePath> &artifacts)
|
const QSet<FilePath> &sharedLibraryArtifacts)
|
||||||
{
|
{
|
||||||
const FilePath currentBuildDir = buildDirectory.resolvePath(t.buildDir);
|
const FilePath currentBuildDir = buildDirectory.resolvePath(t.buildDir);
|
||||||
|
const QSet<FilePath> sharedLibraryArtifactsPaths
|
||||||
|
= transform(sharedLibraryArtifacts, &FilePath::parentDir);
|
||||||
|
|
||||||
CMakeBuildTarget ct;
|
CMakeBuildTarget ct;
|
||||||
ct.title = t.name;
|
ct.title = t.name;
|
||||||
@@ -306,7 +308,6 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t,
|
|||||||
if (f.role == "libraries")
|
if (f.role == "libraries")
|
||||||
tmp = tmp.parentDir();
|
tmp = tmp.parentDir();
|
||||||
|
|
||||||
std::optional<QString> dllName;
|
|
||||||
if (buildDir.osType() == OsTypeWindows && (f.role == "libraries")) {
|
if (buildDir.osType() == OsTypeWindows && (f.role == "libraries")) {
|
||||||
const auto partAsFilePath = FilePath::fromUserInput(part);
|
const auto partAsFilePath = FilePath::fromUserInput(part);
|
||||||
part = partAsFilePath.fileName();
|
part = partAsFilePath.fileName();
|
||||||
@@ -314,24 +315,6 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t,
|
|||||||
// Skip object libraries on Windows. This case can happen with static qml plugins
|
// Skip object libraries on Windows. This case can happen with static qml plugins
|
||||||
if (part.endsWith(".obj") || part.endsWith(".o"))
|
if (part.endsWith(".obj") || part.endsWith(".o"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Only consider dlls, not static libraries
|
|
||||||
for (const QString &suffix :
|
|
||||||
{QString(".lib"), QString(".dll.a"), QString(".a")}) {
|
|
||||||
if (part.endsWith(suffix) && !dllName)
|
|
||||||
dllName = part.chopped(suffix.length()).append(".dll");
|
|
||||||
}
|
|
||||||
|
|
||||||
// MinGW has libQt6Core.a -> Qt6Core.dll
|
|
||||||
// but libFoo.dll.a was already handled above
|
|
||||||
const QString mingwPrefix("lib");
|
|
||||||
const QString mingwSuffix("a");
|
|
||||||
const QString completeSuffix = partAsFilePath.completeSuffix();
|
|
||||||
if (part.startsWith(mingwPrefix) && completeSuffix == mingwSuffix) {
|
|
||||||
dllName = part.chopped(mingwSuffix.length() + 1/*the '.'*/)
|
|
||||||
.sliced(mingwPrefix.length())
|
|
||||||
.append(".dll");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tmp.isEmpty() && tmp.isDir()) {
|
if (!tmp.isEmpty() && tmp.isDir()) {
|
||||||
@@ -345,18 +328,15 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t,
|
|||||||
{"/lib", "/lib64", "/usr/lib", "/usr/lib64", "/usr/local/lib"}))
|
{"/lib", "/lib64", "/usr/lib", "/usr/lib64", "/usr/local/lib"}))
|
||||||
librarySeachPaths.append(tmp);
|
librarySeachPaths.append(tmp);
|
||||||
|
|
||||||
if (buildDir.osType() == OsTypeWindows && dllName) {
|
if (buildDir.osType() == OsTypeWindows) {
|
||||||
const auto validPath = [&artifacts](const FilePath& path) {
|
if (sharedLibraryArtifactsPaths.contains(tmp))
|
||||||
return path.exists() || artifacts.contains(path);
|
|
||||||
};
|
|
||||||
if (validPath(tmp.pathAppended(*dllName)))
|
|
||||||
librarySeachPaths.append(tmp);
|
librarySeachPaths.append(tmp);
|
||||||
|
|
||||||
// Libraries often have their import libs in ../lib and the
|
// Libraries often have their import libs in ../lib and the
|
||||||
// actual dll files in ../bin on windows. Qt is one example of that.
|
// actual dll files in ../bin on windows. Qt is one example of that.
|
||||||
if (tmp.fileName() == "lib") {
|
if (tmp.fileName() == "lib") {
|
||||||
const FilePath path = tmp.parentDir().pathAppended("bin");
|
const FilePath path = tmp.parentDir().pathAppended("bin");
|
||||||
if (path.isDir() && validPath(path.pathAppended(*dllName)))
|
if (path.isDir())
|
||||||
librarySeachPaths.append(path);
|
librarySeachPaths.append(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -375,17 +355,19 @@ static QList<CMakeBuildTarget> generateBuildTargets(const QFuture<void> &cancelF
|
|||||||
const FilePath &buildDirectory,
|
const FilePath &buildDirectory,
|
||||||
bool relativeLibs)
|
bool relativeLibs)
|
||||||
{
|
{
|
||||||
QSet<FilePath> artifacts;
|
QSet<FilePath> sharedLibraryArtifacts;
|
||||||
for (const TargetDetails &t : input.targetDetails)
|
for (const TargetDetails &t : input.targetDetails)
|
||||||
for (const FilePath &p: t.artifacts)
|
if (t.type == "MODULE_LIBRARY" || t.type == "SHARED_LIBRARY")
|
||||||
artifacts.insert(buildDirectory.resolvePath(p));
|
for (const FilePath &p : t.artifacts)
|
||||||
|
sharedLibraryArtifacts.insert(buildDirectory.resolvePath(p));
|
||||||
|
|
||||||
QList<CMakeBuildTarget> result;
|
QList<CMakeBuildTarget> result;
|
||||||
result.reserve(input.targetDetails.size());
|
result.reserve(input.targetDetails.size());
|
||||||
for (const TargetDetails &t : input.targetDetails) {
|
for (const TargetDetails &t : input.targetDetails) {
|
||||||
if (cancelFuture.isCanceled())
|
if (cancelFuture.isCanceled())
|
||||||
return {};
|
return {};
|
||||||
result.append(toBuildTarget(t, sourceDirectory, buildDirectory, relativeLibs, artifacts));
|
result.append(
|
||||||
|
toBuildTarget(t, sourceDirectory, buildDirectory, relativeLibs, sharedLibraryArtifacts));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user