cmakeproject.h 7.18 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
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
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
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33
34
35
#ifndef CMAKEPROJECT_H
#define CMAKEPROJECT_H

hjk's avatar
hjk committed
36
37
#include "cmakeprojectmanager.h"
#include "cmakeprojectnodes.h"
38
#include "cmakebuildconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
39
#include "cmaketarget.h"
40
#include "makestep.h"
hjk's avatar
hjk committed
41

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

50
51
52
#include <QXmlStreamReader>
#include <QPushButton>
#include <QLineEdit>
con's avatar
con committed
53

54
55
56
57
QT_BEGIN_NAMESPACE
class QFileSystemWatcher;
QT_END_NAMESPACE

con's avatar
con committed
58
namespace CMakeProjectManager {
59
namespace Internal {
con's avatar
con committed
60
61

class CMakeFile;
62
class CMakeBuildSettingsWidget;
dt's avatar
dt committed
63
class CMakeUiCodeModelSupport;
con's avatar
con committed
64

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

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

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

Tobias Hunger's avatar
Tobias Hunger committed
90
91
    CMakeTarget *activeTarget() const;

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

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

Tobias Hunger's avatar
Tobias Hunger committed
96
    QStringList files(FilesMode fileMode) const;
97
98
99
    QStringList buildTargetTitles() const;
    QList<CMakeBuildTarget> buildTargets() const;
    bool hasBuildTarget(const QString &title) const;
100

101
    CMakeBuildTarget buildTargetForTitle(const QString &title);
con's avatar
con committed
102

103
104
    QString defaultBuildDirectory() const;

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

dt's avatar
dt committed
107
108
    QString uicCommand() const;

109
110
    bool isProjectFile(const QString &fileName);

111
112
signals:
    /// emitted after parsing
113
    void buildTargetsChanged();
114

115
protected:
Tobias Hunger's avatar
Tobias Hunger committed
116
    bool fromMap(const QVariantMap &map);
117

118
    // called by CMakeBuildSettingsWidget
119
    void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
120

121
122
private slots:
    void fileChanged(const QString &fileName);
Tobias Hunger's avatar
Tobias Hunger committed
123
124
    void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
    void targetAdded(ProjectExplorer::Target *);
125

dt's avatar
dt committed
126
127
128
129
    void editorChanged(Core::IEditor *editor);
    void editorAboutToClose(Core::IEditor *editor);
    void uiEditorContentsChanged();
    void buildStateChanged(ProjectExplorer::Project *project);
con's avatar
con committed
130
131
private:
    void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
132
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
con's avatar
con committed
133
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
dt's avatar
dt committed
134
135
136
    void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
    void createUiCodeModelSupport();
    QString uiHeaderFile(const QString &uiFile);
con's avatar
con committed
137
138
139
140

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

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

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

157
158
159
160
161
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
dt's avatar
dt committed
162
    QList<ProjectExplorer::FileNode *> cmakeFileList();
163
    QStringList includeFiles();
164
    QList<CMakeBuildTarget> buildTargets();
165
    QString projectName() const;
166
    QString compilerName() const;
dt's avatar
dt committed
167
    bool hasCMakeFiles();
168
169
170
171
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
172
    void parseOption();
173
174
    void parseBuildTarget();
    void parseBuildTargetOption();
dt's avatar
dt committed
175
    void parseMakeCommand();
176
177
    void parseBuildTargetBuild();
    void parseBuildTargetClean();
178
179
180
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
181
    void parseUnitOption();
182
183
184
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
185
186
187
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
188
    QStringList m_includeFiles;
dt's avatar
dt committed
189

190
191
192
    CMakeBuildTarget m_buildTarget;
    bool m_buildTargetType;
    QList<CMakeBuildTarget> m_buildTargets;
193
    QString m_projectName;
194
    QString m_compiler;
195
196
};

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

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

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

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

213
    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
214
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
215

dt's avatar
dt committed
216
217
    void rename(const QString &newName);

con's avatar
con committed
218
219
220
221
222
private:
    CMakeProject *m_project;
    QString m_fileName;
};

dt's avatar
dt committed
223
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
con's avatar
con committed
224
{
225
    Q_OBJECT
con's avatar
con committed
226
public:
227
    explicit CMakeBuildSettingsWidget(CMakeTarget *target);
Tobias Hunger's avatar
Tobias Hunger committed
228
    QString displayName() const;
con's avatar
con committed
229
230

    // This is called to set up the config widget before showing it
dt's avatar
dt committed
231
    virtual void init(ProjectExplorer::BuildConfiguration *bc);
232
private slots:
233
    void openChangeBuildDirectoryDialog();
234
    void runCMake();
235
private:
236
    CMakeTarget *m_target;
237
238
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
239
    CMakeBuildConfiguration *m_buildConfiguration;
con's avatar
con committed
240
241
};

hjk's avatar
hjk committed
242
243
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
244
245

#endif // CMAKEPROJECT_H