Commit 75d1c303 authored by Yuchen Deng's avatar Yuchen Deng Committed by Peter Kümmel

CMake: Add option for preferred Ninja user

Change-Id: I5a3aa31db7fa37f31a4b557eb5b09b7987169265
Reviewed-by: default avatarPeter Kümmel <syntheticpp@gmx.net>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent a436ffc0
......@@ -74,7 +74,7 @@ namespace Internal {
Q_DECLARE_TR_FUNCTIONS(CMakeProjectManager::Internal::GeneratorInfo)
public:
enum Ninja { NoNinja, OfferNinja, ForceNinja };
static QList<GeneratorInfo> generatorInfosFor(ProjectExplorer::Kit *k, Ninja n, bool hasCodeBlocks);
static QList<GeneratorInfo> generatorInfosFor(ProjectExplorer::Kit *k, Ninja n, bool preferNinja, bool hasCodeBlocks);
GeneratorInfo();
explicit GeneratorInfo(ProjectExplorer::Kit *kit, bool ninja = false);
......@@ -171,7 +171,7 @@ QString GeneratorInfo::displayName() const
return QString();
}
QList<GeneratorInfo> GeneratorInfo::generatorInfosFor(ProjectExplorer::Kit *k, Ninja n, bool hasCodeBlocks)
QList<GeneratorInfo> GeneratorInfo::generatorInfosFor(ProjectExplorer::Kit *k, Ninja n, bool preferNinja, bool hasCodeBlocks)
{
QList<GeneratorInfo> results;
ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
......@@ -194,8 +194,12 @@ QList<GeneratorInfo> GeneratorInfo::generatorInfosFor(ProjectExplorer::Kit *k, N
results << GeneratorInfo(k);
}
}
if (n != NoNinja)
results << GeneratorInfo(k, true);
if (n != NoNinja) {
if (preferNinja)
results.prepend(GeneratorInfo(k, true));
else
results.append(GeneratorInfo(k, true));
}
return results;
}
......@@ -281,6 +285,7 @@ bool CMakeOpenProjectWizard::compatibleKitExist() const
{
bool hasCodeBlocksGenerator = m_cmakeManager->hasCodeBlocksMsvcGenerator();
bool hasNinjaGenerator = m_cmakeManager->hasCodeBlocksNinjaGenerator();
bool preferNinja = m_cmakeManager->preferNinja();
QList<ProjectExplorer::Kit *> kitList =
ProjectExplorer::KitManager::instance()->kits();
......@@ -291,6 +296,7 @@ bool CMakeOpenProjectWizard::compatibleKitExist() const
// are interested in here
QList<GeneratorInfo> infos = GeneratorInfo::generatorInfosFor(k,
hasNinjaGenerator ? GeneratorInfo::OfferNinja : GeneratorInfo::NoNinja,
preferNinja,
hasCodeBlocksGenerator);
if (!infos.isEmpty())
return true;
......@@ -647,6 +653,7 @@ void CMakeRunPage::initializePage()
bool hasCodeBlocksGenerator = m_cmakeWizard->cmakeManager()->hasCodeBlocksMsvcGenerator();
bool hasNinjaGenerator = m_cmakeWizard->cmakeManager()->hasCodeBlocksNinjaGenerator();
bool preferNinja = m_cmakeWizard->cmakeManager()->preferNinja();
if (m_mode == Initial) {
// Try figuring out generator and toolchain from CMakeCache.txt
......@@ -659,6 +666,7 @@ void CMakeRunPage::initializePage()
foreach (ProjectExplorer::Kit *k, kitList) {
QList<GeneratorInfo> infos = GeneratorInfo::generatorInfosFor(k,
hasNinjaGenerator ? GeneratorInfo::OfferNinja : GeneratorInfo::NoNinja,
preferNinja,
hasCodeBlocksGenerator);
foreach (const GeneratorInfo &info, infos)
......@@ -680,6 +688,7 @@ void CMakeRunPage::initializePage()
QList<GeneratorInfo> infos = GeneratorInfo::generatorInfosFor(m_cmakeWizard->kit(),
ninja,
preferNinja,
true);
foreach (const GeneratorInfo &info, infos)
m_generatorComboBox->addItem(info.displayName(), qVariantFromValue(info));
......
......@@ -161,6 +161,11 @@ bool CMakeManager::hasCodeBlocksNinjaGenerator() const
return m_settingsPage->hasCodeBlocksNinjaGenerator();
}
bool CMakeManager::preferNinja() const
{
return m_settingsPage->preferNinja();
}
// need to refactor this out
// we probably want the process instead of this function
// cmakeproject then could even run the cmake process in the background, adding the files afterwards
......@@ -241,7 +246,7 @@ QString CMakeManager::qtVersionForQMake(const QString &qmakePath)
CMakeSettingsPage::CMakeSettingsPage()
: m_pathchooser(0)
: m_pathchooser(0), m_preferNinja(0)
{
setId("Z.CMake");
setDisplayName(tr("CMake"));
......@@ -288,6 +293,11 @@ QWidget *CMakeSettingsPage::createPage(QWidget *parent)
formLayout->addRow(tr("Executable:"), m_pathchooser);
formLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
m_pathchooser->setPath(m_cmakeValidatorForUser.cmakeExecutable());
m_preferNinja = new QCheckBox(tr("Prefer Ninja generator (CMake 2.8.9 or higher required)"));
m_preferNinja->setChecked(preferNinja());
formLayout->addRow(m_preferNinja);
return outerWidget;
}
......@@ -296,6 +306,7 @@ void CMakeSettingsPage::saveSettings() const
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String("CMakeSettings"));
settings->setValue(QLatin1String("cmakeExecutable"), m_cmakeValidatorForUser.cmakeExecutable());
settings->setValue(QLatin1String("preferNinja"), m_preferNinja->isChecked());
settings->endGroup();
}
......@@ -303,9 +314,8 @@ void CMakeSettingsPage::apply()
{
if (!m_pathchooser) // page was never shown
return;
if (m_cmakeValidatorForUser.cmakeExecutable() == m_pathchooser->path())
return;
m_cmakeValidatorForUser.setCMakeExecutable(m_pathchooser->path());
if (m_cmakeValidatorForUser.cmakeExecutable() != m_pathchooser->path())
m_cmakeValidatorForUser.setCMakeExecutable(m_pathchooser->path());
saveSettings();
}
......@@ -351,6 +361,15 @@ bool CMakeSettingsPage::hasCodeBlocksNinjaGenerator() const
return false;
}
bool CMakeSettingsPage::preferNinja() const
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String("CMakeSettings"));
const bool r = settings->value(QLatin1String("preferNinja"), false).toBool();
settings->endGroup();
return r;
}
TextEditor::Keywords CMakeSettingsPage::keywords()
{
if (m_cmakeValidatorForUser.isValid())
......
......@@ -42,6 +42,7 @@
#include <QFuture>
#include <QStringList>
#include <QCheckBox>
#include <QDir>
#include <QVector>
#include <QAction>
......@@ -81,6 +82,7 @@ public:
const QString &generator);
bool hasCodeBlocksMsvcGenerator() const;
bool hasCodeBlocksNinjaGenerator() const;
bool preferNinja() const;
static QString findCbpFile(const QDir &);
static QString findDumperLibrary(const Utils::Environment &env);
......@@ -115,6 +117,7 @@ public:
bool isCMakeExecutableValid() const;
bool hasCodeBlocksMsvcGenerator() const;
bool hasCodeBlocksNinjaGenerator() const;
bool preferNinja() const;
TextEditor::Keywords keywords();
......@@ -123,6 +126,7 @@ private:
QString findCmakeExecutable() const;
Utils::PathChooser *m_pathchooser;
QCheckBox *m_preferNinja;
CMakeValidator m_cmakeValidatorForUser;
CMakeValidator m_cmakeValidatorForSystem;
};
......
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