cmakeproject.h 7.57 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
hjk's avatar
hjk committed
3
4
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

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

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

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

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

50
51
52
53
QT_BEGIN_NAMESPACE
class QFileSystemWatcher;
QT_END_NAMESPACE

54
55
namespace ProjectExplorer { class Target; }

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

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

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

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

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

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

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

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

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

99
100
    QString defaultBuildDirectory() const;

Tobias Hunger's avatar
Tobias Hunger committed
101

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

104
105
    bool isProjectFile(const QString &fileName);

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

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

112
protected:
Tobias Hunger's avatar
Tobias Hunger committed
113
    bool fromMap(const QVariantMap &map);
114
    bool setupTarget(ProjectExplorer::Target *t);
115

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

119
120
private slots:
    void fileChanged(const QString &fileName);
121
    void activeTargetWasChanged(ProjectExplorer::Target *target);
Tobias Hunger's avatar
Tobias Hunger committed
122
    void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
123

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

130
private:
con's avatar
con committed
131
    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);
Tobias Hunger's avatar
Tobias Hunger committed
137
    void updateRunConfigurations(ProjectExplorer::Target *t);
con's avatar
con committed
138
139

    CMakeManager *m_manager;
140
    ProjectExplorer::Target *m_activeTarget;
con's avatar
con committed
141
142
    QString m_fileName;
    CMakeFile *m_file;
143
    QString m_projectName;
dt's avatar
dt committed
144
    QString m_uicCommand;
con's avatar
con committed
145
146

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

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

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

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

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

196
197
198
    CMakeBuildTarget m_buildTarget;
    bool m_buildTargetType;
    QList<CMakeBuildTarget> m_buildTargets;
199
    QString m_projectName;
200
    QString m_compiler;
201
202
};

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

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

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

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

219
    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
220
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
221

dt's avatar
dt committed
222
223
    void rename(const QString &newName);

con's avatar
con committed
224
225
226
227
228
private:
    CMakeProject *m_project;
    QString m_fileName;
};

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

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

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

hjk's avatar
hjk committed
248
249
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
250
251

#endif // CMAKEPROJECT_H