Commit 5e623ddf authored by Tobias Hunger's avatar Tobias Hunger

CMake: Improve handling of cmake configuration in kits

Use macros. This makes it possible to address the current qt version
and toolchain without having to update those values all the time.

This significantly simplifies changing Qt versions and toolchains in
the kit as well as the code itself.

Change-Id: I35128eebdc96fe6175f565b2e9bdaa40862516a7
Task-number: QTCREATORBUG-15830
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent ca805445
......@@ -60,8 +60,8 @@
namespace CMakeProjectManager {
namespace Internal {
static QStringList toArguments(const CMakeConfig &config) {
return Utils::transform(config, [](const CMakeConfigItem &i) -> QString {
static QStringList toArguments(const CMakeConfig &config, const ProjectExplorer::Kit *k) {
return Utils::transform(config, [k](const CMakeConfigItem &i) -> QString {
QString a = QString::fromLatin1("-D");
a.append(QString::fromUtf8(i.key));
switch (i.type) {
......@@ -81,7 +81,7 @@ static QStringList toArguments(const CMakeConfig &config) {
a.append(QLatin1String(":INTERNAL="));
break;
}
a.append(QString::fromUtf8(i.value));
a.append(QString::fromUtf8(k->macroExpander()->expand(i.value)));
return a;
});
......@@ -424,7 +424,7 @@ void BuildDirManager::startCMake(CMakeTool *tool, const QString &generator,
Utils::QtcProcess::addArg(&args, srcDir);
if (!generator.isEmpty())
Utils::QtcProcess::addArg(&args, QString::fromLatin1("-G%1").arg(generator));
Utils::QtcProcess::addArgs(&args, toArguments(config));
Utils::QtcProcess::addArgs(&args, toArguments(config, kit()));
ProjectExplorer::TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
......
......@@ -316,14 +316,12 @@ void CMakeConfigurationKitInformation::fromStringList(Kit *k, const QStringList
QVariant CMakeConfigurationKitInformation::defaultValue(const Kit *k) const
{
Q_UNUSED(k);
// FIXME: Convert preload scripts
CMakeConfig config;
const QtSupport::BaseQtVersion *const version = QtSupport::QtKitInformation::qtVersion(k);
if (version && version->isValid())
config << CMakeConfigItem(CMAKE_QMAKE_KEY, version->qmakeCommand().toString().toUtf8());
const ToolChain *const tc = ToolChainKitInformation::toolChain(k);
if (tc && tc->isValid())
config << CMakeConfigItem(CMAKE_TOOLCHAIN_KEY, tc->compilerCommand().toString().toUtf8());
config << CMakeConfigItem(CMAKE_QMAKE_KEY, "%{Qt:qmakeExecutable}");
config << CMakeConfigItem(CMAKE_TOOLCHAIN_KEY, "%{Compiler:Executable}");
const QStringList tmp
= Utils::transform(config, [](const CMakeConfigItem &i) { return i.toString(); });
......@@ -339,10 +337,12 @@ QList<Task> CMakeConfigurationKitInformation::validate(const Kit *k) const
QByteArray qmakePath;
QByteArray tcPath;
foreach (const CMakeConfigItem &i, config) {
// Do not use expand(QByteArray) as we can not be sure the input is latin1
const QByteArray expandedValue = k->macroExpander()->expand(QString::fromUtf8(i.value)).toUtf8();
if (i.key == CMAKE_QMAKE_KEY)
qmakePath = i.value;
qmakePath = expandedValue;
else if (i.key == CMAKE_TOOLCHAIN_KEY)
tcPath = i.value;
tcPath = expandedValue;
}
QList<Task> result;
......@@ -397,31 +397,7 @@ void CMakeConfigurationKitInformation::setup(Kit *k)
void CMakeConfigurationKitInformation::fix(Kit *k)
{
const QtSupport::BaseQtVersion *const version = QtSupport::QtKitInformation::qtVersion(k);
const QByteArray qmakePath
= (version && version->isValid()) ? version->qmakeCommand().toString().toUtf8() : QByteArray();
const ToolChain *const tc = ToolChainKitInformation::toolChain(k);
const QByteArray tcPath
= (tc && tc->isValid()) ? tc->compilerCommand().toString().toUtf8() : QByteArray();
CMakeConfig result;
bool haveQmake = false;
bool haveToolChain = false;
foreach (const CMakeConfigItem &i, configuration(k)) {
if (i.key == CMAKE_QMAKE_KEY)
haveQmake = true;
else if (i.key == CMAKE_TOOLCHAIN_KEY)
haveToolChain = true;
result << i;
}
if (!haveQmake && !qmakePath.isEmpty())
result << CMakeConfigItem(CMAKE_QMAKE_KEY, qmakePath);
if (!haveToolChain && !tcPath.isEmpty())
result << CMakeConfigItem(CMAKE_TOOLCHAIN_KEY, tcPath);
setConfiguration(k, result);
Q_UNUSED(k);
}
KitInformation::ItemList CMakeConfigurationKitInformation::toUserOutput(const Kit *k) const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment