cmakeproject.h 6.99 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;
109

110
111
112
113
protected:
    virtual void saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer);
    virtual void restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader);

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

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

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

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

    CMakeManager *m_manager;
    QString m_fileName;
    CMakeFile *m_file;
132
    QString m_projectName;
con's avatar
con committed
133
134

    // TODO probably need a CMake specific node structure
135
    CMakeProjectNode *m_rootNode;
con's avatar
con committed
136
    QStringList m_files;
dt's avatar
dt committed
137
    QList<CMakeTarget> m_targets;
138
    ProjectExplorer::ToolChain *m_toolChain;
139
140
    ProjectExplorer::FileWatcher *m_watcher;
    bool m_insideFileChanged;
con's avatar
con committed
141
142
};

143
144
145
146
147
148
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
    QStringList includeFiles();
dt's avatar
dt committed
149
    QList<CMakeTarget> targets();
150
    QString projectName() const;
151
    QString compilerName() const;
152
153
154
155
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
156
    void parseOption();
157
    void parseTarget();
dt's avatar
dt committed
158
    void parseTargetOption();
dt's avatar
dt committed
159
160
161
    void parseMakeCommand();
    void parseTargetBuild();
    void parseTargetClean();
162
163
164
165
166
167
168
    void parseCompiler();
    void parseAdd();
    void parseUnit();
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
    QStringList m_includeFiles;
dt's avatar
dt committed
169

dt's avatar
dt committed
170
    CMakeTarget m_target;
dt's avatar
dt committed
171
    bool m_targetType;
dt's avatar
dt committed
172
    QList<CMakeTarget> m_targets;
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
194
195
196
197
198
199
200
201
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
{
202
    Q_OBJECT
con's avatar
con committed
203
public:
204
    CMakeBuildSettingsWidget(CMakeProject *project);
con's avatar
con committed
205
206
207
208
209
    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);
210
private slots:
211
    void openChangeBuildDirectoryDialog();
212
213
private:
    CMakeProject *m_project;
214
215
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
216
    QString m_buildConfiguration;
con's avatar
con committed
217
218
};

hjk's avatar
hjk committed
219
220
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
221
222

#endif // CMAKEPROJECT_H