cmakeproject.h 8.16 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 "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>
42
#include <projectexplorer/buildconfiguration.h>
con's avatar
con committed
43 44
#include <coreplugin/ifile.h>

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

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

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

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

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

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

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

76 77 78
    ProjectExplorer::BuildConfiguration *create(const QString &type) const;
    ProjectExplorer::BuildConfiguration *clone(const QString &name, ProjectExplorer::BuildConfiguration *source) const;
    ProjectExplorer::BuildConfiguration *restore(const QString &name) const;
79 80 81 82

private:
    CMakeProject *m_project;
};
83

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

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

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

    virtual bool isApplication() const;

102
    //building environment
103 104
    ProjectExplorer::Environment environment(ProjectExplorer::BuildConfiguration *configuration) const;
    ProjectExplorer::Environment baseEnvironment(ProjectExplorer::BuildConfiguration *configuration) const;
105
    void setUserEnvironmentChanges(ProjectExplorer::BuildConfiguration *configuration, const QList<ProjectExplorer::EnvironmentItem> &diff);
106 107 108
    QList<ProjectExplorer::EnvironmentItem> userEnvironmentChanges(ProjectExplorer::BuildConfiguration *configuration) const;
    bool useSystemEnvironment(ProjectExplorer::BuildConfiguration *configuration) const;
    void setUseSystemEnvironment(ProjectExplorer::BuildConfiguration *configuration, bool b);
109

110
    virtual QString buildDirectory(ProjectExplorer::BuildConfiguration *configuration) const;
con's avatar
con committed
111

dt's avatar
dt committed
112 113
    virtual ProjectExplorer::BuildConfigWidget *createConfigWidget();
    virtual QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
con's avatar
con committed
114 115 116 117

    virtual ProjectExplorer::ProjectNode *rootProjectNode() const;

    virtual QStringList files(FilesMode fileMode) const;
118
    QStringList targets() const;
119
    QString buildParser(ProjectExplorer::BuildConfiguration *configuration) const;
120
    CMakeTarget targetForTitle(const QString &title);
con's avatar
con committed
121

122
    QString sourceDirectory() const;
123
    ProjectExplorer::ToolChain::ToolChainType toolChainType() const;
124
    ProjectExplorer::ToolChain *toolChain(ProjectExplorer::BuildConfiguration *configuration) const;
125

126 127
protected:
    virtual void saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer);
dt's avatar
dt committed
128
    virtual bool restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader);
129

130
    // called by CMakeBuildSettingsWidget
131
    void changeBuildDirectory(ProjectExplorer::BuildConfiguration *configuration, const QString &newBuildDirectory);
132

133 134
private slots:
    void fileChanged(const QString &fileName);
135
    void slotActiveBuildConfiguration();
136

con's avatar
con committed
137
private:
con's avatar
con committed
138
    bool parseCMakeLists();
139
    void updateToolChain(const QString &compiler);
140

con's avatar
con committed
141
    void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
142
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
con's avatar
con committed
143 144 145 146 147
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);

    CMakeManager *m_manager;
    QString m_fileName;
    CMakeFile *m_file;
148
    QString m_projectName;
149
    CMakeBuildConfigurationFactory *m_buildConfigurationFactory;
con's avatar
con committed
150 151

    // TODO probably need a CMake specific node structure
152
    CMakeProjectNode *m_rootNode;
con's avatar
con committed
153
    QStringList m_files;
dt's avatar
dt committed
154
    QList<CMakeTarget> m_targets;
155
    ProjectExplorer::ToolChain *m_toolChain;
156 157
    ProjectExplorer::FileWatcher *m_watcher;
    bool m_insideFileChanged;
158
    QSet<QString> m_watchedFiles;
con's avatar
con committed
159 160

    friend class CMakeBuildConfigurationFactory; // for parseCMakeLists
con's avatar
con committed
161 162
};

163 164 165 166 167
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
dt's avatar
dt committed
168
    QList<ProjectExplorer::FileNode *> cmakeFileList();
169
    QStringList includeFiles();
dt's avatar
dt committed
170
    QList<CMakeTarget> targets();
171
    QString projectName() const;
172
    QString compilerName() const;
dt's avatar
dt committed
173
    bool hasCMakeFiles();
174 175 176 177
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
178
    void parseOption();
179
    void parseTarget();
dt's avatar
dt committed
180
    void parseTargetOption();
dt's avatar
dt committed
181 182 183
    void parseMakeCommand();
    void parseTargetBuild();
    void parseTargetClean();
184 185 186
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
187
    void parseUnitOption();
188 189 190
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
191 192 193
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
194
    QStringList m_includeFiles;
dt's avatar
dt committed
195

dt's avatar
dt committed
196
    CMakeTarget m_target;
dt's avatar
dt committed
197
    bool m_targetType;
dt's avatar
dt committed
198
    QList<CMakeTarget> m_targets;
199
    QString m_projectName;
200
    QString m_compiler;
201 202
};

con's avatar
con committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
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
226
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
con's avatar
con committed
227
{
228
    Q_OBJECT
con's avatar
con committed
229
public:
230
    CMakeBuildSettingsWidget(CMakeProject *project);
con's avatar
con committed
231 232 233 234 235
    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);
236
private slots:
237
    void openChangeBuildDirectoryDialog();
238 239
private:
    CMakeProject *m_project;
240 241
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
242
    QString m_buildConfiguration;
con's avatar
con committed
243 244
};

hjk's avatar
hjk committed
245 246
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
247 248

#endif // CMAKEPROJECT_H