cmakeproject.h 6.61 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) 2010 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
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
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"
Tobias Hunger's avatar
Tobias Hunger committed
36
#include "cmaketarget.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/toolchain.h>
43
#include <projectexplorer/filewatcher.h>
44
#include <projectexplorer/buildconfiguration.h>
con's avatar
con committed
45
46
#include <coreplugin/ifile.h>

hjk's avatar
hjk committed
47
#include <QtCore/QXmlStreamReader>
48
49
#include <QtGui/QPushButton>
#include <QtGui/QLineEdit>
con's avatar
con committed
50
51

namespace CMakeProjectManager {
52
namespace Internal {
con's avatar
con committed
53
54

class CMakeFile;
55
class CMakeBuildSettingsWidget;
con's avatar
con committed
56

57
struct CMakeBuildTarget
dt's avatar
dt committed
58
59
60
61
62
63
64
65
66
{
    QString title;
    QString executable;
    QString workingDirectory;
    QString makeCommand;
    QString makeCleanCommand;
    void clear();
};

con's avatar
con committed
67
68
69
class CMakeProject : public ProjectExplorer::Project
{
    Q_OBJECT
70
71
    // for changeBuildDirectory
    friend class CMakeBuildSettingsWidget;
con's avatar
con committed
72
73
74
75
public:
    CMakeProject(CMakeManager *manager, const QString &filename);
    ~CMakeProject();

Tobias Hunger's avatar
Tobias Hunger committed
76
77
78
    QString displayName() const;
    QString id() const;
    Core::IFile *file() const;
Tobias Hunger's avatar
Tobias Hunger committed
79
    CMakeTargetFactory *targetFactory() const;
Tobias Hunger's avatar
Tobias Hunger committed
80
    CMakeManager *projectManager() const;
con's avatar
con committed
81

Tobias Hunger's avatar
Tobias Hunger committed
82
83
    CMakeTarget *activeTarget() const;

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

Tobias Hunger's avatar
Tobias Hunger committed
86
    bool isApplication() const;
con's avatar
con committed
87

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

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

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

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

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

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

106
protected:
Tobias Hunger's avatar
Tobias Hunger committed
107
    bool fromMap(const QVariantMap &map);
108

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

112
113
private slots:
    void fileChanged(const QString &fileName);
Tobias Hunger's avatar
Tobias Hunger committed
114
115
    void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
    void targetAdded(ProjectExplorer::Target *);
116

con's avatar
con committed
117
118
private:
    void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
119
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
con's avatar
con committed
120
121
122
123
124
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);

    CMakeManager *m_manager;
    QString m_fileName;
    CMakeFile *m_file;
125
    QString m_projectName;
con's avatar
con committed
126
127

    // TODO probably need a CMake specific node structure
128
    CMakeProjectNode *m_rootNode;
con's avatar
con committed
129
    QStringList m_files;
130
    QList<CMakeBuildTarget> m_buildTargets;
131
132
    ProjectExplorer::FileWatcher *m_watcher;
    bool m_insideFileChanged;
133
    QSet<QString> m_watchedFiles;
Tobias Hunger's avatar
Tobias Hunger committed
134
    CMakeTargetFactory *m_targetFactory;
con's avatar
con committed
135
136
};

137
138
139
140
141
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
dt's avatar
dt committed
142
    QList<ProjectExplorer::FileNode *> cmakeFileList();
143
    QStringList includeFiles();
144
    QList<CMakeBuildTarget> buildTargets();
145
    QString projectName() const;
146
    QString compilerName() const;
dt's avatar
dt committed
147
    bool hasCMakeFiles();
148
149
150
151
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
152
    void parseOption();
153
154
    void parseBuildTarget();
    void parseBuildTargetOption();
dt's avatar
dt committed
155
    void parseMakeCommand();
156
157
    void parseBuildTargetBuild();
    void parseBuildTargetClean();
158
159
160
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
161
    void parseUnitOption();
162
163
164
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
165
166
167
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
168
    QStringList m_includeFiles;
dt's avatar
dt committed
169

170
171
172
    CMakeBuildTarget m_buildTarget;
    bool m_buildTargetType;
    QList<CMakeBuildTarget> m_buildTargets;
173
    QString m_projectName;
174
    QString m_compiler;
175
176
};

con's avatar
con committed
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
class CMakeFile : public Core::IFile
{
    Q_OBJECT
public:
    CMakeFile(CMakeProject *parent, QString fileName);

    bool save(const QString &fileName = QString());
    QString fileName() const;

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

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

194
195
196
    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
    void reload(ReloadFlag flag, ChangeType type);

con's avatar
con committed
197
198
199
200
201
private:
    CMakeProject *m_project;
    QString m_fileName;
};

dt's avatar
dt committed
202
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
con's avatar
con committed
203
{
204
    Q_OBJECT
con's avatar
con committed
205
public:
Tobias Hunger's avatar
Tobias Hunger committed
206
207
    explicit CMakeBuildSettingsWidget(CMakeProject *project);
    QString displayName() const;
con's avatar
con committed
208
209
210

    // This is called to set up the config widget before showing it
    // buildConfiguration is QString::null for the non buildConfiguration specific page
dt's avatar
dt committed
211
    virtual void init(ProjectExplorer::BuildConfiguration *bc);
212
private slots:
213
    void openChangeBuildDirectoryDialog();
214
215
private:
    CMakeProject *m_project;
216
217
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
218
    CMakeBuildConfiguration *m_buildConfiguration;
con's avatar
con committed
219
220
};

hjk's avatar
hjk committed
221
222
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
223
224

#endif // CMAKEPROJECT_H