maemotoolchain.cpp 9.58 KB
Newer Older
ck's avatar
ck committed
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
ck's avatar
ck committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
ck's avatar
ck committed
8
9
10
11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12
13
14
15
16
17
** 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.
ck's avatar
ck committed
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23
24
25
26
27
** 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.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
ck's avatar
ck committed
30
31
32
33
**
**************************************************************************/

#include "maemotoolchain.h"
34
35

#include "maemoglobal.h"
dt's avatar
dt committed
36
#include "maemoqtversion.h"
ck's avatar
ck committed
37

38
#include <projectexplorer/gccparser.h>
39
#include <projectexplorer/headerpath.h>
40
#include <projectexplorer/toolchainmanager.h>
41
#include <qt4projectmanager/qt4projectmanagerconstants.h>
42
#include <utils/environment.h>
43
#include <qtsupport/qtversionmanager.h>
ck's avatar
ck committed
44

45
46
47
48
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtGui/QLabel>
#include <QtGui/QVBoxLayout>
ck's avatar
ck committed
49

50
51
using namespace Qt4ProjectManager;

52
namespace Madde {
53
54
namespace Internal {

55
56
57
58
59
60
61
62
63
static const char *const MAEMO_QT_VERSION_KEY = "Qt4ProjectManager.Maemo.QtVersion";

// --------------------------------------------------------------------------
// MaemoToolChain
// --------------------------------------------------------------------------

MaemoToolChain::MaemoToolChain(bool autodetected) :
    ProjectExplorer::GccToolChain(QLatin1String(Constants::MAEMO_TOOLCHAIN_ID), autodetected),
    m_qtVersionId(-1)
ck's avatar
ck committed
64
{
65
    updateId();
ck's avatar
ck committed
66
67
}

68
69
70
71
72
73
74
75
76
MaemoToolChain::MaemoToolChain(const MaemoToolChain &tc) :
    ProjectExplorer::GccToolChain(tc),
    m_qtVersionId(tc.m_qtVersionId)
{ }

MaemoToolChain::~MaemoToolChain()
{ }

QString MaemoToolChain::typeName() const
ck's avatar
ck committed
77
{
78
    return MaemoToolChainFactory::tr("Maemo GCC");
ck's avatar
ck committed
79
80
}

81
ProjectExplorer::Abi MaemoToolChain::targetAbi() const
ck's avatar
ck committed
82
{
83
84
85
    return m_targetAbi;
}

86
Utils::FileName MaemoToolChain::mkspec() const
87
{
88
    return Utils::FileName(); // always use default
89
90
}

91
92
93
94
95
bool MaemoToolChain::isValid() const
{
    return GccToolChain::isValid() && m_qtVersionId >= 0 && m_targetAbi.isValid();
}

96
97
98
99
100
bool MaemoToolChain::canClone() const
{
    return false;
}

101
102
void MaemoToolChain::addToEnvironment(Utils::Environment &env) const
{
103
104
105
106
107
108
109
110
    const QString manglePathsKey = QLatin1String("GCCWRAPPER_PATHMANGLE");
    if (!env.hasKey(manglePathsKey)) {
        const QStringList pathsToMangle = QStringList() << QLatin1String("/lib")
            << QLatin1String("/opt") << QLatin1String("/usr");
        env.set(manglePathsKey, QString());
        foreach (const QString &path, pathsToMangle)
            env.appendOrSet(manglePathsKey, path, QLatin1String(":"));
    }
ck's avatar
ck committed
111
112
}

113
bool MaemoToolChain::operator ==(const ProjectExplorer::ToolChain &tc) const
ck's avatar
ck committed
114
{
115
116
117
118
119
    if (!ToolChain::operator ==(tc))
        return false;

    const MaemoToolChain *tcPtr = static_cast<const MaemoToolChain *>(&tc);
    return m_qtVersionId == tcPtr->m_qtVersionId;
120
121
}

122
ProjectExplorer::ToolChainConfigWidget *MaemoToolChain::configurationWidget()
ck's avatar
ck committed
123
{
124
    return new MaemoToolChainConfigWidget(this);
ck's avatar
ck committed
125
126
}

127
QVariantMap MaemoToolChain::toMap() const
ck's avatar
ck committed
128
{
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    QVariantMap result = GccToolChain::toMap();
    result.insert(QLatin1String(MAEMO_QT_VERSION_KEY), m_qtVersionId);
    return result;
}

bool MaemoToolChain::fromMap(const QVariantMap &data)
{
    if (!GccToolChain::fromMap(data))
        return false;

    m_qtVersionId = data.value(QLatin1String(MAEMO_QT_VERSION_KEY), -1).toInt();

    return isValid();
}

void MaemoToolChain::setQtVersionId(int id)
{
    if (id < 0) {
        m_targetAbi = ProjectExplorer::Abi();
        m_qtVersionId = -1;
Tobias Hunger's avatar
Tobias Hunger committed
149
        updateId(); // Will trigger toolChainUpdated()!
150
        return;
ck's avatar
ck committed
151
152
    }

153
    MaemoQtVersion *version = dynamic_cast<MaemoQtVersion *>(QtSupport::QtVersionManager::instance()->version(id));
154
    Q_ASSERT(version);
155
    if (!version->isValid())
156
        return;
157
    Q_ASSERT(version->qtAbis().count() == 1);
158
159
160
161

    m_qtVersionId = id;
    m_targetAbi = version->qtAbis().at(0);

Tobias Hunger's avatar
Tobias Hunger committed
162
    updateId(); // Will trigger toolChainUpdated()!
Friedemann Kleint's avatar
Friedemann Kleint committed
163
    setDisplayName(MaemoToolChainFactory::tr("Maemo GCC for %1").arg(version->displayName()));
ck's avatar
ck committed
164
}
165

166
167
168
169
170
171
172
int MaemoToolChain::qtVersionId() const
{
    return m_qtVersionId;
}

void MaemoToolChain::updateId()
{
Tobias Hunger's avatar
Tobias Hunger committed
173
174
    setId(QString::fromLatin1("%1:%2.%3").arg(Constants::MAEMO_TOOLCHAIN_ID)
          .arg(m_qtVersionId).arg(debuggerCommand()));
175
176
177
}

// --------------------------------------------------------------------------
Tobias Hunger's avatar
Tobias Hunger committed
178
// MaemoToolChainConfigWidget
179
// --------------------------------------------------------------------------
180

181
182
MaemoToolChainConfigWidget::MaemoToolChainConfigWidget(MaemoToolChain *tc) :
    ProjectExplorer::ToolChainConfigWidget(tc)
183
{
184
185
    QVBoxLayout *layout = new QVBoxLayout(this);
    QLabel *label = new QLabel;
186
    QtSupport::BaseQtVersion *v = QtSupport::QtVersionManager::instance()->version(tc->qtVersionId());
187
    Q_ASSERT(v);
188
189
190
191
    label->setText(tr("<html><head/><body><table>"
                      "<tr><td>Path to MADDE:</td><td>%1</td></tr>"
                      "<tr><td>Path to MADDE target:</td><td>%2</td></tr>"
                      "<tr><td>Debugger:</td/><td>%3</td></tr></body></html>")
192
193
                   .arg(QDir::toNativeSeparators(MaemoGlobal::maddeRoot(v->qmakeCommand().toString())),
                        QDir::toNativeSeparators(MaemoGlobal::targetRoot(v->qmakeCommand().toString())),
194
                        QDir::toNativeSeparators(tc->debuggerCommand())));
195
    layout->addWidget(label);
196
197
}

198
199
200
201
void MaemoToolChainConfigWidget::apply()
{
    // nothing to do!
}
202

203
void MaemoToolChainConfigWidget::discard()
204
{
205
    // nothing to do!
206
207
}

208
bool MaemoToolChainConfigWidget::isDirty() const
209
{
210
    return false;
211
212
}

213
// --------------------------------------------------------------------------
Tobias Hunger's avatar
Tobias Hunger committed
214
// MaemoToolChainFactory
215
216
217
218
219
// --------------------------------------------------------------------------

MaemoToolChainFactory::MaemoToolChainFactory() :
    ProjectExplorer::ToolChainFactory()
{ }
220

221
QString MaemoToolChainFactory::displayName() const
222
{
223
    return tr("Maemo GCC");
224
225
}

226
227
228
229
QString MaemoToolChainFactory::id() const
{
    return QLatin1String(Constants::MAEMO_TOOLCHAIN_ID);
}
Christian Kandeler's avatar
Christian Kandeler committed
230

231
QList<ProjectExplorer::ToolChain *> MaemoToolChainFactory::autoDetect()
Christian Kandeler's avatar
Christian Kandeler committed
232
{
233
    QtSupport::QtVersionManager *vm = QtSupport::QtVersionManager::instance();
234
235
236
237
    connect(vm, SIGNAL(qtVersionsChanged(QList<int>)),
            this, SLOT(handleQtVersionChanges(QList<int>)));

    QList<int> versionList;
238
    foreach (QtSupport::BaseQtVersion *v, vm->versions())
239
240
241
        versionList.append(v->uniqueId());

    return createToolChainList(versionList);
Christian Kandeler's avatar
Christian Kandeler committed
242
243
}

244
245
246
247
248
249
250
void MaemoToolChainFactory::handleQtVersionChanges(const QList<int> &changes)
{
    ProjectExplorer::ToolChainManager *tcm = ProjectExplorer::ToolChainManager::instance();
    QList<ProjectExplorer::ToolChain *> tcList = createToolChainList(changes);
    foreach (ProjectExplorer::ToolChain *tc, tcList)
        tcm->registerToolChain(tc);
}
Christian Kandeler's avatar
Christian Kandeler committed
251

252
QList<ProjectExplorer::ToolChain *> MaemoToolChainFactory::createToolChainList(const QList<int> &changes)
Christian Kandeler's avatar
Christian Kandeler committed
253
{
254
    ProjectExplorer::ToolChainManager *tcm = ProjectExplorer::ToolChainManager::instance();
255
    QtSupport::QtVersionManager *vm = QtSupport::QtVersionManager::instance();
256
257
258
    QList<ProjectExplorer::ToolChain *> result;

    foreach (int i, changes) {
259
        QtSupport::BaseQtVersion *v = vm->version(i);
260
261
262
263
264
265
266
267
268
269
270
271
        // remove tool chain (on removal, change or addition:
        QList<ProjectExplorer::ToolChain *> toRemove;
        foreach (ProjectExplorer::ToolChain *tc, tcm->toolChains()) {
            if (!tc->id().startsWith(QLatin1String(Constants::MAEMO_TOOLCHAIN_ID)))
                continue;
            MaemoToolChain *mTc = static_cast<MaemoToolChain *>(tc);
            if (mTc->qtVersionId() == i)
                toRemove.append(mTc);
        }
        foreach (ProjectExplorer::ToolChain *tc, toRemove)
            tcm->deregisterToolChain(tc);

272
273
274
275
        const MaemoQtVersion * const mqv = dynamic_cast<MaemoQtVersion *>(v);
        if (!mqv || !mqv->isValid())
            continue;

276
        // (Re-)add toolchain:
277
278
279
280
281
282
283
284
        // add tool chain:
        MaemoToolChain *mTc = new MaemoToolChain(true);
        mTc->setQtVersionId(i);
        QString target = "Maemo 5";
        if (v->supportsTargetId(Constants::HARMATTAN_DEVICE_TARGET_ID))
            target = "Maemo 6";
        else if (v->supportsTargetId(Constants::MEEGO_DEVICE_TARGET_ID))
            target = "Meego";
285
286
        mTc->setDisplayName(tr("%1 GCC (%2)").arg(target).arg(MaemoGlobal::maddeRoot(mqv->qmakeCommand().toString())));
        mTc->setCompilerPath(MaemoGlobal::targetRoot(mqv->qmakeCommand().toString()) + QLatin1String("/bin/gcc"));
287
288
        mTc->setDebuggerCommand(ProjectExplorer::ToolChainManager::instance()->defaultDebugger(mqv->qtAbis().at(0)));
        if (mTc->debuggerCommand().isEmpty())
289
            mTc->setDebuggerCommand(MaemoGlobal::targetRoot(mqv->qmakeCommand().toString()) + QLatin1String("/bin/gdb"));
290
        result.append(mTc);
291
292
    }
    return result;
Christian Kandeler's avatar
Christian Kandeler committed
293
294
}

295
} // namespace Internal
296
} // namespace Madde