cmakeproject.h 7.14 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
Eike Ziller's avatar
Eike Ziller committed
7
** Contact: http://www.qt-project.org/
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** 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.
**
con's avatar
con committed
28
**
29
**************************************************************************/
hjk's avatar
hjk committed
30

con's avatar
con committed
31
32
33
#ifndef CMAKEPROJECT_H
#define CMAKEPROJECT_H

hjk's avatar
hjk committed
34
35
#include "cmakeprojectmanager.h"
#include "cmakeprojectnodes.h"
36
#include "cmakebuildconfiguration.h"
37
#include "makestep.h"
hjk's avatar
hjk committed
38

con's avatar
con committed
39
40
41
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/buildstep.h>
42
#include <projectexplorer/buildconfiguration.h>
43
#include <coreplugin/idocument.h>
44
#include <coreplugin/editormanager/editormanager.h>
dt's avatar
dt committed
45
#include <coreplugin/editormanager/ieditor.h>
con's avatar
con committed
46

47
48
49
#include <QXmlStreamReader>
#include <QPushButton>
#include <QLineEdit>
con's avatar
con committed
50

51
52
53
54
QT_BEGIN_NAMESPACE
class QFileSystemWatcher;
QT_END_NAMESPACE

con's avatar
con committed
55
namespace CMakeProjectManager {
56
namespace Internal {
con's avatar
con committed
57
58

class CMakeFile;
59
class CMakeBuildSettingsWidget;
dt's avatar
dt committed
60
class CMakeUiCodeModelSupport;
con's avatar
con committed
61

62
struct CMakeBuildTarget
dt's avatar
dt committed
63
64
{
    QString title;
65
66
    QString executable; // TODO: rename to output?
    bool library;
dt's avatar
dt committed
67
68
69
70
71
72
    QString workingDirectory;
    QString makeCommand;
    QString makeCleanCommand;
    void clear();
};

con's avatar
con committed
73
74
75
class CMakeProject : public ProjectExplorer::Project
{
    Q_OBJECT
76
77
    // for changeBuildDirectory
    friend class CMakeBuildSettingsWidget;
con's avatar
con committed
78
79
80
81
public:
    CMakeProject(CMakeManager *manager, const QString &filename);
    ~CMakeProject();

Tobias Hunger's avatar
Tobias Hunger committed
82
    QString displayName() const;
83
    Core::Id id() const;
84
    Core::IDocument *document() const;
Tobias Hunger's avatar
Tobias Hunger committed
85
    CMakeManager *projectManager() const;
con's avatar
con committed
86

Tobias Hunger's avatar
Tobias Hunger committed
87
    QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
con's avatar
con committed
88

Tobias Hunger's avatar
Tobias Hunger committed
89
    ProjectExplorer::ProjectNode *rootProjectNode() const;
con's avatar
con committed
90

Tobias Hunger's avatar
Tobias Hunger committed
91
    QStringList files(FilesMode fileMode) const;
92
93
94
    QStringList buildTargetTitles() const;
    QList<CMakeBuildTarget> buildTargets() const;
    bool hasBuildTarget(const QString &title) const;
95

96
    CMakeBuildTarget buildTargetForTitle(const QString &title);
con's avatar
con committed
97

98
99
    QString defaultBuildDirectory() const;

Tobias Hunger's avatar
Tobias Hunger committed
100

dt's avatar
dt committed
101
102
    QString uicCommand() const;

103
104
    bool isProjectFile(const QString &fileName);

105
    bool parseCMakeLists();
Tobias Hunger's avatar
Tobias Hunger committed
106

107
108
signals:
    /// emitted after parsing
109
    void buildTargetsChanged();
110

111
protected:
Tobias Hunger's avatar
Tobias Hunger committed
112
    bool fromMap(const QVariantMap &map);
113

114
    // called by CMakeBuildSettingsWidget
115
    void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
116

117
118
private slots:
    void fileChanged(const QString &fileName);
Tobias Hunger's avatar
Tobias Hunger committed
119
120
    void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
    void targetAdded(ProjectExplorer::Target *);
121

dt's avatar
dt committed
122
123
124
125
    void editorChanged(Core::IEditor *editor);
    void editorAboutToClose(Core::IEditor *editor);
    void uiEditorContentsChanged();
    void buildStateChanged(ProjectExplorer::Project *project);
126
    void updateRunConfigurations();
Tobias Hunger's avatar
Tobias Hunger committed
127

128
private:
con's avatar
con committed
129
    void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
130
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
con's avatar
con committed
131
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
dt's avatar
dt committed
132
133
134
    void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
    void createUiCodeModelSupport();
    QString uiHeaderFile(const QString &uiFile);
Tobias Hunger's avatar
Tobias Hunger committed
135
    void updateRunConfigurations(ProjectExplorer::Target *t);
con's avatar
con committed
136
137
138
139

