qtversionmanager.h 9.87 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 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 QTVERSIONMANAGER_H
#define QTVERSIONMANAGER_H

33
#include <projectexplorer/toolchain.h>
34
#include <projectexplorer/task.h>
hjk's avatar
hjk committed
35

36
#include <QtCore/QHash>
37
#include <QtCore/QSet>
38
#include <QtCore/QSharedPointer>
con's avatar
con committed
39

40
namespace Qt4ProjectManager {
41

con's avatar
con committed
42
namespace Internal {
43
class QtOptionsPageWidget;
44
class QtOptionsPage;
45
}
con's avatar
con committed
46

47
class QtVersion
48
{
con's avatar
con committed
49 50
    friend class QtVersionManager;
public:
51
    QtVersion(const QString &name, const QString &qmakeCommand,
52
              bool isAutodetected = false, const QString &autodetectionSource = QString());
53 54 55

    QtVersion(const QString &path, bool isAutodetected = false, const QString &autodetectionSource = QString());

56
    QtVersion(const QString &name, const QString &qmakeCommand, int id,
57
              bool isAutodetected = false, const QString &autodetectionSource = QString());
58
    QtVersion();
59
    ~QtVersion();
con's avatar
con committed
60 61

    bool isValid() const; //TOOD check that the dir exists and the name is non empty
62
    QString invalidReason() const;
63
    bool isAutodetected() const { return m_isAutodetected; }
64
    QString autodetectionSource() const { return m_autodetectionSource; }
con's avatar
con committed
65

66
    QString displayName() const;
con's avatar
con committed
67 68
    QString sourcePath() const;
    QString qmakeCommand() const;
dt's avatar
dt committed
69
    QString uicCommand() const;
70 71
    QString designerCommand() const;
    QString linguistCommand() const;
con's avatar
con committed
72

Tobias Hunger's avatar
Tobias Hunger committed
73 74
    bool supportsTargetId(const QString &id) const;
    QSet<QString> supportedTargetIds() const;
75
    bool supportsMobileTarget() const;
Tobias Hunger's avatar
Tobias Hunger committed
76

con's avatar
con committed
77
    QList<ProjectExplorer::ToolChain::ToolChainType> possibleToolChainTypes() const;
78
    ProjectExplorer::ToolChain *toolChain(ProjectExplorer::ToolChain::ToolChainType type) const;
79 80 81 82 83 84 85

    /// @returns the name of the mkspec, which is generally not enough
    /// to pass to qmake.
    QString mkspec() const;
    /// @returns the full path to the default directory
    /// specifally not the directory the symlink/ORIGINAL_QMAKESPEC points to
    QString mkspecPath() const;
86

87 88
    bool isBuildWithSymbianSbsV2() const;

89
    void setDisplayName(const QString &name);
90
    void setQMakeCommand(const QString &path);
91

92
    QString qtVersionString() const;
con's avatar
con committed
93 94 95
    // Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information
    QHash<QString,QString> versionInfo() const;

con's avatar
con committed
96 97
    QString mwcDirectory() const;
    void setMwcDirectory(const QString &directory);
98 99
    QString s60SDKDirectory() const;
    void setS60SDKDirectory(const QString &directory);
con's avatar
con committed
100 101
    QString gcceDirectory() const;
    void setGcceDirectory(const QString &directory);
102

con's avatar
con committed
103 104 105 106
    QString mingwDirectory() const;
    void setMingwDirectory(const QString &directory);
    QString msvcVersion() const;
    void setMsvcVersion(const QString &version);
107
    void addToEnvironment(ProjectExplorer::Environment &env) const;
108

109
    bool hasDebuggingHelper() const;
110
    QString debuggingHelperLibrary() const;
111
    QStringList debuggingHelperLibraryLocations() const;
112
    bool supportsBinaryDebuggingHelper() const;
113

114 115 116
    // Builds a debugging library
    // returns the output of the commands
    QString buildDebuggingHelperLibrary();
con's avatar
con committed
117

118 119 120 121 122 123 124 125 126
    bool hasExamples() const;
    QString examplesPath() const;

    bool hasDocumentation() const;
    QString documentationPath() const;

    bool hasDemos() const;
    QString demosPath() const;

127 128
    QString headerInstallPath() const;

Tobias Hunger's avatar
Tobias Hunger committed
129
    // All valid Ids are >= 0
con's avatar
con committed
130
    int uniqueId() const;
con's avatar
con committed
131
    bool isQt64Bit() const;
con's avatar
con committed
132 133 134 135 136 137 138 139

    enum QmakeBuildConfig
    {
        NoBuild = 1,
        DebugBuild = 2,
        BuildAll = 8
    };

140
    Q_DECLARE_FLAGS(QmakeBuildConfigs, QmakeBuildConfig)
141

142
    QmakeBuildConfigs defaultBuildConfig() const;
143
    QString toHtml() const;
144 145 146

    bool supportsShadowBuilds() const;

147 148 149 150 151 152
    /// Check a .pro-file/Qt version combination on possible issues with
    /// its symbian setup.
    /// @return a list of tasks, ordered on severity (errors first, then
    ///         warnings and finally info items.
    QList<ProjectExplorer::Task> reportIssues(const QString &proFile);

con's avatar
con committed
153
private:
154
    QList<QSharedPointer<ProjectExplorer::ToolChain> > toolChains() const;
con's avatar
con committed
155
    static int getUniqueId();
156
    // Also used by QtOptionsPageWidget
con's avatar
con committed
157
    void updateSourcePath();
158
    void updateVersionInfo() const;
159
    QString findQtBinary(const QStringList &possibleName) const;
dt's avatar
dt committed
160
    void updateToolChainAndMkspec() const;
161
    QString m_displayName;
con's avatar
con committed
162 163
    QString m_sourcePath;
    QString m_mingwDirectory;
164
    mutable QString m_msvcVersion;
con's avatar
con committed
165
    int m_id;
166
    bool m_isAutodetected;
167
    QString m_autodetectionSource;
168
    mutable bool m_hasDebuggingHelper; // controlled by m_versionInfoUpToDate
169

con's avatar
con committed
170
    QString m_mwcDirectory;
171
    QString m_s60SDKDirectory;
con's avatar
con committed
172
    QString m_gcceDirectory;
173

dt's avatar
dt committed
174
    mutable bool m_toolChainUpToDate;
175 176
    mutable QString m_mkspec; // updated lazily
    mutable QString m_mkspecFullPath;
177
    mutable QList<QSharedPointer<ProjectExplorer::ToolChain> > m_toolChains;
178

179 180
    mutable bool m_versionInfoUpToDate;
    mutable QHash<QString,QString> m_versionInfo; // updated lazily
con's avatar
con committed
181 182 183
    mutable bool m_notInstalled;
    mutable bool m_defaultConfigIsDebug;
    mutable bool m_defaultConfigIsDebugAndRelease;
184 185 186
    mutable bool m_hasExamples;
    mutable bool m_hasDemos;
    mutable bool m_hasDocumentation;
187

con's avatar
con committed
188
    mutable QString m_qmakeCommand;
189
    mutable QString m_qtVersionString;
dt's avatar
dt committed
190
    mutable QString m_uicCommand;
191 192
    mutable QString m_designerCommand;
    mutable QString m_linguistCommand;
193
    mutable QSet<QString> m_targetIds;
194 195

    mutable bool m_isBuildUsingSbsV2;
con's avatar
con committed
196 197
};

198 199 200 201 202 203 204
struct QMakeAssignment
{
    QString variable;
    QString op;
    QString value;
};

205
class QtVersionManager : public QObject
con's avatar
con committed
206 207
{
    Q_OBJECT
208 209
    // for getUniqueId();
    friend class QtVersion;
210
    friend class Internal::QtOptionsPage;
con's avatar
con committed
211
public:
212
    static QtVersionManager *instance();
con's avatar
con committed
213 214 215
    QtVersionManager();
    ~QtVersionManager();

Tobias Hunger's avatar
Tobias Hunger committed
216 217
    // This will *always* return at least one (Qt in Path), even if that is
    // unconfigured.
con's avatar
con committed
218
    QList<QtVersion *> versions() const;
219
    QList<QtVersion *> validVersions() const;
con's avatar
con committed
220

Tobias Hunger's avatar
Tobias Hunger committed
221 222 223
    // Note: DO NOT STORE THIS POINTER!
    //       The QtVersionManager will delete it at random times and you will
    //       need to get a new pointer by calling this method again!
224
    QtVersion *version(int id) const;
Tobias Hunger's avatar
Tobias Hunger committed
225
    QtVersion *emptyVersion() const;
con's avatar
con committed
226

227
    QtVersion *qtVersionForQMakeBinary(const QString &qmakePath);
Tobias Hunger's avatar
Tobias Hunger committed
228

con's avatar
con committed
229 230
    // Used by the projectloadwizard
    void addVersion(QtVersion *version);
231
    void removeVersion(QtVersion *version);
232

Tobias Hunger's avatar
Tobias Hunger committed
233 234 235 236 237 238 239
    // Target Support:
    bool supportsTargetId(const QString &id) const;
    // This returns a list of versions that support the target with the given id.
    // @return A list of QtVersions that supports a target. This list may be empty!
    QList<QtVersion *> versionsForTargetId(const QString &id) const;
    QSet<QString> supportedTargetIds() const;

240
    // Static Methods
241
    static bool makefileIsFor(const QString &directory, const QString &proFile);
242 243
    static QPair<QtVersion::QmakeBuildConfigs, QStringList> scanMakeFile(const QString &directory,
                                                                         QtVersion::QmakeBuildConfigs defaultBuildConfig);
244
    static QString findQMakeBinaryFromMakefile(const QString &directory);
245
    bool isValidId(int id) const;
Tobias Hunger's avatar
Tobias Hunger committed
246

con's avatar
con committed
247
signals:
248
    void qtVersionsChanged(const QList<int> &uniqueIds);
249 250 251 252
    void updateExamples(QString, QString, QString);

private slots:
    void updateExamples();
con's avatar
con committed
253
private:
254 255
    // This function is really simplistic...
    static bool equals(QtVersion *a, QtVersion *b);
256
    static QString findQMakeLine(const QString &directory, const QString &key);
257 258
    static QString trimLine(const QString line);
    static QStringList splitLine(const QString &line);
259 260 261 262 263 264
    static void parseParts(const QStringList &parts,
                           QList<QMakeAssignment> *assignments,
                           QList<QMakeAssignment> *afterAssignments,
                           QStringList *additionalArguments);
    static QtVersion::QmakeBuildConfigs qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments,
                                                                    QtVersion::QmakeBuildConfigs defaultBuildConfig);
265
    // Used by QtOptionsPage
Tobias Hunger's avatar
Tobias Hunger committed
266
    void setNewQtVersions(QList<QtVersion *> newVersions);
267 268 269
    // Used by QtVersion
    int getUniqueId();
    void writeVersionsIntoSettings();
con's avatar
con committed
270 271 272
    void addNewVersionsFromInstaller();
    void updateSystemVersion();
    void updateDocumentation();
273

con's avatar
con committed
274 275 276 277 278 279 280
    static int indexOfVersionInList(const QtVersion * const version, const QList<QtVersion *> &list);
    void updateUniqueIdToIndexMap();

    QtVersion *m_emptyVersion;
    QList<QtVersion *> m_versions;
    QMap<int, int> m_uniqueIdToIndex;
    int m_idcount;
281 282
    // managed by QtProjectManagerPlugin
    static QtVersionManager *m_self;
con's avatar
con committed
283
};
284

285
} // namespace Qt4ProjectManager
con's avatar
con committed
286

287 288
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt4ProjectManager::QtVersion::QmakeBuildConfigs)

hjk's avatar
hjk committed
289
#endif // QTVERSIONMANAGER_H