2009-03-20 14:57:12 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
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.
|
2009-03-20 14:57:12 +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.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2009-07-02 11:30:29 +02:00
|
|
|
|
|
|
|
|
/// TODO
|
|
|
|
|
/// To check
|
|
|
|
|
/// a) with an old cmake
|
|
|
|
|
/// => should not show combobox always use mingw generator
|
|
|
|
|
/// b) with an new cmake
|
|
|
|
|
/// always show combo box, defaulting if there's already a existing build
|
|
|
|
|
|
|
|
|
|
|
2009-03-10 09:36:18 +01:00
|
|
|
#include "cmakeopenprojectwizard.h"
|
|
|
|
|
#include "cmakeprojectmanager.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/pathchooser.h>
|
2011-02-01 18:36:00 +01:00
|
|
|
#include <projectexplorer/toolchainmanager.h>
|
2009-03-10 09:36:18 +01:00
|
|
|
|
|
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
#include <QtGui/QFormLayout>
|
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
#include <QtGui/QPlainTextEdit>
|
|
|
|
|
#include <QtCore/QDateTime>
|
2009-03-16 17:33:05 +01:00
|
|
|
#include <QtCore/QStringList>
|
2009-03-10 09:36:18 +01:00
|
|
|
|
|
|
|
|
using namespace CMakeProjectManager;
|
|
|
|
|
using namespace CMakeProjectManager::Internal;
|
|
|
|
|
|
|
|
|
|
///////
|
|
|
|
|
// Page Flow:
|
|
|
|
|
// Start (No .user file)
|
|
|
|
|
// |
|
|
|
|
|
// |---> In Source Build --> Page: Tell the user about that
|
|
|
|
|
// |--> Already existing cbp file (and new enough) --> Page: Ready to load the project
|
|
|
|
|
// |--> Page: Ask for cmd options, run generator
|
|
|
|
|
// |---> No in source Build --> Page: Ask the user for the build directory
|
|
|
|
|
// |--> Already existing cbp file (and new enough) --> Page: Ready to load the project
|
|
|
|
|
// |--> Page: Ask for cmd options, run generator
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
CMakeOpenProjectWizard::CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory, const Utils::Environment &env)
|
2009-03-10 09:36:18 +01:00
|
|
|
: m_cmakeManager(cmakeManager),
|
2009-03-16 17:33:05 +01:00
|
|
|
m_sourceDirectory(sourceDirectory),
|
2009-05-26 16:10:13 +02:00
|
|
|
m_creatingCbpFiles(false),
|
2011-02-01 18:36:00 +01:00
|
|
|
m_environment(env),
|
|
|
|
|
m_toolChain(0)
|
2009-03-10 09:36:18 +01:00
|
|
|
{
|
|
|
|
|
int startid;
|
|
|
|
|
if (hasInSourceBuild()) {
|
|
|
|
|
startid = InSourcePageId;
|
|
|
|
|
m_buildDirectory = m_sourceDirectory;
|
|
|
|
|
} else {
|
|
|
|
|
startid = ShadowBuildPageId;
|
2010-04-12 17:38:57 +02:00
|
|
|
QDir dir(m_sourceDirectory);
|
|
|
|
|
dir.cdUp();
|
|
|
|
|
m_buildDirectory = dir.absolutePath() + "/qtcreator-build";
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPage(InSourcePageId, new InSourceBuildPage(this));
|
|
|
|
|
setPage(ShadowBuildPageId, new ShadowBuildPage(this));
|
|
|
|
|
setPage(CMakeRunPageId, new CMakeRunPage(this));
|
|
|
|
|
|
2010-03-31 14:48:08 +02:00
|
|
|
Utils::WizardProgress *wp = wizardProgress();
|
|
|
|
|
Utils::WizardProgressItem *inSourceItem = wp->item(InSourcePageId);
|
|
|
|
|
Utils::WizardProgressItem *shadowBuildItem = wp->item(ShadowBuildPageId);
|
|
|
|
|
Utils::WizardProgressItem *cmakeRunItem = wp->item(CMakeRunPageId);
|
|
|
|
|
inSourceItem->setNextItems(QList<Utils::WizardProgressItem *>() << cmakeRunItem);
|
|
|
|
|
shadowBuildItem->setNextItems(QList<Utils::WizardProgressItem *>() << cmakeRunItem);
|
|
|
|
|
|
2009-03-10 09:36:18 +01:00
|
|
|
setStartId(startid);
|
2009-06-10 16:03:16 +02:00
|
|
|
init();
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-16 17:33:05 +01:00
|
|
|
CMakeOpenProjectWizard::CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory,
|
2009-05-26 16:10:13 +02:00
|
|
|
const QString &buildDirectory, CMakeOpenProjectWizard::Mode mode,
|
2010-09-23 10:35:23 +02:00
|
|
|
const Utils::Environment &env)
|
2009-03-16 17:33:05 +01:00
|
|
|
: m_cmakeManager(cmakeManager),
|
|
|
|
|
m_sourceDirectory(sourceDirectory),
|
2009-05-26 16:10:13 +02:00
|
|
|
m_creatingCbpFiles(true),
|
2011-02-01 18:36:00 +01:00
|
|
|
m_environment(env),
|
|
|
|
|
m_toolChain(0)
|
2009-03-16 17:33:05 +01:00
|
|
|
{
|
2010-09-02 13:57:14 +02:00
|
|
|
|
|
|
|
|
CMakeRunPage::Mode rmode;
|
2009-05-26 15:50:27 +02:00
|
|
|
if (mode == CMakeOpenProjectWizard::NeedToCreate)
|
2010-09-02 13:57:14 +02:00
|
|
|
rmode = CMakeRunPage::Recreate;
|
|
|
|
|
else if (mode == CMakeOpenProjectWizard::WantToUpdate)
|
|
|
|
|
rmode = CMakeRunPage::WantToUpdate;
|
2009-05-26 15:50:27 +02:00
|
|
|
else
|
2010-09-02 13:57:14 +02:00
|
|
|
rmode = CMakeRunPage::NeedToUpdate;
|
|
|
|
|
addPage(new CMakeRunPage(this, rmode, buildDirectory));
|
2009-06-10 16:03:16 +02:00
|
|
|
init();
|
2009-03-16 17:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-20 14:35:25 +02:00
|
|
|
CMakeOpenProjectWizard::CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory,
|
2009-05-26 16:10:13 +02:00
|
|
|
const QString &oldBuildDirectory,
|
2010-09-23 10:35:23 +02:00
|
|
|
const Utils::Environment &env)
|
2009-04-20 14:35:25 +02:00
|
|
|
: m_cmakeManager(cmakeManager),
|
|
|
|
|
m_sourceDirectory(sourceDirectory),
|
2009-05-26 16:10:13 +02:00
|
|
|
m_creatingCbpFiles(true),
|
2011-02-01 18:36:00 +01:00
|
|
|
m_environment(env),
|
|
|
|
|
m_toolChain(0)
|
2009-04-20 14:35:25 +02:00
|
|
|
{
|
|
|
|
|
m_buildDirectory = oldBuildDirectory;
|
|
|
|
|
addPage(new ShadowBuildPage(this, true));
|
2010-09-02 13:57:14 +02:00
|
|
|
addPage(new CMakeRunPage(this, CMakeRunPage::ChangeDirectory));
|
2009-06-10 16:03:16 +02:00
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeOpenProjectWizard::init()
|
|
|
|
|
{
|
2009-04-20 14:35:25 +02:00
|
|
|
setOption(QWizard::NoBackButtonOnStartPage);
|
2009-06-10 16:03:16 +02:00
|
|
|
setWindowTitle(tr("CMake Wizard"));
|
2009-04-20 14:35:25 +02:00
|
|
|
}
|
|
|
|
|
|
2009-03-10 09:36:18 +01:00
|
|
|
CMakeManager *CMakeOpenProjectWizard::cmakeManager() const
|
|
|
|
|
{
|
|
|
|
|
return m_cmakeManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CMakeOpenProjectWizard::nextId() const
|
|
|
|
|
{
|
2009-03-16 17:33:05 +01:00
|
|
|
if (m_creatingCbpFiles)
|
|
|
|
|
return QWizard::nextId();
|
2009-03-10 09:36:18 +01:00
|
|
|
int cid = currentId();
|
|
|
|
|
if (cid == InSourcePageId) {
|
2009-07-03 12:46:19 +02:00
|
|
|
return CMakeRunPageId;
|
2009-03-10 09:36:18 +01:00
|
|
|
} else if (cid == ShadowBuildPageId) {
|
2009-07-03 12:46:19 +02:00
|
|
|
return CMakeRunPageId;
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CMakeOpenProjectWizard::hasInSourceBuild() const
|
|
|
|
|
{
|
|
|
|
|
QFileInfo fi(m_sourceDirectory + "/CMakeCache.txt");
|
|
|
|
|
if (fi.exists())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeOpenProjectWizard::existsUpToDateXmlFile() const
|
|
|
|
|
{
|
|
|
|
|
QString cbpFile = CMakeManager::findCbpFile(QDir(buildDirectory()));
|
|
|
|
|
if (!cbpFile.isEmpty()) {
|
|
|
|
|
// We already have a cbp file
|
|
|
|
|
QFileInfo cbpFileInfo(cbpFile);
|
|
|
|
|
QFileInfo cmakeListsFileInfo(sourceDirectory() + "/CMakeLists.txt");
|
|
|
|
|
|
|
|
|
|
if (cbpFileInfo.lastModified() > cmakeListsFileInfo.lastModified())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeOpenProjectWizard::buildDirectory() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeOpenProjectWizard::sourceDirectory() const
|
|
|
|
|
{
|
|
|
|
|
return m_sourceDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeOpenProjectWizard::setBuildDirectory(const QString &directory)
|
|
|
|
|
{
|
|
|
|
|
m_buildDirectory = directory;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
QString CMakeOpenProjectWizard::arguments() const
|
2009-07-02 16:44:51 +02:00
|
|
|
{
|
2011-02-01 18:36:00 +01:00
|
|
|
return m_arguments;
|
2009-07-02 16:44:51 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
void CMakeOpenProjectWizard::setArguments(const QString &args)
|
2009-07-02 16:44:51 +02:00
|
|
|
{
|
2011-02-01 18:36:00 +01:00
|
|
|
m_arguments = args;
|
2009-07-02 16:44:51 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
ProjectExplorer::ToolChain *CMakeOpenProjectWizard::toolChain() const
|
2009-03-10 09:36:18 +01:00
|
|
|
{
|
2011-02-01 18:36:00 +01:00
|
|
|
return m_toolChain;
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
void CMakeOpenProjectWizard::setToolChain(ProjectExplorer::ToolChain *tc)
|
2009-03-10 09:36:18 +01:00
|
|
|
{
|
2011-02-01 18:36:00 +01:00
|
|
|
m_toolChain = tc;
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
Utils::Environment CMakeOpenProjectWizard::environment() const
|
2009-05-26 16:10:13 +02:00
|
|
|
{
|
|
|
|
|
return m_environment;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-10 09:36:18 +01:00
|
|
|
|
|
|
|
|
InSourceBuildPage::InSourceBuildPage(CMakeOpenProjectWizard *cmakeWizard)
|
|
|
|
|
: QWizardPage(cmakeWizard), m_cmakeWizard(cmakeWizard)
|
|
|
|
|
{
|
|
|
|
|
setLayout(new QVBoxLayout);
|
|
|
|
|
QLabel *label = new QLabel(this);
|
|
|
|
|
label->setWordWrap(true);
|
2009-08-13 17:36:56 +02:00
|
|
|
label->setText(tr("Qt Creator has detected an <b>in-source-build in %1</b> "
|
2009-05-07 15:34:52 +02:00
|
|
|
"which prevents shadow builds. Qt Creator will not allow you to change the build directory. "
|
2009-12-03 19:45:09 +01:00
|
|
|
"If you want a shadow build, clean your source directory and re-open the project.")
|
|
|
|
|
.arg(m_cmakeWizard->buildDirectory()));
|
2009-03-10 09:36:18 +01:00
|
|
|
layout()->addWidget(label);
|
2010-03-31 14:48:08 +02:00
|
|
|
setTitle(tr("Build Location"));
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-20 14:35:25 +02:00
|
|
|
ShadowBuildPage::ShadowBuildPage(CMakeOpenProjectWizard *cmakeWizard, bool change)
|
2009-03-10 09:36:18 +01:00
|
|
|
: QWizardPage(cmakeWizard), m_cmakeWizard(cmakeWizard)
|
|
|
|
|
{
|
|
|
|
|
QFormLayout *fl = new QFormLayout;
|
|
|
|
|
this->setLayout(fl);
|
|
|
|
|
|
|
|
|
|
QLabel *label = new QLabel(this);
|
|
|
|
|
label->setWordWrap(true);
|
2009-04-20 14:35:25 +02:00
|
|
|
if (change)
|
|
|
|
|
label->setText(tr("Please enter the directory in which you want to build your project. "));
|
|
|
|
|
else
|
|
|
|
|
label->setText(tr("Please enter the directory in which you want to build your project. "
|
|
|
|
|
"Qt Creator recommends to not use the source directory for building. "
|
|
|
|
|
"This ensures that the source directory remains clean and enables multiple builds "
|
|
|
|
|
"with different settings."));
|
2009-03-10 09:36:18 +01:00
|
|
|
fl->addWidget(label);
|
2009-10-05 11:06:05 +02:00
|
|
|
m_pc = new Utils::PathChooser(this);
|
2010-09-17 14:58:07 +02:00
|
|
|
m_pc->setBaseDirectory(m_cmakeWizard->sourceDirectory());
|
2009-03-10 09:36:18 +01:00
|
|
|
m_pc->setPath(m_cmakeWizard->buildDirectory());
|
2009-06-19 17:55:47 +02:00
|
|
|
connect(m_pc, SIGNAL(changed(QString)), this, SLOT(buildDirectoryChanged()));
|
2009-04-17 21:11:52 +02:00
|
|
|
fl->addRow(tr("Build directory:"), m_pc);
|
2010-03-31 14:48:08 +02:00
|
|
|
setTitle(tr("Build Location"));
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShadowBuildPage::buildDirectoryChanged()
|
|
|
|
|
{
|
|
|
|
|
m_cmakeWizard->setBuildDirectory(m_pc->path());
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-20 14:35:25 +02:00
|
|
|
CMakeRunPage::CMakeRunPage(CMakeOpenProjectWizard *cmakeWizard, Mode mode, const QString &buildDirectory)
|
2009-03-16 17:33:05 +01:00
|
|
|
: QWizardPage(cmakeWizard),
|
|
|
|
|
m_cmakeWizard(cmakeWizard),
|
|
|
|
|
m_complete(false),
|
2009-04-20 14:35:25 +02:00
|
|
|
m_mode(mode),
|
|
|
|
|
m_buildDirectory(buildDirectory)
|
2009-03-16 17:33:05 +01:00
|
|
|
{
|
|
|
|
|
initWidgets();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeRunPage::initWidgets()
|
2009-03-10 09:36:18 +01:00
|
|
|
{
|
|
|
|
|
QFormLayout *fl = new QFormLayout;
|
|
|
|
|
setLayout(fl);
|
2009-09-23 14:33:05 +02:00
|
|
|
// Description Label
|
2009-03-16 17:33:05 +01:00
|
|
|
m_descriptionLabel = new QLabel(this);
|
|
|
|
|
m_descriptionLabel->setWordWrap(true);
|
|
|
|
|
|
|
|
|
|
fl->addRow(m_descriptionLabel);
|
2009-03-10 09:36:18 +01:00
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
if (m_cmakeWizard->cmakeManager()->isCMakeExecutableValid()) {
|
|
|
|
|
m_cmakeExecutable = 0;
|
|
|
|
|
} else {
|
2011-03-31 09:57:24 +02:00
|
|
|
QString text = tr("Please specify the path to the cmake executable. No cmake executable was found in the path.");
|
2009-09-23 14:33:05 +02:00
|
|
|
QString cmakeExecutable = m_cmakeWizard->cmakeManager()->cmakeExecutable();
|
|
|
|
|
if (!cmakeExecutable.isEmpty()) {
|
|
|
|
|
QFileInfo fi(cmakeExecutable);
|
|
|
|
|
if (!fi.exists())
|
2011-03-31 09:57:24 +02:00
|
|
|
text += tr(" The cmake executable (%1) does not exist.").arg(cmakeExecutable);
|
2009-09-23 14:33:05 +02:00
|
|
|
else if (!fi.isExecutable())
|
|
|
|
|
text += tr(" The path %1 is not a executable.").arg(cmakeExecutable);
|
|
|
|
|
else
|
2011-03-31 09:57:24 +02:00
|
|
|
text += tr(" The path %1 is not a valid cmake.").arg(cmakeExecutable);
|
2009-09-23 14:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fl->addRow(new QLabel(text, this));
|
|
|
|
|
// Show a field for the user to enter
|
2009-10-05 11:06:05 +02:00
|
|
|
m_cmakeExecutable = new Utils::PathChooser(this);
|
2010-09-23 17:28:18 +02:00
|
|
|
m_cmakeExecutable->setExpectedKind(Utils::PathChooser::ExistingCommand);
|
2011-03-31 09:57:24 +02:00
|
|
|
fl->addRow("cmake Executable", m_cmakeExecutable);
|
2009-09-23 14:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run CMake Line (with arguments)
|
2009-03-10 09:36:18 +01:00
|
|
|
m_argumentsLineEdit = new QLineEdit(this);
|
2009-06-09 15:45:20 +02:00
|
|
|
connect(m_argumentsLineEdit,SIGNAL(returnPressed()), this, SLOT(runCMake()));
|
2009-03-10 09:36:18 +01:00
|
|
|
|
2009-07-02 11:30:29 +02:00
|
|
|
m_generatorComboBox = new QComboBox(this);
|
2009-07-02 16:44:51 +02:00
|
|
|
|
2009-03-10 09:36:18 +01:00
|
|
|
m_runCMake = new QPushButton(this);
|
2009-04-06 17:07:51 +02:00
|
|
|
m_runCMake->setText(tr("Run CMake"));
|
2009-03-10 09:36:18 +01:00
|
|
|
connect(m_runCMake, SIGNAL(clicked()), this, SLOT(runCMake()));
|
2009-04-06 17:07:51 +02:00
|
|
|
|
|
|
|
|
QHBoxLayout *hbox = new QHBoxLayout;
|
|
|
|
|
hbox->addWidget(m_argumentsLineEdit);
|
2009-07-02 11:30:29 +02:00
|
|
|
hbox->addWidget(m_generatorComboBox);
|
2009-04-06 17:07:51 +02:00
|
|
|
hbox->addWidget(m_runCMake);
|
|
|
|
|
|
|
|
|
|
fl->addRow(tr("Arguments"), hbox);
|
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
// Bottom output window
|
2009-03-10 09:36:18 +01:00
|
|
|
m_output = new QPlainTextEdit(this);
|
2009-03-31 15:02:09 +02:00
|
|
|
m_output->setReadOnly(true);
|
2011-04-27 14:40:14 +02:00
|
|
|
QFont f("Courier");
|
|
|
|
|
f.setStyleHint(QFont::TypeWriter);
|
|
|
|
|
m_output->setFont(f);
|
2009-04-15 16:22:55 +02:00
|
|
|
QSizePolicy pl = m_output->sizePolicy();
|
|
|
|
|
pl.setVerticalStretch(1);
|
|
|
|
|
m_output->setSizePolicy(pl);
|
2009-03-10 09:36:18 +01:00
|
|
|
fl->addRow(m_output);
|
2010-10-04 17:52:55 +02:00
|
|
|
|
|
|
|
|
m_exitCodeLabel = new QLabel(this);
|
|
|
|
|
m_exitCodeLabel->setVisible(false);
|
|
|
|
|
fl->addRow(m_exitCodeLabel);
|
|
|
|
|
|
2010-03-31 14:48:08 +02:00
|
|
|
setTitle(tr("Run CMake"));
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-27 20:44:50 +01:00
|
|
|
void CMakeRunPage::initializePage()
|
|
|
|
|
{
|
2009-04-20 14:35:25 +02:00
|
|
|
if (m_mode == Initial) {
|
2009-07-03 12:46:19 +02:00
|
|
|
m_complete = m_cmakeWizard->existsUpToDateXmlFile();
|
2009-03-27 20:44:50 +01:00
|
|
|
m_buildDirectory = m_cmakeWizard->buildDirectory();
|
2009-07-03 12:46:19 +02:00
|
|
|
|
|
|
|
|
if (m_cmakeWizard->existsUpToDateXmlFile()) {
|
|
|
|
|
m_descriptionLabel->setText(
|
2009-07-31 16:41:12 +02:00
|
|
|
tr("The directory %1 already contains a cbp file, which is recent enough. "
|
2011-03-16 17:59:43 +01:00
|
|
|
"You can pass special arguments or change the used tool chain here and rerun CMake. "
|
2010-09-14 14:51:50 +02:00
|
|
|
"Or simply finish the wizard directly.").arg(m_buildDirectory));
|
2009-07-03 12:46:19 +02:00
|
|
|
} else {
|
|
|
|
|
m_descriptionLabel->setText(
|
2010-09-14 14:51:50 +02:00
|
|
|
tr("The directory %1 does not contain a cbp file. Qt Creator needs to create this file by running CMake. "
|
|
|
|
|
"Some projects require command line arguments to the initial CMake call.").arg(m_buildDirectory));
|
2009-07-03 12:46:19 +02:00
|
|
|
}
|
2010-09-02 13:57:14 +02:00
|
|
|
} else if (m_mode == CMakeRunPage::NeedToUpdate) {
|
2009-04-20 14:35:25 +02:00
|
|
|
m_descriptionLabel->setText(tr("The directory %1 contains an outdated .cbp file. Qt "
|
2010-09-14 14:51:50 +02:00
|
|
|
"Creator needs to update this file by running CMake. "
|
2009-04-20 14:35:25 +02:00
|
|
|
"If you want to add additional command line arguments, "
|
2010-09-14 14:51:50 +02:00
|
|
|
"add them below. Note that CMake remembers command "
|
2009-05-07 15:34:52 +02:00
|
|
|
"line arguments from the previous runs.").arg(m_buildDirectory));
|
2009-04-20 14:35:25 +02:00
|
|
|
} else if(m_mode == CMakeRunPage::Recreate) {
|
2009-05-07 15:34:52 +02:00
|
|
|
m_descriptionLabel->setText(tr("The directory %1 specified in a build-configuration, "
|
2009-04-20 14:35:25 +02:00
|
|
|
"does not contain a cbp file. Qt Creator needs to "
|
2010-09-14 14:51:50 +02:00
|
|
|
"recreate this file, by running CMake. "
|
2009-04-20 14:35:25 +02:00
|
|
|
"Some projects require command line arguments to "
|
2010-09-14 14:51:50 +02:00
|
|
|
"the initial CMake call. Note that CMake remembers command "
|
2009-05-07 15:34:52 +02:00
|
|
|
"line arguments from the previous runs.").arg(m_buildDirectory));
|
2010-09-02 13:57:14 +02:00
|
|
|
} else if(m_mode == CMakeRunPage::ChangeDirectory) {
|
2009-04-20 14:35:25 +02:00
|
|
|
m_buildDirectory = m_cmakeWizard->buildDirectory();
|
2010-09-14 14:51:50 +02:00
|
|
|
m_descriptionLabel->setText(tr("Qt Creator needs to run CMake in the new build directory. "
|
2009-04-20 14:35:25 +02:00
|
|
|
"Some projects require command line arguments to the "
|
2010-09-14 14:51:50 +02:00
|
|
|
"initial CMake call."));
|
2010-09-02 13:57:14 +02:00
|
|
|
} else if (m_mode == CMakeRunPage::WantToUpdate) {
|
|
|
|
|
m_descriptionLabel->setText(tr("Refreshing cbp file in %1.").arg(m_buildDirectory));
|
2009-03-27 20:44:50 +01:00
|
|
|
}
|
2009-07-02 11:30:29 +02:00
|
|
|
if (m_cmakeWizard->cmakeManager()->hasCodeBlocksMsvcGenerator()) {
|
2011-02-01 18:36:00 +01:00
|
|
|
// Try to find out generator from CMakeCache file, if it exists
|
2009-07-02 16:44:51 +02:00
|
|
|
QString cachedGenerator;
|
2009-09-23 14:34:53 +02:00
|
|
|
|
2009-07-02 11:30:29 +02:00
|
|
|
QFile fi(m_buildDirectory + "/CMakeCache.txt");
|
|
|
|
|
if (fi.exists()) {
|
|
|
|
|
// Cache exists, then read it...
|
2009-09-23 14:34:53 +02:00
|
|
|
if (fi.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
2009-09-23 15:40:19 +02:00
|
|
|
while (!fi.atEnd()) {
|
2009-07-02 11:30:29 +02:00
|
|
|
QString line = fi.readLine();
|
|
|
|
|
if (line.startsWith("CMAKE_GENERATOR:INTERNAL=")) {
|
|
|
|
|
int splitpos = line.indexOf('=');
|
|
|
|
|
if (splitpos != -1) {
|
2009-09-23 14:34:53 +02:00
|
|
|
cachedGenerator = line.mid(splitpos + 1).trimmed();
|
2009-07-02 11:30:29 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-29 21:33:57 +01:00
|
|
|
}
|
2009-07-02 16:44:51 +02:00
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
m_generatorComboBox->setVisible(true);
|
|
|
|
|
m_generatorComboBox->clear();
|
2011-04-13 12:01:54 +02:00
|
|
|
ProjectExplorer::Abi abi = ProjectExplorer::Abi::hostAbi();
|
|
|
|
|
abi = ProjectExplorer::Abi(abi.architecture(), abi.os(), ProjectExplorer::Abi::UnknownFlavor,
|
|
|
|
|
abi.binaryFormat(), abi.wordWidth() == 32 ? 32 : 0);
|
2011-02-01 18:36:00 +01:00
|
|
|
QList<ProjectExplorer::ToolChain *> tcs =
|
2011-04-13 12:01:54 +02:00
|
|
|
ProjectExplorer::ToolChainManager::instance()->findToolChains(abi);
|
2011-02-01 18:36:00 +01:00
|
|
|
foreach (ProjectExplorer::ToolChain *tc, tcs) {
|
|
|
|
|
ProjectExplorer::Abi targetAbi = tc->targetAbi();
|
|
|
|
|
QVariant tcVariant = qVariantFromValue(static_cast<void *>(tc));
|
2011-02-23 16:47:08 +01:00
|
|
|
if (targetAbi.os() == ProjectExplorer::Abi::WindowsOS) {
|
2011-03-18 09:54:35 +01:00
|
|
|
if (targetAbi.osFlavor() == ProjectExplorer::Abi::WindowsMsvc2005Flavor
|
|
|
|
|
|| targetAbi.osFlavor() == ProjectExplorer::Abi::WindowsMsvc2008Flavor
|
|
|
|
|
|| targetAbi.osFlavor() == ProjectExplorer::Abi::WindowsMsvc2010Flavor)
|
2011-02-01 18:36:00 +01:00
|
|
|
m_generatorComboBox->addItem(tr("NMake Generator (%1)").arg(tc->displayName()), tcVariant);
|
2011-02-23 16:47:08 +01:00
|
|
|
else if (targetAbi.osFlavor() == ProjectExplorer::Abi::WindowsMSysFlavor)
|
2011-02-01 18:36:00 +01:00
|
|
|
m_generatorComboBox->addItem(tr("MinGW Generator (%1)").arg(tc->displayName()), tcVariant);
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-12-03 19:45:09 +01:00
|
|
|
}
|
2009-07-02 11:30:29 +02:00
|
|
|
} else {
|
|
|
|
|
// No new enough cmake, simply hide the combo box
|
|
|
|
|
m_generatorComboBox->setVisible(false);
|
2011-02-01 18:36:00 +01:00
|
|
|
QList<ProjectExplorer::ToolChain *> tcs =
|
|
|
|
|
ProjectExplorer::ToolChainManager::instance()->findToolChains(ProjectExplorer::Abi::hostAbi());
|
|
|
|
|
if (tcs.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
m_cmakeWizard->setToolChain(tcs.at(0));
|
2009-07-02 11:30:29 +02:00
|
|
|
}
|
2009-03-27 20:44:50 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-10 09:36:18 +01:00
|
|
|
void CMakeRunPage::runCMake()
|
|
|
|
|
{
|
2011-02-01 18:36:00 +01:00
|
|
|
int index = m_generatorComboBox->currentIndex();
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::ToolChain *tc = 0;
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
tc = static_cast<ProjectExplorer::ToolChain *>(m_generatorComboBox->itemData(index).value<void *>());
|
|
|
|
|
if (!tc)
|
|
|
|
|
return;
|
|
|
|
|
m_cmakeWizard->setToolChain(tc);
|
|
|
|
|
} else {
|
|
|
|
|
tc = m_cmakeWizard->toolChain();
|
|
|
|
|
}
|
|
|
|
|
Q_ASSERT(tc);
|
|
|
|
|
|
2009-03-10 09:36:18 +01:00
|
|
|
m_runCMake->setEnabled(false);
|
|
|
|
|
m_argumentsLineEdit->setEnabled(false);
|
2011-02-01 18:36:00 +01:00
|
|
|
m_generatorComboBox->setEnabled(false);
|
2009-03-10 09:36:18 +01:00
|
|
|
CMakeManager *cmakeManager = m_cmakeWizard->cmakeManager();
|
2009-07-02 11:30:29 +02:00
|
|
|
|
2009-07-02 16:44:51 +02:00
|
|
|
QString generator = QLatin1String("-GCodeBlocks - Unix Makefiles");
|
2011-02-23 16:47:08 +01:00
|
|
|
if (tc->targetAbi().os() == ProjectExplorer::Abi::WindowsOS) {
|
2011-03-18 09:54:35 +01:00
|
|
|
if (tc->targetAbi().osFlavor() == ProjectExplorer::Abi::WindowsMSysFlavor)
|
2011-02-01 18:36:00 +01:00
|
|
|
generator = QLatin1String("-GCodeBlocks - MinGW Makefiles");
|
2011-03-18 09:54:35 +01:00
|
|
|
else
|
|
|
|
|
generator = QLatin1String("-GCodeBlocks - NMake Makefiles");
|
2009-07-02 16:44:51 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-01 18:36:00 +01:00
|
|
|
|
|
|
|
|
Utils::Environment env = m_cmakeWizard->environment();
|
|
|
|
|
tc->addToEnvironment(env);
|
|
|
|
|
|
2009-09-23 14:33:05 +02:00
|
|
|
if (m_cmakeExecutable) {
|
|
|
|
|
// We asked the user for the cmake executable
|
|
|
|
|
m_cmakeWizard->cmakeManager()->setCMakeExecutable(m_cmakeExecutable->path());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_output->clear();
|
|
|
|
|
|
|
|
|
|
if (m_cmakeWizard->cmakeManager()->isCMakeExecutableValid()) {
|
2010-10-19 11:14:03 +02:00
|
|
|
m_cmakeProcess = new Utils::QtcProcess();
|
2010-10-04 17:52:55 +02:00
|
|
|
connect(m_cmakeProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(cmakeReadyReadStandardOutput()));
|
|
|
|
|
connect(m_cmakeProcess, SIGNAL(readyReadStandardError()), this, SLOT(cmakeReadyReadStandardError()));
|
2009-09-23 14:33:05 +02:00
|
|
|
connect(m_cmakeProcess, SIGNAL(finished(int)), this, SLOT(cmakeFinished()));
|
2010-10-19 11:14:03 +02:00
|
|
|
cmakeManager->createXmlFile(m_cmakeProcess, m_argumentsLineEdit->text(), m_cmakeWizard->sourceDirectory(), m_buildDirectory, env, generator);
|
2009-09-23 14:33:05 +02:00
|
|
|
} else {
|
|
|
|
|
m_runCMake->setEnabled(true);
|
|
|
|
|
m_argumentsLineEdit->setEnabled(true);
|
2011-02-01 18:36:00 +01:00
|
|
|
m_generatorComboBox->setEnabled(true);
|
2011-03-31 09:57:24 +02:00
|
|
|
m_output->appendPlainText(tr("No valid cmake executable specified."));
|
2009-09-23 14:33:05 +02:00
|
|
|
}
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-04 17:52:55 +02:00
|
|
|
static QColor mix_colors(QColor a, QColor b)
|
|
|
|
|
{
|
|
|
|
|
return QColor((a.red() + 2 * b.red()) / 3, (a.green() + 2 * b.green()) / 3,
|
|
|
|
|
(a.blue() + 2* b.blue()) / 3, (a.alpha() + 2 * b.alpha()) / 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeRunPage::cmakeReadyReadStandardOutput()
|
|
|
|
|
{
|
|
|
|
|
QTextCursor cursor(m_output->document());
|
2011-04-27 14:41:15 +02:00
|
|
|
cursor.movePosition(QTextCursor::End);
|
2010-10-04 17:52:55 +02:00
|
|
|
QTextCharFormat tf;
|
|
|
|
|
|
|
|
|
|
QFont font = m_output->font();
|
|
|
|
|
tf.setFont(font);
|
|
|
|
|
tf.setForeground(m_output->palette().color(QPalette::Text));
|
|
|
|
|
|
|
|
|
|
cursor.insertText(m_cmakeProcess->readAllStandardOutput(), tf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeRunPage::cmakeReadyReadStandardError()
|
2009-03-10 09:36:18 +01:00
|
|
|
{
|
2010-10-04 17:52:55 +02:00
|
|
|
QTextCursor cursor(m_output->document());
|
|
|
|
|
QTextCharFormat tf;
|
|
|
|
|
|
|
|
|
|
QFont font = m_output->font();
|
|
|
|
|
QFont boldFont = font;
|
|
|
|
|
boldFont.setBold(true);
|
|
|
|
|
tf.setFont(boldFont);
|
|
|
|
|
tf.setForeground(mix_colors(m_output->palette().color(QPalette::Text), QColor(Qt::red)));
|
|
|
|
|
|
|
|
|
|
cursor.insertText(m_cmakeProcess->readAllStandardError(), tf);
|
2009-03-10 09:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeRunPage::cmakeFinished()
|
|
|
|
|
{
|
|
|
|
|
m_runCMake->setEnabled(true);
|
|
|
|
|
m_argumentsLineEdit->setEnabled(true);
|
2011-02-01 18:36:00 +01:00
|
|
|
m_generatorComboBox->setEnabled(true);
|
|
|
|
|
|
2010-10-04 17:52:55 +02:00
|
|
|
if (m_cmakeProcess->exitCode() != 0) {
|
|
|
|
|
m_exitCodeLabel->setVisible(true);
|
2011-03-31 09:57:24 +02:00
|
|
|
m_exitCodeLabel->setText(tr("CMake exited with errors. Please check CMake output."));
|
2010-10-04 17:52:55 +02:00
|
|
|
m_complete = false;
|
|
|
|
|
} else {
|
|
|
|
|
m_exitCodeLabel->setVisible(false);
|
|
|
|
|
m_complete = true;
|
|
|
|
|
}
|
2009-03-10 09:36:18 +01:00
|
|
|
m_cmakeProcess->deleteLater();
|
|
|
|
|
m_cmakeProcess = 0;
|
2010-10-19 11:14:03 +02:00
|
|
|
m_cmakeWizard->setArguments(m_argumentsLineEdit->text());
|
2009-03-10 09:36:18 +01:00
|
|
|
//TODO Actually test that running cmake was finished, for setting this bool
|
|
|
|
|
emit completeChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeRunPage::cleanupPage()
|
|
|
|
|
{
|
|
|
|
|
m_output->clear();
|
|
|
|
|
m_complete = false;
|
2010-10-04 17:52:55 +02:00
|
|
|
m_exitCodeLabel->setVisible(false);
|
2009-03-10 09:36:18 +01:00
|
|
|
emit completeChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeRunPage::isComplete() const
|
|
|
|
|
{
|
|
|
|
|
return m_complete;
|
|
|
|
|
}
|