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 #ifndef CMAKEPROJECT_H
34 #define CMAKEPROJECT_H
36 #include "cmakeprojectmanager.h"
37 #include "cmakeprojectnodes.h"
38 #include "cmakebuildconfiguration.h"
39 #include "cmaketarget.h"
42 #include <projectexplorer/project.h>
43 #include <projectexplorer/projectnodes.h>
44 #include <projectexplorer/buildstep.h>
45 #include <projectexplorer/filewatcher.h>
46 #include <projectexplorer/buildconfiguration.h>
47 #include <coreplugin/ifile.h>
48 #include <coreplugin/editormanager/ieditor.h>
50 #include <QtCore/QXmlStreamReader>
51 #include <QtGui/QPushButton>
52 #include <QtGui/QLineEdit>
54 namespace CMakeProjectManager {
58 class CMakeBuildSettingsWidget;
59 class CMakeUiCodeModelSupport;
61 struct CMakeBuildTarget
64 QString executable; // TODO: rename to output?
66 QString workingDirectory;
68 QString makeCleanCommand;
72 class CMakeProject : public ProjectExplorer::Project
75 // for changeBuildDirectory
76 friend class CMakeBuildSettingsWidget;
78 CMakeProject(CMakeManager *manager, const QString &filename);
81 QString displayName() const;
83 Core::IFile *file() const;
84 CMakeManager *projectManager() const;
86 CMakeTarget *activeTarget() const;
88 QList<ProjectExplorer::Project *> dependsOn(); //NBS TODO implement dependsOn
90 QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
92 ProjectExplorer::ProjectNode *rootProjectNode() const;
94 QStringList files(FilesMode fileMode) const;
95 QStringList buildTargetTitles() const;
96 QList<CMakeBuildTarget> buildTargets() const;
97 bool hasBuildTarget(const QString &title) const;
99 CMakeBuildTarget buildTargetForTitle(const QString &title);
101 QString defaultBuildDirectory() const;
103 bool parseCMakeLists();
105 QString uicCommand() const;
108 /// emitted after parsing
109 void buildTargetsChanged();
112 bool fromMap(const QVariantMap &map);
114 // called by CMakeBuildSettingsWidget
115 void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
118 void fileChanged(const QString &fileName);
119 void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
120 void targetAdded(ProjectExplorer::Target *);
122 void editorChanged(Core::IEditor *editor);
123 void editorAboutToClose(Core::IEditor *editor);
124 void uiEditorContentsChanged();
125 void buildStateChanged(ProjectExplorer::Project *project);
127 void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
128 void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
129 ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
130 void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
131 void createUiCodeModelSupport();
132 QString uiHeaderFile(const QString &uiFile);
134 CMakeManager *m_manager;
137 QString m_projectName;
138 QString m_uicCommand;
140 // TODO probably need a CMake specific node structure
141 CMakeProjectNode *m_rootNode;
143 QList<CMakeBuildTarget> m_buildTargets;
144 ProjectExplorer::FileWatcher *m_watcher;
145 bool m_insideFileChanged;
146 QSet<QString> m_watchedFiles;
147 QFuture<void> m_codeModelFuture;
149 QMap<QString, CMakeUiCodeModelSupport *> m_uiCodeModelSupport;
150 Core::IEditor *m_lastEditor;
154 class CMakeCbpParser : public QXmlStreamReader
157 bool parseCbpFile(const QString &fileName);
158 QList<ProjectExplorer::FileNode *> fileList();
159 QList<ProjectExplorer::FileNode *> cmakeFileList();
160 QStringList includeFiles();
161 QList<CMakeBuildTarget> buildTargets();
162 QString projectName() const;
163 QString compilerName() const;
164 bool hasCMakeFiles();
166 void parseCodeBlocks_project_file();
170 void parseBuildTarget();
171 void parseBuildTargetOption();
172 void parseMakeCommand();
173 void parseBuildTargetBuild();
174 void parseBuildTargetClean();
175 void parseCompiler();
178 void parseUnitOption();
179 void parseUnknownElement();
181 QList<ProjectExplorer::FileNode *> m_fileList;
182 QList<ProjectExplorer::FileNode *> m_cmakeFileList;
183 QSet<QString> m_processedUnits;
184 bool m_parsingCmakeUnit;
185 QStringList m_includeFiles;
187 CMakeBuildTarget m_buildTarget;
188 bool m_buildTargetType;
189 QList<CMakeBuildTarget> m_buildTargets;
190 QString m_projectName;
194 class CMakeFile : public Core::IFile
198 CMakeFile(CMakeProject *parent, QString fileName);
200 bool save(const QString &fileName = QString());
201 QString fileName() const;
203 QString defaultPath() const;
204 QString suggestedFileName() const;
205 QString mimeType() const;
207 bool isModified() const;
208 bool isReadOnly() const;
209 bool isSaveAsAllowed() const;
211 ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
212 void reload(ReloadFlag flag, ChangeType type);
214 void rename(const QString &newName);
217 CMakeProject *m_project;
221 class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
225 explicit CMakeBuildSettingsWidget(CMakeTarget *target);
226 QString displayName() const;
228 // This is called to set up the config widget before showing it
229 virtual void init(ProjectExplorer::BuildConfiguration *bc);
231 void openChangeBuildDirectoryDialog();
234 CMakeTarget *m_target;
235 QLineEdit *m_pathLineEdit;
236 QPushButton *m_changeButton;
237 CMakeBuildConfiguration *m_buildConfiguration;
240 } // namespace Internal
241 } // namespace CMakeProjectManager
243 #endif // CMAKEPROJECT_H