2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2011-02-23 15:52:43 +01:00
|
|
|
#include "cmakeopenprojectwizard.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeprojectmanager.h"
|
|
|
|
#include "cmakeprojectconstants.h"
|
|
|
|
#include "cmakeproject.h"
|
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
#include <utils/synchronousprocess.h>
|
2010-10-19 11:14:03 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2010-09-08 15:22:58 +02:00
|
|
|
|
2009-01-23 16:57:38 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2011-02-23 15:52:43 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2011-02-23 15:52:43 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2012-02-09 09:35:03 +01:00
|
|
|
#include <utils/QtConcurrentTools>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtConcurrentRun>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QSpacerItem>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
using namespace CMakeProjectManager::Internal;
|
|
|
|
|
2009-01-21 16:25:21 +01:00
|
|
|
CMakeManager::CMakeManager(CMakeSettingsPage *cmakeSettingsPage)
|
|
|
|
: m_settingsPage(cmakeSettingsPage)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-02-23 15:52:43 +01:00
|
|
|
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
|
2012-03-05 22:30:59 +01:00
|
|
|
connect(projectExplorer, SIGNAL(aboutToShowContextMenu(ProjectExplorer::Project*,ProjectExplorer::Node*)),
|
|
|
|
this, SLOT(updateContextMenu(ProjectExplorer::Project*,ProjectExplorer::Node*)));
|
2011-02-23 15:52:43 +01:00
|
|
|
|
|
|
|
Core::ActionContainer *mbuild =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_BUILDPROJECT);
|
2011-02-23 15:52:43 +01:00
|
|
|
Core::ActionContainer *mproject =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
|
2011-02-23 15:52:43 +01:00
|
|
|
Core::ActionContainer *msubproject =
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
|
2011-02-23 15:52:43 +01:00
|
|
|
|
2011-04-12 12:17:19 +02:00
|
|
|
const Core::Context projectContext(CMakeProjectManager::Constants::PROJECTCONTEXT);
|
|
|
|
|
2011-03-31 09:57:24 +02:00
|
|
|
m_runCMakeAction = new QAction(QIcon(), tr("Run CMake"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(m_runCMakeAction,
|
|
|
|
Constants::RUNCMAKE, projectContext);
|
2011-02-23 15:52:43 +01:00
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
2012-04-26 19:28:59 +02:00
|
|
|
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY);
|
2011-02-23 15:52:43 +01:00
|
|
|
connect(m_runCMakeAction, SIGNAL(triggered()), this, SLOT(runCMake()));
|
|
|
|
|
2011-03-31 09:57:24 +02:00
|
|
|
m_runCMakeActionContextMenu = new QAction(QIcon(), tr("Run CMake"), this);
|
2012-05-24 13:49:06 +02:00
|
|
|
command = Core::ActionManager::registerAction(m_runCMakeActionContextMenu,
|
|
|
|
Constants::RUNCMAKECONTEXTMENU, projectContext);
|
2011-02-23 15:52:43 +01:00
|
|
|
command->setAttribute(Core::Command::CA_Hide);
|
|
|
|
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
|
|
|
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
|
|
|
connect(m_runCMakeActionContextMenu, SIGNAL(triggered()), this, SLOT(runCMakeContextMenu()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeManager::updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node *node)
|
|
|
|
{
|
|
|
|
Q_UNUSED(node);
|
|
|
|
m_contextProject = project;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeManager::runCMake()
|
|
|
|
{
|
2012-01-24 18:57:39 +01:00
|
|
|
runCMake(ProjectExplorer::ProjectExplorerPlugin::currentProject());
|
2011-02-23 15:52:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeManager::runCMakeContextMenu()
|
|
|
|
{
|
|
|
|
runCMake(m_contextProject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeManager::runCMake(ProjectExplorer::Project *project)
|
|
|
|
{
|
|
|
|
if (!project)
|
|
|
|
return;
|
|
|
|
CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(project);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration())
|
2011-02-23 15:52:43 +01:00
|
|
|
return;
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
CMakeBuildConfiguration *bc
|
2012-07-04 13:05:52 +02:00
|
|
|
= static_cast<CMakeBuildConfiguration *>(cmakeProject->activeTarget()->activeBuildConfiguration());
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2011-02-23 15:52:43 +01:00
|
|
|
CMakeOpenProjectWizard copw(this,
|
|
|
|
cmakeProject->projectDirectory(),
|
|
|
|
bc->buildDirectory(),
|
|
|
|
CMakeOpenProjectWizard::WantToUpdate,
|
2012-10-02 17:46:12 +02:00
|
|
|
bc);
|
2012-04-24 15:49:09 +02:00
|
|
|
if (copw.exec() == QDialog::Accepted)
|
2012-07-17 15:56:43 +02:00
|
|
|
cmakeProject->parseCMakeLists();
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2011-09-05 13:47:29 +02:00
|
|
|
ProjectExplorer::Project *CMakeManager::openProject(const QString &fileName, QString *errorString)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-05 13:47:29 +02:00
|
|
|
Q_UNUSED(errorString)
|
2010-01-11 10:22:55 +01:00
|
|
|
// TODO check whether this project is already opened
|
2008-12-02 12:01:29 +01:00
|
|
|
return new CMakeProject(this, fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeManager::mimeType() const
|
|
|
|
{
|
|
|
|
return Constants::CMAKEMIMETYPE;
|
|
|
|
}
|
2009-01-21 16:25:21 +01:00
|
|
|
|
2009-01-23 16:57:38 +01:00
|
|
|
QString CMakeManager::cmakeExecutable() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->cmakeExecutable();
|
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
bool CMakeManager::isCMakeExecutableValid() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->isCMakeExecutableValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeManager::setCMakeExecutable(const QString &executable)
|
|
|
|
{
|
|
|
|
m_settingsPage->setCMakeExecutable(executable);
|
|
|
|
}
|
|
|
|
|
2009-07-02 11:30:29 +02:00
|
|
|
bool CMakeManager::hasCodeBlocksMsvcGenerator() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->hasCodeBlocksMsvcGenerator();
|
|
|
|
}
|
|
|
|
|
2012-10-02 17:46:12 +02:00
|
|
|
bool CMakeManager::hasCodeBlocksNinjaGenerator() const
|
|
|
|
{
|
|
|
|
return m_settingsPage->hasCodeBlocksNinjaGenerator();
|
|
|
|
}
|
|
|
|
|
2012-05-03 16:05:03 +02:00
|
|
|
// need to refactor this out
|
2009-01-23 16:57:38 +01:00
|
|
|
// we probably want the process instead of this function
|
|
|
|
// cmakeproject then could even run the cmake process in the background, adding the files afterwards
|
|
|
|
// sounds like a plan
|
2010-10-19 11:14:03 +02:00
|
|
|
void CMakeManager::createXmlFile(Utils::QtcProcess *proc, const QString &arguments,
|
2010-09-23 10:35:23 +02:00
|
|
|
const QString &sourceDirectory, const QDir &buildDirectory,
|
|
|
|
const Utils::Environment &env, const QString &generator)
|
2009-01-23 16:57:38 +01:00
|
|
|
{
|
|
|
|
// We create a cbp file, only if we didn't find a cbp file in the base directory
|
|
|
|
// Yet that can still override cbp files in subdirectories
|
|
|
|
// And we are creating tons of files in the source directories
|
|
|
|
// All of that is not really nice.
|
|
|
|
// The mid term plan is to move away from the CodeBlocks Generator and use our own
|
|
|
|
// QtCreator generator, which actually can be very similar to the CodeBlock Generator
|
|
|
|
QString buildDirectoryPath = buildDirectory.absolutePath();
|
|
|
|
buildDirectory.mkpath(buildDirectoryPath);
|
2009-10-21 13:45:49 +02:00
|
|
|
proc->setWorkingDirectory(buildDirectoryPath);
|
2010-10-19 11:14:03 +02:00
|
|
|
proc->setEnvironment(env);
|
2009-03-03 17:56:03 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
const QString srcdir = buildDirectory.exists(QLatin1String("CMakeCache.txt")) ?
|
|
|
|
QString(QLatin1Char('.')) : sourceDirectory;
|
2010-10-19 11:14:03 +02:00
|
|
|
QString args;
|
|
|
|
Utils::QtcProcess::addArg(&args, srcdir);
|
|
|
|
Utils::QtcProcess::addArgs(&args, arguments);
|
|
|
|
Utils::QtcProcess::addArg(&args, generator);
|
|
|
|
proc->setCommand(cmakeExecutable(), args);
|
|
|
|
proc->start();
|
2009-01-23 16:57:38 +01:00
|
|
|
}
|
|
|
|
|
2009-03-09 18:13:19 +01:00
|
|
|
QString CMakeManager::findCbpFile(const QDir &directory)
|
|
|
|
{
|
|
|
|
// Find the cbp file
|
2012-05-03 16:05:03 +02:00
|
|
|
// the cbp file is named like the project() command in the CMakeList.txt file
|
2009-03-09 18:13:19 +01:00
|
|
|
// so this method below could find the wrong cbp file, if the user changes the project()
|
|
|
|
// 2name
|
2011-11-16 14:15:54 +01:00
|
|
|
QDateTime t;
|
|
|
|
QString file;
|
2009-03-09 18:13:19 +01:00
|
|
|
foreach (const QString &cbpFile , directory.entryList()) {
|
2011-11-16 14:15:54 +01:00
|
|
|
if (cbpFile.endsWith(QLatin1String(".cbp"))) {
|
|
|
|
QFileInfo fi(directory.path() + QLatin1Char('/') + cbpFile);
|
|
|
|
if (t.isNull() || fi.lastModified() > t) {
|
|
|
|
file = directory.path() + QLatin1Char('/') + cbpFile;
|
|
|
|
t = fi.lastModified();
|
|
|
|
}
|
|
|
|
}
|
2009-03-09 18:13:19 +01:00
|
|
|
}
|
2011-11-16 14:15:54 +01:00
|
|
|
return file;
|
2009-03-09 18:13:19 +01:00
|
|
|
}
|
|
|
|
|
2009-03-25 17:30:48 +01:00
|
|
|
// This code is duplicated from qtversionmanager
|
|
|
|
QString CMakeManager::qtVersionForQMake(const QString &qmakePath)
|
|
|
|
{
|
|
|
|
QProcess qmake;
|
2009-05-14 17:02:30 +02:00
|
|
|
qmake.start(qmakePath, QStringList(QLatin1String("--version")));
|
2010-09-08 15:22:58 +02:00
|
|
|
if (!qmake.waitForStarted()) {
|
|
|
|
qWarning("Cannot start '%s': %s", qPrintable(qmakePath), qPrintable(qmake.errorString()));
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
if (!qmake.waitForFinished()) {
|
|
|
|
Utils::SynchronousProcess::stopProcess(qmake);
|
|
|
|
qWarning("Timeout running '%s'.", qPrintable(qmakePath));
|
2010-06-21 12:05:18 +02:00
|
|
|
return QString();
|
2010-09-08 15:22:58 +02:00
|
|
|
}
|
2009-03-25 17:30:48 +01:00
|
|
|
QString output = qmake.readAllStandardOutput();
|
2009-05-14 17:02:30 +02:00
|
|
|
QRegExp regexp(QLatin1String("(QMake version|Qmake version:)[\\s]*([\\d.]*)"));
|
2009-03-25 17:30:48 +01:00
|
|
|
regexp.indexIn(output);
|
2009-05-14 17:02:30 +02:00
|
|
|
if (regexp.cap(2).startsWith(QLatin1String("2."))) {
|
|
|
|
QRegExp regexp2(QLatin1String("Using Qt version[\\s]*([\\d\\.]*)"));
|
2009-03-25 17:30:48 +01:00
|
|
|
regexp2.indexIn(output);
|
|
|
|
return regexp2.cap(1);
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
2009-03-09 18:13:19 +01:00
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
/////
|
|
|
|
// CMakeSettingsPage
|
2009-04-24 14:59:47 +02:00
|
|
|
////
|
2009-01-21 16:25:21 +01:00
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
|
|
|
|
CMakeSettingsPage::CMakeSettingsPage()
|
2011-02-09 14:21:26 +01:00
|
|
|
: m_pathchooser(0)
|
2009-01-21 16:25:21 +01:00
|
|
|
{
|
2012-05-22 11:17:13 +02:00
|
|
|
setId(QLatin1String("Z.CMake"));
|
|
|
|
setDisplayName(tr("CMake"));
|
|
|
|
setCategory(QLatin1String(ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_CATEGORY));
|
|
|
|
setDisplayCategory(QCoreApplication::translate("ProjectExplorer",
|
|
|
|
ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_TR_CATEGORY));
|
|
|
|
setCategoryIcon(QLatin1String(ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_CATEGORY_ICON));
|
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
m_userCmake.process = 0;
|
|
|
|
m_pathCmake.process = 0;
|
2011-02-09 16:49:35 +01:00
|
|
|
m_userCmake.hasCodeBlocksMsvcGenerator = false;
|
|
|
|
m_pathCmake.hasCodeBlocksMsvcGenerator = false;
|
2012-10-02 17:46:12 +02:00
|
|
|
m_userCmake.hasCodeBlocksNinjaGenerator = false;
|
|
|
|
m_pathCmake.hasCodeBlocksNinjaGenerator = false;
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2009-09-23 14:33:05 +02:00
|
|
|
settings->beginGroup(QLatin1String("CMakeSettings"));
|
2011-02-09 14:21:26 +01:00
|
|
|
m_userCmake.executable = settings->value(QLatin1String("cmakeExecutable")).toString();
|
2009-09-23 14:33:05 +02:00
|
|
|
settings->endGroup();
|
2011-02-09 14:21:26 +01:00
|
|
|
|
|
|
|
updateInfo(&m_userCmake);
|
|
|
|
m_pathCmake.executable = findCmakeExecutable();
|
|
|
|
updateInfo(&m_pathCmake);
|
2009-01-21 17:21:59 +01:00
|
|
|
}
|
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
void CMakeSettingsPage::startProcess(CMakeValidator *cmakeValidator)
|
2009-01-21 17:21:59 +01:00
|
|
|
{
|
2011-02-09 14:21:26 +01:00
|
|
|
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()));
|
2009-01-23 16:57:38 +01:00
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeValidator->process->start(cmakeValidator->executable, QStringList(QLatin1String("--help")));
|
|
|
|
cmakeValidator->process->waitForStarted();
|
|
|
|
}
|
2009-01-23 16:57:38 +01:00
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
void CMakeSettingsPage::userCmakeFinished()
|
|
|
|
{
|
|
|
|
cmakeFinished(&m_userCmake);
|
2009-01-23 16:57:38 +01:00
|
|
|
}
|
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
void CMakeSettingsPage::pathCmakeFinished()
|
2009-01-23 16:57:38 +01:00
|
|
|
{
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeFinished(&m_pathCmake);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeSettingsPage::cmakeFinished(CMakeValidator *cmakeValidator) const
|
|
|
|
{
|
|
|
|
if (cmakeValidator->process) {
|
2011-03-10 14:15:38 +01:00
|
|
|
cmakeValidator->process->waitForFinished();
|
2011-02-09 14:21:26 +01:00
|
|
|
QString response = cmakeValidator->process->readAll();
|
2009-09-23 14:33:05 +02:00
|
|
|
QRegExp versionRegexp(QLatin1String("^cmake version ([\\d\\.]*)"));
|
|
|
|
versionRegexp.indexIn(response);
|
2009-01-23 16:57:38 +01:00
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
//m_supportsQtCreator = response.contains(QLatin1String("QtCreator"));
|
2012-10-02 17:46:12 +02:00
|
|
|
cmakeValidator->hasCodeBlocksNinjaGenerator = response.contains(QLatin1String("CodeBlocks - Ninja"));
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeValidator->hasCodeBlocksMsvcGenerator = response.contains(QLatin1String("CodeBlocks - NMake Makefiles"));
|
|
|
|
cmakeValidator->version = versionRegexp.cap(1);
|
2009-09-23 14:33:05 +02:00
|
|
|
if (!(versionRegexp.capturedTexts().size() > 3))
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeValidator->version += QLatin1Char('.') + versionRegexp.cap(3);
|
2009-01-23 16:57:38 +01:00
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
if (cmakeValidator->version.isEmpty())
|
|
|
|
cmakeValidator->state = CMakeValidator::INVALID;
|
2009-09-23 14:33:05 +02:00
|
|
|
else
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeValidator->state = CMakeValidator::VALID;
|
2009-09-23 14:33:05 +02:00
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeValidator->process->deleteLater();
|
|
|
|
cmakeValidator->process = 0;
|
2009-09-23 14:33:05 +02:00
|
|
|
}
|
2009-07-02 11:30:29 +02:00
|
|
|
}
|
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
bool CMakeSettingsPage::isCMakeExecutableValid() const
|
2009-01-23 16:57:38 +01:00
|
|
|
{
|
2011-02-09 14:21:26 +01:00
|
|
|
if (m_userCmake.state == CMakeValidator::RUNNING) {
|
|
|
|
disconnect(m_userCmake.process, SIGNAL(finished(int)),
|
2011-04-13 13:10:30 +02:00
|
|
|
this, SLOT(userCmakeFinished()));
|
2011-02-09 14:21:26 +01:00
|
|
|
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)),
|
2011-04-13 13:10:30 +02:00
|
|
|
this, SLOT(pathCmakeFinished()));
|
2011-02-09 14:21:26 +01:00
|
|
|
m_pathCmake.process->waitForFinished();
|
2009-09-23 14:33:05 +02:00
|
|
|
// Parse the output now
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeFinished(&m_pathCmake);
|
2009-09-23 14:33:05 +02:00
|
|
|
}
|
2011-02-09 14:21:26 +01:00
|
|
|
return m_pathCmake.state == CMakeValidator::VALID;
|
2009-01-23 16:57:38 +01:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
CMakeSettingsPage::~CMakeSettingsPage()
|
2009-01-23 16:57:38 +01:00
|
|
|
{
|
2011-02-09 14:21:26 +01:00
|
|
|
if (m_userCmake.process)
|
|
|
|
m_userCmake.process->waitForFinished();
|
|
|
|
delete m_userCmake.process;
|
|
|
|
if (m_pathCmake.process)
|
|
|
|
m_pathCmake.process->waitForFinished();
|
|
|
|
delete m_pathCmake.process;
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeSettingsPage::findCmakeExecutable() const
|
|
|
|
{
|
2010-09-23 10:35:23 +02:00
|
|
|
Utils::Environment env = Utils::Environment::systemEnvironment();
|
2009-05-14 17:02:30 +02:00
|
|
|
return env.searchInPath(QLatin1String("cmake"));
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *CMakeSettingsPage::createPage(QWidget *parent)
|
|
|
|
{
|
2009-11-20 16:55:23 +01:00
|
|
|
QWidget *outerWidget = new QWidget(parent);
|
2010-04-13 17:31:42 +02:00
|
|
|
QFormLayout *formLayout = new QFormLayout(outerWidget);
|
2012-01-13 14:24:07 +01:00
|
|
|
formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
|
2009-11-20 16:55:23 +01:00
|
|
|
m_pathchooser = new Utils::PathChooser;
|
2010-09-23 17:28:18 +02:00
|
|
|
m_pathchooser->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
2009-11-20 16:55:23 +01:00
|
|
|
formLayout->addRow(tr("Executable:"), m_pathchooser);
|
2010-04-13 17:31:42 +02:00
|
|
|
formLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
|
2011-02-09 14:21:26 +01:00
|
|
|
m_pathchooser->setPath(m_userCmake.executable);
|
2009-11-20 16:55:23 +01:00
|
|
|
return outerWidget;
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2011-02-09 14:21:26 +01:00
|
|
|
void CMakeSettingsPage::updateInfo(CMakeValidator *cmakeValidator)
|
2009-09-23 14:33:05 +02:00
|
|
|
{
|
2011-02-09 14:21:26 +01:00
|
|
|
QFileInfo fi(cmakeValidator->executable);
|
2009-09-23 14:33:05 +02:00
|
|
|
if (fi.exists() && fi.isExecutable()) {
|
|
|
|
// Run it to find out more
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeValidator->state = CMakeValidator::RUNNING;
|
|
|
|
startProcess(cmakeValidator);
|
2009-09-23 14:33:05 +02:00
|
|
|
} else {
|
2011-02-09 14:21:26 +01:00
|
|
|
cmakeValidator->state = CMakeValidator::INVALID;
|
2009-09-23 14:33:05 +02:00
|
|
|
}
|
|
|
|
saveSettings();
|
|
|
|
}
|
|
|
|
|
2009-01-21 16:25:21 +01:00
|
|
|
void CMakeSettingsPage::saveSettings() const
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2009-05-14 17:02:30 +02:00
|
|
|
settings->beginGroup(QLatin1String("CMakeSettings"));
|
2011-02-09 14:21:26 +01:00
|
|
|
settings->setValue(QLatin1String("cmakeExecutable"), m_userCmake.executable);
|
2009-01-21 16:25:21 +01:00
|
|
|
settings->endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeSettingsPage::apply()
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!m_pathchooser) // page was never shown
|
|
|
|
return;
|
2011-02-09 14:21:26 +01:00
|
|
|
if (m_userCmake.executable == m_pathchooser->path())
|
2009-09-23 14:33:05 +02:00
|
|
|
return;
|
2011-02-09 14:21:26 +01:00
|
|
|
m_userCmake.executable = m_pathchooser->path();
|
|
|
|
updateInfo(&m_userCmake);
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeSettingsPage::finish()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeSettingsPage::cmakeExecutable() const
|
|
|
|
{
|
2011-02-09 14:21:26 +01:00
|
|
|
if (!isCMakeExecutableValid())
|
|
|
|
return QString();
|
|
|
|
if (m_userCmake.state == CMakeValidator::VALID)
|
|
|
|
return m_userCmake.executable;
|
|
|
|
else
|
|
|
|
return m_pathCmake.executable;
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
void CMakeSettingsPage::setCMakeExecutable(const QString &executable)
|
2009-07-02 11:30:29 +02:00
|
|
|
{
|
2011-02-09 14:21:26 +01:00
|
|
|
if (m_userCmake.executable == executable)
|
2009-09-23 14:33:05 +02:00
|
|
|
return;
|
2011-02-09 14:21:26 +01:00
|
|
|
m_userCmake.executable = executable;
|
|
|
|
updateInfo(&m_userCmake);
|
2009-07-02 11:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
bool CMakeSettingsPage::hasCodeBlocksMsvcGenerator() const
|
2009-01-21 16:25:21 +01:00
|
|
|
{
|
2011-02-09 14:21:26 +01:00
|
|
|
if (!isCMakeExecutableValid())
|
|
|
|
return false;
|
|
|
|
if (m_userCmake.state == CMakeValidator::VALID)
|
|
|
|
return m_userCmake.hasCodeBlocksMsvcGenerator;
|
|
|
|
else
|
|
|
|
return m_pathCmake.hasCodeBlocksMsvcGenerator;
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
2012-10-02 17:46:12 +02:00
|
|
|
|
|
|
|
bool CMakeSettingsPage::hasCodeBlocksNinjaGenerator() const
|
|
|
|
{
|
|
|
|
if (!isCMakeExecutableValid())
|
|
|
|
return false;
|
|
|
|
if (m_userCmake.state == CMakeValidator::VALID)
|
|
|
|
return m_userCmake.hasCodeBlocksNinjaGenerator;
|
|
|
|
else
|
|
|
|
return m_pathCmake.hasCodeBlocksNinjaGenerator;
|
|
|
|
}
|