cmakeproject.h 7.21 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>
con's avatar
con committed
46
#include <coreplugin/ifile.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
53
#include <QXmlStreamReader>
#include <QFileSystemWatcher>
#include <QPushButton>
#include <QLineEdit>
con's avatar
con committed
54
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
83
84
85
    QString displayName() const;
    QString id() const;
    Core::IFile *file() const;
    CMakeManager *projectManager() const;
con's avatar
con committed
86

Tobias Hunger's avatar
Tobias Hunger committed
87
88
    CMakeTarget *activeTarget() const;

Tobias Hunger's avatar
Tobias Hunger committed
89
    QList<ProjectExplorer::Project *> dependsOn(); //NBS TODO implement dependsOn
con's avatar
con committed
90

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

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

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

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

102
103
    QString defaultBuildDirectory() const;

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

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

108
109
    bool isProjectFile(const QString &fileName);

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

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

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

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

dt's avatar
dt committed
125
126
127
128
    void editorChanged(Core::IEditor *editor);
    void editorAboutToClose(Core::IEditor *editor);
    void uiEditorContentsChanged();
    void buildStateChanged(ProjectExplorer::Project *project);
con's avatar
con committed
129
130
private:
    void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
131
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
con's avatar
con committed
132
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
dt's avatar
dt committed
133
134
135
    void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
    void createUiCodeModelSupport();
    QString uiHeaderFile(const QString &uiFile);
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();
164
    QString projectName() const;
165
    QString compilerName() const;
dt's avatar
dt committed
166
    bool hasCMakeFiles();
167
168
169
170
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
171
    void parseOption();
172
173
    void parseBuildTarget();
    void parseBuildTargetOption();
dt's avatar
dt committed
174
    void parseMakeCommand();
175
176
    void parseBuildTargetBuild();
    void parseBuildTargetClean();
177
178
179
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
180
    void parseUnitOption();
181
182
183
    void parseUnknownElement();

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

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

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

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

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

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

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

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

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

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

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

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

#endif // CMAKEPROJECT_H