cmakeproject.h 7.14 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 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"
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/toolchain.h>
42
#include <projectexplorer/filewatcher.h>
43
#include <projectexplorer/buildconfiguration.h>
con's avatar
con committed
44
45
#include <coreplugin/ifile.h>

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

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

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

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

66
67
68
69
70
71
72
73
74
75
76
class CMakeBuildConfigurationFactory : public ProjectExplorer::IBuildConfigurationFactory
{
    Q_OBJECT

public:
    CMakeBuildConfigurationFactory(CMakeProject *project);
    ~CMakeBuildConfigurationFactory();

    QStringList availableCreationTypes() const;
    QString displayNameForType(const QString &type) const;

77
    ProjectExplorer::BuildConfiguration *create(const QString &type) const;
dt's avatar
dt committed
78
79
    ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::BuildConfiguration *source) const;
    ProjectExplorer::BuildConfiguration *restore() const;
80
81
82
83

private:
    CMakeProject *m_project;
};
84

con's avatar
con committed
85
86
87
class CMakeProject : public ProjectExplorer::Project
{
    Q_OBJECT
88
89
    // for changeBuildDirectory
    friend class CMakeBuildSettingsWidget;
con's avatar
con committed
90
91
92
93
public:
    CMakeProject(CMakeManager *manager, const QString &filename);
    ~CMakeProject();

dt's avatar
dt committed
94
95
    CMakeBuildConfiguration *activeCMakeBuildConfiguration() const;

con's avatar
con committed
96
97
    virtual QString name() const;
    virtual Core::IFile *file() const;
98
    virtual ProjectExplorer::IBuildConfigurationFactory *buildConfigurationFactory() const;
99
    virtual CMakeManager *projectManager() const;
con's avatar
con committed
100
101
102
103
104

    virtual QList<ProjectExplorer::Project *> dependsOn(); //NBS TODO implement dependsOn

    virtual bool isApplication() const;

dt's avatar
dt committed
105
106
    virtual ProjectExplorer::BuildConfigWidget *createConfigWidget();
    virtual QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
con's avatar
con committed
107
108
109
110

    virtual ProjectExplorer::ProjectNode *rootProjectNode() const;

    virtual QStringList files(FilesMode fileMode) const;
111
    QStringList targets() const;
112

113
    CMakeTarget targetForTitle(const QString &title);
con's avatar
con committed
114

115
116
    QString sourceDirectory() const;

117
118
protected:
    virtual void saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer);
dt's avatar
dt committed
119
    virtual bool restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader);
120

121
    // called by CMakeBuildSettingsWidget
122
    void changeBuildDirectory(ProjectExplorer::BuildConfiguration *configuration, const QString &newBuildDirectory);
123

124
125
private slots:
    void fileChanged(const QString &fileName);
126
    void slotActiveBuildConfiguration();
127

con's avatar
con committed
128
private:
con's avatar
con committed
129
    bool parseCMakeLists();
130

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
134
135
136
137
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);

    CMakeManager *m_manager;
    QString m_fileName;
    CMakeFile *m_file;
138
    QString m_projectName;
139
    CMakeBuildConfigurationFactory *m_buildConfigurationFactory;
con's avatar
con committed
140
141

    // TODO probably need a CMake specific node structure
142
    CMakeProjectNode *m_rootNode;
con's avatar
con committed
143
    QStringList m_files;
dt's avatar
dt committed
144
    QList<CMakeTarget> m_targets;
145
146
    ProjectExplorer::FileWatcher *m_watcher;
    bool m_insideFileChanged;
147
    QSet<QString> m_watchedFiles;
con's avatar
con committed
148
149

    friend class CMakeBuildConfigurationFactory; // for parseCMakeLists
con's avatar
con committed
150
151
};

152
153
154
155
156
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
dt's avatar
dt committed
157
    QList<ProjectExplorer::FileNode *> cmakeFileList();
158
    QStringList includeFiles();
dt's avatar
dt committed
159
    QList<CMakeTarget> targets();
160
    QString projectName() const;
161
    QString compilerName() const;
dt's avatar
dt committed
162
    bool hasCMakeFiles();
163
164
165
166
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
167
    void parseOption();
168
    void parseTarget();
dt's avatar
dt committed
169
    void parseTargetOption();
dt's avatar
dt committed
170
171
172
    void parseMakeCommand();
    void parseTargetBuild();
    void parseTargetClean();
173
174
175
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
176
    void parseUnitOption();
177
178
179
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
180
181
182
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
183
    QStringList m_includeFiles;
dt's avatar
dt committed
184

dt's avatar
dt committed
185
    CMakeTarget m_target;
dt's avatar
dt committed
186
    bool m_targetType;
dt's avatar
dt committed
187
    QList<CMakeTarget> m_targets;
188
    QString m_projectName;
189
    QString m_compiler;
190
191
};

con's avatar
con committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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;

    void modified(ReloadBehavior *behavior);
private:
    CMakeProject *m_project;
    QString m_fileName;
};

dt's avatar
dt committed
215
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
con's avatar
con committed
216
{
217
    Q_OBJECT
con's avatar
con committed
218
public:
219
    CMakeBuildSettingsWidget(CMakeProject *project);
con's avatar
con committed
220
221
222
223
    virtual QString displayName() const;

    // 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
224
    virtual void init(ProjectExplorer::BuildConfiguration *bc);
225
private slots:
226
    void openChangeBuildDirectoryDialog();
227
228
private:
    CMakeProject *m_project;
229
230
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
231
    CMakeBuildConfiguration *m_buildConfiguration;
con's avatar
con committed
232
233
};

hjk's avatar
hjk committed
234
235
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
236
237

#endif // CMAKEPROJECT_H