cmakeproject.h 5.14 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
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
** 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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30

con's avatar
con committed
31 32 33
#ifndef CMAKEPROJECT_H
#define CMAKEPROJECT_H

34
#include "cmake_global.h"
hjk's avatar
hjk committed
35 36
#include "cmakeprojectnodes.h"

con's avatar
con committed
37
#include <projectexplorer/project.h>
38
#include <projectexplorer/buildconfiguration.h>
39
#include <projectexplorer/namedwidget.h>
40
#include <coreplugin/idocument.h>
41
#include <coreplugin/editormanager/editormanager.h>
dt's avatar
dt committed
42
#include <coreplugin/editormanager/ieditor.h>
con's avatar
con committed
43

44 45
#include <utils/fileutils.h>

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

51 52 53 54
QT_BEGIN_NAMESPACE
class QFileSystemWatcher;
QT_END_NAMESPACE

con's avatar
con committed
55 56
namespace CMakeProjectManager {

57
namespace Internal {
con's avatar
con committed
58
class CMakeFile;
59
class CMakeBuildSettingsWidget;
60 61 62 63
class CMakeBuildConfiguration;
class CMakeProjectNode;
class CMakeManager;
}
con's avatar
con committed
64

65 66 67
enum TargetType {
    ExecutableType = 0,
    StaticLibraryType = 2,
68 69
    DynamicLibraryType = 3,
    UtilityType = 64
70 71
};

Tobias Hunger's avatar
Tobias Hunger committed
72
class CMAKE_EXPORT CMakeBuildTarget
dt's avatar
dt committed
73
{
Tobias Hunger's avatar
Tobias Hunger committed
74
public:
dt's avatar
dt committed
75
    QString title;
76
    QString executable; // TODO: rename to output?
77
    TargetType targetType;
dt's avatar
dt committed
78
    QString workingDirectory;
79
    QString sourceDirectory;
dt's avatar
dt committed
80 81
    QString makeCommand;
    QString makeCleanCommand;
82 83 84 85 86 87 88

    // code model
    QStringList includeFiles;
    QStringList compilerOptions;
    QByteArray defines;
    QStringList files;

dt's avatar
dt committed
89 90 91
    void clear();
};

92
class CMAKE_EXPORT CMakeProject : public ProjectExplorer::Project
con's avatar
con committed
93 94
{
    Q_OBJECT
95
    // for changeBuildDirectory
96
    friend class Internal::CMakeBuildSettingsWidget;
con's avatar
con committed
97
public:
98
    CMakeProject(Internal::CMakeManager *manager, const Utils::FileName &filename);
99
    ~CMakeProject() override;
con's avatar
con committed
100

101
    QString displayName() const override;
con's avatar
con committed
102

103
    QStringList files(FilesMode fileMode) const override;
104
    QStringList buildTargetTitles(bool runnable = false) const;
105 106
    QList<CMakeBuildTarget> buildTargets() const;
    bool hasBuildTarget(const QString &title) const;
107

108
    CMakeBuildTarget buildTargetForTitle(const QString &title);
con's avatar
con committed
109

110
    bool isProjectFile(const Utils::FileName &fileName);
111

112
    bool parseCMakeLists();
Tobias Hunger's avatar
Tobias Hunger committed
113

114
    bool needsConfiguration() const override;
115

116
    bool requiresTargetPanel() const override;
117

118 119
    bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage = 0) const override;

120 121
signals:
    /// emitted after parsing
122
    void buildTargetsChanged();
123

124
protected:
125 126
    RestoreResult fromMap(const QVariantMap &map, QString *errorMessage) override;
    bool setupTarget(ProjectExplorer::Target *t) override;
127

128
    // called by CMakeBuildSettingsWidget
129
    void changeBuildDirectory(Internal::CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
130

Tobias Hunger's avatar
Tobias Hunger committed
131
private:
132
    void fileChanged(const QString &fileName);
133
    void activeTargetWasChanged(ProjectExplorer::Target *target);
Tobias Hunger's avatar
Tobias Hunger committed
134
    void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*);
135

136
    void updateRunConfigurations();
Tobias Hunger's avatar
Tobias Hunger committed
137

138
    void buildTree(Internal::CMakeProjectNode *rootNode, QList<ProjectExplorer::FileNode *> list);
139
    void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList<ProjectExplorer::FileNode *> &list);
140
    ProjectExplorer::FolderNode *findOrCreateFolder(Internal::CMakeProjectNode *rootNode, QString directory);
dt's avatar
dt committed
141 142
    void createUiCodeModelSupport();
    QString uiHeaderFile(const QString &uiFile);
Tobias Hunger's avatar
Tobias Hunger committed
143
    void updateTargetRunConfigurations(ProjectExplorer::Target *t);
144
    void updateApplicationAndDeploymentTargets();
145
    QStringList getCXXFlagsFor(const CMakeBuildTarget &buildTarget, QByteArray *cachedBuildNinja);
con's avatar
con committed
146

147
    ProjectExplorer::Target *m_activeTarget = 0;
con's avatar
con committed
148 149 150

    // TODO probably need a CMake specific node structure
    QStringList m_files;
151
    QList<CMakeBuildTarget> m_buildTargets;
152
    QFileSystemWatcher *m_watcher;
153
    QSet<Utils::FileName> m_watchedFiles;
154
    QFuture<void> m_codeModelFuture;
con's avatar
con committed
155 156
};

hjk's avatar
hjk committed
157
} // namespace CMakeProjectManager
con's avatar
con committed
158 159

#endif // CMAKEPROJECT_H