forked from qt-creator/qt-creator
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: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
@@ -60,8 +60,8 @@
|
|||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
static QStringList toArguments(const CMakeConfig &config) {
|
static QStringList toArguments(const CMakeConfig &config, const ProjectExplorer::Kit *k) {
|
||||||
return Utils::transform(config, [](const CMakeConfigItem &i) -> QString {
|
return Utils::transform(config, [k](const CMakeConfigItem &i) -> QString {
|
||||||
QString a = QString::fromLatin1("-D");
|
QString a = QString::fromLatin1("-D");
|
||||||
a.append(QString::fromUtf8(i.key));
|
a.append(QString::fromUtf8(i.key));
|
||||||
switch (i.type) {
|
switch (i.type) {
|
||||||
@@ -81,7 +81,7 @@ static QStringList toArguments(const CMakeConfig &config) {
|
|||||||
a.append(QLatin1String(":INTERNAL="));
|
a.append(QLatin1String(":INTERNAL="));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
a.append(QString::fromUtf8(i.value));
|
a.append(QString::fromUtf8(k->macroExpander()->expand(i.value)));
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
});
|
});
|
||||||
@@ -424,7 +424,7 @@ void BuildDirManager::startCMake(CMakeTool *tool, const QString &generator,
|
|||||||
Utils::QtcProcess::addArg(&args, srcDir);
|
Utils::QtcProcess::addArg(&args, srcDir);
|
||||||
if (!generator.isEmpty())
|
if (!generator.isEmpty())
|
||||||
Utils::QtcProcess::addArg(&args, QString::fromLatin1("-G%1").arg(generator));
|
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);
|
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
|
QVariant CMakeConfigurationKitInformation::defaultValue(const Kit *k) const
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(k);
|
||||||
|
|
||||||
// FIXME: Convert preload scripts
|
// FIXME: Convert preload scripts
|
||||||
CMakeConfig config;
|
CMakeConfig config;
|
||||||
const QtSupport::BaseQtVersion *const version = QtSupport::QtKitInformation::qtVersion(k);
|
config << CMakeConfigItem(CMAKE_QMAKE_KEY, "%{Qt:qmakeExecutable}");
|
||||||
if (version && version->isValid())
|
config << CMakeConfigItem(CMAKE_TOOLCHAIN_KEY, "%{Compiler:Executable}");
|
||||||
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());
|
|
||||||
|
|
||||||
const QStringList tmp
|
const QStringList tmp
|
||||||
= Utils::transform(config, [](const CMakeConfigItem &i) { return i.toString(); });
|
= Utils::transform(config, [](const CMakeConfigItem &i) { return i.toString(); });
|
||||||
@@ -339,10 +337,12 @@ QList<Task> CMakeConfigurationKitInformation::validate(const Kit *k) const
|
|||||||
QByteArray qmakePath;
|
QByteArray qmakePath;
|
||||||
QByteArray tcPath;
|
QByteArray tcPath;
|
||||||
foreach (const CMakeConfigItem &i, config) {
|
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)
|
if (i.key == CMAKE_QMAKE_KEY)
|
||||||
qmakePath = i.value;
|
qmakePath = expandedValue;
|
||||||
else if (i.key == CMAKE_TOOLCHAIN_KEY)
|
else if (i.key == CMAKE_TOOLCHAIN_KEY)
|
||||||
tcPath = i.value;
|
tcPath = expandedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Task> result;
|
QList<Task> result;
|
||||||
@@ -397,31 +397,7 @@ void CMakeConfigurationKitInformation::setup(Kit *k)
|
|||||||
|
|
||||||
void CMakeConfigurationKitInformation::fix(Kit *k)
|
void CMakeConfigurationKitInformation::fix(Kit *k)
|
||||||
{
|
{
|
||||||
const QtSupport::BaseQtVersion *const version = QtSupport::QtKitInformation::qtVersion(k);
|
Q_UNUSED(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KitInformation::ItemList CMakeConfigurationKitInformation::toUserOutput(const Kit *k) const
|
KitInformation::ItemList CMakeConfigurationKitInformation::toUserOutput(const Kit *k) const
|
||||||
|
|||||||
Reference in New Issue
Block a user