cmakeproject.h 7.31 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>
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
    virtual QString buildDirectory(const QString &buildConfiguration) const;

dt's avatar
dt committed
92 93
    virtual ProjectExplorer::BuildConfigWidget *createConfigWidget();
    virtual QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
con's avatar
con committed
94 95 96

    // This method is called for new build configurations
    // You should probably set some default values in this method
97
    virtual bool newBuildConfiguration(const QString &buildConfiguration);
con's avatar
con committed
98 99 100 101

    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;
142
    QSet<QString> m_watchedFiles;
con's avatar
con committed
143 144
};

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

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

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

con's avatar
con committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
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
208
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
con's avatar
con committed
209
{
210
    Q_OBJECT
con's avatar
con committed
211
public:
212
    CMakeBuildSettingsWidget(CMakeProject *project);
con's avatar
con committed
213 214 215 216 217
    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);
218
private slots:
219
    void openChangeBuildDirectoryDialog();
220 221
private:
    CMakeProject *m_project;
222 223
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
224
    QString m_buildConfiguration;
con's avatar
con committed
225 226
};

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

#endif // CMAKEPROJECT_H