Skip to content
Snippets Groups Projects
qtversionmanager.h 10.1 KiB
Newer Older
/**************************************************************************
con's avatar
con committed
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
**
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
**
** Commercial Usage
** 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.
** GNU Lesser General Public License Usage
** 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.
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
**
**************************************************************************/
hjk's avatar
hjk committed

con's avatar
con committed
#ifndef QTVERSIONMANAGER_H
#define QTVERSIONMANAGER_H

#include <projectexplorer/taskwindow.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/task.h>
hjk's avatar
hjk committed

#include <QtCore/QHash>
#include <QtCore/QSet>
#include <QtCore/QSharedPointer>
con's avatar
con committed

namespace Qt4ProjectManager {
con's avatar
con committed
namespace Internal {
class QtOptionsPageWidget;
con's avatar
con committed

class QT4PROJECTMANAGER_EXPORT QtVersion
con's avatar
con committed
    friend class QtVersionManager;
public:
    QtVersion(const QString &name, const QString &qmakeCommand,
              bool isAutodetected = false, const QString &autodetectionSource = QString());
    explicit QtVersion(const QString &path, bool isAutodetected = false, const QString &autodetectionSource = QString());
    QtVersion(const QString &name, const QString &qmakeCommand, int id,
              bool isAutodetected = false, const QString &autodetectionSource = QString());
con's avatar
con committed

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

    QString displayName() const;
con's avatar
con committed
    QString sourcePath() const;
    QString qmakeCommand() const;
dt's avatar
dt committed
    QString uicCommand() const;
    QString designerCommand() const;
    QString linguistCommand() const;
Tobias Hunger's avatar
Tobias Hunger committed
    bool supportsTargetId(const QString &id) const;
    QSet<QString> supportedTargetIds() const;
    bool supportsMobileTarget() const;
    QList<ProjectExplorer::ToolChain::ToolChainType> possibleToolChainTypes() const;
    ProjectExplorer::ToolChain *toolChain(ProjectExplorer::ToolChain::ToolChainType type) const;

    /// @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;
    bool isBuildWithSymbianSbsV2() const;

    void setDisplayName(const QString &name);
    void setQMakeCommand(const QString &path);
    QString qtVersionString() const;
con's avatar
con committed
    // Returns the PREFIX, BINPREFIX, DOCPREFIX and similar information
    QHash<QString,QString> versionInfo() const;

con's avatar
con committed
    QString mwcDirectory() const;
    void setMwcDirectory(const QString &directory);
    QString s60SDKDirectory() const;
    void setS60SDKDirectory(const QString &directory);
    QString gcceDirectory() const;
    void setGcceDirectory(const QString &directory);
con's avatar
con committed
    QString mingwDirectory() const;
    void setMingwDirectory(const QString &directory);
    QString msvcVersion() const;
    void setMsvcVersion(const QString &version);
    void addToEnvironment(Utils::Environment &env) const;
    bool hasDebuggingHelper() const;
    QString debuggingHelperLibrary() const;
    QStringList debuggingHelperLibraryLocations() const;
    bool supportsBinaryDebuggingHelper() const;
    // Builds a debugging library
    // returns the output of the commands
    QString buildDebuggingHelperLibrary();
con's avatar
con committed

    bool hasExamples() const;
    QString examplesPath() const;

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

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

    QString headerInstallPath() const;

Tobias Hunger's avatar
Tobias Hunger committed
    // All valid Ids are >= 0
con's avatar
con committed
    int uniqueId() const;
con's avatar
con committed
    bool isQt64Bit() const;
con's avatar
con committed

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

    Q_DECLARE_FLAGS(QmakeBuildConfigs, QmakeBuildConfig)
    QmakeBuildConfigs defaultBuildConfig() const;

    bool supportsShadowBuilds() const;

