CMakePM: Add build artifacts to the PATH env variable

Projects that have dll artifacts need to have the build paths added to
PATH so that the dependent executables would start.

Previously the code checked only if the dlls were present on disk, now
it also checks if the dlls are part of the project's build artifacts.

Fixes: QTCREATORBUG-30644
Change-Id: I924753ffaf0a9720acb70585ccd589abab1b9cc1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Cristian Adam
2024-04-08 13:43:13 +02:00
parent 7bb017677d
commit ac97ab1abf

View File

@@ -209,7 +209,8 @@ static bool isChildOf(const FilePath &path, const FilePaths &prefixes)
static CMakeBuildTarget toBuildTarget(const TargetDetails &t, 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 FilePath currentBuildDir = buildDirectory.resolvePath(t.buildDir); const FilePath currentBuildDir = buildDirectory.resolvePath(t.buildDir);
@@ -341,14 +342,17 @@ static CMakeBuildTarget toBuildTarget(const TargetDetails &t,
librarySeachPaths.append(tmp); librarySeachPaths.append(tmp);
if (buildDir.osType() == OsTypeWindows && dllName) { if (buildDir.osType() == OsTypeWindows && dllName) {
if (tmp.pathAppended(*dllName).exists()) const auto validPath = [&artifacts](const FilePath& path) {
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" && buildDir.osType() == OsTypeWindows) { if (tmp.fileName() == "lib") {
const FilePath path = tmp.parentDir().pathAppended("bin"); const FilePath path = tmp.parentDir().pathAppended("bin");
if (path.isDir() && path.pathAppended(*dllName).exists()) if (path.isDir() && validPath(path.pathAppended(*dllName)))
librarySeachPaths.append(path); librarySeachPaths.append(path);
} }
} }
@@ -367,12 +371,17 @@ static QList<CMakeBuildTarget> generateBuildTargets(const QFuture<void> &cancelF
const FilePath &buildDirectory, const FilePath &buildDirectory,
bool relativeLibs) bool relativeLibs)
{ {
QSet<FilePath> artifacts;
for (const TargetDetails &t : input.targetDetails)
for (const FilePath &p: t.artifacts)
artifacts.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)); result.append(toBuildTarget(t, sourceDirectory, buildDirectory, relativeLibs, artifacts));
} }
return result; return result;
} }