2012-04-18 20:30:57 +03:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2012 BogDan Vatra <bog_dan_ro@yahoo.com>
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-04-18 20:30:57 +03:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
#include "androidtoolchain.h"
|
|
|
|
|
#include "androidconstants.h"
|
|
|
|
|
#include "androidconfigurations.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "androidmanager.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
#include "androidqtversion.h"
|
|
|
|
|
|
2012-07-03 16:57:44 +03:00
|
|
|
#include <projectexplorer/target.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <projectexplorer/toolchainmanager.h>
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <qt4projectmanager/qt4project.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <qtsupport/qtversionmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/environment.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
#include <QDir>
|
2012-08-16 15:59:10 +02:00
|
|
|
#include <QFormLayout>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
namespace Android {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
using namespace ProjectExplorer;
|
2012-04-18 20:30:57 +03:00
|
|
|
using namespace Qt4ProjectManager;
|
2012-08-23 15:53:58 +02:00
|
|
|
using namespace Utils;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
static const char ANDROID_QT_VERSION_KEY[] = "Qt4ProjectManager.Android.QtVersion";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AndroidToolChain::AndroidToolChain(bool autodetected) :
|
2012-08-09 01:56:51 +02:00
|
|
|
GccToolChain(QLatin1String(Constants::ANDROID_TOOLCHAIN_ID), autodetected),
|
2012-04-18 20:30:57 +03:00
|
|
|
m_qtVersionId(-1)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
AndroidToolChain::AndroidToolChain(const AndroidToolChain &tc) :
|
2012-08-09 01:56:51 +02:00
|
|
|
GccToolChain(tc),
|
2012-04-18 20:30:57 +03:00
|
|
|
m_qtVersionId(tc.m_qtVersionId)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
AndroidToolChain::~AndroidToolChain()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QString AndroidToolChain::type() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("androidgcc");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidToolChain::typeDisplayName() const
|
|
|
|
|
{
|
|
|
|
|
return AndroidToolChainFactory::tr("Android GCC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidToolChain::isValid() const
|
|
|
|
|
{
|
|
|
|
|
return GccToolChain::isValid() && m_qtVersionId >= 0 && targetAbi().isValid();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
void AndroidToolChain::addToEnvironment(Environment &env) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// TODO this vars should be configurable in projects -> build tab
|
|
|
|
|
// TODO invalidate all .pro files !!!
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
Qt4Project *qt4pro = qobject_cast<Qt4Project *>(ProjectExplorerPlugin::instance()->currentProject());
|
2012-07-03 16:57:44 +03:00
|
|
|
if (!qt4pro || !qt4pro->activeTarget()
|
2012-09-03 18:31:44 +02:00
|
|
|
|| QtSupport::QtKitInformation::qtVersion(qt4pro->activeTarget()->kit())->type() != QLatin1String(Constants::ANDROIDQT))
|
2012-07-03 16:57:44 +03:00
|
|
|
return;
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
QString ndkHost;
|
|
|
|
|
switch (HostOsInfo::hostOs()) {
|
|
|
|
|
case HostOsInfo::HostOsLinux:
|
|
|
|
|
ndkHost = QLatin1String("linux-x86");
|
|
|
|
|
break;
|
|
|
|
|
case HostOsInfo::HostOsWindows:
|
|
|
|
|
ndkHost = QLatin1String("windows");
|
|
|
|
|
break;
|
|
|
|
|
case HostOsInfo::HostOsMac:
|
|
|
|
|
ndkHost = QLatin1String("darwin-x86");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
// this env vars are used by qmake mkspecs to generate makefiles (check QTDIR/mkspecs/android-g++/qmake.conf for more info)
|
2012-08-23 15:53:58 +02:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_HOST"), ndkHost);
|
2012-04-24 15:49:09 +02:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_ROOT"), AndroidConfigurations::instance().config().ndkLocation.toUserOutput());
|
2012-04-18 20:30:57 +03:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_TOOLCHAIN_PREFIX"), AndroidConfigurations::toolchainPrefix(targetAbi().architecture()));
|
|
|
|
|
env.set(QLatin1String("ANDROID_NDK_TOOLS_PREFIX"), AndroidConfigurations::toolsPrefix(targetAbi().architecture()));
|
|
|
|
|
env.set(QLatin1String("ANDROID_NDK_TOOLCHAIN_VERSION"), AndroidConfigurations::instance().config().ndkToolchainVersion);
|
|
|
|
|
env.set(QLatin1String("ANDROID_NDK_PLATFORM"),
|
2012-04-24 15:49:09 +02:00
|
|
|
AndroidConfigurations::instance().bestMatch(AndroidManager::targetSDK(qt4pro->activeTarget())));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
bool AndroidToolChain::operator ==(const ToolChain &tc) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
|
if (!ToolChain::operator ==(tc))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const AndroidToolChain *tcPtr = static_cast<const AndroidToolChain *>(&tc);
|
|
|
|
|
return m_qtVersionId == tcPtr->m_qtVersionId;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChainConfigWidget *AndroidToolChain::configurationWidget()
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
|
return new AndroidToolChainConfigWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap AndroidToolChain::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap result = GccToolChain::toMap();
|
|
|
|
|
result.insert(QLatin1String(ANDROID_QT_VERSION_KEY), m_qtVersionId);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidToolChain::fromMap(const QVariantMap &data)
|
|
|
|
|
{
|
|
|
|
|
if (!GccToolChain::fromMap(data))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
m_qtVersionId = data.value(QLatin1String(ANDROID_QT_VERSION_KEY), -1).toInt();
|
|
|
|
|
|
|
|
|
|
return isValid();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
QList<FileName> AndroidToolChain::suggestedMkspecList() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-23 15:53:58 +02:00
|
|
|
return QList<FileName>()<< FileName::fromString(QLatin1String("android-g++"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2012-09-11 15:59:17 +02:00
|
|
|
QString AndroidToolChain::makeCommand(const Utils::Environment &env) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-09-12 17:27:37 +02:00
|
|
|
QString make = HostOsInfo::isWindowsHost()
|
|
|
|
|
? QLatin1String("ma-make.exe") : QLatin1String("make");
|
2012-09-11 15:59:17 +02:00
|
|
|
QString tmp = env.searchInPath(make);
|
|
|
|
|
return tmp.isEmpty() ? make : tmp;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidToolChain::setQtVersionId(int id)
|
|
|
|
|
{
|
|
|
|
|
if (id < 0) {
|
2012-08-09 01:56:51 +02:00
|
|
|
setTargetAbi(Abi());
|
2012-04-18 20:30:57 +03:00
|
|
|
m_qtVersionId = -1;
|
|
|
|
|
toolChainUpdated();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QtSupport::BaseQtVersion *version = QtSupport::QtVersionManager::instance()->version(id);
|
|
|
|
|
Q_ASSERT(version);
|
|
|
|
|
m_qtVersionId = id;
|
|
|
|
|
|
|
|
|
|
Q_ASSERT(version->qtAbis().count() == 1);
|
|
|
|
|
setTargetAbi(version->qtAbis().at(0));
|
|
|
|
|
|
|
|
|
|
toolChainUpdated();
|
2012-08-01 15:25:05 +02:00
|
|
|
setDisplayName(AndroidToolChainFactory::tr("Android GCC for %1").arg(version->displayName()));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AndroidToolChain::qtVersionId() const
|
|
|
|
|
{
|
|
|
|
|
return m_qtVersionId;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<Abi> AndroidToolChain::detectSupportedAbis() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
|
if (m_qtVersionId < 0)
|
2012-08-09 01:56:51 +02:00
|
|
|
return QList<Abi>();
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
AndroidQtVersion *aqv = dynamic_cast<AndroidQtVersion *>(QtSupport::QtVersionManager::instance()->version(m_qtVersionId));
|
|
|
|
|
if (!aqv)
|
2012-08-09 01:56:51 +02:00
|
|
|
return QList<Abi>();
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
return aqv->qtAbis();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// ToolChainConfigWidget
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
AndroidToolChainConfigWidget::AndroidToolChainConfigWidget(AndroidToolChain *tc) :
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChainConfigWidget(tc)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-16 15:59:10 +02:00
|
|
|
QLabel *label = new QLabel(AndroidConfigurations::instance().config().ndkLocation.toUserOutput());
|
|
|
|
|
m_mainLayout->addRow(tr("NDK Root:"), label);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// ToolChainFactory
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
AndroidToolChainFactory::AndroidToolChainFactory() :
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChainFactory()
|
2012-04-18 20:30:57 +03:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QString AndroidToolChainFactory::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return tr("Android GCC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidToolChainFactory::id() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String(Constants::ANDROID_TOOLCHAIN_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<ToolChain *> AndroidToolChainFactory::autoDetect()
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<ToolChain *> result;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
QtSupport::QtVersionManager *vm = QtSupport::QtVersionManager::instance();
|
|
|
|
|
connect(vm, SIGNAL(qtVersionsChanged(QList<int>,QList<int>,QList<int>)),
|
|
|
|
|
this, SLOT(handleQtVersionChanges(QList<int>,QList<int>,QList<int>)));
|
|
|
|
|
|
|
|
|
|
QList<int> versionList;
|
|
|
|
|
foreach (QtSupport::BaseQtVersion *v, vm->versions())
|
|
|
|
|
versionList.append(v->uniqueId());
|
|
|
|
|
|
|
|
|
|
return createToolChainList(versionList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidToolChainFactory::canRestore(const QVariantMap &data)
|
|
|
|
|
{
|
|
|
|
|
return idFromMap(data).startsWith(QLatin1String(Constants::ANDROID_TOOLCHAIN_ID) + QLatin1Char(':'));
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChain *AndroidToolChainFactory::restore(const QVariantMap &data)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
|
AndroidToolChain *tc = new AndroidToolChain(false);
|
|
|
|
|
if (tc->fromMap(data))
|
|
|
|
|
return tc;
|
|
|
|
|
|
|
|
|
|
delete tc;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidToolChainFactory::handleQtVersionChanges(const QList<int> &added, const QList<int> &removed, const QList<int> &changed)
|
|
|
|
|
{
|
|
|
|
|
QList<int> changes;
|
|
|
|
|
changes << added << removed << changed;
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChainManager *tcm = ToolChainManager::instance();
|
|
|
|
|
QList<ToolChain *> tcList = createToolChainList(changes);
|
|
|
|
|
foreach (ToolChain *tc, tcList)
|
2012-04-18 20:30:57 +03:00
|
|
|
tcm->registerToolChain(tc);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<ToolChain *> AndroidToolChainFactory::createToolChainList(const QList<int> &changes)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChainManager *tcm = ToolChainManager::instance();
|
2012-04-18 20:30:57 +03:00
|
|
|
QtSupport::QtVersionManager *vm = QtSupport::QtVersionManager::instance();
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<ToolChain *> result;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
foreach (int i, changes) {
|
|
|
|
|
QtSupport::BaseQtVersion *v = vm->version(i);
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<ToolChain *> toRemove;
|
|
|
|
|
foreach (ToolChain *tc, tcm->toolChains()) {
|
2012-04-18 20:30:57 +03:00
|
|
|
if (tc->id() != QLatin1String(Constants::ANDROID_TOOLCHAIN_ID))
|
|
|
|
|
continue;
|
|
|
|
|
AndroidToolChain *aTc = static_cast<AndroidToolChain *>(tc);
|
|
|
|
|
if (aTc->qtVersionId() == i)
|
|
|
|
|
toRemove.append(aTc);
|
|
|
|
|
}
|
2012-08-09 01:56:51 +02:00
|
|
|
foreach (ToolChain *tc, toRemove)
|
2012-04-18 20:30:57 +03:00
|
|
|
tcm->deregisterToolChain(tc);
|
|
|
|
|
|
|
|
|
|
const AndroidQtVersion * const aqv = dynamic_cast<AndroidQtVersion *>(v);
|
|
|
|
|
if (!aqv || !aqv->isValid())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
AndroidToolChain *aTc = new AndroidToolChain(true);
|
|
|
|
|
aTc->setQtVersionId(i);
|
|
|
|
|
aTc->setDisplayName(tr("Android GCC (%1-%2)")
|
2012-08-09 01:56:51 +02:00
|
|
|
.arg(Abi::toString(aTc->targetAbi().architecture()))
|
2012-04-18 20:30:57 +03:00
|
|
|
.arg(AndroidConfigurations::instance().config().ndkToolchainVersion));
|
2012-04-24 15:49:09 +02:00
|
|
|
aTc->setCompilerCommand(AndroidConfigurations::instance().gccPath(aTc->targetAbi().architecture()));
|
2012-04-18 20:30:57 +03:00
|
|
|
result.append(aTc);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Android
|