gccetoolchain.cpp 6.74 KB
Newer Older
con's avatar
con committed
1
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
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** 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
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
28
29
**
**************************************************************************/

con's avatar
con committed
30
#include "gccetoolchain.h"
31
#include "qt4project.h"
con's avatar
con committed
32

33
#include <utils/qtcassert.h>
34
#include <utils/synchronousprocess.h>
35

con's avatar
con committed
36
#include <QtCore/QDir>
37
#include <QtCore/QProcess>
38
39
40
#include <QtCore/QtDebug>

enum { debug = 0 };
con's avatar
con committed
41
42
43
44

using namespace ProjectExplorer;
using namespace Qt4ProjectManager::Internal;

45
46
47
48
// Locate the compiler via path.
static QString gcceCommand(const QString &dir)
{
    ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
49
    if (!dir.isEmpty()) {
50
        env.prependOrSetPath(dir + QLatin1String("/bin"));
51
52
        env.prependOrSetPath(dir);
    }
53
54
55
56
57
    QString gcce = QLatin1String("arm-none-symbianelf-gcc");
#ifdef Q_OS_WIN
    gcce += QLatin1String(".exe");
#endif
    const QString rc = env.searchInPath(gcce);
58
    if (debug && rc.isEmpty()) {
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        const QString msg = QString::fromLatin1("GCCEToolChain: Unable to locate '%1' in '%2' (GCCE root: '%3')")
                            .arg(gcce, env.value(QLatin1String("PATH")), dir);
        qWarning("%s", qPrintable(msg));
        return gcce;
    }
    return rc;
}

// The GccToolChain base class constructor wants to know the gcc command
GCCEToolChain *GCCEToolChain::create(const S60Devices::Device &device,
                                     const QString &gcceRoot,
                                     ProjectExplorer::ToolChain::ToolChainType type)
{
    const QString gccCommand = gcceCommand(gcceRoot);
    const QFileInfo gccCommandFi(gccCommand);
    const QString binPath = gccCommandFi.isRelative() ? QString() : gccCommandFi.absolutePath();
    return new GCCEToolChain(device, binPath, gccCommand, type);
}

78
GCCEToolChain::GCCEToolChain(const S60Devices::Device &device,
79
                             const QString &gcceBinPath,
80
81
82
83
84
                             const QString &gcceCommand,
                             ProjectExplorer::ToolChain::ToolChainType type) :
    GccToolChain(gcceCommand),
    m_mixin(device),
    m_type(type),
85
    m_gcceBinPath(gcceBinPath)
con's avatar
con committed
86
{
87
88
    QTC_ASSERT(m_type == ProjectExplorer::ToolChain::GCCE || m_type == ProjectExplorer::ToolChain::GCCE_GNUPOC, return)
    if (debug)
89
        qDebug() << "GCCEToolChain on" << m_type << gcceCommand << gcceBinPath << m_mixin.device();
con's avatar
con committed
90
91
92
93
}

ToolChain::ToolChainType GCCEToolChain::type() const
{
94
    return m_type;
con's avatar
con committed
95
96
}

97
98
99
100
101
102
103
104
105
106
107
QByteArray GCCEToolChain::predefinedMacros()
{
    if (m_predefinedMacros.isEmpty()) {
        ProjectExplorer::GccToolChain::predefinedMacros();
        m_predefinedMacros += "\n"
                "#define __GCCE__\n"
                "#define __SYMBIAN32__\n";
    }
    return m_predefinedMacros;
}

con's avatar
con committed
108
109
QList<HeaderPath> GCCEToolChain::systemHeaderPaths()
{
con's avatar
con committed
110
111
    if (m_systemHeaderPaths.isEmpty()) {
        GccToolChain::systemHeaderPaths();
112
113
114
115
116
117
118
119
120
121
        switch (m_type) {
        case ProjectExplorer::ToolChain::GCCE:
            m_systemHeaderPaths += m_mixin.epocHeaderPaths();
            break;
        case ProjectExplorer::ToolChain::GCCE_GNUPOC:
            m_systemHeaderPaths += m_mixin.gnuPocHeaderPaths();
            break;
        default:
            break;
        }
con's avatar
con committed
122
    }
con's avatar
con committed
123
124
125
126
127
    return m_systemHeaderPaths;
}

void GCCEToolChain::addToEnvironment(ProjectExplorer::Environment &env)
{
128
129
130
131
132
    if (debug)
        qDebug() << "GCCEToolChain::addToEnvironment" << m_type << gcc() << m_gcceBinPath<< m_mixin.device();

    if (!m_gcceBinPath.isEmpty())
        env.prependOrSetPath(m_gcceBinPath);
133
134
135
    switch (m_type) {
    case ProjectExplorer::ToolChain::GCCE:
        m_mixin.addEpocToEnvironment(&env);
136
        break;
137
    case ProjectExplorer::ToolChain::GCCE_GNUPOC:
138
        m_mixin.addGnuPocToEnvironment(&env);
139
140
141
142
        break;
    default:
        break;
    }
143
    QString version = gcceVersion();
144
    env.set(QLatin1String("QT_GCCE_VERSION"), version);
145
146
    version = version.remove(QLatin1Char('.'));
    env.set(QString::fromLatin1("SBS_GCCE") + version + QLatin1String("BIN"), QDir::toNativeSeparators(m_gcceBinPath));
con's avatar
con committed
147
148
149
150
}

QString GCCEToolChain::makeCommand() const
{
151
    return QLatin1String("make");
con's avatar
con committed
152
153
}

154
bool GCCEToolChain::equals(ToolChain *otherIn) const
con's avatar
con committed
155
{
156
157
158
159
    if (otherIn->type() != type())
                return false;
    const GCCEToolChain *other = static_cast<const GCCEToolChain *>(otherIn);
    return m_mixin == other->m_mixin
160
161
           && m_gcceBinPath == other->m_gcceBinPath
           && gcc() == other->gcc();
con's avatar
con committed
162
}
163
164
165
166
167
168
169
170
171

QString GCCEToolChain::gcceVersion() const
{
    if (m_gcceVersion.isEmpty()) {
        QString command = gcceCommand(m_gcceBinPath);
        if (command.isEmpty())
            return QString();
        QProcess gxx;
        QStringList arguments;
Tobias Hunger's avatar
Tobias Hunger committed
172
        arguments << QLatin1String("-dumpversion");
173
174
175
176
177
        ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
        env.set(QLatin1String("LC_ALL"), QLatin1String("C"));   //override current locale settings
        gxx.setEnvironment(env.toStringList());
        gxx.setReadChannelMode(QProcess::MergedChannels);
        gxx.start(command, arguments);
178
179
180
181
        if (!gxx.waitForStarted()) {
            qWarning("Cannot start '%s': %s", qPrintable(command), qPrintable(gxx.errorString()));
            return QString();
        }
182
        gxx.closeWriteChannel();
183
184
185
186
        if (!gxx.waitForFinished())      {
            Utils::SynchronousProcess::stopProcess(gxx);
            qWarning("Timeout running '%s'.", qPrintable(command));
            return QString();
187
        }
188
189
190
191
192
193
194
        if (gxx.exitStatus() != QProcess::NormalExit) {
            qWarning("'%s' crashed.", qPrintable(command));
            return QString();
        }

        if (gxx.canReadLine())
            m_gcceVersion = gxx.readLine().trimmed();
195
196
197
    }
    return m_gcceVersion;
}