Commit a764bb49 authored by Tobias Hunger's avatar Tobias Hunger

CMake: Add CMakeGeneratorKitInformation

Change-Id: I877c248c7b93268281fc68e814e479d24b844d5f
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent c3aac762
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
// --------------------------------------------------------------------
// CMakeKitConfigWidget:
// --------------------------------------------------------------------
CMakeKitConfigWidget::CMakeKitConfigWidget(ProjectExplorer::Kit *kit, CMakeKitConfigWidget::CMakeKitConfigWidget(ProjectExplorer::Kit *kit,
const ProjectExplorer::KitInformation *ki) : const ProjectExplorer::KitInformation *ki) :
ProjectExplorer::KitConfigWidget(kit, ki), ProjectExplorer::KitConfigWidget(kit, ki),
...@@ -185,5 +189,76 @@ void CMakeKitConfigWidget::manageCMakeTools() ...@@ -185,5 +189,76 @@ void CMakeKitConfigWidget::manageCMakeTools()
buttonWidget()); buttonWidget());
} }
// --------------------------------------------------------------------
// CMakeGeneratorKitConfigWidget:
// --------------------------------------------------------------------
CMakeGeneratorKitConfigWidget::CMakeGeneratorKitConfigWidget(ProjectExplorer::Kit *kit,
const ProjectExplorer::KitInformation *ki) :
ProjectExplorer::KitConfigWidget(kit, ki),
m_comboBox(new QComboBox)
{
m_comboBox->setToolTip(toolTip());
refresh();
connect(m_comboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, [this](int idx) {
m_ignoreChange = true;
CMakeGeneratorKitInformation::setGenerator(m_kit, m_comboBox->itemData(idx).toString());
m_ignoreChange = false;
});
}
CMakeGeneratorKitConfigWidget::~CMakeGeneratorKitConfigWidget()
{
delete m_comboBox;
}
QString CMakeGeneratorKitConfigWidget::displayName() const
{
return tr("CMake Generator:");
}
void CMakeGeneratorKitConfigWidget::makeReadOnly()
{
m_comboBox->setEnabled(false);
}
void CMakeGeneratorKitConfigWidget::refresh()
{
if (m_ignoreChange)
return;
CMakeTool *const tool = CMakeKitInformation::cmakeTool(m_kit);
if (tool != m_currentTool) {
m_comboBox->clear();
m_comboBox->addItem(tr("<Use Default Generator>"), QString());
if (tool && tool->isValid()) {
foreach (const QString &g, tool->supportedGenerators())
m_comboBox->addItem(g, g);
}
}
const QString generator = CMakeGeneratorKitInformation::generator(m_kit);
m_comboBox->setCurrentIndex(m_comboBox->findData(generator));
}
QWidget *CMakeGeneratorKitConfigWidget::mainWidget() const
{
return m_comboBox;
}
QWidget *CMakeGeneratorKitConfigWidget::buttonWidget() const
{
return nullptr;
}
QString CMakeGeneratorKitConfigWidget::toolTip() const
{
return tr("CMake generator defines how a project is built when using CMake.<br>"
"This setting is ignored when using other build systems.");
}
} // namespace Internal } // namespace Internal
} // namespace CMakeProjectManager } // namespace CMakeProjectManager
...@@ -41,6 +41,10 @@ class CMakeTool; ...@@ -41,6 +41,10 @@ class CMakeTool;
namespace Internal { namespace Internal {
// --------------------------------------------------------------------
// CMakeKitConfigWidget:
// --------------------------------------------------------------------
class CMakeKitConfigWidget : public ProjectExplorer::KitConfigWidget class CMakeKitConfigWidget : public ProjectExplorer::KitConfigWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -70,5 +74,30 @@ private: ...@@ -70,5 +74,30 @@ private:
QPushButton *m_manageButton; QPushButton *m_manageButton;
}; };
// --------------------------------------------------------------------
// CMakeGeneratorKitConfigWidget:
// --------------------------------------------------------------------
class CMakeGeneratorKitConfigWidget : public ProjectExplorer::KitConfigWidget
{
Q_OBJECT
public:
CMakeGeneratorKitConfigWidget(ProjectExplorer::Kit *kit, const ProjectExplorer::KitInformation *ki);
~CMakeGeneratorKitConfigWidget() override;
// KitConfigWidget interface
QString displayName() const override;
void makeReadOnly() override;
void refresh() override;
QWidget *mainWidget() const override;
QWidget *buttonWidget() const override;
QString toolTip() const override;
private:
bool m_ignoreChange = false;
QComboBox *m_comboBox;
CMakeTool *m_currentTool = nullptr;
};
} // namespace Internal } // namespace Internal
} // namespace CMakeProjectManager } // namespace CMakeProjectManager
...@@ -50,6 +50,10 @@ static Core::Id defaultCMakeToolId() ...@@ -50,6 +50,10 @@ static Core::Id defaultCMakeToolId()
static const char TOOL_ID[] = "CMakeProjectManager.CMakeKitInformation"; static const char TOOL_ID[] = "CMakeProjectManager.CMakeKitInformation";
// --------------------------------------------------------------------
// CMakeKitInformation:
// --------------------------------------------------------------------
CMakeKitInformation::CMakeKitInformation() CMakeKitInformation::CMakeKitInformation()
{ {
setObjectName(QLatin1String("CMakeKitInformation")); setObjectName(QLatin1String("CMakeKitInformation"));
...@@ -118,4 +122,120 @@ KitConfigWidget *CMakeKitInformation::createConfigWidget(Kit *k) const ...@@ -118,4 +122,120 @@ KitConfigWidget *CMakeKitInformation::createConfigWidget(Kit *k) const
return new Internal::CMakeKitConfigWidget(k, this); return new Internal::CMakeKitConfigWidget(k, this);
} }
// --------------------------------------------------------------------
// CMakeGeneratorKitInformation:
// --------------------------------------------------------------------
static const char GENERATOR_ID[] = "CMake.GeneratorKitInformation";
CMakeGeneratorKitInformation::CMakeGeneratorKitInformation()
{
setObjectName(QLatin1String("CMakeGeneratorKitInformation"));
setId(GENERATOR_ID);
setPriority(19000);
}
QString CMakeGeneratorKitInformation::generator(const Kit *k)
{
if (!k)
return QString();
return k->value(GENERATOR_ID).toString();
}
void CMakeGeneratorKitInformation::setGenerator(Kit *k, const QString &generator)
{
if (!k)
return;
k->setValue(GENERATOR_ID, generator);
}
QString CMakeGeneratorKitInformation::generatorArgument(const Kit *k)
{
QString tmp = generator(k);
if (tmp.isEmpty())
return QString::fromLatin1("-G") + tmp;
return tmp;
}
QVariant CMakeGeneratorKitInformation::defaultValue(const Kit *k) const
{
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
if (!tool)
return QString();
QStringList known = tool->supportedGenerators();
auto it = std::find_if(known.constBegin(), known.constEnd(),
[](const QString &s) { return s == QLatin1String("CodeBlocks - Ninja"); });
if (it == known.constEnd())
it = std::find_if(known.constBegin(), known.constEnd(),
[](const QString &s) { return s == QLatin1String("CodeBlocks - Unix Makefiles"); });
if (it == known.constEnd())
it = std::find_if(known.constBegin(), known.constEnd(),
[](const QString &s) { return s == QLatin1String("CodeBlocks - NMake Makefiles"); });
if (it == known.constEnd())
it = known.constBegin(); // Fallback to the first generator...
if (it != known.constEnd())
return *it;
return QString();
}
QList<Task> CMakeGeneratorKitInformation::validate(const Kit *k) const
{
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
QString generator = CMakeGeneratorKitInformation::generator(k);
QList<Task> result;
if (!tool) {
if (!generator.isEmpty()) {
result << Task(Task::Warning, tr("No CMake Tool configured, CMake generator will be ignored."),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
}
} else {
if (!tool->isValid()) {
result << Task(Task::Warning, tr("CMake Tool is unconfigured, CMake generator will be ignored."),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
} else {
QStringList known = tool->supportedGenerators();
if (!known.contains(generator)) {
result << Task(Task::Error, tr("CMake Tool does not support the configured generator."),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
}
if (!generator.startsWith(QLatin1String("CodeBlocks -"))) {
result << Task(Task::Warning, tr("CMake generator does not generate CodeBlocks file. "
"Qt Creator will not be able to parse the CMake project."),
Utils::FileName(), -1, Core::Id(Constants::TASK_CATEGORY_BUILDSYSTEM));
}
}
}
return result;
}
void CMakeGeneratorKitInformation::setup(Kit *k)
{
CMakeGeneratorKitInformation::setGenerator(k, defaultValue(k).toString());
}
void CMakeGeneratorKitInformation::fix(Kit *k)
{
const CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
const QString generator = CMakeGeneratorKitInformation::generator(k);
if (!tool)
return;
QStringList known = tool->supportedGenerators();
if (generator.isEmpty() || !known.contains(generator))
CMakeGeneratorKitInformation::setGenerator(k, defaultValue(k).toString());
}
KitInformation::ItemList CMakeGeneratorKitInformation::toUserOutput(const Kit *k) const
{
const QString generator = CMakeGeneratorKitInformation::generator(k);
return ItemList() << qMakePair(tr("CMake Generator"),
generator.isEmpty() ? tr("<Use Default Generator>") : generator);
}
KitConfigWidget *CMakeGeneratorKitInformation::createConfigWidget(Kit *k) const
{
return new Internal::CMakeGeneratorKitConfigWidget(k, this);
}
} // namespace CMakeProjectManager } // namespace CMakeProjectManager
...@@ -51,4 +51,23 @@ public: ...@@ -51,4 +51,23 @@ public:
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const override; ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const override;
}; };
class CMAKE_EXPORT CMakeGeneratorKitInformation : public ProjectExplorer::KitInformation
{
Q_OBJECT
public:
CMakeGeneratorKitInformation();
static QString generator(const ProjectExplorer::Kit *k);
static void setGenerator(ProjectExplorer::Kit *k, const QString &generator);
static QString generatorArgument(const ProjectExplorer::Kit *k);
// KitInformation interface
QVariant defaultValue(const ProjectExplorer::Kit *k) const override;
QList<ProjectExplorer::Task> validate(const ProjectExplorer::Kit *k) const override;
void setup(ProjectExplorer::Kit *k) override;
void fix(ProjectExplorer::Kit *k) override;
ItemList toUserOutput(const ProjectExplorer::Kit *k) const override;
ProjectExplorer::KitConfigWidget *createConfigWidget(ProjectExplorer::Kit *k) const override;
};
} // namespace CMakeProjectManager } // namespace CMakeProjectManager
...@@ -43,7 +43,7 @@ CMakePreloadCacheKitInformation::CMakePreloadCacheKitInformation() ...@@ -43,7 +43,7 @@ CMakePreloadCacheKitInformation::CMakePreloadCacheKitInformation()
{ {
setObjectName(QLatin1String("CMakePreloadCacheKitInformation")); setObjectName(QLatin1String("CMakePreloadCacheKitInformation"));
setId(CMakePreloadCacheKitInformation::id()); setId(CMakePreloadCacheKitInformation::id());
setPriority(19000); setPriority(18000);
} }
Core::Id CMakePreloadCacheKitInformation::id() Core::Id CMakePreloadCacheKitInformation::id()
......
...@@ -63,6 +63,7 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString * ...@@ -63,6 +63,7 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
new CMakeToolManager(this); new CMakeToolManager(this);
ProjectExplorer::KitManager::registerKitInformation(new CMakeKitInformation); ProjectExplorer::KitManager::registerKitInformation(new CMakeKitInformation);
ProjectExplorer::KitManager::registerKitInformation(new CMakeGeneratorKitInformation);
ProjectExplorer::KitManager::registerKitInformation(new CMakePreloadCacheKitInformation); ProjectExplorer::KitManager::registerKitInformation(new CMakePreloadCacheKitInformation);
return true; return true;
......
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