cmakeproject.h 6.89 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
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
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
40
#include <projectexplorer/buildconfiguration.h>
41
#include <projectexplorer/namedwidget.h>
42
#include <coreplugin/idocument.h>
43
#include <coreplugin/editormanager/editormanager.h>
dt's avatar
dt committed
44
#include <coreplugin/editormanager/ieditor.h>
con's avatar
con committed
45

46 47 48
#include <QXmlStreamReader>
#include <QPushButton>
#include <QLineEdit>
con's avatar
con committed
49

50 51 52 53
QT_BEGIN_NAMESPACE
class QFileSystemWatcher;
QT_END_NAMESPACE

54 55
namespace ProjectExplorer { class Target; }

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

class CMakeFile;
60
class CMakeBuildSettingsWidget;
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
    QString displayName() const;
83
    Core::IDocument *document() const;
Tobias Hunger's avatar
Tobias Hunger committed
84
    CMakeManager *projectManager() const;
con's avatar
con committed
85

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

Tobias Hunger's avatar
Tobias Hunger committed
88
    QStringList files(FilesMode fileMode) const;
89
    QStringList buildTargetTitles(bool runnable = false) const;
90 91
    QList<CMakeBuildTarget> buildTargets() const;
    bool hasBuildTarget(const QString &title) const;
92

93
    CMakeBuildTarget buildTargetForTitle(const QString &title);
con's avatar
con committed
94

95 96
    static QString shadowBuildDirectory(const QString &projectFilePath, const ProjectExplorer::Kit *k,
                                        const QString &bcName);
Tobias Hunger's avatar
Tobias Hunger committed
97

98 99
    bool isProjectFile(const QString &fileName);

100
    bool parseCMakeLists();
Tobias Hunger's avatar
Tobias Hunger committed
101

102 103
signals:
    /// emitted after parsing
104
    void buildTargetsChanged();
105

106
protected:
Tobias Hunger's avatar
Tobias Hunger committed
107
    bool fromMap(const QVariantMap &map);
108
    bool setupTarget(ProjectExplorer::Target *t);
109

110
    // called by CMakeBuildSettingsWidget
111
    void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
112

113 114
private slots:
    void fileChanged(const QString &fileName);
115
    void activeTargetWasChanged(ProjectExplorer::Target *target);
Tobias Hunger's avatar
Tobias Hunger committed
116
    void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
117

118
    void updateRunConfigurations();
Tobias Hunger's avatar
Tobias Hunger committed
119

120
private:
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
    ProjectExplorer::FolderNode *findOrCreateFolder(CMakeProjectNode *rootNode, QString directory);
dt's avatar
dt committed
124 125
    void createUiCodeModelSupport();
    QString uiHeaderFile(const QString &uiFile);
Tobias Hunger's avatar
Tobias Hunger committed
126
    void updateRunConfigurations(ProjectExplorer::Target *t);
127
    void updateApplicationAndDeploymentTargets();
con's avatar
con committed
128 129

    CMakeManager *m_manager;
130
    ProjectExplorer::Target *m_activeTarget;
con's avatar
con committed
131 132
    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;
138
    QList<CMakeBuildTarget> m_buildTargets;
139
    QFileSystemWatcher *m_watcher;
140
    QSet<QString> m_watchedFiles;
141
    QFuture<void> m_codeModelFuture;
con's avatar
con committed
142 143
};

144 145 146 147 148
class CMakeCbpParser : public QXmlStreamReader
{
public:
    bool parseCbpFile(const QString &fileName);
    QList<ProjectExplorer::FileNode *> fileList();
dt's avatar
dt committed
149
    QList<ProjectExplorer::FileNode *> cmakeFileList();
150
    QStringList includeFiles();
151
    QList<CMakeBuildTarget> buildTargets();
152
    QByteArray defines() const;
153
    QString projectName() const;
154
    QString compilerName() const;
dt's avatar
dt committed
155
    bool hasCMakeFiles();
Peter Kuemmel's avatar
Peter Kuemmel committed
156

157 158 159 160
private:
    void parseCodeBlocks_project_file();
    void parseProject();
    void parseBuild();
161
    void parseOption();
162 163
    void parseBuildTarget();
    void parseBuildTargetOption();
164
    void parseMakeCommands();
165 166
    void parseBuildTargetBuild();
    void parseBuildTargetClean();
167 168 169
    void parseCompiler();
    void parseAdd();
    void parseUnit();
dt's avatar
dt committed
170
    void parseUnitOption();
171 172 173
    void parseUnknownElement();

    QList<ProjectExplorer::FileNode *> m_fileList;
dt's avatar
dt committed
174 175 176
    QList<ProjectExplorer::FileNode *> m_cmakeFileList;
    QSet<QString> m_processedUnits;
    bool m_parsingCmakeUnit;
177
    QStringList m_includeFiles;
Peter Kuemmel's avatar
Peter Kuemmel committed
178
    QStringList m_compilerOptions;
179
    QByteArray m_defines;
dt's avatar
dt committed
180

181 182
    CMakeBuildTarget m_buildTarget;
    QList<CMakeBuildTarget> m_buildTargets;
183
    QString m_projectName;
184
    QString m_compiler;
185 186
};

187
class CMakeFile : public Core::IDocument
con's avatar
con committed
188 189 190 191 192
{
    Q_OBJECT
public:
    CMakeFile(CMakeProject *parent, QString fileName);

193
    bool save(QString *errorString, const QString &fileName, bool autoSave);
con's avatar
con committed
194 195 196 197 198 199 200

    QString defaultPath() const;
    QString suggestedFileName() const;

    bool isModified() const;
    bool isSaveAsAllowed() const;

201
    ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
202
    bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
203

con's avatar
con committed
204 205 206 207
private:
    CMakeProject *m_project;
};

208
class CMakeBuildSettingsWidget : public ProjectExplorer::NamedWidget
con's avatar
con committed
209
{
210
    Q_OBJECT
con's avatar
con committed
211
public:
212
    CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc);
con's avatar
con committed
213

214
private slots:
215
    void openChangeBuildDirectoryDialog();
216
    void runCMake();
217
private:
218 219
    QLineEdit *m_pathLineEdit;
    QPushButton *m_changeButton;
220
    CMakeBuildConfiguration *m_buildConfiguration;
con's avatar
con committed
221 222
};

hjk's avatar
hjk committed
223 224
} // namespace Internal
} // namespace CMakeProjectManager
con's avatar
con committed
225 226

#endif // CMAKEPROJECT_H