Commit fd761cd7 authored by Tobias Hunger's avatar Tobias Hunger

CMake: Warn if kit settings are overridden by the project

Change-Id: I8f01b267f27617d6561124d173ac2e5ae5b9f4d6
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 51004542
......@@ -300,6 +300,22 @@ static CMakeConfig removeDuplicates(const CMakeConfig &config)
void CMakeBuildConfiguration::setCMakeConfiguration(const CMakeConfig &config)
{
m_configuration = removeDuplicates(config);
const Kit *k = target()->kit();
CMakeConfig kitConfig = CMakeConfigurationKitInformation::configuration(k);
bool hasKitOverride = false;
foreach (const CMakeConfigItem &i, m_configuration) {
const QString b = CMakeConfigItem::expandedValueOf(k, i.key, kitConfig);
if (!b.isNull() && i.expandedValue(k) != b) {
hasKitOverride = true;
break;
}
}
if (hasKitOverride)
setWarning(tr("CMake Configuration set by the Kit was overridden in the project."));
else
setWarning(QString());
}
CMakeConfig CMakeBuildConfiguration::cmakeConfiguration() const
......@@ -316,11 +332,24 @@ void CMakeBuildConfiguration::setError(const QString &message)
emit errorOccured(m_error);
}
void CMakeBuildConfiguration::setWarning(const QString &message)
{
if (m_warning == message)
return;
m_warning = message;
emit warningOccured(m_warning);
}
QString CMakeBuildConfiguration::error() const
{
return m_error;
}
QString CMakeBuildConfiguration::warning() const
{
return m_warning;
}
ProjectExplorer::NamedWidget *CMakeBuildConfiguration::createConfigWidget()
{
return new CMakeBuildSettingsWidget(this);
......
......@@ -68,6 +68,7 @@ public:
CMakeConfig cmakeConfiguration() const;
QString error() const;
QString warning() const;
BuildDirManager *buildDirManager() const;
......@@ -83,6 +84,7 @@ public:
signals:
void errorOccured(const QString &message);
void warningOccured(const QString &message);
void parsingStarted();
void dataAvailable();
......@@ -97,9 +99,11 @@ private:
void setCurrentCMakeConfiguration(const QList<ConfigModel::DataItem> &items);
void setError(const QString &message);
void setWarning(const QString &message);
CMakeConfig m_configuration;
QString m_error;
QString m_warning;
mutable QList<CMakeConfigItem> m_completeConfigurationCache;
......
......@@ -108,6 +108,17 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
boxLayout->addWidget(m_errorMessageLabel);
mainLayout->addLayout(boxLayout, row, 0, 1, 3, Qt::AlignHCenter);
++row;
m_warningLabel = new QLabel;
m_warningLabel->setPixmap(Core::Icons::WARNING.pixmap());
m_warningLabel->setVisible(false);
m_warningMessageLabel = new QLabel;
m_warningMessageLabel->setVisible(false);
auto boxLayout2 = new QHBoxLayout;
boxLayout2->addWidget(m_warningLabel);
boxLayout2->addWidget(m_warningMessageLabel);
mainLayout->addLayout(boxLayout2, row, 0, 1, 3, Qt::AlignHCenter);
++row;
mainLayout->addItem(new QSpacerItem(20, 10), row, 0);
......@@ -161,6 +172,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
updateAdvancedCheckBox();
setError(bc->error());
setWarning(bc->warning());
connect(project, &CMakeProject::parsingStarted, this, [this]() {
updateButtonState();
......@@ -203,22 +215,33 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
});
connect(bc, &CMakeBuildConfiguration::errorOccured, this, &CMakeBuildSettingsWidget::setError);
connect(bc, &CMakeBuildConfiguration::warningOccured, this, &CMakeBuildSettingsWidget::setWarning);
}
void CMakeBuildSettingsWidget::setError(const QString &message)
{
bool showWarning = !message.isEmpty();
m_errorLabel->setVisible(showWarning);
bool showError = !message.isEmpty();
m_errorLabel->setVisible(showError);
m_errorLabel->setToolTip(message);
m_errorMessageLabel->setVisible(showWarning);
m_errorMessageLabel->setVisible(showError);
m_errorMessageLabel->setText(message);
m_errorMessageLabel->setToolTip(message);
m_configView->setVisible(!showWarning);
m_editButton->setVisible(!showWarning);
m_resetButton->setVisible(!showWarning);
m_showAdvancedCheckBox->setVisible(!showWarning);
m_reconfigureButton->setVisible(!showWarning);
m_configView->setVisible(!showError);
m_editButton->setVisible(!showError);
m_resetButton->setVisible(!showError);
m_showAdvancedCheckBox->setVisible(!showError);
m_reconfigureButton->setVisible(!showError);
}
void CMakeBuildSettingsWidget::setWarning(const QString &message)
{
bool showWarning = !message.isEmpty();
m_warningLabel->setVisible(showWarning);
m_warningLabel->setToolTip(message);
m_warningMessageLabel->setVisible(showWarning);
m_warningMessageLabel->setText(message);
m_warningMessageLabel->setToolTip(message);
}
void CMakeBuildSettingsWidget::updateButtonState()
......
......@@ -54,6 +54,7 @@ public:
CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc);
void setError(const QString &message);
void setWarning(const QString &message);
private:
void updateButtonState();
......@@ -70,7 +71,9 @@ private:
QPushButton *m_reconfigureButton;
QTimer m_showProgressTimer;
QLabel *m_errorLabel;
QLabel *m_warningLabel;
QLabel *m_errorMessageLabel;
QLabel *m_warningMessageLabel;
};
} // namespace Internal
......
......@@ -63,6 +63,16 @@ QByteArray CMakeConfigItem::valueOf(const QByteArray &key, const QList<CMakeConf
return QByteArray();
}
QString CMakeConfigItem::expandedValueOf(const ProjectExplorer::Kit *k, const QByteArray &key,
const QList<CMakeConfigItem> &input)
{
for (auto it = input.constBegin(); it != input.constEnd(); ++it) {
if (it->key == key)
return it->expandedValue(k);
}
return QString();
}
QString CMakeConfigItem::expandedValue(const ProjectExplorer::Kit *k) const
{
return k->macroExpander()->expand(QString::fromUtf8(value));
......
......@@ -43,7 +43,8 @@ public:
CMakeConfigItem(const QByteArray &k, const QByteArray &v);
static QByteArray valueOf(const QByteArray &key, const QList<CMakeConfigItem> &input);
static QString expandedValueOf(const ProjectExplorer::Kit *k, const QByteArray &key,
const QList<CMakeConfigItem> &input);
bool isNull() const { return key.isEmpty(); }
QString expandedValue(const ProjectExplorer::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