Skip to content
Snippets Groups Projects
qtversionmanager.cpp 42.9 KiB
Newer Older
con's avatar
con committed

QString QtVersion::findQtBinary(const QStringList &possibleCommands) const
{
    const QString qtdirbin = versionInfo().value(QLatin1String("QT_INSTALL_BINS")) + QLatin1Char('/');
    foreach (const QString &possibleCommand, possibleCommands) {
        const QString fullPath = qtdirbin + possibleCommand;
        if (QFileInfo(fullPath).isFile())
            return QDir::cleanPath(fullPath);
    }
    return QString::null;
}

dt's avatar
dt committed
QString QtVersion::uicCommand() const
{
    if (!isValid())
        return QString::null;
    if (!m_uicCommand.isNull())
        return m_uicCommand;
#ifdef Q_OS_WIN
    const QStringList possibleCommands(QLatin1String("uic.exe"));
#else
dt's avatar
dt committed
    QStringList possibleCommands;
    possibleCommands << QLatin1String("uic-qt4") << QLatin1String("uic4") << QLatin1String("uic");
#endif
    m_uicCommand = findQtBinary(possibleCommands);
    return m_uicCommand;
}

// Return a list of GUI binary names
// 'foo', 'foo.exe', 'Foo.app/Contents/MacOS/Foo'
static inline QStringList possibleGuiBinaries(const QString &name)
{
dt's avatar
dt committed
#ifdef Q_OS_WIN
    return QStringList(name + QLatin1String(".exe"));
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
#elif defined(Q_OS_MAC) // 'Foo.app/Contents/MacOS/Foo'
    QString upCaseName = name;
    upCaseName[0] = upCaseName.at(0).toUpper();
    QString macBinary = upCaseName;
    macBinary += QLatin1String(".app/Contents/MacOS/");
    macBinary += upCaseName;
    return QStringList(macBinary);
dt's avatar
dt committed
#else
    return QStringList(name);
dt's avatar
dt committed
#endif
}

QString QtVersion::designerCommand() const
{
    if (!isValid())
        return QString::null;
    if (m_designerCommand.isNull())
        m_designerCommand = findQtBinary(possibleGuiBinaries(QLatin1String("designer")));
    return m_designerCommand;
}

QString QtVersion::linguistCommand() const
{
    if (!isValid())
        return QString::null;
    if (m_linguistCommand.isNull())
        m_linguistCommand = findQtBinary(possibleGuiBinaries(QLatin1String("linguist")));
    return m_linguistCommand;
QList<ProjectExplorer::ToolChain *> QtVersion::toolChains() const
{
    updateToolChain();
    return m_toolChains;
}

QList<ProjectExplorer::ToolChain::ToolChainType> QtVersion::possibleToolChainTypes() const
con's avatar
con committed
{
    QList<ProjectExplorer::ToolChain::ToolChainType> types;
    foreach(ProjectExplorer::ToolChain *tc, toolChains())
        types << tc->type();
    return types;
}

ProjectExplorer::ToolChain::ToolChainType QtVersion::defaultToolchainType() const
{
    const QList<ProjectExplorer::ToolChain::ToolChainType> & list = possibleToolChainTypes();
    if (list.isEmpty())
        return ProjectExplorer::ToolChain::INVALID;
    return list.first();
}

// if none, then it's INVALID everywhere this function is called
void QtVersion::updateToolChain() const
{
    if (m_toolChainUpToDate)
        return;

    qDeleteAll(m_toolChains);

    QString mkspecPath = versionInfo().value("QMAKE_MKSPECS");
    if (mkspecPath.isEmpty())
        mkspecPath = versionInfo().value("QT_INSTALL_DATA") + "/mkspecs/default";
    else
        mkspecPath = mkspecPath + "/default";

    ProFileReader *reader = new ProFileReader();
    reader->setCumulative(false);
    reader->setParsePreAndPostFiles(false);
    reader->readProFile(mkspecPath + "/qmake.conf");
    QString qmakeCXX = reader->value("QMAKE_CXX");
    QString makefileGenerator = reader->value("MAKEFILE_GENERATOR");
    QString ce_sdk = reader->value("CE_SDK");
    QString ce_arch = reader->value("CE_ARCH");
    QString qt_arch = reader->value("QT_ARCH");
    if (!ce_sdk.isEmpty() && !ce_arch.isEmpty()) {
        QString wincePlatformName = ce_sdk + " (" + ce_arch + ")";
        m_toolChains << ProjectExplorer::ToolChain::createWinCEToolChain(msvcVersion(), wincePlatformName);
    } else if (makefileGenerator == "SYMBIAN_ABLD") {
#ifdef QTCREATOR_WITH_S60
        m_toolChains << S60Manager::instance()->createGCCEToolChain(this);
        m_toolChains << S60Manager::instance()->createRVCTToolChain(this, ProjectExplorer::ToolChain::RVCT_ARMV5);
        m_toolChains << S60Manager::instance()->createRVCTToolChain(this, ProjectExplorer::ToolChain::RVCT_ARMV6);
        m_toolChains << S60Manager::instance()->createWINSCWToolChain(this);
ck's avatar
ck committed
#endif
    } else if (qt_arch == "arm") {
ck's avatar
ck committed
#ifdef QTCREATOR_WITH_MAEMO
        m_toolChains << MaemoManager::instance()->maemoToolChain(this);

        ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
        //addToEnvironment(env);
        qmakeCXX = env.searchInPath(qmakeCXX);
        m_toolChains << ProjectExplorer::ToolChain::createGccToolChain(qmakeCXX);
#endif
    } else if (qmakeCXX == "cl" || qmakeCXX == "icl") {
        // TODO proper support for intel cl
        m_toolChains << ProjectExplorer::ToolChain::createMSVCToolChain(msvcVersion(), isQt64Bit());
    } else if (qmakeCXX == "g++" && makefileGenerator == "MINGW") {
        ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
        //addToEnvironment(env);
        env.prependOrSetPath(mingwDirectory() + "/bin");
        qmakeCXX = env.searchInPath(qmakeCXX);
        m_toolChains << ProjectExplorer::ToolChain::createMinGWToolChain(qmakeCXX, mingwDirectory());
    } else if (qmakeCXX == "g++" || qmakeCXX == "icc") {
        ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
        //addToEnvironment(env);
        qmakeCXX = env.searchInPath(qmakeCXX);
        if (qmakeCXX.isEmpty()) {
            // macx-xcode mkspec resets the value of QMAKE_CXX.
            // Unfortunately, we need a valid QMAKE_CXX to configure the parser.
            qmakeCXX = QLatin1String("cc");
        }
        m_toolChains << ProjectExplorer::ToolChain::createGccToolChain(qmakeCXX);
ck's avatar
ck committed
    }
    if (m_toolChains.isEmpty()) {
        qDebug()<<"Could not create ToolChain for"<<mkspecPath<<qmakeCXX;
        qDebug()<<"Qt Creator doesn't know about the system includes, nor the systems defines.";
    }

    delete reader;
    m_toolChainUpToDate = true;
con's avatar
con committed
}

con's avatar
con committed
#ifdef QTCREATOR_WITH_S60
QString QtVersion::mwcDirectory() const
{
    return m_mwcDirectory;
}

void QtVersion::setMwcDirectory(const QString &directory)
{
    m_mwcDirectory = directory;
}
#endif

con's avatar
con committed
QString QtVersion::mingwDirectory() const
{
    return m_mingwDirectory;
}

void QtVersion::setMingwDirectory(const QString &directory)
{
    m_mingwDirectory = directory;
    m_toolChainUpToDate = false;
con's avatar
con committed
}

QString QtVersion::msvcVersion() const
{
    return m_msvcVersion;
}

void QtVersion::setMsvcVersion(const QString &version)
{
    m_msvcVersion = version;
    m_toolChainUpToDate = false;
con's avatar
con committed
}

void QtVersion::addToEnvironment(ProjectExplorer::Environment &env) const
con's avatar
con committed
{
    env.set("QTDIR", versionInfo().value("QT_INSTALL_DATA"));
con's avatar
con committed
    QString qtdirbin = versionInfo().value("QT_INSTALL_BINS");
dt's avatar
dt committed
    env.prependOrSetPath(qtdirbin);
con's avatar
con committed
}

int QtVersion::uniqueId() const
{
    return m_id;
}

int QtVersion::getUniqueId()
{
    return QtVersionManager::instance()->getUniqueId();
con's avatar
con committed
}

bool QtVersion::isValid() const
{
    return (!(m_id == -1 || m_qmakeCommand == QString::null || m_name == QString::null || mkspec() == QString::null) && !m_notInstalled);
con's avatar
con committed
}

QtVersion::QmakeBuildConfig QtVersion::defaultBuildConfig() const
{
    updateVersionInfo();
    QtVersion::QmakeBuildConfig result = QtVersion::QmakeBuildConfig(0);
    if (m_defaultConfigIsDebugAndRelease)
        result = QtVersion::BuildAll;
    if (m_defaultConfigIsDebug)
        result = QtVersion::QmakeBuildConfig(result | QtVersion::DebugBuild);
    return result;
}

bool QtVersion::hasDebuggingHelper() const
{
    return m_hasDebuggingHelper;
}

QString QtVersion::debuggingHelperLibrary() const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
        return QString::null;
    return DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData);
QStringList QtVersion::debuggingHelperLibraryLocations() const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
con's avatar
con committed
        return QStringList();
    return DebuggingHelperLibrary::debuggingHelperLibraryLocationsByInstallData(qtInstallData);
bool QtVersion::hasDocumentation() const
{
    updateVersionInfo();
    return m_hasDocumentation;
}

QString QtVersion::documentationPath() const
{
    updateVersionInfo();
    return m_versionInfo["QT_INSTALL_DOCS"];
}

bool QtVersion::hasDemos() const
{
    updateVersionInfo();
    return m_hasDemos;
}

QString QtVersion::demosPath() const
{
    updateVersionInfo();
    return m_versionInfo["QT_INSTALL_DEMOS"];
}

bool QtVersion::hasExamples() const
{
    updateVersionInfo();
    return m_hasExamples;
}

QString QtVersion::examplesPath() const
{
    updateVersionInfo();
    return m_versionInfo["QT_INSTALL_EXAMPLES"];
}
con's avatar
con committed
bool QtVersion::isQt64Bit() const
{
        const QString make = qmakeCommand();
Daniel Molkentin's avatar
Daniel Molkentin committed
//        qDebug() << make;
        bool isAmd64 = false;
#ifdef Q_OS_WIN32
#  ifdef __GNUC__   // MinGW lacking some definitions/winbase.h
#    define SCS_64BIT_BINARY 6
#  endif   
        DWORD binaryType = 0;
        bool success = GetBinaryTypeW(reinterpret_cast<const TCHAR*>(make.utf16()), &binaryType) != 0;
        if (success && binaryType == SCS_64BIT_BINARY)
            isAmd64=true;
//        qDebug() << "isAmd64:" << isAmd64 << binaryType;
        return isAmd64;
#else
        Q_UNUSED(isAmd64)
        return false;
QString QtVersion::buildDebuggingHelperLibrary()
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
    ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
    addToEnvironment(env);

    // TODO: the debugging helper doesn't comply to actual tool chain yet
    QList<ProjectExplorer::ToolChain *> alltc = toolChains();
    ProjectExplorer::ToolChain *tc = alltc.isEmpty() ? 0 : alltc.first();
    tc->addToEnvironment(env);
    QString directory = DebuggingHelperLibrary::copyDebuggingHelperLibrary(qtInstallData, &output);
    if (!directory.isEmpty())
        output += DebuggingHelperLibrary::buildDebuggingHelperLibrary(directory, tc->makeCommand(), qmakeCommand(), mkspec(), env);
    m_hasDebuggingHelper = !debuggingHelperLibrary().isEmpty();