cmakeproject.h 6.88 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** 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
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
40
#include <projectexplorer/buildconfiguration.h>
41
#include <projectexplorer/namedwidget.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;
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
    ProjectExplorer::ProjectNode *rootProjectNode() const;
con's avatar
con committed
88

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

94
    CMakeBuildTarget buildTargetForTitle(const QString &title);
con's avatar
con committed
95

96
97
    QString shadowBuildDirectory(const QString &projectFilePath, const ProjectExplorer::Kit *k,
                                 const QString &bcName);
Tobias Hunger's avatar
Tobias Hunger committed
98

99
100
    bool isProjectFile(const QString &fileName);

101
    bool parseCMakeLists();
Tobias Hunger's avatar
Tobias Hunger committed
102

103
104
signals:
    /// emitted after parsing
105
    void buildTargetsChanged();
106

107
protected:
Tobias Hunger's avatar
Tobias Hunger committed
108
    bool fromMap(const QVariantMap &map);
109
    bool setupTarget(ProjectExplorer::Target *t);
110

111
    // called by CMakeBuildSettingsWidget
112
    void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
113

114
115
private slots:
    void fileChanged(const QString &fileName);
116
    void activeTargetWasChanged(ProjectExplorer::Target *target);
Tobias Hunger's avatar
Tobias Hunger committed
117
    void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
118

119
    void updateRunConfigurations();
Tobias Hunger's avatar
Tobias Hunger committed
120

121
private:
con's avatar
con committed
122
    void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
123
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
con's avatar
con committed
124
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
dt's avatar
dt committed
125
126
    void createUiCodeModelSupport();
    QString uiHeaderFile(const QString &uiFile);
Tobias Hunger's avatar
Tobias Hunger committed
127
    void updateRunConfigurations(ProjectExplorer::Target *t);
con's avatar
con committed
128
129

    CMakeManager *m_manager;
130
    ProjectExplorer::Target *m_activeTarget;
con's avatar
con committed
131
132
    QString m_fileName;
    CMakeFile *m_file;
133
    QString m_projectName;
con's avatar
con committed
134
135

    // TODO probably need a CMake specific node structure
136
    CMakeProjectNode *m_rootNode;
con's avatar
con committed
137
    QStringList m_files;
138
    QList<CMakeBuildTarget> m_buildTargets;
139
    QFileSystemWatcher *m_watcher;
140
    QSet<QString> m_watchedFiles;
141
    QFuture<void> m_codeModelFuture;
con's avatar
con committed
142
143
};

144
145
146
147
148
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
dt's avatar
dt committed
149
    QList<ProjectExplorer::FileNode *> cmakeFileList();
150
    QStringList includeFiles();
151
    QList<CMakeBuildTarget> buildTargets();
152
    QByteArray defines() const;
153
    QString projectName() const;
154
    QString compilerName() const;
dt's avatar
dt committed
155
    bool hasCMakeFiles();
Peter Kuemmel's avatar
Peter Kuemmel committed
156

157
158
159
160
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
161
    void parseOption();
162
163
    void parseBuildTarget();
    void parseBuildTargetOption();
164
    void parseMakeCommands();
165
166
    void parseBuildTargetBuild();
    void parseBuildTargetClean();
167
168
169
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
170
    void parseUnitOption();
171
172
173
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
174
175
176
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
177
    QStringList m_includeFiles;
Peter Kuemmel's avatar
Peter Kuemmel committed
178
    QStringList m_compilerOptions;
179
    QByteArray m_defines;
dt's avatar
dt committed
180

181
182
    CMakeBuildTarget m_buildTarget;
    QList<CMakeBuildTarget> m_buildTargets;
183
    QString m_projectName;
184
    QString m_compiler;
185
186
};

187
class CMakeFile : public Core::IDocument
con's avatar
con committed
188
189
190
191
192
{
    Q_OBJECT
public:
    CMakeFile(CMakeProject *parent, QString fileName);

193
    bool save(QString *errorString, const QString &fileName, bool autoSave);
con's avatar
con committed
194
195
196
197
198
199
200
201

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

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

202
    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
203
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
204

con's avatar
con committed
205
206
207
208
private:
    CMakeProject *m_project;
};

209
class CMakeBuildSettingsWidget : public ProjectExplorer::NamedWidget
con's avatar
con committed
210
{
211
    Q_OBJECT
con's avatar
con committed
212
public:
213
    CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc);
con's avatar
con committed
214

215
private slots:
216
    void openChangeBuildDirectoryDialog();
217
    void runCMake();
218
private:
219
220
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
221
    CMakeBuildConfiguration *m_buildConfiguration;
con's avatar
con committed
222
223
};

hjk's avatar
hjk committed
224
225
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
226
227

#endif // CMAKEPROJECT_H