1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "gccetoolchain.h"
34 #include "qt4projectmanagerconstants.h"
35 #include "qtversionmanager.h"
37 #include <utils/environment.h>
38 #include <utils/synchronousprocess.h>
39 #include <projectexplorer/headerpath.h>
41 #include <QtCore/QDir>
43 namespace Qt4ProjectManager {
46 static QString gcceVersion(const QString &command)
48 if (command.isEmpty())
52 QStringList arguments;
53 arguments << QLatin1String("-dumpversion");
54 Utils::Environment env = Utils::Environment::systemEnvironment();
55 env.set(QLatin1String("LC_ALL"), QLatin1String("C")); //override current locale settings
56 gxx.setEnvironment(env.toStringList());
57 gxx.setReadChannelMode(QProcess::MergedChannels);
58 gxx.start(command, arguments);
59 if (!gxx.waitForStarted()) {
60 qWarning("Cannot start '%s': %s", qPrintable(command), qPrintable(gxx.errorString()));
63 gxx.closeWriteChannel();
64 if (!gxx.waitForFinished()) {
65 Utils::SynchronousProcess::stopProcess(gxx);
66 qWarning("Timeout running '%s'.", qPrintable(command));
69 if (gxx.exitStatus() != QProcess::NormalExit) {
70 qWarning("'%s' crashed.", qPrintable(command));
74 if (gxx.canReadLine())
75 return gxx.readLine().trimmed();
81 // ==========================================================================
83 // ==========================================================================
85 QString GcceToolChain::typeName() const
87 return GcceToolChainFactory::tr("GCCE");
90 QByteArray GcceToolChain::predefinedMacros() const
92 if (m_predefinedMacros.isEmpty()) {
93 ProjectExplorer::GccToolChain::predefinedMacros();
94 m_predefinedMacros += "\n"
96 "#define __SYMBIAN32__\n";
98 return m_predefinedMacros;
101 void GcceToolChain::addToEnvironment(Utils::Environment &env) const
103 GccToolChain::addToEnvironment(env);
105 if (m_gcceVersion.isEmpty())
106 m_gcceVersion = gcceVersion(compilerPath());
107 if (m_gcceVersion.isEmpty())
110 env.set(QLatin1String("QT_GCCE_VERSION"), m_gcceVersion);
111 QString version = m_gcceVersion;
112 env.set(QString::fromLatin1("SBS_GCCE") + version.remove(QLatin1Char('.'))
113 + QLatin1String("BIN"),
114 QDir::toNativeSeparators(QFileInfo(compilerPath()).absolutePath()));
115 // Required for SBS, which checks the version output from its tools
116 // and gets confused by localized output.
117 env.set(QLatin1String("LANG"), QString(QLatin1Char('C')));
120 QString GcceToolChain::defaultMakeTarget() const
122 return QLatin1String("gcce");
125 ProjectExplorer::ToolChain *GcceToolChain::clone() const
127 return new GcceToolChain(*this);
130 GcceToolChain::GcceToolChain(bool autodetected) :
131 GccToolChain(QLatin1String(Constants::GCCE_TOOLCHAIN_ID), autodetected)
134 // ==========================================================================
135 // GcceToolChainFactory
136 // ==========================================================================
138 QString GcceToolChainFactory::displayName() const
143 QString GcceToolChainFactory::id() const
145 return QLatin1String(Constants::GCCE_TOOLCHAIN_ID);
148 QList<ProjectExplorer::ToolChain *> GcceToolChainFactory::autoDetect()
150 QList<ProjectExplorer::ToolChain *> result;
152 // Compatibility to pre-2.2:
154 const QString path = QtVersionManager::instance()->popPendingGcceUpdate();
158 QFileInfo fi(path + QLatin1String("/bin/arm-none-symbianelf-g++.exe"));
159 if (fi.exists() && fi.isExecutable()) {
160 GcceToolChain *tc = new GcceToolChain(false);
161 tc->setCompilerPath(fi.absoluteFilePath());
162 tc->setDisplayName(tr("GCCE from Qt version"));
167 QString fullPath = Utils::Environment::systemEnvironment().searchInPath(QLatin1String("arm-none-symbianelf-gcc"));
168 if (!fullPath.isEmpty()) {
169 GcceToolChain *tc = new GcceToolChain(true);
170 tc->setCompilerPath(fullPath);
171 tc->setDisplayName(tr("GCCE (%1)").arg(gcceVersion(fullPath)));
172 if (tc->targetAbi() == ProjectExplorer::Abi(ProjectExplorer::Abi::ArmArchitecture,
173 ProjectExplorer::Abi::SymbianOS,
174 ProjectExplorer::Abi::SymbianDeviceFlavor,
175 ProjectExplorer::Abi::ElfFormat,
182 bool GcceToolChainFactory::canCreate()
187 ProjectExplorer::ToolChain *GcceToolChainFactory::create()
189 GcceToolChain *tc = new GcceToolChain(false);
190 tc->setDisplayName(tr("GCCE"));
194 bool GcceToolChainFactory::canRestore(const QVariantMap &data)
196 return idFromMap(data).startsWith(QLatin1String(Constants::GCCE_TOOLCHAIN_ID));
199 ProjectExplorer::ToolChain *GcceToolChainFactory::restore(const QVariantMap &data)
201 GcceToolChain *tc = new GcceToolChain(false);
202 if (tc->fromMap(data))
209 } // namespace Internal
210 } // namespace Qt4ProjectManager