cmakeproject.h 7.29 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
26
** contact the sales department at http://www.qtsoftware.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 "makestep.h"
hjk's avatar
hjk committed
36

con's avatar
con committed
37
38
39
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/buildstep.h>
40
#include <projectexplorer/toolchain.h>
41
#include <projectexplorer/filewatcher.h>
con's avatar
con committed
42
43
#include <coreplugin/ifile.h>

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

namespace CMakeProjectManager {
49
namespace Internal {
con's avatar
con committed
50
51
52

class CMakeFile;

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

63
64
class CMakeBuildSettingsWidget;

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

    virtual QString name() const;
    virtual Core::IFile *file() const;
76
    virtual CMakeManager *projectManager() const;
con's avatar
con committed
77
78
79
80
81

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

    virtual bool isApplication() const;

82
83
84
85
86
87
88
89
    //building environment
    ProjectExplorer::Environment environment(const QString &buildConfiguration) const;
    ProjectExplorer::Environment baseEnvironment(const QString &buildConfiguration) const;
    void setUserEnvironmentChanges(const QString &buildConfig, const QList<ProjectExplorer::EnvironmentItem> &diff);
    QList<ProjectExplorer::EnvironmentItem> userEnvironmentChanges(const QString &buildConfig) const;
    bool useSystemEnvironment(const QString &buildConfiguration) const;
    void setUseSystemEnvironment(const QString &buildConfiguration, bool b);

con's avatar
con committed
90
91
92
93
94
95
96
97
98
99
100
101
    virtual QString buildDirectory(const QString &buildConfiguration) const;

    virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
    virtual QList<ProjectExplorer::BuildStepConfigWidget*> subConfigWidgets();

    // This method is called for new build configurations
    // You should probably set some default values in this method
    virtual void newBuildConfiguration(const QString &buildConfiguration);

    virtual ProjectExplorer::ProjectNode *rootProjectNode() const;

    virtual QStringList files(FilesMode fileMode) const;
102
103
    MakeStep *makeStep() const;
    QStringList targets() const;
104
    QString buildParser(const QString &buildConfiguration) const;
105
    CMakeTarget targetForTitle(const QString &title);
con's avatar
con committed
106

107
    QString sourceDirectory() const;
108
    ProjectExplorer::ToolChain::ToolChainType toolChainType() const;
dt's avatar
dt committed
109
    ProjectExplorer::ToolChain *toolChain(const QString &buildConfiguration) const;
110

111
112
protected:
    virtual void saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer);
dt's avatar
dt committed
113
    virtual bool restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader);
114

115
116
117
    // called by CMakeBuildSettingsWidget
    void changeBuildDirectory(const QString &buildConfiguration, const QString &newBuildDirectory);

118
119
private slots:
    void fileChanged(const QString &fileName);
120
    void slotActiveBuildConfiguration();
121

con's avatar
con committed
122
private:
dt's avatar
dt committed
123
    bool parseCMakeLists();
124
    void updateToolChain(const QString &compiler);
125

con's avatar
con committed
126
    void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
127
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
con's avatar
con committed
128
129
130
131
132
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);

    CMakeManager *m_manager;
    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;
dt's avatar
dt committed
138
    QList<CMakeTarget> m_targets;
139
    ProjectExplorer::ToolChain *m_toolChain;
140
141
    ProjectExplorer::FileWatcher *m_watcher;
    bool m_insideFileChanged;
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();
dt's avatar
dt committed
151
    QList<CMakeTarget> targets();
152
    QString projectName() const;
153
    QString compilerName() const;
dt's avatar
dt committed
154
    bool hasCMakeFiles();
155
156
157
158
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
159
    void parseOption();
160
    void parseTarget();
dt's avatar
dt committed
161
    void parseTargetOption();
dt's avatar
dt committed
162
163
164
    void parseMakeCommand();
    void parseTargetBuild();
    void parseTargetClean();
165
166
167
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
168
    void parseUnitOption();
169
170
171
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
172
173
174
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
175
    QStringList m_includeFiles;
dt's avatar
dt committed
176

dt's avatar
dt committed
177
    CMakeTarget m_target;
dt's avatar
dt committed
178
    bool m_targetType;
dt's avatar
dt committed
179
    QList<CMakeTarget> m_targets;
180
    QString m_projectName;
181
    QString m_compiler;
182
183
};

con's avatar
con committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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;
};

class CMakeBuildSettingsWidget : public ProjectExplorer::BuildStepConfigWidget
{
209
    Q_OBJECT
con's avatar
con committed
210
public:
211
    CMakeBuildSettingsWidget(CMakeProject *project);
con's avatar
con committed
212
213
214
215
216
    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
    virtual void init(const QString &buildConfiguration);
217
private slots:
218
    void openChangeBuildDirectoryDialog();
219
220
private:
    CMakeProject *m_project;
221
222
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
223
    QString m_buildConfiguration;
con's avatar
con committed
224
225
};

hjk's avatar
hjk committed
226
227
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
228
229

#endif // CMAKEPROJECT_H