cmakeproject.h 6.84 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

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

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

dt's avatar
dt committed
75
76
    CMakeBuildConfiguration *activeCMakeBuildConfiguration() const;

Tobias Hunger's avatar
Tobias Hunger committed
77
78
79
80
81
    QString displayName() const;
    QString id() const;
    Core::IFile *file() const;
    ProjectExplorer::IBuildConfigurationFactory *buildConfigurationFactory() const;
    CMakeManager *projectManager() const;
con's avatar
con committed
82

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

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

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

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

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

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

99
100
    QString sourceDirectory() const;

101
102
103
104
105
signals:
    /// convenience signal emitted if the activeBuildConfiguration emits environmentChanged
    /// or if the activeBuildConfiguration changes
    void environmentChanged();
    /// emitted after parsing
106
    void buildTargetsChanged();
107

108
protected:
Tobias Hunger's avatar
Tobias Hunger committed
109
    bool fromMap(const QVariantMap &map);
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 slotActiveBuildConfiguration();
117

con's avatar
con committed
118
private:
con's avatar
con committed
119
    bool parseCMakeLists();
120

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

    CMakeManager *m_manager;
    QString m_fileName;
    CMakeFile *m_file;
128
    QString m_projectName;
129
    CMakeBuildConfigurationFactory *m_buildConfigurationFactory;
con's avatar
con committed
130
131

    // TODO probably need a CMake specific node structure
132
    CMakeProjectNode *m_rootNode;
con's avatar
con committed
133
    QStringList m_files;
134
    QList<CMakeBuildTarget> m_buildTargets;
135
136
    ProjectExplorer::FileWatcher *m_watcher;
    bool m_insideFileChanged;
137
    QSet<QString> m_watchedFiles;
138
    CMakeBuildConfiguration *m_lastActiveBuildConfiguration;
con's avatar
con committed
139
140

    friend class CMakeBuildConfigurationFactory; // for parseCMakeLists
con's avatar
con committed
141
142
};

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

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

176
177
178
    CMakeBuildTarget m_buildTarget;
    bool m_buildTargetType;
    QList<CMakeBuildTarget> m_buildTargets;
179
    QString m_projectName;
180
    QString m_compiler;
181
182
};

con's avatar
con committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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
206
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
con's avatar
con committed
207
{
208
    Q_OBJECT
con's avatar
con committed
209
public:
Tobias Hunger's avatar
Tobias Hunger committed
210
211
    explicit CMakeBuildSettingsWidget(CMakeProject *project);
    QString displayName() const;
con's avatar
con committed
212
213
214

    // 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
215
    virtual void init(ProjectExplorer::BuildConfiguration *bc);
216
private slots:
217
    void openChangeBuildDirectoryDialog();
218
219
private:
    CMakeProject *m_project;
220
221
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
222
    CMakeBuildConfiguration *m_buildConfiguration;
con's avatar
con committed
223
224
};

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

#endif // CMAKEPROJECT_H