1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "cmakeproject.h"
34 #include "cmakeprojectconstants.h"
35 #include "cmakeprojectnodes.h"
36 #include "cmakerunconfiguration.h"
37 #include "cmaketarget.h"
39 #include "cmakeopenprojectwizard.h"
40 #include "cmakebuildconfiguration.h"
41 #include "cmakeuicodemodelsupport.h"
43 #include <projectexplorer/projectexplorerconstants.h>
44 #include <projectexplorer/projectexplorer.h>
45 #include <projectexplorer/headerpath.h>
46 #include <projectexplorer/buildenvironmentwidget.h>
47 #include <projectexplorer/buildsteplist.h>
48 #include <projectexplorer/buildmanager.h>
49 #include <projectexplorer/toolchain.h>
50 #include <cplusplus/ModelManagerInterface.h>
51 #include <extensionsystem/pluginmanager.h>
52 #include <utils/qtcassert.h>
53 #include <coreplugin/icore.h>
54 #include <coreplugin/editormanager/editormanager.h>
56 #include <QtCore/QMap>
57 #include <QtCore/QDebug>
58 #include <QtCore/QDir>
59 #include <QtCore/QDateTime>
60 #include <QtCore/QProcess>
61 #include <QtGui/QFormLayout>
62 #include <QtGui/QMainWindow>
63 #include <QtGui/QInputDialog>
65 using namespace CMakeProjectManager;
66 using namespace CMakeProjectManager::Internal;
67 using namespace ProjectExplorer;
69 // QtCreator CMake Generator wishlist:
70 // Which make targets we need to build to get all executables
71 // What is the make we need to call
72 // What is the actual compiler executable
76 // Who sets up the environment for cl.exe ? INCLUDEPATH and so on
78 // Test for form editor (loosely coupled)
79 static inline bool isFormWindowEditor(const QObject *o)
81 return o && !qstrcmp(o->metaObject()->className(), "Designer::FormWindowEditor");
84 // Return contents of form editor (loosely coupled)
85 static inline QString formWindowEditorContents(const QObject *editor)
87 const QVariant contentV = editor->property("contents");
88 QTC_ASSERT(contentV.isValid(), return QString(); )
89 return contentV.toString();
95 CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
98 m_rootNode(new CMakeProjectNode(m_fileName)),
99 m_insideFileChanged(false),
102 m_file = new CMakeFile(this, fileName);
104 connect(this, SIGNAL(addedTarget(ProjectExplorer::Target*)),
105 SLOT(targetAdded(ProjectExplorer::Target*)));
108 CMakeProject::~CMakeProject()
110 // Remove CodeModel support
111 CPlusPlus::CppModelManagerInterface *modelManager
112 = CPlusPlus::CppModelManagerInterface::instance();
113 QMap<QString, CMakeUiCodeModelSupport *>::const_iterator it, end;
114 it = m_uiCodeModelSupport.constBegin();
115 end = m_uiCodeModelSupport.constEnd();
116 for (; it!=end; ++it) {
117 modelManager->removeEditorSupport(it.value());
121 m_codeModelFuture.cancel();
125 void CMakeProject::fileChanged(const QString &fileName)
128 if (!activeTarget() ||
129 !activeTarget()->activeBuildConfiguration())
132 if (m_insideFileChanged)
134 m_insideFileChanged = true;
135 changeActiveBuildConfiguration(activeTarget()->activeBuildConfiguration());
136 m_insideFileChanged = false;
139 void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
141 if (!bc || bc->target() != activeTarget())
144 CMakeBuildConfiguration * cmakebc(qobject_cast<CMakeBuildConfiguration *>(bc));
148 // Pop up a dialog asking the user to rerun cmake
149 QFileInfo sourceFileInfo(m_fileName);
151 QString cbpFile = CMakeManager::findCbpFile(QDir(bc->buildDirectory()));
152 QFileInfo cbpFileFi(cbpFile);
153 CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
154 if (!cbpFileFi.exists()) {
155 mode = CMakeOpenProjectWizard::NeedToCreate;
157 foreach(const QString &file, m_watchedFiles) {
158 if (QFileInfo(file).lastModified() > cbpFileFi.lastModified()) {
159 mode = CMakeOpenProjectWizard::NeedToUpdate;
165 if (mode != CMakeOpenProjectWizard::Nothing) {
166 CMakeOpenProjectWizard copw(m_manager,
167 sourceFileInfo.absolutePath(),
168 cmakebc->buildDirectory(),
170 cmakebc->environment());
177 void CMakeProject::targetAdded(ProjectExplorer::Target *t)
182 connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
183 SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
186 void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory)
188 bc->setBuildDirectory(newBuildDirectory);
192 QString CMakeProject::defaultBuildDirectory() const
194 return projectDirectory() + QLatin1String("/qtcreator-build");
197 bool CMakeProject::parseCMakeLists()
199 if (!activeTarget() ||
200 !activeTarget()->activeBuildConfiguration())
204 CMakeBuildConfiguration *activeBC = activeTarget()->activeBuildConfiguration();
205 QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory());
208 m_rootNode->setDisplayName(QFileInfo(cbpFile).completeBaseName());
209 CMakeCbpParser cbpparser;
211 //qDebug()<<"Parsing file "<<cbpFile;
212 if (!cbpparser.parseCbpFile(cbpFile)) {
214 qDebug()<<"Parsing failed";
215 // activeBC->updateToolChain(QString::null);
216 emit buildTargetsChanged();
221 // activeBC->updateToolChain(cbpparser.compilerName());
222 m_projectName = cbpparser.projectName();
223 m_rootNode->setDisplayName(cbpparser.projectName());
225 //qDebug()<<"Building Tree";
226 QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
227 QSet<QString> projectFiles;
228 if (cbpparser.hasCMakeFiles()) {
229 fileList.append(cbpparser.cmakeFileList());
230 foreach(const ProjectExplorer::FileNode *node, cbpparser.cmakeFileList())
231 projectFiles.insert(node->path());
233 // Manually add the CMakeLists.txt file
234 QString cmakeListTxt = projectDirectory() + "/CMakeLists.txt";
235 bool generated = false;
236 fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, generated));
237 projectFiles.insert(cmakeListTxt);
240 QSet<QString> added = projectFiles;
241 added.subtract(m_watchedFiles);
242 foreach(const QString &add, added)
243 m_watcher->addFile(add);
244 foreach(const QString &remove, m_watchedFiles.subtract(projectFiles))
245 m_watcher->removeFile(remove);
246 m_watchedFiles = projectFiles;
249 foreach (ProjectExplorer::FileNode *fn, fileList)
250 m_files.append(fn->path());
253 buildTree(m_rootNode, fileList);
255 //qDebug()<<"Adding Targets";
256 m_buildTargets = cbpparser.buildTargets();
257 // qDebug()<<"Printing targets";
258 // foreach(CMakeBuildTarget ct, m_buildTargets) {
259 // qDebug()<<ct.title<<" with executable:"<<ct.executable;
260 // qDebug()<<"WD:"<<ct.workingDirectory;
261 // qDebug()<<ct.makeCommand<<ct.makeCleanCommand;
266 // TOOD this code ain't very pretty ...
267 m_uicCommand.clear();
268 QFile cmakeCache(activeBC->buildDirectory() + "/CMakeCache.txt");
269 cmakeCache.open(QIODevice::ReadOnly);
270 while (!cmakeCache.atEnd()) {
271 QString line = cmakeCache.readLine();
272 if (line.startsWith("QT_UIC_EXECUTABLE")) {
273 if (int pos = line.indexOf('=')) {
274 m_uicCommand = line.mid(pos + 1).trimmed();
281 //qDebug()<<"Updating CodeModel";
282 createUiCodeModelSupport();
284 if (!activeBC->toolChain())
287 QStringList allIncludePaths;
288 // This explicitly adds -I. to the include paths
289 allIncludePaths.append(projectDirectory());
290 allIncludePaths.append(cbpparser.includeFiles());
292 QStringList allFrameworkPaths;
293 QList<ProjectExplorer::HeaderPath> allHeaderPaths = activeBC->toolChain()->systemHeaderPaths();
294 foreach (const ProjectExplorer::HeaderPath &headerPath, allHeaderPaths) {
295 if (headerPath.kind() == ProjectExplorer::HeaderPath::FrameworkHeaderPath)
296 allFrameworkPaths.append(headerPath.path());
298 allIncludePaths.append(headerPath.path());
301 CPlusPlus::CppModelManagerInterface *modelmanager =
302 CPlusPlus::CppModelManagerInterface::instance();
304 CPlusPlus::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
305 if (pinfo.includePaths != allIncludePaths
306 || pinfo.sourceFiles != m_files
307 || pinfo.defines != activeBC->toolChain()->predefinedMacros()
308 || pinfo.frameworkPaths != allFrameworkPaths) {
309 pinfo.includePaths = allIncludePaths;
310 // TODO we only want C++ files, not all other stuff that might be in the project
311 pinfo.sourceFiles = m_files;
312 pinfo.defines = activeBC->toolChain()->predefinedMacros(); // TODO this is to simplistic
313 pinfo.frameworkPaths = allFrameworkPaths;
314 modelmanager->updateProjectInfo(pinfo);
315 m_codeModelFuture.cancel();
316 m_codeModelFuture = modelmanager->updateSourceFiles(pinfo.sourceFiles);
320 emit buildTargetsChanged();
321 emit fileListChanged();
325 QList<CMakeBuildTarget> CMakeProject::buildTargets() const
327 return m_buildTargets;
330 QStringList CMakeProject::buildTargetTitles() const
333 foreach (const CMakeBuildTarget &ct, m_buildTargets) {
334 if (ct.executable.isEmpty())
336 if (ct.title.endsWith(QLatin1String("/fast")))
343 bool CMakeProject::hasBuildTarget(const QString &title) const
345 foreach (const CMakeBuildTarget &ct, m_buildTargets) {
346 if (ct.executable.isEmpty())
348 if (ct.title.endsWith(QLatin1String("/fast")))
350 if (ct.title == title)
356 void CMakeProject::gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list)
358 foreach(ProjectExplorer::FolderNode *folder, parent->subFolderNodes())
359 gatherFileNodes(folder, list);
360 foreach(ProjectExplorer::FileNode *file, parent->fileNodes())
364 void CMakeProject::buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> newList)
367 QList<ProjectExplorer::FileNode *> oldList;
368 gatherFileNodes(rootNode, oldList);
369 qSort(oldList.begin(), oldList.end(), ProjectExplorer::ProjectNode::sortNodesByPath);
370 qSort(newList.begin(), newList.end(), ProjectExplorer::ProjectNode::sortNodesByPath);
372 // generate added and deleted list
373 QList<ProjectExplorer::FileNode *>::const_iterator oldIt = oldList.constBegin();
374 QList<ProjectExplorer::FileNode *>::const_iterator oldEnd = oldList.constEnd();
375 QList<ProjectExplorer::FileNode *>::const_iterator newIt = newList.constBegin();
376 QList<ProjectExplorer::FileNode *>::const_iterator newEnd = newList.constEnd();
378 QList<ProjectExplorer::FileNode *> added;
379 QList<ProjectExplorer::FileNode *> deleted;
382 while(oldIt != oldEnd && newIt != newEnd) {
383 if ( (*oldIt)->path() == (*newIt)->path()) {
387 } else if ((*oldIt)->path() < (*newIt)->path()) {
388 deleted.append(*oldIt);
391 added.append(*newIt);
396 while (oldIt != oldEnd) {
397 deleted.append(*oldIt);
401 while (newIt != newEnd) {
402 added.append(*newIt);
407 foreach (ProjectExplorer::FileNode *fn, added) {
408 // qDebug()<<"added"<<fn->path();
409 // Get relative path to rootNode
410 QString parentDir = QFileInfo(fn->path()).absolutePath();
411 ProjectExplorer::FolderNode *folder = findOrCreateFolder(rootNode, parentDir);
412 rootNode->addFileNodes(QList<ProjectExplorer::FileNode *>()<< fn, folder);
415 // remove old file nodes and check whether folder nodes can be removed
416 foreach (ProjectExplorer::FileNode *fn, deleted) {
417 ProjectExplorer::FolderNode *parent = fn->parentFolderNode();
418 // qDebug()<<"removed"<<fn->path();
419 rootNode->removeFileNodes(QList<ProjectExplorer::FileNode *>() << fn, parent);
420 // Check for empty parent
421 while (parent->subFolderNodes().isEmpty() && parent->fileNodes().isEmpty()) {
422 ProjectExplorer::FolderNode *grandparent = parent->parentFolderNode();
423 rootNode->removeFolderNodes(QList<ProjectExplorer::FolderNode *>() << parent, grandparent);
424 parent = grandparent;
425 if (parent == rootNode)
431 ProjectExplorer::FolderNode *CMakeProject::findOrCreateFolder(CMakeProjectNode *rootNode, QString directory)
433 QString relativePath = QDir(QFileInfo(rootNode->path()).path()).relativeFilePath(directory);
434 QStringList parts = relativePath.split(QLatin1Char('/'), QString::SkipEmptyParts);
435 ProjectExplorer::FolderNode *parent = rootNode;
436 QString path = QFileInfo(rootNode->path()).path();
437 foreach (const QString &part, parts) {
438 path += QLatin1Char('/');
440 // Find folder in subFolders
442 foreach (ProjectExplorer::FolderNode *folder, parent->subFolderNodes()) {
443 if (folder->path() == path) {
444 // yeah found something :)
451 // No FolderNode yet, so create it
452 ProjectExplorer::FolderNode *tmp = new ProjectExplorer::FolderNode(path);
453 tmp->setDisplayName(part);
454 rootNode->addFolderNodes(QList<ProjectExplorer::FolderNode *>() << tmp, parent);
461 QString CMakeProject::displayName() const
463 return m_projectName;
466 QString CMakeProject::id() const
468 return QLatin1String(Constants::CMAKEPROJECT_ID);
471 Core::IFile *CMakeProject::file() const
476 CMakeManager *CMakeProject::projectManager() const
481 CMakeTarget *CMakeProject::activeTarget() const
483 return static_cast<CMakeTarget *>(Project::activeTarget());
486 QList<ProjectExplorer::Project *> CMakeProject::dependsOn()
488 return QList<Project *>();
491 QList<ProjectExplorer::BuildConfigWidget*> CMakeProject::subConfigWidgets()
493 QList<ProjectExplorer::BuildConfigWidget*> list;
494 list << new BuildEnvironmentWidget;
498 ProjectExplorer::ProjectNode *CMakeProject::rootProjectNode() const
504 QStringList CMakeProject::files(FilesMode fileMode) const
510 bool CMakeProject::fromMap(const QVariantMap &map)
512 if (!Project::fromMap(map))
515 bool hasUserFile = activeTarget();
517 CMakeTargetFactory *factory =
518 ExtensionSystem::PluginManager::instance()->getObject<CMakeTargetFactory>();
519 CMakeTarget *t = factory->create(this, QLatin1String(DEFAULT_CMAKE_TARGET_ID));
522 Q_ASSERT(t->activeBuildConfiguration());
524 // Ask the user for where he wants to build it
525 // and the cmake command line
527 CMakeOpenProjectWizard copw(m_manager, projectDirectory(), Utils::Environment::systemEnvironment());
528 if (copw.exec() != QDialog::Accepted)
531 CMakeBuildConfiguration *bc =
532 static_cast<CMakeBuildConfiguration *>(t->buildConfigurations().at(0));
533 if (!copw.buildDirectory().isEmpty())
534 bc->setBuildDirectory(copw.buildDirectory());
535 bc->setToolChain(copw.toolChain());
539 // We have a user file, but we could still be missing the cbp file
540 // or simply run createXml with the saved settings
541 QFileInfo sourceFileInfo(m_fileName);
542 CMakeBuildConfiguration *activeBC = activeTarget()->activeBuildConfiguration();
543 QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory()));
544 QFileInfo cbpFileFi(cbpFile);
546 CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
547 if (!cbpFileFi.exists())
548 mode = CMakeOpenProjectWizard::NeedToCreate;
549 else if (cbpFileFi.lastModified() < sourceFileInfo.lastModified())
550 mode = CMakeOpenProjectWizard::NeedToUpdate;
552 if (mode != CMakeOpenProjectWizard::Nothing) {
553 CMakeOpenProjectWizard copw(m_manager,
554 sourceFileInfo.absolutePath(),
555 activeBC->buildDirectory(),
557 activeBC->environment());
558 if (copw.exec() != QDialog::Accepted)
560 activeBC->setToolChain(copw.toolChain());
564 m_watcher = new ProjectExplorer::FileWatcher(this);
565 connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
567 if (!parseCMakeLists()) // Gets the directory from the active buildconfiguration
570 if (!hasUserFile && hasBuildTarget("all")) {
571 MakeStep *makeStep = qobject_cast<MakeStep *>(
572 activeTarget()->activeBuildConfiguration()->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD)->at(0));
574 makeStep->setBuildTarget("all", true);
577 foreach (Target *t, targets()) {
578 connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
579 this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
580 connect(t, SIGNAL(environmentChanged()),
581 this, SLOT(changeEnvironment()));
584 connect(Core::EditorManager::instance(), SIGNAL(editorAboutToClose(Core::IEditor*)),
585 this, SLOT(editorAboutToClose(Core::IEditor*)));
587 connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
588 this, SLOT(editorChanged(Core::IEditor*)));
590 connect(ProjectExplorer::ProjectExplorerPlugin::instance()->buildManager(), SIGNAL(buildStateChanged(ProjectExplorer::Project*)),
591 this, SLOT(buildStateChanged(ProjectExplorer::Project*)));
596 CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title)
598 foreach(const CMakeBuildTarget &ct, m_buildTargets)
599 if (ct.title == title)
601 return CMakeBuildTarget();
604 QString CMakeProject::uicCommand() const
609 QString CMakeProject::uiHeaderFile(const QString &uiFile)
611 QDir srcDirRoot = QDir(projectDirectory());
612 QString relativePath = srcDirRoot.relativeFilePath(uiFile);
613 QDir buildDir = QDir(activeTarget()->activeBuildConfiguration()->buildDirectory());
614 QString uiHeaderFilePath = buildDir.absoluteFilePath(relativePath);
616 QFileInfo fi(uiHeaderFilePath);
617 uiHeaderFilePath = fi.absolutePath();
618 uiHeaderFilePath += QLatin1String("/ui_");
619 uiHeaderFilePath += fi.completeBaseName();
620 uiHeaderFilePath += QLatin1String(".h");
621 return QDir::cleanPath(uiHeaderFilePath);
624 void CMakeProject::createUiCodeModelSupport()
626 // qDebug()<<"creatUiCodeModelSupport()";
627 CPlusPlus::CppModelManagerInterface *modelManager
628 = CPlusPlus::CppModelManagerInterface::instance();
631 QMap<QString, CMakeUiCodeModelSupport *> oldCodeModelSupport;
632 oldCodeModelSupport = m_uiCodeModelSupport;
633 m_uiCodeModelSupport.clear();
636 foreach (const QString &uiFile, m_files) {
637 if (uiFile.endsWith(".ui")) {
638 // UI file, not convert to
639 QString uiHeaderFilePath = uiHeaderFile(uiFile);
640 QMap<QString, CMakeUiCodeModelSupport *>::iterator it
641 = oldCodeModelSupport.find(uiFile);
642 if (it != oldCodeModelSupport.end()) {
643 // qDebug()<<"updated old codemodelsupport";
644 CMakeUiCodeModelSupport *cms = it.value();
645 cms->setFileName(uiHeaderFilePath);
646 m_uiCodeModelSupport.insert(it.key(), cms);
647 oldCodeModelSupport.erase(it);
649 // qDebug()<<"adding new codemodelsupport";
650 CMakeUiCodeModelSupport *cms = new CMakeUiCodeModelSupport(modelManager, this, uiFile, uiHeaderFilePath);
651 m_uiCodeModelSupport.insert(uiFile, cms);
652 modelManager->addEditorSupport(cms);
658 QMap<QString, CMakeUiCodeModelSupport *>::const_iterator it, end;
659 end = oldCodeModelSupport.constEnd();
660 for (it = oldCodeModelSupport.constBegin(); it!=end; ++it) {
661 modelManager->removeEditorSupport(it.value());
666 void CMakeProject::updateCodeModelSupportFromEditor(const QString &uiFileName,
667 const QString &contents)
669 const QMap<QString, CMakeUiCodeModelSupport *>::const_iterator it =
670 m_uiCodeModelSupport.constFind(uiFileName);
671 if (it != m_uiCodeModelSupport.constEnd())
672 it.value()->updateFromEditor(contents);
675 void CMakeProject::editorChanged(Core::IEditor *editor)
678 if (isFormWindowEditor(m_lastEditor)) {
679 disconnect(m_lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
681 const QString contents = formWindowEditorContents(m_lastEditor);
682 updateCodeModelSupportFromEditor(m_lastEditor->file()->fileName(), contents);
687 m_lastEditor = editor;
690 if (isFormWindowEditor(editor))
691 connect(editor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
694 void CMakeProject::editorAboutToClose(Core::IEditor *editor)
696 if (m_lastEditor == editor) {
697 // Oh no our editor is going to be closed
698 // get the content first
699 if (isFormWindowEditor(m_lastEditor)) {
700 disconnect(m_lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
702 const QString contents = formWindowEditorContents(m_lastEditor);
703 updateCodeModelSupportFromEditor(m_lastEditor->file()->fileName(), contents);
711 void CMakeProject::uiEditorContentsChanged()
713 // cast sender, get filename
714 if (!m_dirtyUic && isFormWindowEditor(sender()))
718 void CMakeProject::buildStateChanged(ProjectExplorer::Project *project)
720 if (project == this) {
721 if (!ProjectExplorer::ProjectExplorerPlugin::instance()->buildManager()->isBuilding(this)) {
722 QMap<QString, CMakeUiCodeModelSupport *>::const_iterator it, end;
723 end = m_uiCodeModelSupport.constEnd();
724 for (it = m_uiCodeModelSupport.constBegin(); it != end; ++it) {
725 it.value()->updateFromBuild();
733 CMakeFile::CMakeFile(CMakeProject *parent, QString fileName)
734 : Core::IFile(parent), m_project(parent), m_fileName(fileName)
739 bool CMakeFile::save(const QString &fileName)
741 // Once we have an texteditor open for this file, we probably do
742 // need to implement this, don't we.
747 QString CMakeFile::fileName() const
752 QString CMakeFile::defaultPath() const
757 QString CMakeFile::suggestedFileName() const
762 QString CMakeFile::mimeType() const
764 return Constants::CMAKEMIMETYPE;
768 bool CMakeFile::isModified() const
773 bool CMakeFile::isReadOnly() const
778 bool CMakeFile::isSaveAsAllowed() const
783 void CMakeFile::rename(const QString &newName)
790 Core::IFile::ReloadBehavior CMakeFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
794 return BehaviorSilent;
797 void CMakeFile::reload(ReloadFlag flag, ChangeType type)
803 CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeTarget *target)
804 : m_target(target), m_buildConfiguration(0)
806 QFormLayout *fl = new QFormLayout(this);
807 fl->setContentsMargins(20, -1, 0, -1);
808 fl->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
811 // TODO add action to Build menu?
812 QPushButton *runCmakeButton = new QPushButton("Run cmake");
813 connect(runCmakeButton, SIGNAL(clicked()),
814 this, SLOT(runCMake()));
815 fl->addRow(tr("Reconfigure project:"), runCmakeButton);
817 m_pathLineEdit = new QLineEdit(this);
818 m_pathLineEdit->setReadOnly(true);
820 QHBoxLayout *hbox = new QHBoxLayout();
821 hbox->addWidget(m_pathLineEdit);
823 m_changeButton = new QPushButton(this);
824 m_changeButton->setText(tr("&Change"));
825 connect(m_changeButton, SIGNAL(clicked()), this, SLOT(openChangeBuildDirectoryDialog()));
826 hbox->addWidget(m_changeButton);
828 fl->addRow("Build directory:", hbox);
831 QString CMakeBuildSettingsWidget::displayName() const
836 void CMakeBuildSettingsWidget::init(BuildConfiguration *bc)
838 m_buildConfiguration = static_cast<CMakeBuildConfiguration *>(bc);
839 m_pathLineEdit->setText(m_buildConfiguration->buildDirectory());
840 if (m_buildConfiguration->buildDirectory() == m_target->cmakeProject()->projectDirectory())
841 m_changeButton->setEnabled(false);
843 m_changeButton->setEnabled(true);
846 void CMakeBuildSettingsWidget::openChangeBuildDirectoryDialog()
848 CMakeProject *project = m_target->cmakeProject();
849 CMakeOpenProjectWizard copw(project->projectManager(),
850 project->projectDirectory(),
851 m_buildConfiguration->buildDirectory(),
852 m_buildConfiguration->environment());
853 if (copw.exec() == QDialog::Accepted) {
854 project->changeBuildDirectory(m_buildConfiguration, copw.buildDirectory());
855 m_pathLineEdit->setText(m_buildConfiguration->buildDirectory());
859 void CMakeBuildSettingsWidget::runCMake()
861 // TODO skip build directory
862 CMakeProject *project = m_target->cmakeProject();
863 CMakeOpenProjectWizard copw(project->projectManager(),
864 project->projectDirectory(),
865 m_buildConfiguration->buildDirectory(),
866 CMakeOpenProjectWizard::WantToUpdate,
867 m_buildConfiguration->environment());
868 if (copw.exec() == QDialog::Accepted) {
869 project->parseCMakeLists();
877 bool CMakeCbpParser::parseCbpFile(const QString &fileName)
880 if (fi.exists() && fi.open(QFile::ReadOnly)) {
885 if (name() == "CodeBlocks_project_file") {
886 parseCodeBlocks_project_file();
887 } else if (isStartElement()) {
888 parseUnknownElement();
892 m_includeFiles.sort();
893 m_includeFiles.removeDuplicates();
899 void CMakeCbpParser::parseCodeBlocks_project_file()
903 if (isEndElement()) {
905 } else if (name() == "Project") {
907 } else if (isStartElement()) {
908 parseUnknownElement();
913 void CMakeCbpParser::parseProject()
917 if (isEndElement()) {
919 } else if (name() == "Option") {
921 } else if (name() == "Unit") {
923 } else if (name() == "Build") {
925 } else if (isStartElement()) {
926 parseUnknownElement();
931 void CMakeCbpParser::parseBuild()
935 if (isEndElement()) {
937 } else if (name() == "Target") {
939 } else if (isStartElement()) {
940 parseUnknownElement();
945 void CMakeCbpParser::parseBuildTarget()
947 m_buildTargetType = false;
948 m_buildTarget.clear();
950 if (attributes().hasAttribute("title"))
951 m_buildTarget.title = attributes().value("title").toString();
954 if (isEndElement()) {
955 if (m_buildTargetType || m_buildTarget.title == "all" || m_buildTarget.title == "install") {
956 m_buildTargets.append(m_buildTarget);
959 } else if (name() == "Compiler") {
961 } else if (name() == "Option") {
962 parseBuildTargetOption();
963 } else if (isStartElement()) {
964 parseUnknownElement();
969 void CMakeCbpParser::parseBuildTargetOption()
971 if (attributes().hasAttribute("output")) {
972 m_buildTarget.executable = attributes().value("output").toString();
973 } else if (attributes().hasAttribute("type") && (attributes().value("type") == "1" || attributes().value("type") == "0")) {
974 m_buildTargetType = true;
975 } else if (attributes().hasAttribute("type") && (attributes().value("type") == "3" || attributes().value("type") == "2")) {
976 m_buildTargetType = true;
977 m_buildTarget.library = true;
978 } else if (attributes().hasAttribute("working_dir")) {
979 m_buildTarget.workingDirectory = attributes().value("working_dir").toString();
983 if (isEndElement()) {
985 } else if (name() == "MakeCommand") {
987 } else if (isStartElement()) {
988 parseUnknownElement();
993 QString CMakeCbpParser::projectName() const
995 return m_projectName;
998 void CMakeCbpParser::parseOption()
1000 if (attributes().hasAttribute("title"))
1001 m_projectName = attributes().value("title").toString();
1003 if (attributes().hasAttribute("compiler"))
1004 m_compiler = attributes().value("compiler").toString();
1008 if (isEndElement()) {
1010 } else if(isStartElement()) {
1011 parseUnknownElement();
1016 void CMakeCbpParser::parseMakeCommand()
1020 if (isEndElement()) {
1022 } else if (name() == "Build") {
1023 parseBuildTargetBuild();
1024 } else if (name() == "Clean") {
1025 parseBuildTargetClean();
1026 } else if (isStartElement()) {
1027 parseUnknownElement();
1032 void CMakeCbpParser::parseBuildTargetBuild()
1034 if (attributes().hasAttribute("command"))
1035 m_buildTarget.makeCommand = attributes().value("command").toString();
1038 if (isEndElement()) {
1040 } else if (isStartElement()) {
1041 parseUnknownElement();
1046 void CMakeCbpParser::parseBuildTargetClean()
1048 if (attributes().hasAttribute("command"))
1049 m_buildTarget.makeCleanCommand = attributes().value("command").toString();
1052 if (isEndElement()) {
1054 } else if (isStartElement()) {
1055 parseUnknownElement();
1060 void CMakeCbpParser::parseCompiler()
1064 if (isEndElement()) {
1066 } else if (name() == "Add") {
1068 } else if (isStartElement()) {
1069 parseUnknownElement();
1074 void CMakeCbpParser::parseAdd()
1076 m_includeFiles.append(attributes().value("directory").toString());
1079 if (isEndElement()) {
1081 } else if (isStartElement()) {
1082 parseUnknownElement();
1087 void CMakeCbpParser::parseUnit()
1089 //qDebug()<<stream.attributes().value("filename");
1090 QString fileName = attributes().value("filename").toString();
1091 m_parsingCmakeUnit = false;
1094 if (isEndElement()) {
1095 if (!fileName.endsWith(QLatin1String(".rule")) && !m_processedUnits.contains(fileName)) {
1096 // Now check whether we found a virtual element beneath
1097 if (m_parsingCmakeUnit) {
1098 m_cmakeFileList.append( new ProjectExplorer::FileNode(fileName, ProjectExplorer::ProjectFileType, false));
1100 bool generated = false;
1101 QString onlyFileName = QFileInfo(fileName).fileName();
1102 if ( (onlyFileName.startsWith("moc_") && onlyFileName.endsWith(".cxx"))
1103 || (onlyFileName.startsWith("ui_") && onlyFileName.endsWith(".h"))
1104 || (onlyFileName.startsWith("qrc_") && onlyFileName.endsWith(".cxx")))
1107 if (fileName.endsWith(QLatin1String(".qrc")))
1108 m_fileList.append( new ProjectExplorer::FileNode(fileName, ProjectExplorer::ResourceType, generated));
1110 m_fileList.append( new ProjectExplorer::FileNode(fileName, ProjectExplorer::SourceType, generated));
1112 m_processedUnits.insert(fileName);
1115 } else if (name() == "Option") {
1117 } else if (isStartElement()) {
1118 parseUnknownElement();
1123 void CMakeCbpParser::parseUnitOption()
1125 if (attributes().hasAttribute("virtualFolder"))
1126 m_parsingCmakeUnit = true;
1134 if (isStartElement())
1135 parseUnknownElement();
1139 void CMakeCbpParser::parseUnknownElement()
1141 Q_ASSERT(isStartElement());
1149 if (isStartElement())
1150 parseUnknownElement();
1154 QList<ProjectExplorer::FileNode *> CMakeCbpParser::fileList()
1159 QList<ProjectExplorer::FileNode *> CMakeCbpParser::cmakeFileList()
1161 return m_cmakeFileList;
1164 bool CMakeCbpParser::hasCMakeFiles()
1166 return !m_cmakeFileList.isEmpty();
1169 QStringList CMakeCbpParser::includeFiles()
1171 return m_includeFiles;
1174 QList<CMakeBuildTarget> CMakeCbpParser::buildTargets()
1176 return m_buildTargets;
1179 QString CMakeCbpParser::compilerName() const
1184 void CMakeBuildTarget::clear()
1187 makeCommand.clear();
1188 makeCleanCommand.clear();
1189 workingDirectory.clear();