    /// 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, const QString &buildDir);
con's avatar
con committed
private:
    QList<QSharedPointer<ProjectExplorer::ToolChain> > toolChains() const;
con's avatar
con committed
    static int getUniqueId();
    // Also used by QtOptionsPageWidget
con's avatar
con committed
    void updateSourcePath();
    void updateVersionInfo() const;
    QString findQtBinary(const QStringList &possibleName) const;
dt's avatar
dt committed
    void updateToolChainAndMkspec() const;
    QString m_displayName;
con's avatar
con committed
    QString m_sourcePath;
    QString m_mingwDirectory;
    mutable QString m_msvcVersion;
con's avatar
con committed
    int m_id;
    bool m_isAutodetected;
    QString m_autodetectionSource;
    mutable bool m_hasDebuggingHelper; // controlled by m_versionInfoUpToDate
con's avatar
con committed
    QString m_mwcDirectory;
    QString m_s60SDKDirectory;
    QString m_gcceDirectory;
dt's avatar
dt committed
    mutable bool m_toolChainUpToDate;
    mutable QString m_mkspec; // updated lazily
    mutable QString m_mkspecFullPath;
    mutable QList<QSharedPointer<ProjectExplorer::ToolChain> > m_toolChains;
    mutable bool m_versionInfoUpToDate;
    mutable QHash<QString,QString> m_versionInfo; // updated lazily
con's avatar
con committed
    mutable bool m_notInstalled;
    mutable bool m_defaultConfigIsDebug;
    mutable bool m_defaultConfigIsDebugAndRelease;
    mutable bool m_hasExamples;
    mutable bool m_hasDemos;
    mutable bool m_hasDocumentation;
con's avatar
con committed
    mutable QString m_qmakeCommand;
    mutable QString m_qtVersionString;
dt's avatar
dt committed
    mutable QString m_uicCommand;
    mutable QString m_designerCommand;
    mutable QString m_linguistCommand;
    mutable QSet<QString> m_targetIds;

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

struct QMakeAssignment
{
    QString variable;
    QString op;
    QString value;
};

class QT4PROJECTMANAGER_EXPORT QtVersionManager : public QObject
con's avatar
con committed
{
    Q_OBJECT
    // for getUniqueId();
    friend class QtVersion;
    friend class Internal::QtOptionsPage;
con's avatar
con committed
public:
    static QtVersionManager *instance();
con's avatar
con committed
    QtVersionManager();
    ~QtVersionManager();

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

Tobias Hunger's avatar
Tobias Hunger committed
    // 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!
    QtVersion *version(int id) const;
Tobias Hunger's avatar
Tobias Hunger committed
    QtVersion *emptyVersion() const;
con's avatar
con committed

    QtVersion *qtVersionForQMakeBinary(const QString &qmakePath);
con's avatar
con committed
    // Used by the projectloadwizard
    void addVersion(QtVersion *version);
    void removeVersion(QtVersion *version);
Tobias Hunger's avatar
Tobias Hunger committed
    // 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;

    // Static Methods
    static bool makefileIsFor(const QString &directory, const QString &proFile);
    static QPair<QtVersion::QmakeBuildConfigs, QStringList> scanMakeFile(const QString &directory,
                                                                         QtVersion::QmakeBuildConfigs defaultBuildConfig);
    static QString findQMakeBinaryFromMakefile(const QString &directory);
    bool isValidId(int id) const;
con's avatar
con committed
signals:
    void qtVersionsChanged(const QList<int> &uniqueIds);
    void updateExamples(QString, QString, QString);

private slots:
    void updateExamples();
con's avatar
con committed
private:
    // This function is really simplistic...
    static bool equals(QtVersion *a, QtVersion *b);
    static QString findQMakeLine(const QString &directory, const QString &key);
    static QString trimLine(const QString line);
    static QStringList splitLine(const QString &line);
    static void parseParts(const QStringList &parts,
                           QList<QMakeAssignment> *assignments,
                           QList<QMakeAssignment> *afterAssignments,
                           QStringList *additionalArguments);
    static QtVersion::QmakeBuildConfigs qmakeBuildConfigFromCmdArgs(QList<QMakeAssignment> *assignments,
                                                                    QtVersion::QmakeBuildConfigs defaultBuildConfig);
    // Used by QtOptionsPage
Tobias Hunger's avatar
Tobias Hunger committed
    void setNewQtVersions(QList<QtVersion *> newVersions);
    // Used by QtVersion
    int getUniqueId();
    void writeVersionsIntoSettings();
con's avatar
con committed
    void addNewVersionsFromInstaller();
    void updateSystemVersion();
    void updateDocumentation();
con's avatar
con committed
    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;
    // managed by QtProjectManagerPlugin
    static QtVersionManager *m_self;
con's avatar
con committed
};
} // namespace Qt4ProjectManager
con's avatar
con committed

Q_DECLARE_OPERATORS_FOR_FLAGS(Qt4ProjectManager::QtVersion::QmakeBuildConfigs)

hjk's avatar
hjk committed
#endif // QTVERSIONMANAGER_H