cmakeproject.h 7.26 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 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
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
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
**
con's avatar
con committed
25 26 27 28 29 30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
con's avatar
con committed
31
**
32
**************************************************************************/
hjk's avatar
hjk committed
33

con's avatar
con committed
34 35 36
#ifndef CMAKEPROJECT_H
#define CMAKEPROJECT_H

hjk's avatar
hjk committed
37 38
#include "cmakeprojectmanager.h"
#include "cmakeprojectnodes.h"
39
#include "cmakebuildconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
40
#include "cmaketarget.h"
41
#include "makestep.h"
hjk's avatar
hjk committed
42

con's avatar
con committed
43 44 45
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/buildstep.h>
46
#include <projectexplorer/filewatcher.h>
47
#include <projectexplorer/buildconfiguration.h>
con's avatar
con committed
48
#include <coreplugin/ifile.h>
dt's avatar
dt committed
49
#include <coreplugin/editormanager/ieditor.h>
con's avatar
con committed
50

hjk's avatar
hjk committed
51
#include <QtCore/QXmlStreamReader>
52 53
#include <QtGui/QPushButton>
#include <QtGui/QLineEdit>
con's avatar
con committed
54 55

namespace CMakeProjectManager {
56
namespace Internal {
con's avatar
con committed
57 58

class CMakeFile;
59
class CMakeBuildSettingsWidget;
dt's avatar
dt committed
60
class CMakeUiCodeModelSupport;
con's avatar
con committed
61

62
struct CMakeBuildTarget
dt's avatar
dt committed
63 64
{
    QString title;
65 66
    QString executable; // TODO: rename to output?
    bool library;
dt's avatar
dt committed
67 68 69 70 71 72
    QString workingDirectory;
    QString makeCommand;
    QString makeCleanCommand;
    void clear();
};

con's avatar
con committed
73 74 75
class CMakeProject : public ProjectExplorer::Project
{
    Q_OBJECT
76 77
    // for changeBuildDirectory
    friend class CMakeBuildSettingsWidget;
con's avatar
con committed
78 79 80 81
public:
    CMakeProject(CMakeManager *manager, const QString &filename);
    ~CMakeProject();

Tobias Hunger's avatar
Tobias Hunger committed
82 83 84 85
    QString displayName() const;
    QString id() const;
    Core::IFile *file() const;
    CMakeManager *projectManager() const;
con's avatar
con committed
86

Tobias Hunger's avatar
Tobias Hunger committed
87 88
    CMakeTarget *activeTarget() const;

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

Tobias Hunger's avatar
Tobias Hunger committed
91
    QList<ProjectExplorer::BuildConfigWidget*> subConfigWidgets();
con's avatar
con committed
92

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

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

100
    CMakeBuildTarget buildTargetForTitle(const QString &title);
con's avatar
con committed
101

102 103
    QString defaultBuildDirectory() const;

Tobias Hunger's avatar
Tobias Hunger committed
104 105
    bool parseCMakeLists();

dt's avatar
dt committed
106 107
    QString uicCommand() const;

108 109
signals:
    /// emitted after parsing
110
    void buildTargetsChanged();
111

112
protected:
Tobias Hunger's avatar
Tobias Hunger committed
113
    bool fromMap(const QVariantMap &map);
114

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

118 119
private slots:
    void fileChanged(const QString &fileName);
Tobias Hunger's avatar
Tobias Hunger committed
120 121
    void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
    void targetAdded(ProjectExplorer::Target *);
122

dt's avatar
dt committed
123 124 125 126
    void editorChanged(Core::IEditor *editor);
    void editorAboutToClose(Core::IEditor *editor);
    void uiEditorContentsChanged();
    void buildStateChanged(ProjectExplorer::Project *project);
con's avatar
con committed
127 128
private:
    void buildTree(CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
129
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
con's avatar
con committed
130
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
dt's avatar
dt committed
131 132 133
    void updateCodeModelSupportFromEditor(const QString &uiFileName, const QString &contents);
    void createUiCodeModelSupport();
    QString uiHeaderFile(const QString &uiFile);
con's avatar
con committed
134 135 136 137

    CMakeManager *m_manager;
    QString m_fileName;
    CMakeFile *m_file;
138
    QString m_projectName;
dt's avatar
dt committed
139
    QString m_uicCommand;
con's avatar
con committed
140 141

    // TODO probably need a CMake specific node structure
142
    CMakeProjectNode *m_rootNode;
con's avatar
con committed
143
    QStringList m_files;
144
    QList<CMakeBuildTarget> m_buildTargets;
145 146
    ProjectExplorer::FileWatcher *m_watcher;
    bool m_insideFileChanged;
147
    QSet<QString> m_watchedFiles;
148
    QFuture<void> m_codeModelFuture;
dt's avatar
dt committed
149 150 151 152

    QMap<QString, CMakeUiCodeModelSupport *> m_uiCodeModelSupport;
    Core::IEditor *m_lastEditor;
    bool m_dirtyUic;
con's avatar
con committed
153 154
};

155 156 157 158 159
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
dt's avatar
dt committed
160
    QList<ProjectExplorer::FileNode *> cmakeFileList();
161
    QStringList includeFiles();
162
    QList<CMakeBuildTarget> buildTargets();
163
    QString projectName() const;
164
    QString compilerName() const;
dt's avatar
dt committed
165
    bool hasCMakeFiles();
166 167 168 169
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
170
    void parseOption();
171 172
    void parseBuildTarget();
    void parseBuildTargetOption();
dt's avatar
dt committed
173
    void parseMakeCommand();
174 175
    void parseBuildTargetBuild();
    void parseBuildTargetClean();
176 177 178
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
179
    void parseUnitOption();
180 181 182
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
183 184 185
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
186
    QStringList m_includeFiles;
dt's avatar
dt committed
187

188 189 190
    CMakeBuildTarget m_buildTarget;
    bool m_buildTargetType;
    QList<CMakeBuildTarget> m_buildTargets;
191
    QString m_projectName;
192
    QString m_compiler;
193 194
};

con's avatar
con committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
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;

212 213 214
    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
    void reload(ReloadFlag flag, ChangeType type);

dt's avatar
dt committed
215 216
    void rename(const QString &newName);

con's avatar
con committed
217 218 219 220 221
private:
    CMakeProject *m_project;
    QString m_fileName;
};

dt's avatar
dt committed
222
class CMakeBuildSettingsWidget : public ProjectExplorer::BuildConfigWidget
con's avatar
con committed
223
{
224
    Q_OBJECT
con's avatar
con committed
225
public:
226
    explicit CMakeBuildSettingsWidget(CMakeTarget *target);
Tobias Hunger's avatar
Tobias Hunger committed
227
    QString displayName() const;
con's avatar
con committed
228 229

    // This is called to set up the config widget before showing it
dt's avatar
dt committed
230
    virtual void init(ProjectExplorer::BuildConfiguration *bc);
231
private slots:
232
    void openChangeBuildDirectoryDialog();
233
    void runCMake();
234
private:
235
    CMakeTarget *m_target;
236 237
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
238
    CMakeBuildConfiguration *m_buildConfiguration;
con's avatar
con committed
239 240
};

hjk's avatar
hjk committed
241 242
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
243 244

#endif // CMAKEPROJECT_H