forked from qt-creator/qt-creator
CMake: Add LD_LIBRARY support
Extract all the information necessary for the "Add build library search path to LD_LIBRARY_PATH" from fileapi and enable the relevant UI in the desktop run configuration. This allows to remove a workaround introduced for QTCREATORBUG-19354. Note that this is only supported by fileapi at this time. Task-number: QTCREATORBUG-23464 Change-Id: I390d26ed8cd559bd7ff8c2701cd3b1cb8e764339 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -538,6 +538,14 @@ CMakeBuildConfiguration *CMakeBuildSystem::cmakeBuildConfiguration() const
|
|||||||
return m_buildConfiguration;
|
return m_buildConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Utils::FilePaths librarySearchPaths(const CMakeBuildSystem *bs, const QString &buildKey)
|
||||||
|
{
|
||||||
|
const CMakeBuildTarget cmakeBuildTarget
|
||||||
|
= Utils::findOrDefault(bs->buildTargets(), Utils::equal(&CMakeBuildTarget::title, buildKey));
|
||||||
|
|
||||||
|
return cmakeBuildTarget.libraryDirectories;
|
||||||
|
}
|
||||||
|
|
||||||
const QList<BuildTargetInfo> CMakeBuildSystem::appTargets() const
|
const QList<BuildTargetInfo> CMakeBuildSystem::appTargets() const
|
||||||
{
|
{
|
||||||
QList<BuildTargetInfo> appTargetList;
|
QList<BuildTargetInfo> appTargetList;
|
||||||
@@ -548,20 +556,21 @@ const QList<BuildTargetInfo> CMakeBuildSystem::appTargets() const
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ct.targetType == ExecutableType || (forAndroid && ct.targetType == DynamicLibraryType)) {
|
if (ct.targetType == ExecutableType || (forAndroid && ct.targetType == DynamicLibraryType)) {
|
||||||
|
const QString buildKey = ct.title;
|
||||||
|
|
||||||
BuildTargetInfo bti;
|
BuildTargetInfo bti;
|
||||||
bti.displayName = ct.title;
|
bti.displayName = ct.title;
|
||||||
bti.targetFilePath = ct.executable;
|
bti.targetFilePath = ct.executable;
|
||||||
bti.projectFilePath = ct.sourceDirectory.stringAppended("/");
|
bti.projectFilePath = ct.sourceDirectory.stringAppended("/");
|
||||||
bti.workingDirectory = ct.workingDirectory;
|
bti.workingDirectory = ct.workingDirectory;
|
||||||
bti.buildKey = ct.title;
|
bti.buildKey = buildKey;
|
||||||
bti.usesTerminal = !ct.linksToQtGui;
|
bti.usesTerminal = !ct.linksToQtGui;
|
||||||
|
|
||||||
// Workaround for QTCREATORBUG-19354:
|
// Workaround for QTCREATORBUG-19354:
|
||||||
bti.runEnvModifier = [this](Environment &env, bool) {
|
bti.runEnvModifier = [this, buildKey](Environment &env, bool enabled) {
|
||||||
if (HostOsInfo::isWindowsHost()) {
|
if (enabled) {
|
||||||
const Kit *k = target()->kit();
|
const Utils::FilePaths paths = librarySearchPaths(this, buildKey);
|
||||||
if (const QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(k))
|
env.prependOrSetLibrarySearchPaths(Utils::transform(paths, &FilePath::toString));
|
||||||
env.prependOrSetPath(qt->binPath().toString());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -57,6 +57,7 @@ public:
|
|||||||
Utils::FilePath workingDirectory;
|
Utils::FilePath workingDirectory;
|
||||||
Utils::FilePath sourceDirectory;
|
Utils::FilePath sourceDirectory;
|
||||||
Utils::FilePath makeCommand;
|
Utils::FilePath makeCommand;
|
||||||
|
Utils::FilePaths libraryDirectories;
|
||||||
|
|
||||||
Backtrace backtrace;
|
Backtrace backtrace;
|
||||||
|
|
||||||
|
@@ -147,6 +147,7 @@ PreprocessedData preprocess(FileApiData &data,
|
|||||||
|
|
||||||
// Simplify to only one configuration:
|
// Simplify to only one configuration:
|
||||||
result.codemodel = extractConfiguration(data.codemodel, errorMessage);
|
result.codemodel = extractConfiguration(data.codemodel, errorMessage);
|
||||||
|
|
||||||
if (!errorMessage.isEmpty()) {
|
if (!errorMessage.isEmpty()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -208,6 +209,8 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
|
|||||||
|
|
||||||
const QList<CMakeBuildTarget> result = transform<QList>(
|
const QList<CMakeBuildTarget> result = transform<QList>(
|
||||||
input.targetDetails, [&sourceDir, &buildDir](const TargetDetails &t) -> CMakeBuildTarget {
|
input.targetDetails, [&sourceDir, &buildDir](const TargetDetails &t) -> CMakeBuildTarget {
|
||||||
|
const auto currentBuildDir = QDir(buildDir.absoluteFilePath(t.buildDir.toString()));
|
||||||
|
|
||||||
CMakeBuildTarget ct;
|
CMakeBuildTarget ct;
|
||||||
ct.title = t.name;
|
ct.title = t.name;
|
||||||
ct.executable = t.artifacts.isEmpty()
|
ct.executable = t.artifacts.isEmpty()
|
||||||
@@ -226,9 +229,9 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
|
|||||||
else
|
else
|
||||||
type = UtilityType;
|
type = UtilityType;
|
||||||
ct.targetType = type;
|
ct.targetType = type;
|
||||||
ct.workingDirectory = ct.executable.isEmpty() ? FilePath::fromString(
|
ct.workingDirectory = ct.executable.isEmpty()
|
||||||
buildDir.absoluteFilePath(t.buildDir.toString()))
|
? FilePath::fromString(currentBuildDir.absolutePath())
|
||||||
: ct.executable.parentDir();
|
: ct.executable.parentDir();
|
||||||
ct.sourceDirectory = FilePath::fromString(
|
ct.sourceDirectory = FilePath::fromString(
|
||||||
QDir::cleanPath(sourceDir.absoluteFilePath(t.sourceDir.toString())));
|
QDir::cleanPath(sourceDir.absoluteFilePath(t.sourceDir.toString())));
|
||||||
|
|
||||||
@@ -258,15 +261,38 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Is this a terminal application?
|
// Is this a terminal application?
|
||||||
|
Utils::FilePaths librarySeachPaths;
|
||||||
if (ct.targetType == ExecutableType && t.link && t.link.value().language == "CXX") {
|
if (ct.targetType == ExecutableType && t.link && t.link.value().language == "CXX") {
|
||||||
for (const FragmentInfo &f : t.link.value().fragments) {
|
for (const FragmentInfo &f : t.link.value().fragments) {
|
||||||
if (f.role != "libraries")
|
FilePath tmp;
|
||||||
continue;
|
// Some projects abuse linking to libraries to pass random flags to the linker!
|
||||||
if (f.fragment.contains("QtGui") || f.fragment.contains("Qt5Gui")
|
if (f.role != "flags"
|
||||||
|| f.fragment.contains("Qt6Gui"))
|
&& !(f.fragment.startsWith("-") || f.fragment.contains(" -"))) {
|
||||||
ct.linksToQtGui = true;
|
tmp = FilePath::fromString(currentBuildDir.absoluteFilePath(
|
||||||
|
QDir::fromNativeSeparators(f.fragment)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f.role == "libraries") {
|
||||||
|
tmp = tmp.parentDir();
|
||||||
|
|
||||||
|
if (f.fragment.contains("QtGui") || f.fragment.contains("Qt5Gui")
|
||||||
|
|| f.fragment.contains("Qt6Gui"))
|
||||||
|
ct.linksToQtGui = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tmp.isEmpty()) {
|
||||||
|
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");
|
||||||
|
|
||||||
|
librarySeachPaths.append(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ct.libraryDirectories = filteredUnique(librarySeachPaths);
|
||||||
|
|
||||||
return ct;
|
return ct;
|
||||||
});
|
});
|
||||||
|
@@ -80,9 +80,6 @@ DesktopRunConfiguration::DesktopRunConfiguration(Target *target, Core::Id id, Ki
|
|||||||
|
|
||||||
setUpdater([this] { updateTargetInformation(); });
|
setUpdater([this] { updateTargetInformation(); });
|
||||||
|
|
||||||
if (m_kind == CMake)
|
|
||||||
libAspect->setVisible(false);
|
|
||||||
|
|
||||||
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
|
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user