1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "winscwtoolchain.h"
36 #include "qt4projectmanager/qt4projectmanagerconstants.h"
37 #include "qtversionmanager.h"
39 #include "ui_winscwtoolchainconfigwidget.h"
40 #include "winscwparser.h"
42 #include <projectexplorer/abi.h>
43 #include <projectexplorer/headerpath.h>
44 #include <utils/environment.h>
46 #include <QtCore/QDir>
47 #include <QtCore/QFileInfo>
48 #include <QtCore/QStringList>
50 namespace Qt4ProjectManager {
53 static const char winscwCompilerPathKeyC[] = "Qt4ProjectManager.Winscw.CompilerPath";
54 static const char winscwSystemIncludePathKeyC[] = "Qt4ProjectManager.Winscw.IncludePath";
55 static const char winscwSystemLibraryPathKeyC[] = "Qt4ProjectManager.Winscw.LibraryPath";
57 static const char *const WINSCW_DEFAULT_SYSTEM_INCLUDES[] = {
58 "/MSL/MSL_C/MSL_Common/Include",
59 "/MSL/MSL_C/MSL_Win32/Include",
61 "/MSL/MSL_C++/MSL_Common/Include",
62 "/MSL/MSL_Extras/MSL_Common/Include",
63 "/MSL/MSL_Extras/MSL_Win32/Include",
64 "/Win32-x86 Support/Headers/Win32 SDK",
68 static const char *const WINSCW_DEFAULT_SYSTEM_LIBRARIES[] = {
69 "/Win32-x86 Support/Libraries/Win32 SDK",
70 "/Runtime/Runtime_x86/Runtime_Win32/Libs",
74 static QString winscwRoot(const QString &path)
83 dir.cd("Symbian_Support");
84 return dir.absolutePath();
87 static QString toNativePath(const QStringList &list)
89 return QDir::toNativeSeparators(list.join(QString(QLatin1Char(';'))));
92 static QStringList fromNativePath(const QString &list)
94 QString tmp = QDir::fromNativeSeparators(list);
95 return tmp.split(';');
98 static QStringList detectIncludesFor(const QString path)
100 QString root = winscwRoot(path);
102 for (int i = 0; WINSCW_DEFAULT_SYSTEM_INCLUDES[i] != 0; ++i) {
103 QDir dir(root + QLatin1String(WINSCW_DEFAULT_SYSTEM_INCLUDES[i]));
105 result.append(dir.absolutePath());
110 static QStringList detectLibrariesFor(const QString path)
112 QString root = winscwRoot(path);
114 for (int i = 0; WINSCW_DEFAULT_SYSTEM_LIBRARIES[i] != 0; ++i) {
115 QDir dir(root + QLatin1String(WINSCW_DEFAULT_SYSTEM_LIBRARIES[i]));
117 result.append(dir.absolutePath());
122 // --------------------------------------------------------------------------
124 // --------------------------------------------------------------------------
126 WinscwToolChain::WinscwToolChain(bool autodetected) :
127 ProjectExplorer::ToolChain(QLatin1String(Constants::WINSCW_TOOLCHAIN_ID), autodetected)
130 WinscwToolChain::WinscwToolChain(const WinscwToolChain &tc) :
131 ProjectExplorer::ToolChain(tc),
132 m_systemIncludePathes(tc.m_systemIncludePathes),
133 m_systemLibraryPathes(tc.m_systemLibraryPathes),
134 m_compilerPath(tc.m_compilerPath)
137 WinscwToolChain::~WinscwToolChain()
140 QString WinscwToolChain::typeName() const
142 return WinscwToolChainFactory::tr("WINSCW");
145 ProjectExplorer::Abi WinscwToolChain::targetAbi() const
147 return ProjectExplorer::Abi(ProjectExplorer::Abi::ArmArchitecture, ProjectExplorer::Abi::SymbianOS,
148 ProjectExplorer::Abi::SymbianEmulatorFlavor,
149 ProjectExplorer::Abi::ElfFormat, false);
152 bool WinscwToolChain::isValid() const
154 if (m_compilerPath.isEmpty())
157 QFileInfo fi(m_compilerPath);
158 return fi.exists() && fi.isExecutable();
161 QByteArray WinscwToolChain::predefinedMacros() const
163 return QByteArray("#define __SYMBIAN32__\n");
166 QList<ProjectExplorer::HeaderPath> WinscwToolChain::systemHeaderPaths() const
168 QList<ProjectExplorer::HeaderPath> result;
169 foreach (const QString &value, m_systemIncludePathes)
170 result.append(ProjectExplorer::HeaderPath(value, ProjectExplorer::HeaderPath::GlobalHeaderPath));
174 void WinscwToolChain::addToEnvironment(Utils::Environment &env) const
179 env.set(QLatin1String("MWCSYM2INCLUDES"), toNativePath(m_systemIncludePathes));
180 env.set(QLatin1String("MWSYM2LIBRARIES"), toNativePath(m_systemLibraryPathes));
181 env.set(QLatin1String("MWSYM2LIBRARYFILES"),
182 QLatin1String("MSL_All_MSE_Symbian_D.lib;gdi32.lib;user32.lib;kernel32.lib"));
183 env.prependOrSetPath(QFileInfo(m_compilerPath).absolutePath());
186 QString WinscwToolChain::makeCommand() const
189 return QLatin1String("make.exe");
191 return QLatin1String("make");
195 QString WinscwToolChain::debuggerCommand() const
200 QString WinscwToolChain::defaultMakeTarget() const
202 return QLatin1String("winscw");
205 ProjectExplorer::IOutputParser *WinscwToolChain::outputParser() const
207 return new WinscwParser;
210 bool WinscwToolChain::operator ==(const ProjectExplorer::ToolChain &tc) const
212 if (!ToolChain::operator ==(tc))
215 const WinscwToolChain *tcPtr = dynamic_cast<const WinscwToolChain *>(&tc);
217 return m_compilerPath == tcPtr->m_compilerPath
218 && m_systemIncludePathes == tcPtr->m_systemIncludePathes
219 && m_systemLibraryPathes == tcPtr->m_systemLibraryPathes;
222 ProjectExplorer::ToolChainConfigWidget *WinscwToolChain::configurationWidget()
224 return new WinscwToolChainConfigWidget(this);
227 ProjectExplorer::ToolChain *WinscwToolChain::clone() const
229 return new WinscwToolChain(*this);
232 QVariantMap WinscwToolChain::toMap() const
234 QVariantMap result = ToolChain::toMap();
235 result.insert(QLatin1String(winscwCompilerPathKeyC), m_compilerPath);
236 const QString semicolon = QString(QLatin1Char(';'));
237 result.insert(QLatin1String(winscwSystemIncludePathKeyC), m_systemIncludePathes.join(semicolon));
238 result.insert(QLatin1String(winscwSystemLibraryPathKeyC), m_systemLibraryPathes.join(semicolon));
242 bool WinscwToolChain::fromMap(const QVariantMap &data)
244 if (!ToolChain::fromMap(data))
246 m_compilerPath = data.value(QLatin1String(winscwCompilerPathKeyC)).toString();
247 const QChar semicolon = QLatin1Char(';');
248 m_systemIncludePathes = data.value(QLatin1String(winscwSystemIncludePathKeyC)).toString().split(semicolon);
249 m_systemLibraryPathes = data.value(QLatin1String(winscwSystemLibraryPathKeyC)).toString().split(semicolon);
253 void WinscwToolChain::setSystemIncludePathes(const QStringList &pathes)
255 if (m_systemIncludePathes == pathes)
257 m_systemIncludePathes = pathes;
261 QStringList WinscwToolChain::systemIncludePathes() const
263 return m_systemIncludePathes;
266 void WinscwToolChain::setSystemLibraryPathes(const QStringList &pathes)
268 if (m_systemLibraryPathes == pathes)
270 m_systemLibraryPathes = pathes;
274 QStringList WinscwToolChain::systemLibraryPathes() const
276 return m_systemLibraryPathes;
279 void WinscwToolChain::setCompilerPath(const QString &path)
281 if (m_compilerPath == path)
284 m_compilerPath = path;
285 updateId(); // Will trigger topolChainUpdated()!
288 QString WinscwToolChain::compilerPath() const
290 return m_compilerPath;
293 void WinscwToolChain::updateId()
295 setId(QString::fromLatin1("%1:%2").arg(Constants::WINSCW_TOOLCHAIN_ID).arg(m_compilerPath));
298 // --------------------------------------------------------------------------
299 // ToolChainConfigWidget
300 // --------------------------------------------------------------------------
302 WinscwToolChainConfigWidget::WinscwToolChainConfigWidget(WinscwToolChain *tc) :
303 ProjectExplorer::ToolChainConfigWidget(tc),
304 m_ui(new Ui::WinscwToolChainConfigWidget)
308 m_ui->compilerPath->setExpectedKind(Utils::PathChooser::ExistingCommand);
309 connect(m_ui->compilerPath, SIGNAL(changed(QString)),
310 this, SLOT(handleCompilerPathUpdate()));
311 connect(m_ui->includeEdit, SIGNAL(textChanged(QString)), this, SLOT(makeDirty()));
312 connect(m_ui->libraryEdit, SIGNAL(textChanged(QString)), this, SLOT(makeDirty()));
317 void WinscwToolChainConfigWidget::apply()
319 WinscwToolChain *tc = static_cast<WinscwToolChain *>(toolChain());
321 tc->setCompilerPath(m_ui->compilerPath->path());
322 tc->setSystemIncludePathes(fromNativePath(m_ui->includeEdit->text()));
323 tc->setSystemLibraryPathes(fromNativePath(m_ui->libraryEdit->text()));
326 void WinscwToolChainConfigWidget::discard()
328 WinscwToolChain *tc = static_cast<WinscwToolChain *>(toolChain());
330 m_ui->compilerPath->setPath(tc->compilerPath());
331 m_ui->includeEdit->setText(toNativePath(tc->systemIncludePathes()));
332 m_ui->libraryEdit->setText(toNativePath(tc->systemLibraryPathes()));
335 bool WinscwToolChainConfigWidget::isDirty() const
337 WinscwToolChain *tc = static_cast<WinscwToolChain *>(toolChain());
339 return tc->compilerPath() != m_ui->compilerPath->path()
340 || tc->systemIncludePathes() != fromNativePath(m_ui->includeEdit->text())
341 || tc->systemLibraryPathes() != fromNativePath(m_ui->libraryEdit->text());
344 void WinscwToolChainConfigWidget::handleCompilerPathUpdate()
346 QString path = m_ui->compilerPath->path();
352 m_ui->includeEdit->setText(toNativePath(detectIncludesFor(path)));
353 m_ui->libraryEdit->setText(toNativePath(detectLibrariesFor(path)));
356 void WinscwToolChainConfigWidget::makeDirty()
358 emit dirty(toolChain());
361 // --------------------------------------------------------------------------
363 // --------------------------------------------------------------------------
365 WinscwToolChainFactory::WinscwToolChainFactory() :
366 ProjectExplorer::ToolChainFactory()
369 QString WinscwToolChainFactory::displayName() const
374 QString WinscwToolChainFactory::id() const
376 return QLatin1String(Constants::WINSCW_TOOLCHAIN_ID);
379 QList<ProjectExplorer::ToolChain *> WinscwToolChainFactory::autoDetect()
381 QList<ProjectExplorer::ToolChain *> result;
383 // Compatibility to pre-2.2:
385 const QString path = QtVersionManager::instance()->popPendingMwcUpdate();
389 QFileInfo fi(path + QLatin1String("/x86Build/Symbian_Tools/Command_Line_Tools/mwwinrc.exe"));
390 if (fi.exists() && fi.isExecutable()) {
391 WinscwToolChain *tc = new WinscwToolChain(false);
392 tc->setCompilerPath(fi.absoluteFilePath());
393 tc->setDisplayName(tr("WINSCW from Qt version"));
398 QString cc = Utils::Environment::systemEnvironment().searchInPath(QLatin1String("mwwinrc"));
400 WinscwToolChain *tc = new WinscwToolChain(true);
401 tc->setCompilerPath(cc);
402 tc->setSystemIncludePathes(detectIncludesFor(cc));
403 tc->setSystemLibraryPathes(detectLibrariesFor(cc));
409 bool WinscwToolChainFactory::canCreate()
414 ProjectExplorer::ToolChain *WinscwToolChainFactory::create()
416 return new WinscwToolChain(false);
419 bool WinscwToolChainFactory::canRestore(const QVariantMap &data)
421 return idFromMap(data).startsWith(QLatin1String(Constants::WINSCW_TOOLCHAIN_ID));
424 ProjectExplorer::ToolChain *WinscwToolChainFactory::restore(const QVariantMap &data)
426 WinscwToolChain *tc = new WinscwToolChain(false);
427 if (tc->fromMap(data))
434 } // namespace Internal
435 } // namespace Qt4ProjectManager