    CMakeManager *m_manager;
    QString m_fileName;
    CMakeFile *m_file;
140
    QString m_projectName;
dt's avatar
dt committed
141
    QString m_uicCommand;
con's avatar
con committed
142
143

    // TODO probably need a CMake specific node structure
144
    CMakeProjectNode *m_rootNode;
con's avatar
con committed
145
    QStringList m_files;
146
    QList<CMakeBuildTarget> m_buildTargets;
147
    QFileSystemWatcher *m_watcher;
148
    QSet<QString> m_watchedFiles;
149
    QFuture<void> m_codeModelFuture;
dt's avatar
dt committed
150
151
152
153

    QMap<QString, CMakeUiCodeModelSupport *> m_uiCodeModelSupport;
    Core::IEditor *m_lastEditor;
    bool m_dirtyUic;
con's avatar
con committed
154
155
};

156
157
158
159
160
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
dt's avatar
dt committed
161
    QList<ProjectExplorer::FileNode *> cmakeFileList();
162
    QStringList includeFiles();
163
    QList<CMakeBuildTarget> buildTargets();
Peter Kuemmel's avatar
Peter Kuemmel committed
164
    QByteArray defines() const;
165
    QString projectName() const;
166
    QString compilerName() const;
dt's avatar
dt committed
167
    bool hasCMakeFiles();
Peter Kuemmel's avatar
Peter Kuemmel committed
168

169
170
171
172
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
173
    void parseOption();
174
175
    void parseBuildTarget();
    void parseBuildTargetOption();
dt's avatar
dt committed
176
    void parseMakeCommand();
177
178
    void parseBuildTargetBuild();
    void parseBuildTargetClean();
179
180
181
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
182
    void parseUnitOption();
183
184
185
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
186
187
188
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
189
    QStringList m_includeFiles;
Peter Kuemmel's avatar
Peter Kuemmel committed
190
191
    QStringList m_compilerOptions;
    QByteArray m_defines;
dt's avatar
dt committed
192

193
194
195
    CMakeBuildTarget m_buildTarget;
    bool m_buildTargetType;
    QList<CMakeBuildTarget> m_buildTargets;
196
    QString m_projectName;
197
    QString m_compiler;
198
199
};

200
class CMakeFile : public Core::IDocument
con's avatar
con committed
201
202
203
204
205
{
    Q_OBJECT
public:
    CMakeFile(CMakeProject *parent, QString fileName);

206
    bool save(QString *errorString, const QString &fileName, bool autoSave);
con's avatar
con committed
207
208
209
210
211
212
213
214
215
    QString fileName() const;

    QString defaultPath() const;
    QString suggestedFileName() const;
    QString mimeType() const;

    bool isModified() const;
    bool isSaveAsAllowed() const;

216
    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
217
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
218

dt's avatar
dt committed
219
220
    void rename(const QString &newName);

con's avatar
con committed
221
222
223
224
225
private:
    CMakeProject *m_project;
    QString m_fileName;
};

dt's avatar
dt committed
226
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
con's avatar
con committed
227
{
228
    Q_OBJECT
con's avatar
con committed
229
public:
Tobias Hunger's avatar
Tobias Hunger committed
230
    CMakeBuildSettingsWidget();
Tobias Hunger's avatar
Tobias Hunger committed
231
    QString displayName() const;
con's avatar
con committed
232
233

    // This is called to set up the config widget before showing it
Tobias Hunger's avatar
Tobias Hunger committed
234
235
    void init(ProjectExplorer::BuildConfiguration *bc);

236
private slots:
237
    void openChangeBuildDirectoryDialog();
238
    void runCMake();
239
private:
240
241
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
242
    CMakeBuildConfiguration *m_buildConfiguration;
con's avatar
con committed
243
244
};

hjk's avatar
hjk committed
245
246
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
247
248

#endif // CMAKEPROJECT_H