Merge remote-tracking branch 'origin/9.0' into qds/dev

Change-Id: I5f72661f1fc54ff861e2cbbaa4cb32f867924c3b
This commit is contained in:
Tim Jenssen
2022-11-03 14:09:36 +01:00
206 changed files with 2163 additions and 1328 deletions

View File

@@ -197,19 +197,27 @@ static CMakeConfig configurationFromPresetProbe(
const CMakeConfig cache = configurePreset.cacheVariables
? configurePreset.cacheVariables.value()
: CMakeConfig();
const FilePath cmakeMakeProgram = cache.filePathValueOf(QByteArray("CMAKE_MAKE_PROGRAM"));
const FilePath toolchainFile = cache.filePathValueOf(QByteArray("CMAKE_TOOLCHAIN_FILE"));
const QString prefixPath = cache.stringValueOf(QByteArray("CMAKE_PREFIX_PATH"));
const QString findRootPath = cache.stringValueOf(QByteArray("CMAKE_FIND_ROOT_PATH"));
const QString qtHostPath = cache.stringValueOf(QByteArray("QT_HOST_PATH"));
auto expandCacheValue =
[configurePreset, env, importPath, cache](const QString &key) -> QString {
QString result = cache.stringValueOf(key.toUtf8());
CMakePresets::Macros::expand(configurePreset, env, importPath, result);
return result;
};
const QString cmakeMakeProgram = expandCacheValue("CMAKE_MAKE_PROGRAM");
const QString toolchainFile = expandCacheValue("CMAKE_TOOLCHAIN_FILE");
const QString prefixPath = expandCacheValue("CMAKE_PREFIX_PATH");
const QString findRootPath = expandCacheValue("CMAKE_FIND_ROOT_PATH");
const QString qtHostPath = expandCacheValue("QT_HOST_PATH");
if (!cmakeMakeProgram.isEmpty()) {
args.emplace_back(
QStringLiteral("-DCMAKE_MAKE_PROGRAM=%1").arg(cmakeMakeProgram.toString()));
QStringLiteral("-DCMAKE_MAKE_PROGRAM=%1").arg(cmakeMakeProgram));
}
if (!toolchainFile.isEmpty()) {
args.emplace_back(
QStringLiteral("-DCMAKE_TOOLCHAIN_FILE=%1").arg(toolchainFile.toString()));
QStringLiteral("-DCMAKE_TOOLCHAIN_FILE=%1").arg(toolchainFile));
}
if (!prefixPath.isEmpty()) {
args.emplace_back(QStringLiteral("-DCMAKE_PREFIX_PATH=%1").arg(prefixPath));
@@ -412,6 +420,27 @@ static QVector<ToolChainDescription> extractToolChainsFromCache(const CMakeConfi
return result;
}
static QString extractVisualStudioPlatformFromConfig(const CMakeConfig &config)
{
const QString cmakeGenerator = config.stringValueOf(QByteArray("CMAKE_GENERATOR"));
QString platform;
if (cmakeGenerator.contains("Visual Studio")) {
const FilePath linker = config.filePathValueOf("CMAKE_LINKER");
const QString toolsDir = linker.parentDir().fileName();
if (toolsDir.compare("x64", Qt::CaseInsensitive) == 0) {
platform = "x64";
} else if (toolsDir.compare("x86", Qt::CaseInsensitive) == 0) {
platform = "Win32";
} else if (toolsDir.compare("arm64", Qt::CaseInsensitive) == 0) {
platform = "ARM64";
} else if (toolsDir.compare("arm", Qt::CaseInsensitive) == 0) {
platform = "ARM";
}
}
return platform;
}
QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
QString *warningMessage) const
{
@@ -476,6 +505,17 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
QApplication::setOverrideCursor(Qt::WaitCursor);
config = configurationFromPresetProbe(importPath, configurePreset);
QApplication::restoreOverrideCursor();
if (!configurePreset.generator) {
QString cmakeGenerator = config.stringValueOf(QByteArray("CMAKE_GENERATOR"));
configurePreset.generator = cmakeGenerator;
data->generator = cmakeGenerator;
data->platform = extractVisualStudioPlatformFromConfig(config);
if (!data->platform.isEmpty()) {
configurePreset.architecture = PresetsDetails::ValueStrategyPair();
configurePreset.architecture->value = data->platform;
}
}
} else {
config = cache;
config << CMakeConfigItem("CMAKE_COMMAND",
@@ -566,6 +606,8 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
data->generator = config.stringValueOf("CMAKE_GENERATOR");
data->extraGenerator = config.stringValueOf("CMAKE_EXTRA_GENERATOR");
data->platform = config.stringValueOf("CMAKE_GENERATOR_PLATFORM");
if (data->platform.isEmpty())
data->platform = extractVisualStudioPlatformFromConfig(config);
data->toolset = config.stringValueOf("CMAKE_GENERATOR_TOOLSET");
data->sysroot = config.filePathValueOf("CMAKE_SYSROOT");
@@ -618,22 +660,24 @@ bool CMakeProjectImporter::matchKit(void *directoryData, const Kit *k) const
if (data->qt.qt && QtSupport::QtKitAspect::qtVersionId(k) != data->qt.qt->uniqueId())
return false;
const QList<Id> allLanguages = ToolChainManager::allLanguages();
for (const ToolChainDescription &tcd : data->toolChains) {
if (!Utils::contains(allLanguages, [&tcd](const Id& language) {return language == tcd.language;}))
continue;
ToolChain *tc = ToolChainKitAspect::toolChain(k, tcd.language);
if (!tc || !tc->matchesCompilerCommand(tcd.compilerPath)) {
return false;
}
}
bool haveCMakePreset = false;
if (!data->cmakePreset.isEmpty()) {
auto presetConfigItem = CMakeConfigurationKitAspect::cmakePresetConfigItem(k);
if (data->cmakePreset != presetConfigItem.expandedValue(k))
return false;
ensureBuildDirectory(*data, k);
haveCMakePreset = true;
}
const QList<Id> allLanguages = ToolChainManager::allLanguages();
for (const ToolChainDescription &tcd : data->toolChains) {
if (!Utils::contains(allLanguages, [&tcd](const Id& language) {return language == tcd.language;}))
continue;
ToolChain *tc = ToolChainKitAspect::toolChain(k, tcd.language);
if ((!tc || !tc->matchesCompilerCommand(tcd.compilerPath)) && !haveCMakePreset) {
return false;
}
}
qCDebug(cmInputLog) << k->displayName()

View File

@@ -462,6 +462,7 @@ void CMakeToolItemConfigWidget::onBinaryPathEditingFinished()
{
updateQchFilePath();
store();
load(m_model->cmakeToolItem(m_id));
}
void CMakeToolItemConfigWidget::updateQchFilePath()

View File

@@ -295,6 +295,9 @@ CMakeTool::Version CMakeTool::version() const
QString CMakeTool::versionDisplay() const
{
if (m_executable.isEmpty())
return {};
if (!isValid())
return Tr::tr("Version not parseable");

View File

@@ -99,22 +99,17 @@ static QString expandMacroEnv(const QString &macroPrefix,
return result;
}
static QHash<QString, QString> getEnvCombined(
const std::optional<QHash<QString, QString>> &optPresetEnv, const Utils::Environment &env)
static Utils::Environment getEnvCombined(const std::optional<Utils::Environment> &optPresetEnv,
const Utils::Environment &env)
{
QHash<QString, QString> result;
for (auto it = env.constBegin(); it != env.constEnd(); ++it) {
if (it.value().second)
result.insert(it.key().name, it.value().first);
}
Utils::Environment result = env;
if (!optPresetEnv)
return result;
QHash<QString, QString> presetEnv = optPresetEnv.value();
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
result[it->first] = it->second;
Utils::Environment presetEnv = optPresetEnv.value();
for (auto it = presetEnv.constBegin(); it != presetEnv.constEnd(); ++it) {
result.set(it.key().name, it.value().first);
}
return result;
@@ -125,10 +120,10 @@ void expand(const PresetType &preset,
Utils::Environment &env,
const Utils::FilePath &sourceDirectory)
{
const QHash<QString, QString> presetEnv = getEnvCombined(preset.environment, env);
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
const QString key = it->first;
QString value = it->second;
const Utils::Environment presetEnv = getEnvCombined(preset.environment, env);
for (auto it = presetEnv.constBegin(); it != presetEnv.constEnd(); ++it) {
const QString key = it.key().name;
QString value = it.value().first;
expandAllButEnv(preset, sourceDirectory, value);
value = expandMacroEnv("env", value, [presetEnv](const QString &macroName) {
@@ -161,15 +156,15 @@ void expand(const PresetType &preset,
Utils::EnvironmentItems &envItems,
const Utils::FilePath &sourceDirectory)
{
const QHash<QString, QString> presetEnv = preset.environment ? preset.environment.value()
: QHash<QString, QString>();
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
const QString key = it->first;
QString value = it->second;
const Utils::Environment presetEnv = preset.environment ? preset.environment.value()
: Utils::Environment();
for (auto it = presetEnv.constBegin(); it != presetEnv.constEnd(); ++it) {
const QString key = it.key().name;
QString value = it.value().first;
expandAllButEnv(preset, sourceDirectory, value);
value = expandMacroEnv("env", value, [presetEnv](const QString &macroName) {
if (presetEnv.contains(macroName))
if (presetEnv.hasKey(macroName))
return presetEnv.value(macroName);
return QString("${%1}").arg(macroName);
});
@@ -199,7 +194,7 @@ void expand(const PresetType &preset,
{
expandAllButEnv(preset, sourceDirectory, value);
const QHash<QString, QString> presetEnv = getEnvCombined(preset.environment, env);
const Utils::Environment presetEnv = getEnvCombined(preset.environment, env);
value = expandMacroEnv("env", value, [presetEnv](const QString &macroName) {
return presetEnv.value(macroName);
});
@@ -225,7 +220,7 @@ void updateToolchainFile(
Utils::FilePath toolchainFile = Utils::FilePath::fromString(toolchainFileName);
if (toolchainFile.isRelativePath()) {
for (const auto &path : {sourceDirectory, buildDirectory}) {
Utils::FilePath probePath = toolchainFile.resolvePath(path);
Utils::FilePath probePath = path.resolvePath(toolchainFile);
if (probePath.exists() && probePath != path) {
toolchainFile = probePath;
break;
@@ -236,6 +231,8 @@ void updateToolchainFile(
if (!toolchainFile.exists())
return;
const QString toolchainFileString = toolchainFile.cleanPath().toString();
// toolchainFile takes precedence to CMAKE_TOOLCHAIN_FILE
CMakeConfig cache = configurePreset.cacheVariables ? configurePreset.cacheVariables.value()
: CMakeConfig();
@@ -244,11 +241,11 @@ void updateToolchainFile(
return item.key == "CMAKE_TOOLCHAIN_FILE";
});
if (it != cache.end())
it->value = toolchainFile.toString().toUtf8();
it->value = toolchainFileString.toUtf8();
else
cache << CMakeConfigItem("CMAKE_TOOLCHAIN_FILE",
CMakeConfigItem::FILEPATH,
toolchainFile.toString().toUtf8());
toolchainFileString.toUtf8());
configurePreset.cacheVariables = cache;
}

View File

@@ -208,10 +208,10 @@ bool parseConfigurePresets(const QJsonValue &jsonValue,
const QJsonObject environmentObj = object.value("environment").toObject();
for (const QString &envKey : environmentObj.keys()) {
if (!preset.environment)
preset.environment = QHash<QString, QString>();
preset.environment = Utils::Environment();
QJsonValue envValue = environmentObj.value(envKey);
preset.environment.value().insert(envKey, envValue.toString());
preset.environment.value().set(envKey, envValue.toString());
}
const QJsonObject warningsObj = object.value("warnings").toObject();
@@ -335,10 +335,10 @@ bool parseBuildPresets(const QJsonValue &jsonValue,
const QJsonObject environmentObj = object.value("environment").toObject();
for (const QString &envKey : environmentObj.keys()) {
if (!preset.environment)
preset.environment = QHash<QString, QString>();
preset.environment = Utils::Environment();
QJsonValue envValue = environmentObj.value(envKey);
preset.environment.value().insert(envKey, envValue.toString());
preset.environment.value().set(envKey, envValue.toString());
}
if (object.contains("configurePreset"))
@@ -441,6 +441,44 @@ bool PresetsParser::parse(const Utils::FilePath &jsonFile, QString &errorMessage
return true;
}
static QHash<QString, QString> merge(const QHash<QString, QString> &first,
const QHash<QString, QString> &second)
{
QHash<QString, QString> result = first;
for (auto it = second.constKeyValueBegin(); it != second.constKeyValueEnd(); ++it) {
result[it->first] = it->second;
}
return result;
}
static Utils::Environment merge(const Utils::Environment &first, const Utils::Environment &second)
{
Utils::Environment result = first;
for (auto it = second.constBegin(); it != second.constEnd(); ++it) {
result.set(it.key().name, it.value().first);
}
return result;
}
static CMakeConfig merge(const CMakeConfig &first, const CMakeConfig &second)
{
return Utils::setUnionMerge<CMakeConfig>(
first,
second,
[](const auto & /*left*/, const auto &right) { return right; },
&CMakeConfigItem::less);
}
static QStringList merge(const QStringList &first, const QStringList &second)
{
return Utils::setUnionMerge<QStringList>(
first,
second,
[](const auto & /*left*/, const auto &right) { return right; });
}
void PresetsDetails::ConfigurePreset::inheritFrom(const ConfigurePreset &other)
{
if (!condition && other.condition && !other.condition.value().isNull())
@@ -449,6 +487,9 @@ void PresetsDetails::ConfigurePreset::inheritFrom(const ConfigurePreset &other)
if (!vendor && other.vendor)
vendor = other.vendor;
if (vendor && other.vendor)
vendor = merge(other.vendor.value(), vendor.value());
if (!generator && other.generator)
generator = other.generator;
@@ -472,9 +513,13 @@ void PresetsDetails::ConfigurePreset::inheritFrom(const ConfigurePreset &other)
if (!cacheVariables && other.cacheVariables)
cacheVariables = other.cacheVariables;
else if (cacheVariables && other.cacheVariables)
cacheVariables = merge(other.cacheVariables.value(), cacheVariables.value());
if (!environment && other.environment)
environment = other.environment;
else if (environment && other.environment)
environment = merge(other.environment.value(), environment.value());
if (!warnings && other.warnings)
warnings = other.warnings;
@@ -494,8 +539,13 @@ void PresetsDetails::BuildPreset::inheritFrom(const BuildPreset &other)
if (!vendor && other.vendor)
vendor = other.vendor;
if (vendor && other.vendor)
vendor = merge(other.vendor.value(), vendor.value());
if (!environment && other.environment)
environment = other.environment;
else if (environment && other.environment)
environment = merge(other.environment.value(), environment.value());
if (!configurePreset && other.configurePreset)
configurePreset = other.configurePreset;
@@ -508,6 +558,8 @@ void PresetsDetails::BuildPreset::inheritFrom(const BuildPreset &other)
if (!targets && other.targets)
targets = other.targets;
else if (targets && other.targets)
targets = merge(other.targets.value(), targets.value());
if (!configuration && other.configuration)
configuration = other.configuration;
@@ -520,6 +572,8 @@ void PresetsDetails::BuildPreset::inheritFrom(const BuildPreset &other)
if (!nativeToolOptions && other.nativeToolOptions)
nativeToolOptions = other.nativeToolOptions;
else if (nativeToolOptions && other.nativeToolOptions)
nativeToolOptions = merge(other.nativeToolOptions.value(), nativeToolOptions.value());
}
bool PresetsDetails::Condition::evaluate() const

View File

@@ -5,6 +5,7 @@
#include "cmakeconfigitem.h"
#include <utils/environment.h>
#include <utils/filepath.h>
#include <QHash>
@@ -103,7 +104,7 @@ public:
std::optional<QString> installDir;
std::optional<QString> cmakeExecutable;
std::optional<CMakeConfig> cacheVariables;
std::optional<QHash<QString, QString>> environment;
std::optional<Utils::Environment> environment;
std::optional<Warnings> warnings;
std::optional<Errors> errors;
std::optional<Debug> debug;
@@ -120,7 +121,7 @@ public:
std::optional<QHash<QString, QString>> vendor;
std::optional<QString> displayName;
std::optional<QString> description;
std::optional<QHash<QString, QString>> environment;
std::optional<Utils::Environment> environment;
std::optional<QString> configurePreset;
std::optional<bool> inheritConfigureEnvironment = true;
std::optional<int> jobs;