2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Nokia.
|
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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, 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
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
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>
|
|
|
|
|
2009-01-23 16:57:38 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2009-01-23 16:57:38 +01:00
|
|
|
#include <qtconcurrent/QtConcurrentTools>
|
|
|
|
#include <QtCore/QtConcurrentRun>
|
2010-06-16 17:30:18 +02:00
|
|
|
#include <QtCore/QCoreApplication>
|
2009-01-21 16:25:21 +01:00
|
|
|
#include <QtCore/QSettings>
|
2009-01-23 16:57:38 +01:00
|
|
|
#include <QtGui/QFormLayout>
|
2009-11-20 16:55:23 +01:00
|
|
|
#include <QtGui/QBoxLayout>
|
2009-03-25 17:30:48 +01:00
|
|
|
#include <QtGui/QDesktopServices>
|
|
|
|
#include <QtGui/QApplication>
|
2009-09-23 14:33:05 +02:00
|
|
|
#include <QtGui/QLabel>
|
2009-11-20 16:55:23 +01:00
|
|
|
#include <QtGui/QGroupBox>
|
|
|
|
#include <QtGui/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
|
|
|
{
|
2010-07-02 13:43:41 +02:00
|
|
|
m_projectContext = Core::Context(CMakeProjectManager::Constants::PROJECTCONTEXT);
|
2010-07-02 14:00:05 +02:00
|
|
|
m_projectLanguage = Core::Context(ProjectExplorer::Constants::LANG_CXX);
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2010-07-02 13:43:41 +02:00
|
|
|
Core::Context CMakeManager::projectContext() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
return m_projectContext;
|
|
|
|
}
|
|
|
|
|
2010-07-02 14:00:05 +02:00
|
|
|
Core::Context CMakeManager::projectLanguage() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
return m_projectLanguage;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectExplorer::Project *CMakeManager::openProject(const QString &fileName)
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
2009-01-23 16:57:38 +01:00
|
|
|
// TODO 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
|
|
|
|
// sounds like a plan
|
2010-09-23 10:35:23 +02:00
|
|
|
void CMakeManager::createXmlFile(QProcess *proc, const QStringList &arguments,
|
|
|
|
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
|
|
|
|
|
|
|
|
// TODO we need to pass on the same paremeters as the cmakestep
|
|
|
|
QString buildDirectoryPath = buildDirectory.absolutePath();
|
|
|
|
buildDirectory.mkpath(buildDirectoryPath);
|
2009-10-21 13:45:49 +02:00
|
|
|
proc->setWorkingDirectory(buildDirectoryPath);
|
|
|
|
proc->setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
proc->setEnvironment(env.toStringList());
|
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;
|
2009-10-21 13:45:49 +02:00
|
|
|
proc->start(cmakeExecutable(), QStringList() << srcdir << arguments << generator);
|
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
|
|
|
|
// TODO the cbp file is named like the project() command in the CMakeList.txt file
|
|
|
|
// so this method below could find the wrong cbp file, if the user changes the project()
|
|
|
|
// 2name
|
|
|
|
foreach (const QString &cbpFile , directory.entryList()) {
|
2009-05-14 17:02:30 +02:00
|
|
|
if (cbpFile.endsWith(QLatin1String(".cbp")))
|
|
|
|
return directory.path() + QLatin1Char('/') + cbpFile;
|
2009-03-09 18:13:19 +01:00
|
|
|
}
|
2010-02-02 17:09:41 +01:00
|
|
|
return QString();
|
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()
|
2009-09-25 11:35:44 +02:00
|
|
|
: m_pathchooser(0), m_process(0)
|
2009-01-21 16:25:21 +01:00
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
|
|
|
QSettings * settings = core->settings();
|
|
|
|
settings->beginGroup(QLatin1String("CMakeSettings"));
|
|
|
|
m_cmakeExecutable = 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;
|
|
|
|
}
|
2009-01-23 16:57:38 +01:00
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
settings->endGroup();
|
2009-01-21 17:21:59 +01:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
void CMakeSettingsPage::startProcess()
|
2009-01-21 17:21:59 +01:00
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
m_process = new QProcess();
|
2009-01-23 16:57:38 +01:00
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
connect(m_process, SIGNAL(finished(int)),
|
|
|
|
this, SLOT(cmakeFinished()));
|
2009-01-23 16:57:38 +01:00
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
m_process->start(m_cmakeExecutable, QStringList(QLatin1String("--help")));
|
|
|
|
m_process->waitForStarted();
|
2009-01-23 16:57:38 +01:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
void CMakeSettingsPage::cmakeFinished()
|
2009-01-23 16:57:38 +01:00
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
if (m_process) {
|
|
|
|
QString response = m_process->readAll();
|
|
|
|
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"));
|
|
|
|
m_hasCodeBlocksMsvcGenerator = response.contains(QLatin1String("CodeBlocks - NMake Makefiles"));
|
|
|
|
m_version = versionRegexp.cap(1);
|
|
|
|
if (!(versionRegexp.capturedTexts().size() > 3))
|
|
|
|
m_version += QLatin1Char('.') + versionRegexp.cap(3);
|
2009-01-23 16:57:38 +01:00
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
if (m_version.isEmpty())
|
|
|
|
m_state = INVALID;
|
|
|
|
else
|
|
|
|
m_state = VALID;
|
|
|
|
|
|
|
|
m_process->deleteLater();
|
|
|
|
m_process = 0;
|
|
|
|
}
|
2009-07-02 11:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
bool CMakeSettingsPage::isCMakeExecutableValid()
|
2009-01-23 16:57:38 +01:00
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
if (m_state == RUNNING) {
|
|
|
|
disconnect(m_process, SIGNAL(finished(int)),
|
|
|
|
this, SLOT(cmakeFinished()));
|
|
|
|
m_process->waitForFinished();
|
|
|
|
// Parse the output now
|
|
|
|
cmakeFinished();
|
|
|
|
}
|
|
|
|
return m_state == 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
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
if (m_process)
|
|
|
|
m_process->waitForFinished();
|
|
|
|
delete m_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
|
|
|
}
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
QString CMakeSettingsPage::id() const
|
|
|
|
{
|
2010-03-26 17:41:10 +01:00
|
|
|
return QLatin1String("Z.CMake");
|
2009-03-18 16:43:01 +01:00
|
|
|
}
|
2009-01-21 16:25:21 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString CMakeSettingsPage::displayName() const
|
2009-01-21 16:25:21 +01:00
|
|
|
{
|
2009-03-18 16:43:01 +01:00
|
|
|
return tr("CMake");
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeSettingsPage::category() const
|
|
|
|
{
|
2010-03-26 17:41:10 +01:00
|
|
|
return QLatin1String(ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_CATEGORY);
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString CMakeSettingsPage::displayCategory() const
|
2009-01-21 16:25:21 +01:00
|
|
|
{
|
2010-06-16 17:30:18 +02:00
|
|
|
return QCoreApplication::translate("ProjectExplorer",
|
|
|
|
ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_TR_CATEGORY);
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2010-03-26 17:34:10 +01:00
|
|
|
QIcon CMakeSettingsPage::categoryIcon() const
|
|
|
|
{
|
2010-03-26 17:41:10 +01:00
|
|
|
return QIcon(QLatin1String(ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_CATEGORY_ICON));
|
2010-03-26 17:34:10 +01:00
|
|
|
}
|
|
|
|
|
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);
|
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));
|
2009-01-21 16:25:21 +01:00
|
|
|
m_pathchooser->setPath(cmakeExecutable());
|
2009-11-20 16:55:23 +01:00
|
|
|
return outerWidget;
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
void CMakeSettingsPage::updateInfo()
|
|
|
|
{
|
|
|
|
QFileInfo fi(m_cmakeExecutable);
|
|
|
|
if (fi.exists() && fi.isExecutable()) {
|
|
|
|
// Run it to find out more
|
|
|
|
m_state = RUNNING;
|
|
|
|
startProcess();
|
|
|
|
} else {
|
|
|
|
m_state = INVALID;
|
|
|
|
}
|
|
|
|
saveSettings();
|
|
|
|
}
|
|
|
|
|
2009-01-21 16:25:21 +01:00
|
|
|
void CMakeSettingsPage::saveSettings() const
|
|
|
|
{
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
2009-05-14 17:02:30 +02:00
|
|
|
settings->beginGroup(QLatin1String("CMakeSettings"));
|
2009-09-23 14:33:05 +02:00
|
|
|
settings->setValue(QLatin1String("cmakeExecutable"), m_cmakeExecutable);
|
2009-01-21 16:25:21 +01:00
|
|
|
settings->endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeSettingsPage::apply()
|
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
if (m_cmakeExecutable == m_pathchooser->path())
|
|
|
|
return;
|
|
|
|
m_cmakeExecutable = m_pathchooser->path();
|
|
|
|
updateInfo();
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMakeSettingsPage::finish()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CMakeSettingsPage::cmakeExecutable() const
|
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
return m_cmakeExecutable;
|
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
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
if (m_cmakeExecutable == executable)
|
|
|
|
return;
|
|
|
|
m_cmakeExecutable = executable;
|
|
|
|
updateInfo();
|
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
|
|
|
{
|
2009-09-23 14:33:05 +02:00
|
|
|
return m_hasCodeBlocksMsvcGenerator;
|
2009-01-21 16:25:21 +01:00
|
|
|
}
|