Commit 35ce2acd authored by dt's avatar dt

CMake: always fallback to path cmake

We used to only fallback at start time from a invalid/empty setting
to the cmake in path. Now we do that even if the setting is later
edited.

Task-Nr: QTCREATORBUG-3739
parent 3f42c75e
...@@ -178,78 +178,99 @@ QString CMakeManager::qtVersionForQMake(const QString &qmakePath) ...@@ -178,78 +178,99 @@ QString CMakeManager::qtVersionForQMake(const QString &qmakePath)
CMakeSettingsPage::CMakeSettingsPage() CMakeSettingsPage::CMakeSettingsPage()
: m_pathchooser(0), m_process(0) : m_pathchooser(0)
{ {
m_userCmake.process = 0;
m_pathCmake.process = 0;
Core::ICore *core = Core::ICore::instance(); Core::ICore *core = Core::ICore::instance();
QSettings * settings = core->settings(); QSettings * settings = core->settings();
settings->beginGroup(QLatin1String("CMakeSettings")); settings->beginGroup(QLatin1String("CMakeSettings"));
m_cmakeExecutable = settings->value(QLatin1String("cmakeExecutable")).toString(); m_userCmake.executable = settings->value(QLatin1String("cmakeExecutable")).toString();
QFileInfo fi(m_cmakeExecutable);
if (!fi.exists() || !fi.isExecutable())
m_cmakeExecutable = findCmakeExecutable();
fi.setFile(m_cmakeExecutable);
if (fi.exists() && fi.isExecutable()) {
// Run it to find out more
m_state = RUNNING;
startProcess();
} else {
m_state = INVALID;
}
settings->endGroup(); settings->endGroup();
updateInfo(&m_userCmake);
m_pathCmake.executable = findCmakeExecutable();
updateInfo(&m_pathCmake);
} }
void CMakeSettingsPage::startProcess() void CMakeSettingsPage::startProcess(CMakeValidator *cmakeValidator)
{ {
m_process = new QProcess(); cmakeValidator->process = new QProcess();
if (cmakeValidator == &m_pathCmake) // ugly
connect(cmakeValidator->process, SIGNAL(finished(int)),
this, SLOT(userCmakeFinished()));
else
connect(cmakeValidator->process, SIGNAL(finished(int)),
this, SLOT(pathCmakeFinished()));
connect(m_process, SIGNAL(finished(int)), cmakeValidator->process->start(cmakeValidator->executable, QStringList(QLatin1String("--help")));
this, SLOT(cmakeFinished())); cmakeValidator->process->waitForStarted();
}
m_process->start(m_cmakeExecutable, QStringList(QLatin1String("--help"))); void CMakeSettingsPage::userCmakeFinished()
m_process->waitForStarted(); {
cmakeFinished(&m_userCmake);
} }
void CMakeSettingsPage::cmakeFinished() void CMakeSettingsPage::pathCmakeFinished()
{ {
if (m_process) { cmakeFinished(&m_pathCmake);
QString response = m_process->readAll(); }
void CMakeSettingsPage::cmakeFinished(CMakeValidator *cmakeValidator) const
{
if (cmakeValidator->process) {
QString response = cmakeValidator->process->readAll();
QRegExp versionRegexp(QLatin1String("^cmake version ([\\d\\.]*)")); QRegExp versionRegexp(QLatin1String("^cmake version ([\\d\\.]*)"));
versionRegexp.indexIn(response); versionRegexp.indexIn(response);
//m_supportsQtCreator = response.contains(QLatin1String("QtCreator")); //m_supportsQtCreator = response.contains(QLatin1String("QtCreator"));
m_hasCodeBlocksMsvcGenerator = response.contains(QLatin1String("CodeBlocks - NMake Makefiles")); cmakeValidator->hasCodeBlocksMsvcGenerator = response.contains(QLatin1String("CodeBlocks - NMake Makefiles"));
m_version = versionRegexp.cap(1); cmakeValidator->version = versionRegexp.cap(1);
if (!(versionRegexp.capturedTexts().size() > 3)) if (!(versionRegexp.capturedTexts().size() > 3))
m_version += QLatin1Char('.') + versionRegexp.cap(3); cmakeValidator->version += QLatin1Char('.') + versionRegexp.cap(3);
if (m_version.isEmpty()) if (cmakeValidator->version.isEmpty())
m_state = INVALID; cmakeValidator->state = CMakeValidator::INVALID;
else else
m_state = VALID; cmakeValidator->state = CMakeValidator::VALID;
m_process->deleteLater(); cmakeValidator->process->deleteLater();
m_process = 0; cmakeValidator->process = 0;
} }
} }
bool CMakeSettingsPage::isCMakeExecutableValid() bool CMakeSettingsPage::isCMakeExecutableValid() const
{ {
if (m_state == RUNNING) { if (m_userCmake.state == CMakeValidator::RUNNING) {
disconnect(m_process, SIGNAL(finished(int)), disconnect(m_userCmake.process, SIGNAL(finished(int)),
this, SLOT(cmakeFinished()));
m_userCmake.process->waitForFinished();
// Parse the output now
cmakeFinished(&m_userCmake);
}
if (m_userCmake.state == CMakeValidator::VALID)
return true;
if (m_pathCmake.state == CMakeValidator::RUNNING) {
disconnect(m_userCmake.process, SIGNAL(finished(int)),
this, SLOT(cmakeFinished())); this, SLOT(cmakeFinished()));
m_process->waitForFinished(); m_pathCmake.process->waitForFinished();
// Parse the output now // Parse the output now
cmakeFinished(); cmakeFinished(&m_pathCmake);
} }
return m_state == VALID; return m_pathCmake.state == CMakeValidator::VALID;
} }
CMakeSettingsPage::~CMakeSettingsPage() CMakeSettingsPage::~CMakeSettingsPage()
{ {
if (m_process) if (m_userCmake.process)
m_process->waitForFinished(); m_userCmake.process->waitForFinished();
delete m_process; delete m_userCmake.process;
if (m_pathCmake.process)
m_pathCmake.process->waitForFinished();
delete m_pathCmake.process;
} }
QString CMakeSettingsPage::findCmakeExecutable() const QString CMakeSettingsPage::findCmakeExecutable() const
...@@ -292,19 +313,19 @@ QWidget *CMakeSettingsPage::createPage(QWidget *parent) ...@@ -292,19 +313,19 @@ QWidget *CMakeSettingsPage::createPage(QWidget *parent)
m_pathchooser->setExpectedKind(Utils::PathChooser::ExistingCommand); m_pathchooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
formLayout->addRow(tr("Executable:"), m_pathchooser); formLayout->addRow(tr("Executable:"), m_pathchooser);
formLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); formLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
m_pathchooser->setPath(cmakeExecutable()); m_pathchooser->setPath(m_userCmake.executable);
return outerWidget; return outerWidget;
} }
void CMakeSettingsPage::updateInfo() void CMakeSettingsPage::updateInfo(CMakeValidator *cmakeValidator)
{ {
QFileInfo fi(m_cmakeExecutable); QFileInfo fi(cmakeValidator->executable);
if (fi.exists() && fi.isExecutable()) { if (fi.exists() && fi.isExecutable()) {
// Run it to find out more // Run it to find out more
m_state = RUNNING; cmakeValidator->state = CMakeValidator::RUNNING;
startProcess(); startProcess(cmakeValidator);
} else { } else {
m_state = INVALID; cmakeValidator->state = CMakeValidator::INVALID;
} }
saveSettings(); saveSettings();
} }
...@@ -313,7 +334,7 @@ void CMakeSettingsPage::saveSettings() const ...@@ -313,7 +334,7 @@ void CMakeSettingsPage::saveSettings() const
{ {
QSettings *settings = Core::ICore::instance()->settings(); QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(QLatin1String("CMakeSettings")); settings->beginGroup(QLatin1String("CMakeSettings"));
settings->setValue(QLatin1String("cmakeExecutable"), m_cmakeExecutable); settings->setValue(QLatin1String("cmakeExecutable"), m_userCmake.executable);
settings->endGroup(); settings->endGroup();
} }
...@@ -321,10 +342,10 @@ void CMakeSettingsPage::apply() ...@@ -321,10 +342,10 @@ void CMakeSettingsPage::apply()
{ {
if (!m_pathchooser) // page was never shown if (!m_pathchooser) // page was never shown
return; return;
if (m_cmakeExecutable == m_pathchooser->path()) if (m_userCmake.executable == m_pathchooser->path())
return; return;
m_cmakeExecutable = m_pathchooser->path(); m_userCmake.executable = m_pathchooser->path();
updateInfo(); updateInfo(&m_userCmake);
} }
void CMakeSettingsPage::finish() void CMakeSettingsPage::finish()
...@@ -334,18 +355,28 @@ void CMakeSettingsPage::finish() ...@@ -334,18 +355,28 @@ void CMakeSettingsPage::finish()
QString CMakeSettingsPage::cmakeExecutable() const QString CMakeSettingsPage::cmakeExecutable() const
{ {
return m_cmakeExecutable; if (!isCMakeExecutableValid())
return QString();
if (m_userCmake.state == CMakeValidator::VALID)
return m_userCmake.executable;
else
return m_pathCmake.executable;
} }
void CMakeSettingsPage::setCMakeExecutable(const QString &executable) void CMakeSettingsPage::setCMakeExecutable(const QString &executable)
{ {
if (m_cmakeExecutable == executable) if (m_userCmake.executable == executable)
return; return;
m_cmakeExecutable = executable; m_userCmake.executable = executable;
updateInfo(); updateInfo(&m_userCmake);
} }
bool CMakeSettingsPage::hasCodeBlocksMsvcGenerator() const bool CMakeSettingsPage::hasCodeBlocksMsvcGenerator() const
{ {
return m_hasCodeBlocksMsvcGenerator; if (!isCMakeExecutableValid())
return false;
if (m_userCmake.state == CMakeValidator::VALID)
return m_userCmake.hasCodeBlocksMsvcGenerator;
else
return m_pathCmake.hasCodeBlocksMsvcGenerator;
} }
...@@ -92,6 +92,16 @@ private: ...@@ -92,6 +92,16 @@ private:
CMakeSettingsPage *m_settingsPage; CMakeSettingsPage *m_settingsPage;
}; };
struct CMakeValidator
{
enum STATE { VALID, INVALID, RUNNING };
STATE state;
QProcess *process;
bool hasCodeBlocksMsvcGenerator;
QString version;
QString executable;
};
class CMakeSettingsPage : public Core::IOptionsPage class CMakeSettingsPage : public Core::IOptionsPage
{ {
Q_OBJECT Q_OBJECT
...@@ -110,22 +120,21 @@ public: ...@@ -110,22 +120,21 @@ public:
QString cmakeExecutable() const; QString cmakeExecutable() const;
void setCMakeExecutable(const QString &executable); void setCMakeExecutable(const QString &executable);
bool isCMakeExecutableValid(); bool isCMakeExecutableValid() const;
bool hasCodeBlocksMsvcGenerator() const; bool hasCodeBlocksMsvcGenerator() const;
private slots: private slots:
void cmakeFinished(); void userCmakeFinished();
void pathCmakeFinished();
private: private:
void cmakeFinished(CMakeValidator *cmakeValidator) const;
void saveSettings() const; void saveSettings() const;
void startProcess();
QString findCmakeExecutable() const; QString findCmakeExecutable() const;
void updateInfo(); void startProcess(CMakeValidator *cmakeValidator);
void updateInfo(CMakeValidator *cmakeValidator);
Utils::PathChooser *m_pathchooser; Utils::PathChooser *m_pathchooser;
QString m_cmakeExecutable; mutable CMakeValidator m_userCmake;
enum STATE { VALID, INVALID, RUNNING } m_state; mutable CMakeValidator m_pathCmake;
QProcess *m_process;
QString m_version;
bool m_hasCodeBlocksMsvcGenerator;
}; };
} // namespace Internal } // namespace Internal
......
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