1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef CMAKEPROJECT_H
35 #define CMAKEPROJECT_H
37 #include "cmakeprojectmanager.h"
38 #include "cmakeprojectnodes.h"
39 #include "cmakebuildconfiguration.h"
40 #include "cmaketarget.h"
43 #include <projectexplorer/project.h>
44 #include <projectexplorer/projectnodes.h>
45 #include <projectexplorer/buildstep.h>
46 #include <projectexplorer/filewatcher.h>
47 #include <projectexplorer/buildconfiguration.h>
48 #include <coreplugin/ifile.h>
49 #include <coreplugin/editormanager/ieditor.h>
51 #include <QtCore/QXmlStreamReader>
52 #include <QtGui/QPushButton>
53 #include <QtGui/QLineEdit>
55 namespace CMakeProjectManager {
59 class CMakeBuildSettingsWidget;
60 class CMakeUiCodeModelSupport;
62 struct CMakeBuildTarget
65 QString executable; // TODO: rename to output?
67 QString workingDirectory;
69 QString makeCleanCommand;
73 class CMakeProject : public ProjectExplorer::Project
76 // for changeBuildDirectory
77 friend class CMakeBuildSettingsWidget;
79 CMakeProject(CMakeManager *manager, const QString &filename);
82 QString displayName() const;
84 Core::IFile *file() const;
85 CMakeManager *projectManager() const;
87 CMakeTarget *activeTarget() const;
89 QList<ProjectExplorer::Project *> dependsOn(); //NBS TODO implement dependsOn
91 QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
93 ProjectExplorer::ProjectNode *rootProjectNode() const;
95 QStringList files(FilesMode fileMode) const;
96 QStringList buildTargetTitles() const;
97 QList<CMakeBuildTarget> buildTargets() const;
98 bool hasBuildTarget(const QString &title) const;
100 CMakeBuildTarget buildTargetForTitle(const QString &title);
102 QString defaultBuildDirectory() const;
104 bool parseCMakeLists();
106 QString uicCommand() const;
109 /// emitted after parsing
110 void buildTargetsChanged();
113 bool fromMap(const QVariantMap &map);
115 // called by CMakeBuildSettingsWidget
116 void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
119 void fileChanged(const QString &fileName);
120 void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
121 void targetAdded(ProjectExplorer::Target *);
123 void editorChanged(Core::IEditor *editor);
124 void editorAboutToClose(Core::IEditor *editor);
125 void uiEditorContentsChanged();
126 void buildStateChanged(ProjectExplorer::Project *project);
128 void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
129 void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
130 ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
131 void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
132 void createUiCodeModelSupport();
133 QString uiHeaderFile(const QString &uiFile);
135 CMakeManager *m_manager;
138 QString m_projectName;
139 QString m_uicCommand;
141 // TODO probably need a CMake specific node structure
142 CMakeProjectNode *m_rootNode;
144 QList<CMakeBuildTarget> m_buildTargets;
145 ProjectExplorer::FileWatcher *m_watcher;
146 bool m_insideFileChanged;
147 QSet<QString> m_watchedFiles;
148 QFuture<void> m_codeModelFuture;
150 QMap<QString, CMakeUiCodeModelSupport *> m_uiCodeModelSupport;
151 Core::IEditor *m_lastEditor;
155 class CMakeCbpParser : public QXmlStreamReader
158 bool parseCbpFile(const QString &fileName);
159 QList<ProjectExplorer::FileNode *> fileList();
160 QList<ProjectExplorer::FileNode *> cmakeFileList();
161 QStringList includeFiles();
162 QList<CMakeBuildTarget> buildTargets();
163 QString projectName() const;
164 QString compilerName() const;
165 bool hasCMakeFiles();
167 void parseCodeBlocks_project_file();
171 void parseBuildTarget();
172 void parseBuildTargetOption();
173 void parseMakeCommand();
174 void parseBuildTargetBuild();
175 void parseBuildTargetClean();
176 void parseCompiler();
179 void parseUnitOption();
180 void parseUnknownElement();
182 QList<ProjectExplorer::FileNode *> m_fileList;
183 QList<ProjectExplorer::FileNode *> m_cmakeFileList;
184 QSet<QString> m_processedUnits;
185 bool m_parsingCmakeUnit;
186 QStringList m_includeFiles;
188 CMakeBuildTarget m_buildTarget;
189 bool m_buildTargetType;
190 QList<CMakeBuildTarget> m_buildTargets;
191 QString m_projectName;
195 class CMakeFile : public Core::IFile
199 CMakeFile(CMakeProject *parent, QString fileName);
201 bool save(const QString &fileName = QString());
202 QString fileName() const;
204 QString defaultPath() const;
205 QString suggestedFileName() const;
206 QString mimeType() const;
208 bool isModified() const;
209 bool isReadOnly() const;
210 bool isSaveAsAllowed() const;
212 ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
213 void reload(ReloadFlag flag, ChangeType type);
215 void rename(const QString &newName);
218 CMakeProject *m_project;
222 class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
226 explicit CMakeBuildSettingsWidget(CMakeTarget *target);
227 QString displayName() const;
229 // This is called to set up the config widget before showing it
230 virtual void init(ProjectExplorer::BuildConfiguration *bc);
232 void openChangeBuildDirectoryDialog();
235 CMakeTarget *m_target;
236 QLineEdit *m_pathLineEdit;
237 QPushButton *m_changeButton;
238 CMakeBuildConfiguration *m_buildConfiguration;
241 } // namespace Internal
242 } // namespace CMakeProjectManager
244 #endif // CMAKEPROJECT_H