| 
									
										
										
										
											2009-03-20 14:57:12 +01:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2009-06-17 00:01:27 +10:00
										 |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							| 
									
										
										
										
											2009-03-20 14:57:12 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Commercial Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** 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. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** 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.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** If you are unsure which license is appropriate for your use, please | 
					
						
							| 
									
										
										
										
											2009-06-17 00:01:27 +10:00
										 |  |  | ** contact the sales department at http://www.qtsoftware.com/contact.
 | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							|  |  |  | #include <projectexplorer/environment.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-26 16:10:13 +02:00
										 |  |  | CMakeOpenProjectWizard::CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory, const ProjectExplorer::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), | 
					
						
							|  |  |  |       m_environment(env) | 
					
						
							| 
									
										
										
										
											2009-03-10 09:36:18 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     int startid; | 
					
						
							|  |  |  |     if (hasInSourceBuild()) { | 
					
						
							|  |  |  |         startid = InSourcePageId; | 
					
						
							|  |  |  |         m_buildDirectory = m_sourceDirectory; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         startid = ShadowBuildPageId; | 
					
						
							|  |  |  |         m_buildDirectory = m_sourceDirectory + "/qtcreator-build"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setPage(InSourcePageId, new InSourceBuildPage(this)); | 
					
						
							|  |  |  |     setPage(ShadowBuildPageId, new ShadowBuildPage(this)); | 
					
						
							|  |  |  |     setPage(XmlFileUpToDatePageId, new XmlFileUpToDatePage(this)); | 
					
						
							|  |  |  |     setPage(CMakeRunPageId, new CMakeRunPage(this)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setStartId(startid); | 
					
						
							| 
									
										
										
										
											2009-04-15 16:22:55 +02:00
										 |  |  |     setOption(QWizard::NoCancelButton); | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							|  |  |  |                                                const ProjectExplorer::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), | 
					
						
							|  |  |  |       m_environment(env) | 
					
						
							| 
									
										
										
										
											2009-03-16 17:33:05 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-26 15:50:27 +02:00
										 |  |  |     if (mode == CMakeOpenProjectWizard::NeedToCreate) | 
					
						
							| 
									
										
										
										
											2009-04-20 14:35:25 +02:00
										 |  |  |         addPage(new CMakeRunPage(this, CMakeRunPage::Recreate, buildDirectory)); | 
					
						
							| 
									
										
										
										
											2009-05-26 15:50:27 +02:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2009-04-20 14:35:25 +02:00
										 |  |  |         addPage(new CMakeRunPage(this, CMakeRunPage::Update, buildDirectory)); | 
					
						
							| 
									
										
										
										
											2009-04-15 16:22:55 +02:00
										 |  |  |     setOption(QWizard::NoCancelButton); | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							|  |  |  |                                                const ProjectExplorer::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), | 
					
						
							|  |  |  |       m_environment(env) | 
					
						
							| 
									
										
										
										
											2009-04-20 14:35:25 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_buildDirectory = oldBuildDirectory; | 
					
						
							|  |  |  |     addPage(new ShadowBuildPage(this, true)); | 
					
						
							|  |  |  |     addPage(new CMakeRunPage(this, CMakeRunPage::Change)); | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							|  |  |  |         if (existsUpToDateXmlFile()) | 
					
						
							|  |  |  |             return XmlFileUpToDatePageId; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             return CMakeRunPageId; | 
					
						
							|  |  |  |     } else if (cid == ShadowBuildPageId) { | 
					
						
							|  |  |  |         if (existsUpToDateXmlFile()) | 
					
						
							|  |  |  |             return XmlFileUpToDatePageId; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             return CMakeRunPageId; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QStringList CMakeOpenProjectWizard::arguments() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_arguments; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CMakeOpenProjectWizard::setArguments(const QStringList &args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_arguments = args; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-26 16:10:13 +02:00
										 |  |  | ProjectExplorer::Environment CMakeOpenProjectWizard::environment() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     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-05-07 15:34:52 +02:00
										 |  |  |     label->setText(tr("Qt Creator has detected an in-source-build " | 
					
						
							|  |  |  |                    "which prevents shadow builds. Qt Creator will not allow you to change the build directory. " | 
					
						
							|  |  |  |                    "If you want a shadow build, clean your source directory and re-open the project.")); | 
					
						
							| 
									
										
										
										
											2009-03-10 09:36:18 +01:00
										 |  |  |     layout()->addWidget(label); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | XmlFileUpToDatePage::XmlFileUpToDatePage(CMakeOpenProjectWizard *cmakeWizard) | 
					
						
							|  |  |  |     : QWizardPage(cmakeWizard), m_cmakeWizard(cmakeWizard) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     setLayout(new QVBoxLayout); | 
					
						
							|  |  |  |     QLabel *label = new QLabel(this); | 
					
						
							|  |  |  |     label->setWordWrap(true); | 
					
						
							| 
									
										
										
										
											2009-04-07 15:27:51 +02:00
										 |  |  |     label->setText(tr("Qt Creator has found a recent cbp file, which Qt Creator will parse to gather information about the project. " | 
					
						
							| 
									
										
										
										
											2009-04-07 15:00:30 +02:00
										 |  |  |                    "You can change the command line arguments used to create this file in the project mode. " | 
					
						
							| 
									
										
										
										
											2009-05-07 15:34:52 +02:00
										 |  |  |                    "Click finish to load the project.")); | 
					
						
							| 
									
										
										
										
											2009-03-10 09:36:18 +01:00
										 |  |  |     layout()->addWidget(label); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  |     m_pc = new Core::Utils::PathChooser(this); | 
					
						
							|  |  |  |     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); | 
					
						
							| 
									
										
										
										
											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-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
										 |  |  | 
 | 
					
						
							|  |  |  |     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); | 
					
						
							|  |  |  |     m_generatorComboBox->addItems(QStringList() << tr("NMake Generator") << tr("MinGW Generator")); | 
					
						
							| 
									
										
										
										
											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-03-10 09:36:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_output = new QPlainTextEdit(this); | 
					
						
							| 
									
										
										
										
											2009-03-31 15:02:09 +02:00
										 |  |  |     m_output->setReadOnly(true); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-27 20:44:50 +01:00
										 |  |  | void CMakeRunPage::initializePage() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-20 14:35:25 +02:00
										 |  |  |     if (m_mode == Initial) { | 
					
						
							| 
									
										
										
										
											2009-03-27 20:44:50 +01:00
										 |  |  |         m_buildDirectory = m_cmakeWizard->buildDirectory(); | 
					
						
							|  |  |  |         m_descriptionLabel->setText( | 
					
						
							| 
									
										
										
										
											2009-04-07 15:27:51 +02:00
										 |  |  |                 tr("The directory %1 does not contain a cbp file. Qt Creator needs to create this file by running cmake. " | 
					
						
							| 
									
										
										
										
											2009-03-27 20:44:50 +01:00
										 |  |  |                    "Some projects require command line arguments to the initial cmake call.").arg(m_buildDirectory)); | 
					
						
							| 
									
										
										
										
											2009-04-20 14:35:25 +02:00
										 |  |  |     } else if (m_mode == CMakeRunPage::Update) { | 
					
						
							|  |  |  |         m_descriptionLabel->setText(tr("The directory %1 contains an outdated .cbp file. Qt " | 
					
						
							|  |  |  |                                        "Creator needs to update this file by running cmake. " | 
					
						
							|  |  |  |                                        "If you want to add additional command line arguments, " | 
					
						
							| 
									
										
										
										
											2009-05-07 15:34:52 +02:00
										 |  |  |                                        "add them below. Note that cmake remembers command " | 
					
						
							|  |  |  |                                        "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 " | 
					
						
							|  |  |  |                                        "recreate this file, by running cmake. " | 
					
						
							|  |  |  |                                        "Some projects require command line arguments to " | 
					
						
							| 
									
										
										
										
											2009-05-07 15:34:52 +02:00
										 |  |  |                                        "the initial cmake call. Note that cmake remembers command " | 
					
						
							|  |  |  |                                        "line arguments from the previous runs.").arg(m_buildDirectory)); | 
					
						
							| 
									
										
										
										
											2009-04-20 14:35:25 +02:00
										 |  |  |     } else if(m_mode == CMakeRunPage::Change) { | 
					
						
							|  |  |  |         m_buildDirectory = m_cmakeWizard->buildDirectory(); | 
					
						
							|  |  |  |         m_descriptionLabel->setText(tr("Qt Creator needs to run cmake in the new build directory. " | 
					
						
							|  |  |  |                                        "Some projects require command line arguments to the " | 
					
						
							|  |  |  |                                        "initial cmake call.")); | 
					
						
							| 
									
										
										
										
											2009-03-27 20:44:50 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-07-02 11:30:29 +02:00
										 |  |  |     if (m_cmakeWizard->cmakeManager()->hasCodeBlocksMsvcGenerator()) { | 
					
						
							|  |  |  |         m_generatorComboBox->setVisible(true); | 
					
						
							|  |  |  |         QString generator; | 
					
						
							|  |  |  |         // Try to find out generator from CMakeCachhe file, if it exists
 | 
					
						
							|  |  |  |         QFile fi(m_buildDirectory + "/CMakeCache.txt"); | 
					
						
							|  |  |  |         if (fi.exists()) { | 
					
						
							|  |  |  |             // Cache exists, then read it...
 | 
					
						
							|  |  |  |             if (fi.open(QIODevice::ReadOnly)) { | 
					
						
							|  |  |  |                 while (fi.canReadLine()) { | 
					
						
							|  |  |  |                     QString line = fi.readLine(); | 
					
						
							|  |  |  |                     if (line.startsWith("CMAKE_GENERATOR:INTERNAL=")) { | 
					
						
							|  |  |  |                         int splitpos = line.indexOf('='); | 
					
						
							|  |  |  |                         if (splitpos != -1) { | 
					
						
							|  |  |  |                             generator = line.mid(splitpos).trimmed(); | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (!generator.isEmpty()) { | 
					
						
							|  |  |  |             m_generatorComboBox->setCurrentIndex((generator == "NMake Makefiles" ? 0 : 1)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         // No new enough cmake, simply hide the combo box
 | 
					
						
							|  |  |  |         m_generatorComboBox->setVisible(false); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-27 20:44:50 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-10 09:36:18 +01:00
										 |  |  | void CMakeRunPage::runCMake() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_runCMake->setEnabled(false); | 
					
						
							|  |  |  |     m_argumentsLineEdit->setEnabled(false); | 
					
						
							|  |  |  |     QStringList arguments = ProjectExplorer::Environment::parseCombinedArgString(m_argumentsLineEdit->text()); | 
					
						
							|  |  |  |     CMakeManager *cmakeManager = m_cmakeWizard->cmakeManager(); | 
					
						
							| 
									
										
										
										
											2009-07-02 11:30:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef Q_OS_WIN
 | 
					
						
							|  |  |  |     const QString generator = m_generatorComboBox->currentIndex() == 0 ? QLatin1String("-GCodeBlocks - NMake Makefiles") : QLatin1String("-GCodeBlocks - MinGW Makefiles"); | 
					
						
							|  |  |  | #else // Q_OS_WIN
 | 
					
						
							|  |  |  |     const QString generator = QLatin1String("-GCodeBlocks - Unix Makefiles"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |     m_cmakeProcess = cmakeManager->createXmlFile(arguments, m_cmakeWizard->sourceDirectory(), m_buildDirectory, m_cmakeWizard->environment(), generator); | 
					
						
							| 
									
										
										
										
											2009-03-10 09:36:18 +01:00
										 |  |  |     connect(m_cmakeProcess, SIGNAL(readyRead()), this, SLOT(cmakeReadyRead())); | 
					
						
							|  |  |  |     connect(m_cmakeProcess, SIGNAL(finished(int)), this, SLOT(cmakeFinished())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CMakeRunPage::cmakeReadyRead() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_output->appendPlainText(m_cmakeProcess->readAll()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CMakeRunPage::cmakeFinished() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_runCMake->setEnabled(true); | 
					
						
							|  |  |  |     m_argumentsLineEdit->setEnabled(true); | 
					
						
							|  |  |  |     m_cmakeProcess->deleteLater(); | 
					
						
							|  |  |  |     m_cmakeProcess = 0; | 
					
						
							|  |  |  |     m_cmakeWizard->setArguments(ProjectExplorer::Environment::parseCombinedArgString(m_argumentsLineEdit->text())); | 
					
						
							|  |  |  |     //TODO Actually test that running cmake was finished, for setting this bool
 | 
					
						
							|  |  |  |     m_complete = true; | 
					
						
							|  |  |  |     emit completeChanged(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CMakeRunPage::cleanupPage() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_output->clear(); | 
					
						
							|  |  |  |     m_complete = false; | 
					
						
							|  |  |  |     emit completeChanged(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CMakeRunPage::isComplete() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_complete; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |