baseqtversion.cpp 39.5 KB
Newer Older
dt's avatar
dt committed
1
2
3
4
5
6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
dt's avatar
dt committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
dt's avatar
dt committed
30
31
32
33
34
35
36
37
38
**
**************************************************************************/

#include "baseqtversion.h"
#include "qmlobservertool.h"
#include "qmldumptool.h"
#include "qmldebugginglibrary.h"

#include "qtversionmanager.h"
39
#include "profilereader.h"
dt's avatar
dt committed
40
#include <projectexplorer/toolchainmanager.h>
41
#include <projectexplorer/toolchain.h>
dt's avatar
dt committed
42
43
44
45
46
47
#include <projectexplorer/debugginghelper.h>
#include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/toolchainmanager.h>

Jarek Kobus's avatar
Jarek Kobus committed
48
#include <utils/persistentsettings.h>
49
#include <utils/environment.h>
dt's avatar
dt committed
50
51
52
#include <utils/synchronousprocess.h>

#include <QtCore/QDir>
53
#include <QtCore/QFileInfo>
dt's avatar
dt committed
54
55
56
#include <QtCore/QCoreApplication>
#include <QtCore/QProcess>

57
58
using namespace QtSupport;
using namespace QtSupport::Internal;
dt's avatar
dt committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164

static const char QTVERSIONID[] = "Id";
static const char QTVERSIONNAME[] = "Name";
static const char QTVERSIONAUTODETECTED[] = "isAutodetected";
static const char QTVERSIONAUTODETECTIONSOURCE []= "autodetectionSource";
static const char QTVERSIONQMAKEPATH[] = "QMakePath";

///////////////
// QtVersionNumber
///////////////
QtVersionNumber::QtVersionNumber(int ma, int mi, int p)
    : majorVersion(ma), minorVersion(mi), patchVersion(p)
{
}

QtVersionNumber::QtVersionNumber(const QString &versionString)
{
    if (!checkVersionString(versionString)) {
        majorVersion = minorVersion = patchVersion = -1;
        return;
    }

    QStringList parts = versionString.split(QLatin1Char('.'));
    majorVersion = parts.at(0).toInt();
    minorVersion = parts.at(1).toInt();
    patchVersion = parts.at(2).toInt();
}

QtVersionNumber::QtVersionNumber()
{
    majorVersion = minorVersion = patchVersion = -1;
}

bool QtVersionNumber::checkVersionString(const QString &version) const
{
    int dots = 0;
    QString validChars = "0123456789.";
    foreach (const QChar &c, version) {
        if (!validChars.contains(c))
            return false;
        if (c == '.')
            ++dots;
    }
    if (dots != 2)
        return false;
    return true;
}

bool QtVersionNumber::operator <(const QtVersionNumber &b) const
{
    if (majorVersion < b.majorVersion)
        return true;
    if (majorVersion > b.majorVersion)
        return false;
    if (minorVersion < b.minorVersion)
        return true;
    if (minorVersion > b.minorVersion)
        return false;
    if (patchVersion < b.patchVersion)
        return true;
    return false;
}

bool QtVersionNumber::operator >(const QtVersionNumber &b) const
{
    return b < *this;
}

bool QtVersionNumber::operator ==(const QtVersionNumber &b) const
{
    return majorVersion == b.majorVersion
            && minorVersion == b.minorVersion
            && patchVersion == b.patchVersion;
}

bool QtVersionNumber::operator !=(const QtVersionNumber &b) const
{
    return !(*this == b);
}

bool QtVersionNumber::operator <=(const QtVersionNumber &b) const
{
    return !(*this > b);
}

bool QtVersionNumber::operator >=(const QtVersionNumber &b) const
{
    return b <= *this;
}

///////////////
// QtConfigWidget
///////////////
QtConfigWidget::QtConfigWidget()
{

}

///////////////
// BaseQtVersion
///////////////
int BaseQtVersion::getUniqueId()
{
    return QtVersionManager::instance()->getUniqueId();
}

165
BaseQtVersion::BaseQtVersion(const Utils::FileName &qmakeCommand, bool isAutodetected, const QString &autodetectionSource)
dt's avatar
dt committed
166
167
168
169
170
171
172
173
174
175
176
177
    : m_id(getUniqueId()),
      m_isAutodetected(isAutodetected),
      m_autodetectionSource(autodetectionSource),
      m_hasDebuggingHelper(false),
      m_hasQmlDump(false),
      m_hasQmlDebuggingLibrary(false),
      m_hasQmlObserver(false),
      m_mkspecUpToDate(false),
      m_mkspecReadUpToDate(false),
      m_defaultConfigIsDebug(true),
      m_defaultConfigIsDebugAndRelease(true),
      m_versionInfoUpToDate(false),
hjk's avatar
hjk committed
178
      m_installed(true),
dt's avatar
dt committed
179
180
181
      m_hasExamples(false),
      m_hasDemos(false),
      m_hasDocumentation(false),
182
      m_qmakeIsExecutable(true)
dt's avatar
dt committed
183
184
{
    ctor(qmakeCommand);
185
    setDisplayName(defaultDisplayName(qtVersionString(), qmakeCommand, false));
dt's avatar
dt committed
186
187
188
189
190
191
192
193
194
195
196
197
198
}

BaseQtVersion::BaseQtVersion()
    :  m_id(-1), m_isAutodetected(false),
    m_hasDebuggingHelper(false),
    m_hasQmlDump(false),
    m_hasQmlDebuggingLibrary(false),
    m_hasQmlObserver(false),
    m_mkspecUpToDate(false),
    m_mkspecReadUpToDate(false),
    m_defaultConfigIsDebug(true),
    m_defaultConfigIsDebugAndRelease(true),
    m_versionInfoUpToDate(false),
hjk's avatar
hjk committed
199
    m_installed(true),
dt's avatar
dt committed
200
201
    m_hasExamples(false),
    m_hasDemos(false),
202
203
    m_hasDocumentation(false),
    m_qmakeIsExecutable(true)
dt's avatar
dt committed
204
{
205
    ctor(Utils::FileName());
dt's avatar
dt committed
206
207
}

208
void BaseQtVersion::ctor(const Utils::FileName &qmakePath)
dt's avatar
dt committed
209
{
210
    m_qmakeCommand = qmakePath;
dt's avatar
dt committed
211
212
213
214
215
216
217
218
219
220
221
222
223
    m_designerCommand.clear();
    m_linguistCommand.clear();
    m_qmlviewerCommand.clear();
    m_uicCommand.clear();
    m_mkspecUpToDate = false;
    m_mkspecReadUpToDate = false;
    m_versionInfoUpToDate = false;
    m_qtVersionString.clear();
    m_sourcePath.clear();
}

BaseQtVersion::~BaseQtVersion()
{
224
225
}

226
QString BaseQtVersion::defaultDisplayName(const QString &versionString, const Utils::FileName &qmakePath,
227
228
229
230
231
232
233
234
                                          bool fromPath)
{
    QString location;
    if (qmakePath.isEmpty()) {
        location = QCoreApplication::translate("QtVersion", "<unknown>");
    } else {
        // Deduce a description from '/foo/qt-folder/[qtbase]/bin/qmake' -> '/foo/qt-folder'.
        // '/usr' indicates System Qt 4.X on Linux.
235
        QDir dir = qmakePath.toFileInfo().absoluteDir();
236
237
238
239
240
241
242
243
244
245
246
247
248
        do {
            const QString dirName = dir.dirName();
            if (dirName == QLatin1String("usr")) { // System-installed Qt.
                location = QCoreApplication::translate("QtVersion", "System");
                break;
            }
            if (dirName.compare(QLatin1String("bin"), Qt::CaseInsensitive)
                && dirName.compare(QLatin1String("qtbase"), Qt::CaseInsensitive)) {
                location = dirName;
                break;
            }
        } while (dir.cdUp());
    }
dt's avatar
dt committed
249

250
251
252
    return fromPath ?
        QCoreApplication::translate("QtVersion", "Qt %1 in PATH (%2)").arg(versionString, location) :
        QCoreApplication::translate("QtVersion", "Qt %1 (%2)").arg(versionString, location);
dt's avatar
dt committed
253
254
255
256
257
258
259
}

void BaseQtVersion::setId(int id)
{
    m_id = id;
}

260
261
262
263
264
void BaseQtVersion::restoreLegacySettings(QSettings *s)
{
    Q_UNUSED(s);
}

dt's avatar
dt committed
265
266
267
268
269
270
271
272
273
void BaseQtVersion::fromMap(const QVariantMap &map)
{
    m_id = map.value(QLatin1String(QTVERSIONID)).toInt();
    if (m_id == -1) // this happens on adding from installer, see updateFromInstaller => get a new unique id
        m_id = QtVersionManager::instance()->getUniqueId();
    m_displayName = map.value(QLatin1String(QTVERSIONNAME)).toString();
    m_isAutodetected = map.value(QLatin1String(QTVERSIONAUTODETECTED)).toBool();
    if (m_isAutodetected)
        m_autodetectionSource = map.value(QLatin1String(QTVERSIONAUTODETECTIONSOURCE)).toString();
274
275
276
277
    QString string = map.value(QLatin1String(QTVERSIONQMAKEPATH)).toString();
    if (string.startsWith('~'))
        string.remove(0, 1).prepend(QDir::homePath());
    ctor(Utils::FileName::fromUserInput(string));
dt's avatar
dt committed
278
279
280
281
282
283
284
285
286
287
}

QVariantMap BaseQtVersion::toMap() const
{
    QVariantMap result;
    result.insert(QLatin1String(QTVERSIONID), uniqueId());
    result.insert(QLatin1String(QTVERSIONNAME), displayName());
    result.insert(QLatin1String(QTVERSIONAUTODETECTED), isAutodetected());
    if (isAutodetected())
        result.insert(QLatin1String(QTVERSIONAUTODETECTIONSOURCE), autodetectionSource());
288
    result.insert(QLatin1String(QTVERSIONQMAKEPATH), qmakeCommand().toString());
dt's avatar
dt committed
289
290
291
292
293
    return result;
}

bool BaseQtVersion::isValid() const
{
dt's avatar
dt committed
294
    if (uniqueId() == -1 || displayName().isEmpty())
dt's avatar
dt committed
295
296
297
298
299
        return false;
    updateVersionInfo();
    updateMkspec();

    return  !qmakeCommand().isEmpty()
hjk's avatar
hjk committed
300
            && m_installed
dt's avatar
dt committed
301
            && m_versionInfo.contains("QT_INSTALL_BINS")
302
            && !m_mkspecFullPath.isEmpty()
dt's avatar
dt committed
303
304
305
306
307
308
309
310
311
312
313
            && m_qmakeIsExecutable;
}

QString BaseQtVersion::invalidReason() const
{
    if (displayName().isEmpty())
        return QCoreApplication::translate("QtVersion", "Qt version has no name");
    if (qmakeCommand().isEmpty())
        return QCoreApplication::translate("QtVersion", "No qmake path set");
    if (!m_qmakeIsExecutable)
        return QCoreApplication::translate("QtVersion", "qmake does not exist or is not executable");
hjk's avatar
hjk committed
314
    if (!m_installed)
dt's avatar
dt committed
315
316
317
318
319
320
321
322
323
        return QCoreApplication::translate("QtVersion", "Qt version is not properly installed, please run make install");
    if (!m_versionInfo.contains("QT_INSTALL_BINS"))
        return QCoreApplication::translate("QtVersion",
                                           "Could not determine the path to the binaries of the Qt installation, maybe the qmake path is wrong?");
    if (m_mkspecUpToDate && m_mkspecFullPath.isEmpty())
        return QCoreApplication::translate("QtVersion", "The default mkspec symlink is broken.");
    return QString();
}

324
325
326
327
328
QString BaseQtVersion::warningReason() const
{
    return QString();
}

329
Utils::FileName BaseQtVersion::qmakeCommand() const
dt's avatar
dt committed
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
{
    return m_qmakeCommand;
}

bool BaseQtVersion::toolChainAvailable(const QString &id) const
{
    Q_UNUSED(id)
    if (!isValid())
        return false;
    foreach (const ProjectExplorer::Abi &abi, qtAbis())
        if (!ProjectExplorer::ToolChainManager::instance()->findToolChains(abi).isEmpty())
            return true;
    return false;
}

345
346
347
348
349
350
351
352
353
QList<ProjectExplorer::Abi> BaseQtVersion::qtAbis() const
{
    if (m_qtAbis.isEmpty())
        m_qtAbis = detectQtAbis();
    if (m_qtAbis.isEmpty())
        m_qtAbis.append(ProjectExplorer::Abi()); // add empty ABI by default: This is compatible with all TCs.
    return m_qtAbis;
}

dt's avatar
dt committed
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
bool BaseQtVersion::equals(BaseQtVersion *other)
{
    if (type() != other->type())
        return false;
    if (uniqueId() != other->uniqueId())
        return false;
    if (displayName() != other->displayName())
        return false;

    return true;
}

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

bool BaseQtVersion::isAutodetected() const
{
    return m_isAutodetected;
}

QString BaseQtVersion::autodetectionSource() const
{
    return m_autodetectionSource;
}

dt's avatar
dt committed
381
382
383
384
385
void BaseQtVersion::setAutoDetectionSource(const QString &autodetectionSource)
{
    m_autodetectionSource = autodetectionSource;
}

dt's avatar
dt committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
QString BaseQtVersion::displayName() const
{
    return m_displayName;
}

void BaseQtVersion::setDisplayName(const QString &name)
{
    m_displayName = name;
}

QString BaseQtVersion::toHtml(bool verbose) const
{
    QString rc;
    QTextStream str(&rc);
    str << "<html><body><table>";
    str << "<tr><td><b>" << QCoreApplication::translate("BaseQtVersion", "Name:")
        << "</b></td><td>" << displayName() << "</td></tr>";
    if (!isValid()) {
        str << "<tr><td colspan=2><b>" + QCoreApplication::translate("BaseQtVersion", "Invalid Qt version") +"</b></td></tr>";
    } else {
        QString prefix = QLatin1String("<tr><td><b>") + QCoreApplication::translate("BaseQtVersion", "ABI:") + QLatin1String("</b></td>");
        foreach (const ProjectExplorer::Abi &abi, qtAbis()) {
            str << prefix << "<td>" << abi.toString() << "</td></tr>";
            prefix = QLatin1String("<tr><td></td>");
        }
        str << "<tr><td><b>" << QCoreApplication::translate("BaseQtVersion", "Source:")
412
            << "</b></td><td>" << sourcePath().toUserOutput() << "</td></tr>";
dt's avatar
dt committed
413
        str << "<tr><td><b>" << QCoreApplication::translate("BaseQtVersion", "mkspec:")
414
            << "</b></td><td>" << mkspec().toUserOutput() << "</td></tr>";
dt's avatar
dt committed
415
        str << "<tr><td><b>" << QCoreApplication::translate("BaseQtVersion", "qmake:")
416
            << "</b></td><td>" << m_qmakeCommand.toUserOutput() << "</td></tr>";
dt's avatar
dt committed
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
        ensureMkSpecParsed();
        if (!mkspecPath().isEmpty()) {
            if (m_defaultConfigIsDebug || m_defaultConfigIsDebugAndRelease) {
                str << "<tr><td><b>" << QCoreApplication::translate("BaseQtVersion", "Default:") << "</b></td><td>"
                    << (m_defaultConfigIsDebug ? "debug" : "release");
                if (m_defaultConfigIsDebugAndRelease)
                    str << " debug_and_release";
                str << "</td></tr>";
            } // default config.
        }
        str << "<tr><td><b>" << QCoreApplication::translate("BaseQtVersion", "Version:")
            << "</b></td><td>" << qtVersionString() << "</td></tr>";
        if (verbose) {
            const QHash<QString,QString> vInfo = versionInfo();
            if (!vInfo.isEmpty()) {
                const QHash<QString,QString>::const_iterator vcend = vInfo.constEnd();
                for (QHash<QString,QString>::const_iterator it = vInfo.constBegin(); it != vcend; ++it)
                    str << "<tr><td><pre>" << it.key() <<  "</pre></td><td>" << it.value() << "</td></tr>";
            }
        }
    }
    str << "</table></body></html>";
    return rc;
}

void BaseQtVersion::updateSourcePath() const
{
    if (!m_sourcePath.isEmpty())
        return;
    updateVersionInfo();
    const QString installData = m_versionInfo["QT_INSTALL_DATA"];
448
    QString sourcePath = installData;
dt's avatar
dt committed
449
450
451
452
453
454
455
    QFile qmakeCache(installData + QLatin1String("/.qmake.cache"));
    if (qmakeCache.exists()) {
        qmakeCache.open(QIODevice::ReadOnly | QIODevice::Text);
        QTextStream stream(&qmakeCache);
        while (!stream.atEnd()) {
            QString line = stream.readLine().trimmed();
            if (line.startsWith(QLatin1String("QT_SOURCE_TREE"))) {
456
457
458
459
                sourcePath = line.split(QLatin1Char('=')).at(1).trimmed();
                if (sourcePath.startsWith(QLatin1String("$$quote("))) {
                    sourcePath.remove(0, 8);
                    sourcePath.chop(1);
dt's avatar
dt committed
460
461
462
463
464
                }
                break;
            }
        }
    }
465
    m_sourcePath = Utils::FileName::fromUserInput(sourcePath);
dt's avatar
dt committed
466
467
}

468
Utils::FileName BaseQtVersion::sourcePath() const
dt's avatar
dt committed
469
470
471
472
473
474
475
476
477
478
{
    updateSourcePath();
    return m_sourcePath;
}

QString BaseQtVersion::designerCommand() const
{
    if (!isValid())
        return QString();
    if (m_designerCommand.isNull())
479
        m_designerCommand = findQtBinary(Designer);
dt's avatar
dt committed
480
481
482
483
484
485
486
487
    return m_designerCommand;
}

QString BaseQtVersion::linguistCommand() const
{
    if (!isValid())
        return QString();
    if (m_linguistCommand.isNull())
488
        m_linguistCommand = findQtBinary(Linguist);
dt's avatar
dt committed
489
490
491
492
493
494
495
496
    return m_linguistCommand;
}

QString BaseQtVersion::qmlviewerCommand() const
{
    if (!isValid())
        return QString();

497
498
    if (m_qmlviewerCommand.isNull())
        m_qmlviewerCommand = findQtBinary(QmlViewer);
dt's avatar
dt committed
499
500
501
    return m_qmlviewerCommand;
}

Daniel Teske's avatar
Compile    
Daniel Teske committed
502
QString BaseQtVersion::findQtBinary(Binaries binary) const
dt's avatar
dt committed
503
{
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
    QString baseDir;
    if (qtVersion() < QtVersionNumber(5, 0, 0)) {
        baseDir = versionInfo().value(QLatin1String("QT_INSTALL_BINS"));
    } else {
        ensureMkSpecParsed();
        switch (binary) {
        case QmlViewer:
            baseDir = m_mkspecValues.value("QT.declarative.bins");
            break;
        case Designer:
        case Linguist:
            baseDir = m_mkspecValues.value("QT.designer.bins");
            break;
        case Uic:
            baseDir = versionInfo().value(QLatin1String("QT_INSTALL_BINS"));
            break;
        default:
            // Can't happen
            Q_ASSERT(false);
        }
    }

    if (baseDir.isEmpty())
dt's avatar
dt committed
527
        return QString();
528
529
    if (!baseDir.endsWith('/'))
        baseDir += QLatin1Char('/');
dt's avatar
dt committed
530

531
532
    QStringList possibleCommands;
    switch (binary) {
533
534
    case QmlViewer: {
        if (qtVersion() < QtVersionNumber(5, 0, 0)) {
Kai Koehne's avatar
Kai Koehne committed
535
536
537
538
539
540
541
#if defined(Q_OS_WIN)
            possibleCommands << QLatin1String("qmlviewer.exe");
#elif defined(Q_OS_MAC)
            possibleCommands << QLatin1String("QMLViewer.app/Contents/MacOS/QMLViewer");
#else
            possibleCommands << QLatin1String("qmlviewer");
#endif
542
543
544
        } else {
#if defined(Q_OS_WIN)
            possibleCommands << QLatin1String("qmlscene.exe");
545
#else
546
            possibleCommands << QLatin1String("qmlscene");
547
#endif
548
549
        }
    }
550
551
        break;
    case Designer:
Kai Koehne's avatar
Kai Koehne committed
552
553
554
555
556
557
558
#if defined(Q_OS_WIN)
        possibleCommands << QLatin1String("designer.exe");
#elif defined(Q_OS_MAC)
        possibleCommands << QLatin1String("Designer.app/Contents/MacOS/Designer");
#else
        possibleCommands << QLatin1String("designer");
#endif
559
560
        break;
    case Linguist:
Kai Koehne's avatar
Kai Koehne committed
561
562
563
564
565
566
567
#if defined(Q_OS_WIN)
        possibleCommands << QLatin1String("linguist.exe");
#elif defined(Q_OS_MAC)
        possibleCommands << QLatin1String("Linguist.app/Contents/MacOS/Linguist");
#else
        possibleCommands << QLatin1String("linguist");
#endif
568
569
570
571
572
573
574
575
576
577
578
        break;
    case Uic:
#ifdef Q_OS_WIN
        possibleCommands << QLatin1String("uic.exe");
#else
        possibleCommands << QLatin1String("uic-qt4") << QLatin1String("uic4") << QLatin1String("uic");
#endif
        break;
    default:
        Q_ASSERT(false);
    }
dt's avatar
dt committed
579
    foreach (const QString &possibleCommand, possibleCommands) {
580
        const QString fullPath = baseDir + possibleCommand;
dt's avatar
dt committed
581
582
583
584
585
586
587
588
589
590
591
592
        if (QFileInfo(fullPath).isFile())
            return QDir::cleanPath(fullPath);
    }
    return QString();
}

QString BaseQtVersion::uicCommand() const
{
    if (!isValid())
        return QString();
    if (!m_uicCommand.isNull())
        return m_uicCommand;
593
    m_uicCommand = findQtBinary(Uic);
dt's avatar
dt committed
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
    return m_uicCommand;
}

QString BaseQtVersion::systemRoot() const
{
    return QString();
}

void BaseQtVersion::updateMkspec() const
{
    if (uniqueId() == -1 || m_mkspecUpToDate)
        return;

    m_mkspecUpToDate = true;
    m_mkspecFullPath = mkspecFromVersionInfo(versionInfo());

    m_mkspec = m_mkspecFullPath;
    if (m_mkspecFullPath.isEmpty())
        return;

614
    Utils::FileName baseMkspecDir = Utils::FileName::fromUserInput(versionInfo().value("QMAKE_MKSPECS"));
dt's avatar
dt committed
615
    if (baseMkspecDir.isEmpty())
616
        baseMkspecDir = Utils::FileName::fromUserInput(versionInfo().value("QT_INSTALL_DATA") + "/mkspecs");
dt's avatar
dt committed
617

618
619
    if (m_mkspec.isChildOf(baseMkspecDir)) {
        m_mkspec = m_mkspec.relativeChildPath(baseMkspecDir);
dt's avatar
dt committed
620
621
//        qDebug() << "Setting mkspec to"<<mkspec;
    } else {
622
623
624
        Utils::FileName sourceMkSpecPath = sourcePath().appendPath("mkspecs");
        if (m_mkspec.isChildOf(sourceMkSpecPath)) {
            m_mkspec = m_mkspec.relativeChildPath(sourceMkSpecPath);
dt's avatar
dt committed
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
        } else {
            // Do nothing
        }
    }
}

void BaseQtVersion::ensureMkSpecParsed() const
{
    if (m_mkspecReadUpToDate)
        return;
    m_mkspecReadUpToDate = true;

    if (mkspecPath().isEmpty())
        return;

    ProFileOption option;
    option.properties = versionInfo();
    ProMessageHandler msgHandler(true);
    ProFileCacheManager::instance()->incRefCount();
    ProFileParser parser(ProFileCacheManager::instance()->cache(), &msgHandler);
    ProFileEvaluator evaluator(&option, &parser, &msgHandler);
646
    if (ProFile *pro = parser.parsedProFile(mkspecPath().toString() + "/qmake.conf")) {
dt's avatar
dt committed
647
648
649
650
651
652
653
654
655
656
657
658
659
660
        evaluator.setCumulative(false);
        evaluator.accept(pro, ProFileEvaluator::LoadProOnly);
        pro->deref();
    }

    parseMkSpec(&evaluator);

    ProFileCacheManager::instance()->decRefCount();
}

void BaseQtVersion::parseMkSpec(ProFileEvaluator *evaluator) const
{
    QStringList configValues = evaluator->values("CONFIG");
    m_defaultConfigIsDebugAndRelease = false;
dt's avatar
dt committed
661
    foreach (const QString &value, configValues) {
dt's avatar
dt committed
662
663
664
665
666
667
668
        if (value == "debug")
            m_defaultConfigIsDebug = true;
        else if (value == "release")
            m_defaultConfigIsDebug = false;
        else if (value == "build_all")
            m_defaultConfigIsDebugAndRelease = true;
    }
669
670
671

    m_mkspecValues.insert("QT.designer.bins", evaluator->value("QT.designer.bins"));
    m_mkspecValues.insert("QT.declarative.bins", evaluator->value("QT.declarative.bins"));
dt's avatar
dt committed
672
673
}

674
Utils::FileName BaseQtVersion::mkspec() const
dt's avatar
dt committed
675
676
677
678
679
{
    updateMkspec();
    return m_mkspec;
}

680
Utils::FileName BaseQtVersion::mkspecPath() const
dt's avatar
dt committed
681
682
683
684
685
{
    updateMkspec();
    return m_mkspecFullPath;
}

686
bool BaseQtVersion::hasMkspec(const Utils::FileName &spec) const
687
688
689
{
    updateVersionInfo();
    QFileInfo fi;
690
    fi.setFile(QDir::fromNativeSeparators(m_versionInfo.value("QMAKE_MKSPECS")) + '/' + spec.toString());
691
692
    if (fi.isDir())
        return true;
693
    fi.setFile(sourcePath().toString() + QLatin1String("/mkspecs/") + spec.toString());
694
695
696
    return fi.isDir();
}

dt's avatar
dt committed
697
698
699
700
701
702
703
704
705
706
707
708
709
710
BaseQtVersion::QmakeBuildConfigs BaseQtVersion::defaultBuildConfig() const
{
    ensureMkSpecParsed();
    BaseQtVersion::QmakeBuildConfigs result = BaseQtVersion::QmakeBuildConfig(0);

    if (m_defaultConfigIsDebugAndRelease)
        result = BaseQtVersion::BuildAll;
    if (m_defaultConfigIsDebug)
        result = result | BaseQtVersion::DebugBuild;
    return result;
}

QString BaseQtVersion::qtVersionString() const
{
711
712
713
714
    if (!m_qtVersionString.isNull())
        return m_qtVersionString;
    m_qtVersionString.clear();
    if (m_qmakeIsExecutable) {
715
        const QString qmake = qmakeCommand().toString();
716
717
718
        m_qtVersionString =
            ProjectExplorer::DebuggingHelperLibrary::qtVersionForQMake(qmake, &m_qmakeIsExecutable);
    } else {
719
        qWarning("Cannot determine the Qt version: %s cannot be run.", qPrintable(qmakeCommand().toString()));
dt's avatar
dt committed
720
721
722
723
724
725
726
727
728
729
730
731
732
    }
    return m_qtVersionString;
}

QtVersionNumber BaseQtVersion::qtVersion() const
{
    return QtVersionNumber(qtVersionString());
}

void BaseQtVersion::updateVersionInfo() const
{
    if (m_versionInfoUpToDate)
        return;
733
734
    if (!m_qmakeIsExecutable) {
        qWarning("Cannot update Qt version information: %s cannot be run.",
735
                 qPrintable(qmakeCommand().toString()));
736
737
        return;
    }
dt's avatar
dt committed
738
739
740

    // extract data from qmake executable
    m_versionInfo.clear();
hjk's avatar
hjk committed
741
    m_installed = true;
dt's avatar
dt committed
742
743
744
745
746
747
748
    m_hasExamples = false;
    m_hasDocumentation = false;
    m_hasDebuggingHelper = false;
    m_hasQmlDump = false;
    m_hasQmlDebuggingLibrary = false;
    m_hasQmlObserver = false;

749
    if (!queryQMakeVariables(qmakeCommand(), &m_versionInfo, &m_qmakeIsExecutable))
dt's avatar
dt committed
750
751
752
753
        return;

    if (m_versionInfo.contains("QT_INSTALL_DATA")) {
        QString qtInstallData = m_versionInfo.value("QT_INSTALL_DATA");
754
        QString qtInstallBins = m_versionInfo.value("QT_INSTALL_BINS");
dt's avatar
dt committed
755
756
757
758
759
760
        QString qtHeaderData = m_versionInfo.value("QT_INSTALL_HEADERS");
        m_versionInfo.insert("QMAKE_MKSPECS", QDir::cleanPath(qtInstallData+"/mkspecs"));

        if (!qtInstallData.isEmpty()) {
            m_hasDebuggingHelper = !ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData).isEmpty();
            m_hasQmlDump
761
762
                    = !QmlDumpTool::toolForQtPaths(qtInstallData, qtInstallBins, qtHeaderData, false).isEmpty()
                    || !QmlDumpTool::toolForQtPaths(qtInstallData, qtInstallBins, qtHeaderData, true).isEmpty();
dt's avatar
dt committed
763
764
765
766
767
768
769
770
771
772
773
            m_hasQmlDebuggingLibrary
                    = !QmlDebuggingLibrary::libraryByInstallData(qtInstallData, false).isEmpty()
                || !QmlDebuggingLibrary::libraryByInstallData(qtInstallData, true).isEmpty();
            m_hasQmlObserver = !QmlObserverTool::toolByInstallData(qtInstallData).isEmpty();
        }
    }

    // Now check for a qt that is configured with a prefix but not installed
    if (m_versionInfo.contains("QT_INSTALL_BINS")) {
        QFileInfo fi(m_versionInfo.value("QT_INSTALL_BINS"));
        if (!fi.exists())
hjk's avatar
hjk committed
774
            m_installed = false;
dt's avatar
dt committed
775
776
777
778
    }
    if (m_versionInfo.contains("QT_INSTALL_HEADERS")){
        QFileInfo fi(m_versionInfo.value("QT_INSTALL_HEADERS"));
        if (!fi.exists())
hjk's avatar
hjk committed
779
            m_installed = false;
dt's avatar
dt committed
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
    }
    if (m_versionInfo.contains("QT_INSTALL_DOCS")){
        QFileInfo fi(m_versionInfo.value("QT_INSTALL_DOCS"));
        if (fi.exists())
            m_hasDocumentation = true;
    }
    if (m_versionInfo.contains("QT_INSTALL_EXAMPLES")){
        QFileInfo fi(m_versionInfo.value("QT_INSTALL_EXAMPLES"));
        if (fi.exists())
            m_hasExamples = true;
    }
    if (m_versionInfo.contains("QT_INSTALL_DEMOS")){
        QFileInfo fi(m_versionInfo.value("QT_INSTALL_DEMOS"));
        if (fi.exists())
            m_hasDemos = true;
    }

    m_versionInfoUpToDate = true;
}

QHash<QString,QString> BaseQtVersion::versionInfo() const
{
    updateVersionInfo();
    return m_versionInfo;
}

bool BaseQtVersion::hasDocumentation() const
{
    updateVersionInfo();
    return m_hasDocumentation;
}

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

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

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

QString BaseQtVersion::frameworkInstallPath() const
{
#ifdef Q_OS_MAC
    updateVersionInfo();
    return m_versionInfo["QT_INSTALL_LIBS"];
#else
    return QString();
#endif
}

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

QString BaseQtVersion::examplesPath() const
{
    updateVersionInfo();
    return m_versionInfo["QT_INSTALL_EXAMPLES"];
}

QList<ProjectExplorer::HeaderPath> BaseQtVersion::systemHeaderPathes() const
{
    QList<ProjectExplorer::HeaderPath> result;
855
    result.append(ProjectExplorer::HeaderPath(mkspecPath().toString(), ProjectExplorer::HeaderPath::GlobalHeaderPath));
dt's avatar
dt committed
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
    return result;
}

void BaseQtVersion::addToEnvironment(Utils::Environment &env) const
{
    env.set("QTDIR", QDir::toNativeSeparators(versionInfo().value("QT_INSTALL_DATA")));
    env.prependOrSetPath(versionInfo().value("QT_INSTALL_BINS"));
    env.prependOrSetLibrarySearchPath(versionInfo().value("QT_INSTALL_LIBS"));
}

bool BaseQtVersion::hasGdbDebuggingHelper() const
{
    updateVersionInfo();
    return m_hasDebuggingHelper;
}


bool BaseQtVersion::hasQmlDump() const
{
    updateVersionInfo();
    return m_hasQmlDump;
}

879
880
881
882
883
884
bool BaseQtVersion::needsQmlDump() const
{
    updateVersionInfo();
    return qtVersion() < QtVersionNumber(4, 8, 0);
}

dt's avatar
dt committed
885
886
887
888
889
890
bool BaseQtVersion::hasQmlDebuggingLibrary() const
{
    updateVersionInfo();
    return m_hasQmlDebuggingLibrary;
}

891
892
893
894
895
896
bool BaseQtVersion::needsQmlDebuggingLibrary() const
{
    updateVersionInfo();
    return qtVersion() < QtVersionNumber(4, 8, 0);
}

dt's avatar
dt committed
897
898
899
900
901
902
903
904
905
906
907
908
909
bool BaseQtVersion::hasQmlObserver() const
{
    updateVersionInfo();
    return m_hasQmlObserver;
}

Utils::Environment BaseQtVersion::qmlToolsEnvironment() const
{
    // FIXME: This seems broken!
    Utils::Environment environment = Utils::Environment::systemEnvironment();
    addToEnvironment(environment);

    // add preferred tool chain, as that is how the tools are built, compare QtVersion::buildDebuggingHelperLibrary
910
911
912
913
914
915
    if (!qtAbis().isEmpty()) {
        QList<ProjectExplorer::ToolChain *> alltc =
                ProjectExplorer::ToolChainManager::instance()->findToolChains(qtAbis().at(0));
        if (!alltc.isEmpty())
            alltc.first()->addToEnvironment(environment);
    }
dt's avatar
dt committed
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930

    return environment;
}

QString BaseQtVersion::gdbDebuggingHelperLibrary() const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
        return QString();
    return ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryByInstallData(qtInstallData);
}

QString BaseQtVersion::qmlDumpTool(bool debugVersion) const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
931
    QString qtInstallBins = versionInfo().value("QT_INSTALL_BINS");
dt's avatar
dt committed
932
933
934
    QString qtHeaderData = versionInfo().value("QT_INSTALL_HEADERS");
    if (qtInstallData.isEmpty())
        return QString();
935
    return QmlDumpTool::toolForQtPaths(qtInstallData, qtInstallBins, qtHeaderData, debugVersion);
dt's avatar
dt committed
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
}

QString BaseQtVersion::qmlDebuggingHelperLibrary(bool debugVersion) const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
        return QString();
    return QmlDebuggingLibrary::libraryByInstallData(qtInstallData, debugVersion);
}

QString BaseQtVersion::qmlObserverTool() const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
        return QString();
    return QmlObserverTool::toolByInstallData(qtInstallData);
}

QStringList BaseQtVersion::debuggingHelperLibraryLocations() const
{
    QString qtInstallData = versionInfo().value("QT_INSTALL_DATA");
    if (qtInstallData.isEmpty())
        return QStringList();
959
    return ProjectExplorer::DebuggingHelperLibrary::debuggingHelperLibraryDirectories(qtInstallData);
dt's avatar
dt committed
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
}

bool BaseQtVersion::supportsBinaryDebuggingHelper() const
{
    if (!isValid())
        return false;
    return true;
}

void BaseQtVersion::recheckDumper()
{
    m_versionInfoUpToDate = false;
}

bool BaseQtVersion::supportsShadowBuilds() const
{
    return true;
}

QList<ProjectExplorer::Task> BaseQtVersion::reportIssuesImpl(const QString &proFile, const QString &buildDir)
{
    QList<ProjectExplorer::Task> results;

    QString tmpBuildDir = QDir(buildDir).absolutePath();
    if (!tmpBuildDir.endsWith(QLatin1Char('/')))
        tmpBuildDir.append(QLatin1Char('/'));

    if (!isValid()) {
        //: %1: Reason for being invalid
        const QString msg = QCoreApplication::translate("Qt4ProjectManager::QtVersion", "The Qt version is invalid: %1").arg(invalidReason());
        results.append(ProjectExplorer::Task(ProjectExplorer::Task::Error, msg, QString(), -1,
                                             QLatin1String(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
    }

994
    QFileInfo qmakeInfo = qmakeCommand().toFileInfo();
dt's avatar
dt committed
995
996
997
998
    if (!qmakeInfo.exists() ||
        !qmakeInfo.isExecutable()) {
        //: %1: Path to qmake executable
        const QString msg = QCoreApplication::translate("Qt4ProjectManager::QtVersion",
999
                                                        "The qmake command \"%1\" was not found or is not executable.").arg(qmakeCommand().toUserOutput());
dt's avatar
dt committed
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
        results.append(ProjectExplorer::Task(ProjectExplorer::Task::Error, msg, QString(), -1,
                                             QLatin1String(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
    }

    QString sourcePath = QFileInfo(proFile).absolutePath();
    if (!sourcePath.endsWith(QLatin1Char('/')))
        sourcePath.append(QLatin1Char('/'));
    if ((tmpBuildDir.startsWith(sourcePath)) && (tmpBuildDir != sourcePath)) {
        const QString msg = QCoreApplication::translate("Qt4ProjectManager::QtVersion",
                                                        "Qmake does not support build directories below the source directory.");
        results.append(ProjectExplorer::Task(ProjectExplorer::Task::Warning, msg, QString(), -1,
                                             QLatin1String(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
1012
    } else if (tmpBuildDir.count(QChar('/')) != sourcePath.count(QChar('/')) && qtVersion() < QtVersionNumber(4,8, 0)) {
dt's avatar
dt committed
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
        const QString msg = QCoreApplication::translate("Qt4ProjectManager::QtVersion",
                                                        "The build directory needs to be at the same level as the source directory.");

        results.append(ProjectExplorer::Task(ProjectExplorer::Task::Warning, msg, QString(), -1,
                                             QLatin1String(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM)));
    }

    return results;
}

QList<ProjectExplorer::Task>
1024
BaseQtVersion::reportIssues(const QString &proFile, const QString &buildDir)
dt's avatar
dt committed
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
{
    QList<ProjectExplorer::Task> results = reportIssuesImpl(proFile, buildDir);
    qSort(results);
    return results;
}

ProjectExplorer::IOutputParser *BaseQtVersion::createOutputParser() const
{
    return new ProjectExplorer::GnuMakeParser;
}

QtConfigWidget *BaseQtVersion::createConfigurationWidget() const
{
    return 0;
}

1041
bool BaseQtVersion::queryQMakeVariables(const Utils::FileName &binary, QHash<QString, QString> *versionInfo)
1042
1043
1044
1045
1046
{
    bool qmakeIsExecutable;
    return BaseQtVersion::queryQMakeVariables(binary, versionInfo, &qmakeIsExecutable);
}

1047
bool BaseQtVersion::queryQMakeVariables(const Utils::FileName &binary, QHash<QString, QString> *versionInfo,
1048
                                        bool *qmakeIsExecutable)
dt's avatar
dt committed
1049
1050
{
    const int timeOutMS = 30000; // Might be slow on some machines.
1051
    const QFileInfo qmake = binary.toFileInfo();
1052
1053
    *qmakeIsExecutable = qmake.exists() && qmake.isExecutable() && !qmake.isDir();
    if (!*qmakeIsExecutable)
dt's avatar
dt committed
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
        return false;
    static const char * const variables[] = {
             "QT_VERSION",
             "QT_INSTALL_DATA",
             "QT_INSTALL_LIBS",
             "QT_INSTALL_HEADERS",
             "QT_INSTALL_DEMOS",
             "QT_INSTALL_EXAMPLES",
             "QT_INSTALL_CONFIGURATION",
             "QT_INSTALL_TRANSLATIONS",
             "QT_INSTALL_PLUGINS",
             "QT_INSTALL_BINS",
             "QT_INSTALL_DOCS",
             "QT_INSTALL_PREFIX",
             "QT_INSTALL_IMPORTS",
             "QMAKEFEATURES"
        };
1071
    const QString queryArg = QLatin1String("-query");
dt's avatar
dt committed
1072
1073
    QStringList args;
    for (uint i = 0; i < sizeof variables / sizeof variables[0]; ++i)
1074
        args << queryArg << variables[i];
dt's avatar
dt committed
1075
1076
1077
    QProcess process;
    process.start(qmake.absoluteFilePath(), args, QIODevice::ReadOnly);
    if (!process.waitForStarted()) {
1078
        *qmakeIsExecutable = false;
1079
        qWarning("Cannot start '%s': %s", qPrintable(binary.toUserOutput()), qPrintable(process.errorString()));
dt's avatar
dt committed
1080
1081
1082
1083
        return false;
    }
    if (!process.waitForFinished(timeOutMS)) {
        Utils::SynchronousProcess::stopProcess(process);
1084
        qWarning("Timeout running '%s' (%dms).", qPrintable(binary.toUserOutput()), timeOutMS);
dt's avatar
dt committed
1085
1086
1087
        return false;
    }
    if (process.exitStatus() != QProcess::NormalExit) {
1088
        *qmakeIsExecutable = false;
1089
        qWarning("'%s' crashed.", qPrintable(binary.toUserOutput()));
dt's avatar
dt committed
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
        return false;
    }
    QByteArray output = process.readAllStandardOutput();
    QTextStream stream(&output);
    while (!stream.atEnd()) {
        const QString line = stream.readLine();
        const int index = line.indexOf(QLatin1Char(':'));
        if (index != -1) {
            const QString value = QDir::fromNativeSeparators(line.mid(index+1));
            if (value != "**Unknown**")
                versionInfo->insert(line.left(index), value);
        }
    }
    return true;
}

1106
Utils::FileName BaseQtVersion::mkspecFromVersionInfo(const QHash<QString, QString> &versionInfo)
dt's avatar
dt committed
1107
{
1108
    Utils::FileName baseMkspecDir = Utils::FileName::fromUserInput(versionInfo.value("QMAKE_MKSPECS"));
dt's avatar
dt committed
1109
    if (baseMkspecDir.isEmpty())
1110
        baseMkspecDir = Utils::FileName::fromUserInput(versionInfo.value("QT_INSTALL_DATA") + "/mkspecs");
dt's avatar
dt committed
1111
    if (baseMkspecDir.isEmpty())
1112
        return Utils::FileName();
dt's avatar
dt committed
1113

1114
    Utils::FileName mkspecFullPath = Utils::FileName::fromString(baseMkspecDir.toString() + "/default");
dt's avatar
dt committed
1115
1116
1117
1118

    // qDebug() << "default mkspec is located at" << mkspecFullPath;

#ifdef Q_OS_WIN
1119
    QFile f2(mkspecFullPath.toString() + "/qmake.conf");
dt's avatar
dt committed
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
    if (f2.exists() && f2.open(QIODevice::ReadOnly)) {
        while (!f2.atEnd()) {
            QByteArray line = f2.readLine();
            if (line.startsWith("QMAKESPEC_ORIGINAL")) {
                const QList<QByteArray> &temp = line.split('=');
                if (temp.size() == 2) {
                    QString possibleFullPath = temp.at(1).trimmed();
                    // We sometimes get a mix of different slash styles here...
                    possibleFullPath = possibleFullPath.replace('\\', '/');
                    if (QFileInfo(possibleFullPath).exists()) // Only if the path exists
1130
                        mkspecFullPath = Utils::FileName::fromUserInput(possibleFullPath);
dt's avatar
dt committed
1131
1132
1133
1134
1135
1136
1137
                }
                break;
            }
        }
        f2.close();
    }
#elif defined(Q_OS_MAC)
1138
    QFile f2(mkspecFullPath.toString() + "/qmake.conf");
dt's avatar
dt committed
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
    if (f2.exists() && f2.open(QIODevice::ReadOnly)) {
        while (!f2.atEnd()) {
            QByteArray line = f2.readLine();
            if (line.startsWith("MAKEFILE_GENERATOR")) {
                const QList<QByteArray> &temp = line.split('=');
                if (temp.size() == 2) {
                    const QByteArray &value = temp.at(1);
                    if (value.contains("XCODE")) {
                        // we don't want to generate xcode projects...
//                      qDebug() << "default mkspec is xcode, falling back to g++";
1149
                        mkspecFullPath = baseMkspecDir.appendPath("macx-g++");
dt's avatar
dt committed
1150
1151
                    }
                    //resolve mkspec link
1152
                    mkspecFullPath = Utils::FileName::fromString(mkspecFullPath.toFileInfo().canonicalFilePath());
dt's avatar
dt committed
1153
1154
1155
1156
1157
1158
1159
                }
                break;
            }
        }
        f2.close();
    }
#else
1160
    mkspecFullPath = Utils::FileName::fromString(mkspecFullPath.toFileInfo().canonicalFilePath());
dt's avatar
dt committed
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
#endif

    return mkspecFullPath;
}

QString BaseQtVersion::qtCorePath(const QHash<QString,QString> &versionInfo, const QString &versionString)
{
    QStringList dirs;
    dirs << versionInfo.value(QLatin1String("QT_INSTALL_LIBS"))
         << versionInfo.value(QLatin1String("QT_INSTALL_BINS"));

    QFileInfoList staticLibs;
    foreach (const QString &dir, dirs) {
        if (dir.isEmpty())
            continue;
        QDir d(dir);
        QFileInfoList infoList = d.entryInfoList();
        foreach (const QFileInfo &info, infoList) {
            const QString file = info.fileName();
            if (info.isDir()
                    && file.startsWith(QLatin1String("QtCore"))
                    && file.endsWith(QLatin1String(".framework"))) {
                // handle Framework
                const QString libName = file.left(file.lastIndexOf('.'));
                return info.absoluteFilePath() + '/' + libName;
            }
            if (info.isReadable()) {
                if (file.startsWith(QLatin1String("libQtCore"))
                        || file.startsWith(QLatin1String("QtCore"))) {
                    // Only handle static libs if we can not find dynamic ones:
                    if (file.endsWith(".a") || file.endsWith(".lib"))
                        staticLibs.append(info);
                    else if (file.endsWith(QLatin1String(".dll"))
                             || file.endsWith(QString::fromLatin1(".so.") + versionString)
                             || file.endsWith(QLatin1Char('.') + versionString + QLatin1String(".dylib")))
                        return info.absoluteFilePath();
                }
            }
        }
    }
    // Return path to first static library found:
    if (!staticLibs.isEmpty())
        return staticLibs.at(0).absoluteFilePath();
    return QString();
}

1207
QList<ProjectExplorer::Abi> BaseQtVersion::qtAbisFromLibrary(const QString &coreLibrary)
dt's avatar
dt committed
1208
{
1209
    return ProjectExplorer::Abi::abisOfBinary(coreLibrary);
dt's avatar
dt committed
1210
}