2009-03-20 14:57:12 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2009-02-10 15:34:25 +01:00
|
|
|
#include "toolchain.h"
|
2009-09-29 11:39:55 +02:00
|
|
|
#include "project.h"
|
2009-02-10 15:34:25 +01:00
|
|
|
#include "cesdkhandler.h"
|
2009-09-25 11:35:44 +02:00
|
|
|
#include "projectexplorersettings.h"
|
2009-12-09 13:54:46 +01:00
|
|
|
#include "gccparser.h"
|
|
|
|
|
#include "msvcparser.h"
|
2010-04-09 18:43:05 +02:00
|
|
|
#include "linuxiccparser.h"
|
2009-03-20 14:57:12 +01:00
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
|
|
|
|
|
#include <utils/synchronousprocess.h>
|
|
|
|
|
|
2009-12-09 13:54:46 +01:00
|
|
|
#include <QtCore/QDebug>
|
2009-02-10 15:34:25 +01:00
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QProcess>
|
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QTemporaryFile>
|
|
|
|
|
#include <QtCore/QString>
|
2009-06-18 15:16:18 +02:00
|
|
|
#include <QtCore/QCoreApplication>
|
2009-02-10 15:34:25 +01:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace ProjectExplorer::Internal;
|
|
|
|
|
|
2010-03-04 15:23:02 +01:00
|
|
|
enum { debug = 0 };
|
|
|
|
|
|
2009-05-20 12:59:19 +02:00
|
|
|
#ifdef Q_OS_WIN64
|
2010-03-04 15:23:02 +01:00
|
|
|
static const char MSVC_RegKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7";
|
2009-05-20 12:59:19 +02:00
|
|
|
#else
|
2010-03-04 15:23:02 +01:00
|
|
|
static const char MSVC_RegKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7";
|
2009-05-20 12:59:19 +02:00
|
|
|
#endif
|
|
|
|
|
|
2009-02-10 15:34:25 +01:00
|
|
|
bool ToolChain::equals(ToolChain *a, ToolChain *b)
|
|
|
|
|
{
|
|
|
|
|
if (a == b)
|
|
|
|
|
return true;
|
|
|
|
|
if (a == 0 || b == 0)
|
|
|
|
|
return false;
|
|
|
|
|
if (a->type() == b->type())
|
2009-06-22 12:45:07 +02:00
|
|
|
return a->equals(b);
|
2009-02-11 13:01:38 +01:00
|
|
|
return false;
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain::ToolChain()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain::~ToolChain()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain *ToolChain::createGccToolChain(const QString &gcc)
|
|
|
|
|
{
|
|
|
|
|
return new GccToolChain(gcc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain *ToolChain::createMinGWToolChain(const QString &gcc, const QString &mingwPath)
|
|
|
|
|
{
|
|
|
|
|
return new MinGWToolChain(gcc, mingwPath);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-09 18:43:05 +02:00
|
|
|
ToolChain *ToolChain::createLinuxIccToolChain()
|
|
|
|
|
{
|
|
|
|
|
return new LinuxIccToolChain();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-04 15:23:02 +01:00
|
|
|
ToolChain *ToolChain::createMSVCToolChain(const QString &name, bool amd64)
|
2009-02-10 15:34:25 +01:00
|
|
|
{
|
2010-03-04 15:23:02 +01:00
|
|
|
return MSVCToolChain::create(name, amd64);
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain *ToolChain::createWinCEToolChain(const QString &name, const QString &platform)
|
|
|
|
|
{
|
2010-03-04 15:23:02 +01:00
|
|
|
return WinCEToolChain::create(name, platform);
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ToolChain::availableMSVCVersions()
|
|
|
|
|
{
|
2010-03-04 15:23:02 +01:00
|
|
|
QStringList rc;
|
|
|
|
|
foreach(const MSVCToolChain::Installation &i, MSVCToolChain::installations())
|
|
|
|
|
rc.push_back(i.name);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ToolChain::availableMSVCVersions(bool amd64)
|
|
|
|
|
{
|
|
|
|
|
QStringList rc;
|
|
|
|
|
foreach(const MSVCToolChain::Installation &i, MSVCToolChain::installations())
|
|
|
|
|
if (i.is64bit() == amd64)
|
|
|
|
|
rc.push_back(i.name);
|
|
|
|
|
return rc;
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
2009-08-13 16:42:17 +02:00
|
|
|
QList<ToolChain::ToolChainType> ToolChain::supportedToolChains()
|
2009-03-12 13:50:43 +01:00
|
|
|
{
|
2009-08-13 16:42:17 +02:00
|
|
|
QList<ToolChain::ToolChainType> toolChains;
|
|
|
|
|
for (int i = 0; i < LAST_VALID; ++i) {
|
|
|
|
|
toolChains.append(ToolChainType(i));
|
|
|
|
|
}
|
|
|
|
|
return toolChains;
|
2009-03-12 13:50:43 +01:00
|
|
|
}
|
|
|
|
|
|
2009-06-18 15:16:18 +02:00
|
|
|
QString ToolChain::toolChainName(ToolChainType tc)
|
|
|
|
|
{
|
|
|
|
|
switch (tc) {
|
|
|
|
|
case GCC:
|
2009-08-12 14:26:04 +02:00
|
|
|
return QCoreApplication::translate("ToolChain", "GCC");
|
2010-04-09 18:43:05 +02:00
|
|
|
case LINUX_ICC:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "Intel C++ Compiler (Linux)");
|
2009-06-18 15:16:18 +02:00
|
|
|
case MinGW:
|
2009-11-05 14:05:21 +01:00
|
|
|
return QString::fromLatin1("MinGW");
|
2009-06-18 15:16:18 +02:00
|
|
|
case MSVC:
|
2009-08-13 14:07:27 +02:00
|
|
|
return QCoreApplication::translate("ToolChain", "Microsoft Visual C++");
|
2009-06-18 15:16:18 +02:00
|
|
|
case WINCE:
|
2009-08-12 14:26:04 +02:00
|
|
|
return QCoreApplication::translate("ToolChain", "Windows CE");
|
2009-08-13 16:42:17 +02:00
|
|
|
case WINSCW:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "WINSCW");
|
|
|
|
|
case GCCE:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "GCCE");
|
2009-11-13 15:47:35 +01:00
|
|
|
case GCCE_GNUPOC:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "GCCE/GnuPoc");
|
2010-02-17 17:38:48 +01:00
|
|
|
case RVCT_ARMV5_GNUPOC:
|
2009-11-13 15:47:35 +01:00
|
|
|
return QCoreApplication::translate("ToolChain", "RVCT (ARMV6)/GnuPoc");
|
2009-08-13 16:42:17 +02:00
|
|
|
case RVCT_ARMV5:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "RVCT (ARMV5)");
|
|
|
|
|
case RVCT_ARMV6:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "RVCT (ARMV6)");
|
2009-10-16 17:33:12 +02:00
|
|
|
case GCC_MAEMO:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "GCC for Maemo");
|
2009-06-18 15:16:18 +02:00
|
|
|
case OTHER:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "Other");
|
|
|
|
|
case INVALID:
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "<Invalid>");
|
|
|
|
|
case UNKNOWN:
|
|
|
|
|
break;
|
2009-08-21 15:59:17 +02:00
|
|
|
default:
|
2009-08-13 17:36:23 +02:00
|
|
|
Q_ASSERT("Missing name for Toolchaintype");
|
2009-06-18 15:16:18 +02:00
|
|
|
};
|
|
|
|
|
return QCoreApplication::translate("ToolChain", "<Unknown>");
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-10 15:34:25 +01:00
|
|
|
GccToolChain::GccToolChain(const QString &gcc)
|
|
|
|
|
: m_gcc(gcc)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain::ToolChainType GccToolChain::type() const
|
|
|
|
|
{
|
|
|
|
|
return ToolChain::GCC;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
static QByteArray gccPredefinedMacros(const QString &gcc, const QStringList &env)
|
2009-02-10 15:34:25 +01:00
|
|
|
{
|
2010-09-08 15:22:58 +02:00
|
|
|
QStringList arguments;
|
|
|
|
|
arguments << QLatin1String("-xc++")
|
|
|
|
|
<< QLatin1String("-E")
|
|
|
|
|
<< QLatin1String("-dM")
|
|
|
|
|
<< QLatin1String("-");
|
2009-02-10 15:34:25 +01:00
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
QProcess cpp;
|
|
|
|
|
cpp.setEnvironment(env);
|
|
|
|
|
cpp.start(gcc, arguments);
|
|
|
|
|
if (!cpp.waitForStarted()) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Cannot start '%s': %s", Q_FUNC_INFO, qPrintable(gcc),
|
|
|
|
|
qPrintable(cpp.errorString()));
|
2010-09-08 15:22:58 +02:00
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
cpp.closeWriteChannel();
|
|
|
|
|
if (!cpp.waitForFinished()) {
|
|
|
|
|
Utils::SynchronousProcess::stopProcess(cpp);
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Timeout running '%s'.", Q_FUNC_INFO, qPrintable(gcc));
|
2010-09-08 15:22:58 +02:00
|
|
|
return QByteArray();
|
|
|
|
|
}
|
2010-09-09 09:58:17 +02:00
|
|
|
if (cpp.exitStatus() != QProcess::NormalExit) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: '%s' crashed.", Q_FUNC_INFO, qPrintable(gcc));
|
2010-09-09 09:58:17 +02:00
|
|
|
return QByteArray();
|
|
|
|
|
}
|
2010-09-08 15:22:58 +02:00
|
|
|
QByteArray predefinedMacros = cpp.readAllStandardOutput();
|
2010-01-22 09:33:34 +01:00
|
|
|
#ifdef Q_OS_MAC
|
2010-09-08 15:22:58 +02:00
|
|
|
// Turn off flag indicating Apple's blocks support
|
|
|
|
|
const QByteArray blocksDefine("#define __BLOCKS__ 1");
|
|
|
|
|
const QByteArray blocksUndefine("#undef __BLOCKS__");
|
|
|
|
|
const int idx = predefinedMacros.indexOf(blocksDefine);
|
|
|
|
|
if (idx != -1) {
|
|
|
|
|
predefinedMacros.replace(idx, blocksDefine.length(), blocksUndefine);
|
|
|
|
|
}
|
2010-01-22 10:04:01 +01:00
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
// Define __strong and __weak (used for Apple's GC extension of C) to be empty
|
|
|
|
|
predefinedMacros.append("#define __strong\n");
|
|
|
|
|
predefinedMacros.append("#define __weak\n");
|
2010-01-22 09:33:34 +01:00
|
|
|
#endif // Q_OS_MAC
|
2010-09-08 15:22:58 +02:00
|
|
|
return predefinedMacros;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray GccToolChain::predefinedMacros()
|
|
|
|
|
{
|
|
|
|
|
if (m_predefinedMacros.isEmpty()) {
|
|
|
|
|
ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
|
|
|
|
|
addToEnvironment(env);
|
|
|
|
|
m_predefinedMacros = gccPredefinedMacros(m_gcc, env.toStringList());
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
return m_predefinedMacros;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
static QList<HeaderPath> gccSystemHeaderPaths(const QString &gcc, ProjectExplorer::Environment env)
|
2009-02-10 15:34:25 +01:00
|
|
|
{
|
2010-09-08 15:22:58 +02:00
|
|
|
QList<HeaderPath> systemHeaderPaths;
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
arguments << QLatin1String("-xc++")
|
|
|
|
|
<< QLatin1String("-E")
|
|
|
|
|
<< QLatin1String("-v")
|
|
|
|
|
<< QLatin1String("-");
|
2009-02-10 15:34:25 +01:00
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
QProcess cpp;
|
|
|
|
|
env.set(QLatin1String("LC_ALL"), QLatin1String("C")); //override current locale settings
|
|
|
|
|
cpp.setEnvironment(env.toStringList());
|
|
|
|
|
cpp.setReadChannelMode(QProcess::MergedChannels);
|
|
|
|
|
cpp.start(gcc, arguments);
|
|
|
|
|
if (!cpp.waitForStarted()) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Cannot start '%s': %s", Q_FUNC_INFO, qPrintable(gcc),
|
|
|
|
|
qPrintable(cpp.errorString()));
|
2010-09-08 15:22:58 +02:00
|
|
|
return systemHeaderPaths;
|
|
|
|
|
}
|
|
|
|
|
cpp.closeWriteChannel();
|
|
|
|
|
if (!cpp.waitForFinished()) {
|
|
|
|
|
Utils::SynchronousProcess::stopProcess(cpp);
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Timeout running '%s'.", Q_FUNC_INFO, qPrintable(gcc));
|
2010-09-08 15:22:58 +02:00
|
|
|
return systemHeaderPaths;
|
|
|
|
|
}
|
2010-09-09 09:58:17 +02:00
|
|
|
if (cpp.exitStatus() != QProcess::NormalExit) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: '%s' crashed.", Q_FUNC_INFO, qPrintable(gcc));
|
2010-09-09 09:58:17 +02:00
|
|
|
return systemHeaderPaths;
|
|
|
|
|
}
|
2010-09-08 15:22:58 +02:00
|
|
|
QByteArray line;
|
|
|
|
|
while (cpp.canReadLine()) {
|
|
|
|
|
line = cpp.readLine();
|
|
|
|
|
if (line.startsWith("#include"))
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-02-10 15:34:25 +01:00
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
if (! line.isEmpty() && line.startsWith("#include")) {
|
|
|
|
|
HeaderPath::Kind kind = HeaderPath::UserHeaderPath;
|
|
|
|
|
while (cpp.canReadLine()) {
|
|
|
|
|
line = cpp.readLine();
|
|
|
|
|
if (line.startsWith("#include")) {
|
|
|
|
|
kind = HeaderPath::GlobalHeaderPath;
|
|
|
|
|
} else if (! line.isEmpty() && QChar(line.at(0)).isSpace()) {
|
|
|
|
|
HeaderPath::Kind thisHeaderKind = kind;
|
|
|
|
|
|
|
|
|
|
line = line.trimmed();
|
|
|
|
|
if (line.endsWith('\n'))
|
|
|
|
|
line.chop(1);
|
|
|
|
|
|
|
|
|
|
const int index = line.indexOf(" (framework directory)");
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
line.truncate(index);
|
|
|
|
|
thisHeaderKind = HeaderPath::FrameworkHeaderPath;
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
2010-09-08 15:22:58 +02:00
|
|
|
|
|
|
|
|
systemHeaderPaths.append(HeaderPath(QFile::decodeName(line), thisHeaderKind));
|
|
|
|
|
} else if (line.startsWith("End of search list.")) {
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "ignore line:" << line;
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-08 15:22:58 +02:00
|
|
|
return systemHeaderPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<HeaderPath> GccToolChain::systemHeaderPaths()
|
|
|
|
|
{
|
|
|
|
|
if (m_systemHeaderPaths.isEmpty()) {
|
|
|
|
|
ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
|
|
|
|
|
addToEnvironment(env);
|
|
|
|
|
m_systemHeaderPaths = gccSystemHeaderPaths(m_gcc, env);
|
|
|
|
|
}
|
2009-02-10 15:34:25 +01:00
|
|
|
return m_systemHeaderPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GccToolChain::addToEnvironment(ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(env)
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-16 18:13:45 +01:00
|
|
|
QString GccToolChain::makeCommand() const
|
|
|
|
|
{
|
2009-12-09 13:54:46 +01:00
|
|
|
return QLatin1String("make");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IOutputParser *GccToolChain::outputParser() const
|
|
|
|
|
{
|
|
|
|
|
return new GccParser;
|
2009-03-16 18:13:45 +01:00
|
|
|
}
|
|
|
|
|
|
2009-02-10 15:34:25 +01:00
|
|
|
bool GccToolChain::equals(ToolChain *other) const
|
|
|
|
|
{
|
|
|
|
|
return (m_gcc == static_cast<GccToolChain *>(other)->m_gcc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinGWToolChain::MinGWToolChain(const QString &gcc, const QString &mingwPath)
|
|
|
|
|
: GccToolChain(gcc), m_mingwPath(mingwPath)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain::ToolChainType MinGWToolChain::type() const
|
|
|
|
|
{
|
|
|
|
|
return ToolChain::MinGW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MinGWToolChain::equals(ToolChain *other) const
|
|
|
|
|
{
|
|
|
|
|
MinGWToolChain *o = static_cast<MinGWToolChain *>(other);
|
|
|
|
|
return (m_mingwPath == o->m_mingwPath && this->GccToolChain::equals(other));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MinGWToolChain::addToEnvironment(ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
2010-03-04 15:23:02 +01:00
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "MinGWToolChain::addToEnvironment" << m_mingwPath;
|
2009-07-03 19:06:00 +02:00
|
|
|
if (m_mingwPath.isEmpty())
|
|
|
|
|
return;
|
2010-03-04 15:23:02 +01:00
|
|
|
const QString binDir = m_mingwPath + "/bin";
|
2009-02-10 15:34:25 +01:00
|
|
|
if (QFileInfo(binDir).exists())
|
|
|
|
|
env.prependOrSetPath(binDir);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-16 18:13:45 +01:00
|
|
|
QString MinGWToolChain::makeCommand() const
|
|
|
|
|
{
|
2009-12-09 13:54:46 +01:00
|
|
|
return QLatin1String("mingw32-make.exe");
|
2009-03-16 18:13:45 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-09 13:54:46 +01:00
|
|
|
IOutputParser *MinGWToolChain::outputParser() const
|
|
|
|
|
{
|
|
|
|
|
return new GccParser;
|
|
|
|
|
}
|
2009-02-10 15:34:25 +01:00
|
|
|
|
2010-04-09 18:43:05 +02:00
|
|
|
LinuxIccToolChain::LinuxIccToolChain()
|
|
|
|
|
: GccToolChain(QLatin1String("icpc"))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain::ToolChainType LinuxIccToolChain::type() const
|
|
|
|
|
{
|
|
|
|
|
return ToolChain::LINUX_ICC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IOutputParser *LinuxIccToolChain::outputParser() const
|
|
|
|
|
{
|
|
|
|
|
return new LinuxIccParser;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-04 15:23:02 +01:00
|
|
|
// ---------------- MSVC installation location code
|
|
|
|
|
|
|
|
|
|
// Format the name of an SDK or VC installation version with platform
|
|
|
|
|
static inline QString installationName(const QString &name,
|
|
|
|
|
MSVCToolChain::Installation::Type t,
|
|
|
|
|
MSVCToolChain::Installation::Platform p)
|
2009-02-10 15:34:25 +01:00
|
|
|
{
|
2010-03-04 15:23:02 +01:00
|
|
|
if (t == MSVCToolChain::Installation::WindowsSDK) {
|
|
|
|
|
QString sdkName = name;
|
|
|
|
|
sdkName += QLatin1String(" (");
|
|
|
|
|
sdkName += MSVCToolChain::Installation::platformName(p);
|
|
|
|
|
sdkName += QLatin1Char(')');
|
|
|
|
|
return sdkName;
|
2009-02-12 16:09:23 +01:00
|
|
|
}
|
2010-03-04 15:23:02 +01:00
|
|
|
// Comes as "9.0" from the registry
|
|
|
|
|
QString vcName = QLatin1String("Microsoft Visual C++ Compilers ");
|
|
|
|
|
vcName += name;
|
|
|
|
|
vcName+= QLatin1String(" (");
|
|
|
|
|
vcName += MSVCToolChain::Installation::platformName(p);
|
|
|
|
|
vcName += QLatin1Char(')');
|
|
|
|
|
return vcName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSVCToolChain::Installation::Installation(Type t, const QString &n, Platform p,
|
|
|
|
|
const QString &v, const QString &a) :
|
|
|
|
|
type(t), name(installationName(n, t, p)), platform(p), varsBat(v), varsBatArg(a)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSVCToolChain::Installation::Installation() : platform(s32)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MSVCToolChain::Installation::platformName(Platform t)
|
|
|
|
|
{
|
|
|
|
|
switch (t) {
|
|
|
|
|
case s32:
|
|
|
|
|
return QLatin1String("x86");
|
|
|
|
|
case s64:
|
|
|
|
|
return QLatin1String("x64");
|
|
|
|
|
case ia64:
|
|
|
|
|
return QLatin1String("ia64");
|
|
|
|
|
case amd64:
|
|
|
|
|
return QLatin1String("amd64");
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MSVCToolChain::Installation::is64bit() const
|
|
|
|
|
{
|
|
|
|
|
return platform != s32;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSVCToolChain::InstallationList MSVCToolChain::installations()
|
|
|
|
|
{
|
|
|
|
|
static InstallationList installs;
|
|
|
|
|
static bool firstTime = true;
|
|
|
|
|
if (firstTime) {
|
|
|
|
|
firstTime = false;
|
|
|
|
|
// 1) Installed SDKs preferred over standalone Visual studio
|
|
|
|
|
const char sdk_RegKeyC[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows";
|
|
|
|
|
const QSettings sdkRegistry(sdk_RegKeyC, QSettings::NativeFormat);
|
|
|
|
|
const QString defaultSdkPath = sdkRegistry.value(QLatin1String("CurrentInstallFolder")).toString();
|
|
|
|
|
if (!defaultSdkPath.isEmpty()) {
|
|
|
|
|
foreach(const QString &sdkKey, sdkRegistry.childGroups()) {
|
|
|
|
|
const QString name = sdkRegistry.value(sdkKey + QLatin1String("/ProductName")).toString();
|
|
|
|
|
const QString folder = sdkRegistry.value(sdkKey + QLatin1String("/InstallationFolder")).toString();
|
|
|
|
|
if (!folder.isEmpty()) {
|
|
|
|
|
const QString sdkVcVarsBat = folder + QLatin1String("bin\\SetEnv.cmd");
|
|
|
|
|
if (QFileInfo(sdkVcVarsBat).exists()) {
|
|
|
|
|
// Add all platforms
|
|
|
|
|
InstallationList newInstalls;
|
|
|
|
|
newInstalls.push_back(Installation(Installation::WindowsSDK, name, Installation::s32, sdkVcVarsBat, QLatin1String("/x86")));
|
|
|
|
|
#ifdef Q_OS_WIN64
|
|
|
|
|
newInstalls.push_back(Installation(Installation::WindowsSDK, name, Installation::s64, sdkVcVarsBat, QLatin1String("/x64")));
|
|
|
|
|
newInstalls.push_back(Installation(Installation::WindowsSDK, name, Installation::ia64, sdkVcVarsBat, QLatin1String("/ia64")));
|
|
|
|
|
#endif
|
|
|
|
|
// Make sure the default is front.
|
|
|
|
|
if (folder == defaultSdkPath && !installs.empty()) {
|
|
|
|
|
const InstallationList old = installs;
|
|
|
|
|
installs = newInstalls + old;
|
|
|
|
|
} else {
|
|
|
|
|
installs.append(newInstalls);
|
|
|
|
|
}
|
|
|
|
|
} // bat exists
|
|
|
|
|
} // folder
|
|
|
|
|
} // foreach
|
|
|
|
|
}
|
|
|
|
|
// 2) Installed MSVCs
|
|
|
|
|
const QSettings vsRegistry(MSVC_RegKey, QSettings::NativeFormat);
|
|
|
|
|
foreach(const QString &vsName, vsRegistry.allKeys()) {
|
2010-06-23 10:58:40 +02:00
|
|
|
const int dotPos = vsName.indexOf(QLatin1Char('.'));
|
|
|
|
|
if (dotPos != -1) { // Scan for version major.minor
|
2010-03-04 15:23:02 +01:00
|
|
|
const QString path = vsRegistry.value(vsName).toString();
|
2010-06-23 10:58:40 +02:00
|
|
|
const int version = vsName.left(dotPos).toInt();
|
2010-03-04 15:23:02 +01:00
|
|
|
// Check existence of various install scripts
|
|
|
|
|
const QString vcvars32bat = path + QLatin1String("bin\\vcvars32.bat");
|
|
|
|
|
if (QFileInfo(vcvars32bat).isFile())
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::s32, vcvars32bat));
|
2010-06-23 10:58:40 +02:00
|
|
|
if (version >= 10) {
|
|
|
|
|
// Just one common file
|
|
|
|
|
const QString vcvarsAllbat = path + QLatin1String("vcvarsall.bat");
|
|
|
|
|
if (QFileInfo(vcvarsAllbat).isFile()) {
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::s32, vcvarsAllbat, QLatin1String("x86")));
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::amd64, vcvarsAllbat, QLatin1String("amd64")));
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::s64, vcvarsAllbat, QLatin1String("x64")));
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::ia64, vcvarsAllbat, QLatin1String("ia64")));
|
|
|
|
|
} else {
|
|
|
|
|
qWarning("Unable to find MSVC setup script %s in version %d", qPrintable(vcvarsAllbat), version);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Amd 64 is the preferred 64bit platform
|
|
|
|
|
const QString vcvarsAmd64bat = path + QLatin1String("bin\\amd64\\vcvarsamd64.bat");
|
|
|
|
|
if (QFileInfo(vcvarsAmd64bat).isFile())
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::amd64, vcvarsAmd64bat));
|
|
|
|
|
const QString vcvarsAmd64bat2 = path + QLatin1String("bin\\vcvarsx86_amd64.bat");
|
|
|
|
|
if (QFileInfo(vcvarsAmd64bat2).isFile())
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::amd64, vcvarsAmd64bat2));
|
|
|
|
|
const QString vcvars64bat = path + QLatin1String("bin\\vcvars64.bat");
|
|
|
|
|
if (QFileInfo(vcvars64bat).isFile())
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::s64, vcvars64bat));
|
|
|
|
|
const QString vcvarsIA64bat = path + QLatin1String("bin\\vcvarsx86_ia64.bat");
|
|
|
|
|
if (QFileInfo(vcvarsIA64bat).isFile())
|
|
|
|
|
installs.push_back(Installation(Installation::VS, vsName, Installation::ia64, vcvarsIA64bat));
|
|
|
|
|
}
|
2010-03-04 15:23:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (debug)
|
|
|
|
|
foreach(const Installation &i, installs)
|
|
|
|
|
qDebug() << i;
|
|
|
|
|
return installs;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-21 17:24:37 +02:00
|
|
|
// Return a substring to match the MSVC official version against by mkSpec name.
|
|
|
|
|
static inline const QString msvcVersionStringFromMkSpec(const QString &mkSpec)
|
|
|
|
|
{
|
|
|
|
|
if (mkSpec.isEmpty())
|
|
|
|
|
return QString();
|
|
|
|
|
if (mkSpec.endsWith(QLatin1String("msvc2002")))
|
|
|
|
|
return QLatin1String(" 7.0");
|
|
|
|
|
if (mkSpec.endsWith(QLatin1String("msvc2003")))
|
|
|
|
|
return QLatin1String(" 7.1");
|
|
|
|
|
if (mkSpec.endsWith(QLatin1String("msvc2005")))
|
|
|
|
|
return QLatin1String(" 8.0");
|
|
|
|
|
if (mkSpec.endsWith(QLatin1String("msvc2008")))
|
|
|
|
|
return QLatin1String(" 9.0");
|
|
|
|
|
if (mkSpec.endsWith(QLatin1String("msvc2010")))
|
|
|
|
|
return QLatin1String(" 10.0");
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSVCToolChain::Installation MSVCToolChain::findInstallationByMkSpec(bool is64Bit,
|
|
|
|
|
const QString &mkSpec,
|
|
|
|
|
bool excludeSDK)
|
|
|
|
|
{
|
|
|
|
|
const QString mkSpecMatchString = msvcVersionStringFromMkSpec(mkSpec);
|
|
|
|
|
if (!mkSpecMatchString.isEmpty()) {
|
|
|
|
|
foreach(const Installation &i, installations()) {
|
|
|
|
|
if ((i.type == Installation::VS) && (i.is64bit() == is64Bit)
|
|
|
|
|
&& (i.name.indexOf(mkSpecMatchString) != -1))
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return findInstallationByName(is64Bit, QString(), excludeSDK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSVCToolChain::Installation MSVCToolChain::findInstallationByName(bool is64Bit,
|
2010-03-04 15:23:02 +01:00
|
|
|
const QString &name,
|
|
|
|
|
bool excludeSDK)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "find" << (is64Bit ? 64 : 32) << name << excludeSDK;
|
|
|
|
|
foreach(const Installation &i, installations()) {
|
|
|
|
|
if (i.type != Installation::WindowsSDK || !excludeSDK) {
|
|
|
|
|
if ((i.is64bit() == is64Bit) && (name.isEmpty() || name == i.name))
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Installation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
PROJECTEXPLORER_EXPORT QDebug operator<<(QDebug in, const MSVCToolChain::Installation &i)
|
|
|
|
|
{
|
|
|
|
|
QDebug nsp = in.nospace();
|
|
|
|
|
nsp << "Type: " << i.type << " Platform: " << i.platform << " Name: " << i.name
|
|
|
|
|
<< "\nSetup: " << i.varsBat;
|
|
|
|
|
if (!i.varsBatArg.isEmpty())
|
|
|
|
|
nsp << "\nSetup argument: " << i.varsBatArg;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSVCToolChain *MSVCToolChain::create(const QString &name, bool amd64)
|
|
|
|
|
{
|
2010-04-21 17:24:37 +02:00
|
|
|
return new MSVCToolChain(MSVCToolChain::findInstallationByName(amd64, name));
|
2010-03-04 15:23:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSVCToolChain::MSVCToolChain(const Installation &in) :
|
|
|
|
|
m_installation(in),
|
|
|
|
|
m_valuesSet(false)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "\nMSVCToolChain::CT\n" << m_installation;
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain::ToolChainType MSVCToolChain::type() const
|
|
|
|
|
{
|
|
|
|
|
return ToolChain::MSVC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MSVCToolChain::equals(ToolChain *other) const
|
|
|
|
|
{
|
|
|
|
|
MSVCToolChain *o = static_cast<MSVCToolChain *>(other);
|
2010-03-04 15:23:02 +01:00
|
|
|
return (m_installation.name == o->m_installation.name);
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
2009-09-16 17:16:29 +02:00
|
|
|
QByteArray msvcCompilationFile() {
|
|
|
|
|
static const char* macros[] = {"_ATL_VER", "_CHAR_UNSIGNED", "__CLR_VER",
|
|
|
|
|
"__cplusplus_cli", "__COUNTER__", "__cplusplus",
|
|
|
|
|
"_CPPLIB_VER", "_CPPRTTI", "_CPPUNWIND",
|
|
|
|
|
"_DEBUG", "_DLL", "__FUNCDNAME__",
|
|
|
|
|
"__FUNCSIG__","__FUNCTION__","_INTEGRAL_MAX_BITS",
|
|
|
|
|
"_M_ALPHA","_M_CEE","_M_CEE_PURE",
|
|
|
|
|
"_M_CEE_SAFE","_M_IX86","_M_IA64",
|
|
|
|
|
"_M_IX86_FP","_M_MPPC","_M_MRX000",
|
|
|
|
|
"_M_PPC","_M_X64","_MANAGED",
|
2009-12-10 16:39:04 +01:00
|
|
|
"_MFC_VER","_MSC_BUILD", /* "_MSC_EXTENSIONS", */
|
2009-09-16 17:16:29 +02:00
|
|
|
"_MSC_FULL_VER","_MSC_VER","__MSVC_RUNTIME_CHECKS",
|
|
|
|
|
"_MT", "_NATIVE_WCHAR_T_DEFINED", "_OPENMP",
|
|
|
|
|
"_VC_NODEFAULTLIB", "_WCHAR_T_DEFINED", "_WIN32",
|
2009-10-15 16:32:38 +02:00
|
|
|
"_WIN32_WCE", "_WIN64", "_Wp64", "__DATE__",
|
|
|
|
|
"__DATE__", "__TIME__", "__TIMESTAMP__",
|
2009-09-16 17:16:29 +02:00
|
|
|
0};
|
|
|
|
|
QByteArray file = "#define __PPOUT__(x) V##x=x\n\n";
|
|
|
|
|
int i =0;
|
|
|
|
|
while (macros[i] != 0) {
|
|
|
|
|
const QByteArray macro(macros[i]);
|
|
|
|
|
file += "#if defined(" + macro + ")\n__PPOUT__("
|
|
|
|
|
+ macro + ")\n#endif\n";
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
file += "\nvoid main(){}\n\n";
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
// Run MSVC 'cl' compiler to obtain #defines.
|
|
|
|
|
static QByteArray msvcPredefinedMacros(const QStringList &env)
|
|
|
|
|
{
|
|
|
|
|
QByteArray predefinedMacros = "#define __MSVCRT__\n"
|
|
|
|
|
"#define __w64\n"
|
|
|
|
|
"#define __int64 long long\n"
|
|
|
|
|
"#define __int32 long\n"
|
|
|
|
|
"#define __int16 short\n"
|
|
|
|
|
"#define __int8 char\n"
|
|
|
|
|
"#define __ptr32\n"
|
|
|
|
|
"#define __ptr64\n";
|
|
|
|
|
|
|
|
|
|
QString tmpFilePath;
|
|
|
|
|
{
|
|
|
|
|
// QTemporaryFile is buggy and will not unlock the file for cl.exe
|
|
|
|
|
QTemporaryFile tmpFile(QDir::tempPath()+"/envtestXXXXXX.cpp");
|
|
|
|
|
tmpFile.setAutoRemove(false);
|
|
|
|
|
if (!tmpFile.open())
|
|
|
|
|
return predefinedMacros;
|
|
|
|
|
tmpFilePath = QFileInfo(tmpFile).canonicalFilePath();
|
|
|
|
|
tmpFile.write(msvcCompilationFile());
|
|
|
|
|
tmpFile.close();
|
|
|
|
|
}
|
|
|
|
|
QProcess cpp;
|
|
|
|
|
cpp.setEnvironment(env);
|
|
|
|
|
cpp.setWorkingDirectory(QDir::tempPath());
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
const QString binary = QLatin1String("cl.exe");
|
|
|
|
|
arguments << QLatin1String("/EP") << QDir::toNativeSeparators(tmpFilePath);
|
|
|
|
|
cpp.start(QLatin1String("cl.exe"), arguments);
|
|
|
|
|
if (!cpp.waitForStarted()) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Cannot start '%s': %s", Q_FUNC_INFO, qPrintable(binary),
|
|
|
|
|
qPrintable(cpp.errorString()));
|
2010-09-08 15:22:58 +02:00
|
|
|
return predefinedMacros;
|
|
|
|
|
}
|
|
|
|
|
cpp.closeWriteChannel();
|
|
|
|
|
if (!cpp.waitForFinished()) {
|
|
|
|
|
Utils::SynchronousProcess::stopProcess(cpp);
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Timeout running '%s'.", Q_FUNC_INFO, qPrintable(binary));
|
2010-09-08 15:22:58 +02:00
|
|
|
return predefinedMacros;
|
|
|
|
|
}
|
2010-09-09 09:58:17 +02:00
|
|
|
if (cpp.exitStatus() != QProcess::NormalExit) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: '%s' crashed.", Q_FUNC_INFO, qPrintable(binary));
|
2010-09-09 09:58:17 +02:00
|
|
|
return predefinedMacros;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-08 15:22:58 +02:00
|
|
|
const QList<QByteArray> output = cpp.readAllStandardOutput().split('\n');
|
|
|
|
|
foreach (const QByteArray& line, output) {
|
|
|
|
|
if (line.startsWith('V')) {
|
|
|
|
|
QList<QByteArray> split = line.split('=');
|
|
|
|
|
const QByteArray key = split.at(0).mid(1);
|
|
|
|
|
QByteArray value = split.at(1);
|
|
|
|
|
if (!value.isEmpty()) {
|
|
|
|
|
value.chop(1); //remove '\n'
|
|
|
|
|
}
|
|
|
|
|
predefinedMacros += "#define ";
|
|
|
|
|
predefinedMacros += key;
|
|
|
|
|
predefinedMacros += ' ';
|
|
|
|
|
predefinedMacros += value;
|
|
|
|
|
predefinedMacros += '\n';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QFile::remove(tmpFilePath);
|
|
|
|
|
return predefinedMacros;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-10 15:34:25 +01:00
|
|
|
QByteArray MSVCToolChain::predefinedMacros()
|
|
|
|
|
{
|
2009-09-16 17:16:29 +02:00
|
|
|
if (m_predefinedMacros.isEmpty()) {
|
|
|
|
|
ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
|
|
|
|
|
addToEnvironment(env);
|
2010-09-08 15:22:58 +02:00
|
|
|
m_predefinedMacros = msvcPredefinedMacros(env.toStringList());
|
2009-09-16 17:16:29 +02:00
|
|
|
}
|
|
|
|
|
return m_predefinedMacros;
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<HeaderPath> MSVCToolChain::systemHeaderPaths()
|
|
|
|
|
{
|
|
|
|
|
//TODO fix this code
|
|
|
|
|
ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
|
|
|
|
|
addToEnvironment(env);
|
2009-02-12 16:09:23 +01:00
|
|
|
QList<HeaderPath> headerPaths;
|
|
|
|
|
foreach(const QString &path, env.value("INCLUDE").split(QLatin1Char(';'))) {
|
|
|
|
|
headerPaths.append(HeaderPath(path, HeaderPath::GlobalHeaderPath));
|
|
|
|
|
}
|
|
|
|
|
return headerPaths;
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-04 15:23:02 +01:00
|
|
|
MSVCToolChain::StringStringPairList MSVCToolChain::readEnvironmentSetting(const QString &varsBat,
|
|
|
|
|
const QStringList &args,
|
|
|
|
|
const ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
const StringStringPairList rc = readEnvironmentSettingI(varsBat, args, env);
|
|
|
|
|
if (debug) {
|
|
|
|
|
qDebug() << "Running: " << varsBat << args;
|
|
|
|
|
if (debug > 1) {
|
|
|
|
|
qDebug() << "Incoming: " << env.toStringList();
|
|
|
|
|
foreach(const StringStringPair &e, rc)
|
|
|
|
|
qDebug() << e.first << e.second;
|
|
|
|
|
} else {
|
|
|
|
|
qDebug() << "Read: " << rc.size() << " variables.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Windows: Expand the delayed evaluation references returned by the
|
|
|
|
|
// SDK setup scripts: "PATH=!Path!;foo". Some values might expand
|
|
|
|
|
// to empty and should not be added
|
|
|
|
|
static inline QString winExpandDelayedEnvReferences(QString in, const ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
const QChar exclamationMark = QLatin1Char('!');
|
|
|
|
|
for (int pos = 0; pos < in.size(); ) {
|
|
|
|
|
// Replace "!REF!" by its value in process environment
|
|
|
|
|
pos = in.indexOf(exclamationMark, pos);
|
|
|
|
|
if (pos == -1)
|
|
|
|
|
break;
|
|
|
|
|
const int nextPos = in.indexOf(exclamationMark, pos + 1);
|
|
|
|
|
if (nextPos == -1)
|
|
|
|
|
break;
|
|
|
|
|
const QString var = in.mid(pos + 1, nextPos - pos - 1);
|
|
|
|
|
const QString replacement = env.value(var.toUpper());
|
|
|
|
|
in.replace(pos, nextPos + 1 - pos, replacement);
|
|
|
|
|
pos += replacement.size();
|
|
|
|
|
}
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MSVCToolChain::StringStringPairList MSVCToolChain::readEnvironmentSettingI(const QString &varsBat,
|
|
|
|
|
const QStringList &args,
|
|
|
|
|
const ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
// Run the setup script and extract the variables
|
|
|
|
|
if (!QFileInfo(varsBat).exists())
|
|
|
|
|
return StringStringPairList();
|
|
|
|
|
const QString tempOutputFileName = QDir::tempPath() + QLatin1String("\\qtcreator-msvc-environment.txt");
|
|
|
|
|
QTemporaryFile tf(QDir::tempPath() + "\\XXXXXX.bat");
|
|
|
|
|
tf.setAutoRemove(true);
|
|
|
|
|
if (!tf.open())
|
|
|
|
|
return StringStringPairList();
|
|
|
|
|
const QString filename = tf.fileName();
|
|
|
|
|
QByteArray call = "call \"";
|
|
|
|
|
call += varsBat.toLocal8Bit();
|
|
|
|
|
call += '"';
|
|
|
|
|
if (!args.isEmpty()) {
|
|
|
|
|
call += ' ';
|
|
|
|
|
call += args.join(QString(QLatin1Char(' '))).toLocal8Bit();
|
|
|
|
|
}
|
|
|
|
|
call += "\r\n";
|
|
|
|
|
tf.write(call);
|
2010-09-08 15:22:58 +02:00
|
|
|
const QByteArray redirect = "set > \"" + QDir::toNativeSeparators(tempOutputFileName).toLocal8Bit() + "\"\r\n";
|
|
|
|
|
tf.write(redirect);
|
2010-03-04 15:23:02 +01:00
|
|
|
tf.flush();
|
|
|
|
|
tf.waitForBytesWritten(30000);
|
|
|
|
|
|
|
|
|
|
QProcess run;
|
|
|
|
|
run.setEnvironment(env.toStringList());
|
|
|
|
|
const QString cmdPath = QString::fromLocal8Bit(qgetenv("COMSPEC"));
|
2010-09-08 15:22:58 +02:00
|
|
|
run.start(cmdPath, QStringList()<< QLatin1String("/c")<<QDir::toNativeSeparators(filename));
|
|
|
|
|
if (!run.waitForStarted()) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Unable to run '%s': %s", Q_FUNC_INFO, qPrintable(varsBat),
|
|
|
|
|
qPrintable(run.errorString()));
|
2010-03-04 15:23:02 +01:00
|
|
|
return StringStringPairList();
|
2010-09-08 15:22:58 +02:00
|
|
|
}
|
|
|
|
|
if (!run.waitForFinished()) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Timeout running '%s'", Q_FUNC_INFO, qPrintable(varsBat));
|
2010-09-08 15:22:58 +02:00
|
|
|
Utils::SynchronousProcess::stopProcess(run);
|
|
|
|
|
return StringStringPairList();
|
|
|
|
|
}
|
2010-03-04 15:23:02 +01:00
|
|
|
tf.close();
|
|
|
|
|
|
|
|
|
|
QFile varsFile(tempOutputFileName);
|
|
|
|
|
if (!varsFile.open(QIODevice::ReadOnly|QIODevice::Text))
|
|
|
|
|
return StringStringPairList();
|
|
|
|
|
|
|
|
|
|
QRegExp regexp(QLatin1String("(\\w*)=(.*)"));
|
|
|
|
|
StringStringPairList rc;
|
|
|
|
|
while (!varsFile.atEnd()) {
|
|
|
|
|
const QString line = QString::fromLocal8Bit(varsFile.readLine()).trimmed();
|
|
|
|
|
if (regexp.exactMatch(line)) {
|
|
|
|
|
const QString varName = regexp.cap(1);
|
|
|
|
|
const QString expandedValue = winExpandDelayedEnvReferences(regexp.cap(2), env);
|
|
|
|
|
if (!expandedValue.isEmpty())
|
|
|
|
|
rc.append(StringStringPair(varName, expandedValue));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
varsFile.close();
|
|
|
|
|
varsFile.remove();
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-10 15:34:25 +01:00
|
|
|
void MSVCToolChain::addToEnvironment(ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
2010-03-04 15:23:02 +01:00
|
|
|
if (debug)
|
|
|
|
|
qDebug() << "MSVCToolChain::addToEnvironment" << m_installation.name;
|
|
|
|
|
if (m_installation.name.isEmpty() || m_installation.varsBat.isEmpty()) {
|
2010-09-09 15:12:02 +02:00
|
|
|
qWarning("%s: Attempt to set up invalid MSVC Toolchain.", Q_FUNC_INFO);
|
2010-03-04 15:23:02 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// We cache the full environment (incoming + modifications by setup script).
|
2009-03-19 18:15:33 +01:00
|
|
|
if (!m_valuesSet || env != m_lastEnvironment) {
|
|
|
|
|
m_lastEnvironment = env;
|
2010-03-04 15:23:02 +01:00
|
|
|
const QStringList args = m_installation.varsBatArg.isEmpty() ?
|
|
|
|
|
QStringList() : QStringList(m_installation.varsBatArg);
|
|
|
|
|
m_values = readEnvironmentSetting(m_installation.varsBat, args, env);
|
2009-02-10 15:34:25 +01:00
|
|
|
m_valuesSet = true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-04 15:23:02 +01:00
|
|
|
const StringStringPairList::const_iterator end = m_values.constEnd();
|
|
|
|
|
for (StringStringPairList::const_iterator it = m_values.constBegin(); it != end; ++it)
|
2009-02-10 15:34:25 +01:00
|
|
|
env.set((*it).first, (*it).second);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-16 18:13:45 +01:00
|
|
|
QString MSVCToolChain::makeCommand() const
|
|
|
|
|
{
|
2009-08-12 15:20:36 +02:00
|
|
|
if (ProjectExplorerPlugin::instance()->projectExplorerSettings().useJom) {
|
|
|
|
|
// We want jom! Try to find it.
|
|
|
|
|
QString jom = QCoreApplication::applicationDirPath() + QLatin1String("/jom.exe");
|
|
|
|
|
if (QFileInfo(jom).exists())
|
|
|
|
|
return jom;
|
|
|
|
|
else
|
2009-12-09 13:54:46 +01:00
|
|
|
return QLatin1String("jom.exe");
|
2009-08-12 15:20:36 +02:00
|
|
|
}
|
2009-12-09 13:54:46 +01:00
|
|
|
return QLatin1String("nmake.exe");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IOutputParser *MSVCToolChain::outputParser() const
|
|
|
|
|
{
|
|
|
|
|
return new MsvcParser;
|
2009-03-16 18:13:45 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-04 15:23:02 +01:00
|
|
|
WinCEToolChain *WinCEToolChain::create(const QString &name, const QString &platform)
|
2009-02-10 15:34:25 +01:00
|
|
|
{
|
2010-03-04 15:23:02 +01:00
|
|
|
const bool excludeSDK = true;
|
2010-04-21 17:24:37 +02:00
|
|
|
return new WinCEToolChain(findInstallationByName(false, name, excludeSDK), platform);
|
2010-03-04 15:23:02 +01:00
|
|
|
}
|
2009-02-10 15:34:25 +01:00
|
|
|
|
2010-03-04 15:23:02 +01:00
|
|
|
WinCEToolChain::WinCEToolChain(const Installation &in, const QString &platform) :
|
|
|
|
|
MSVCToolChain(in),
|
|
|
|
|
m_platform(platform)
|
|
|
|
|
{
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolChain::ToolChainType WinCEToolChain::type() const
|
|
|
|
|
{
|
|
|
|
|
return ToolChain::WINCE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WinCEToolChain::equals(ToolChain *other) const
|
|
|
|
|
{
|
|
|
|
|
WinCEToolChain *o = static_cast<WinCEToolChain *>(other);
|
|
|
|
|
return (m_platform == o->m_platform && this->MSVCToolChain::equals(other));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray WinCEToolChain::predefinedMacros()
|
|
|
|
|
{
|
|
|
|
|
//TODO
|
|
|
|
|
return MSVCToolChain::predefinedMacros();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<HeaderPath> WinCEToolChain::systemHeaderPaths()
|
|
|
|
|
{
|
|
|
|
|
//TODO fix this code
|
|
|
|
|
ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
|
|
|
|
|
addToEnvironment(env);
|
2009-03-30 14:54:57 +02:00
|
|
|
|
|
|
|
|
QList<HeaderPath> headerPaths;
|
|
|
|
|
|
|
|
|
|
const QStringList includes = env.value("INCLUDE").split(QLatin1Char(';'));
|
|
|
|
|
|
|
|
|
|
foreach (const QString &path, includes) {
|
|
|
|
|
const HeaderPath headerPath(path, HeaderPath::GlobalHeaderPath);
|
|
|
|
|
headerPaths.append(headerPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return headerPaths;
|
2009-02-10 15:34:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WinCEToolChain::addToEnvironment(ProjectExplorer::Environment &env)
|
|
|
|
|
{
|
|
|
|
|
MSVCToolChain::addToEnvironment(env);
|
2009-05-20 12:59:19 +02:00
|
|
|
QSettings registry(MSVC_RegKey, QSettings::NativeFormat);
|
2010-03-04 15:23:02 +01:00
|
|
|
QString path = registry.value(m_installation.name).toString();
|
2009-05-18 10:46:12 +02:00
|
|
|
|
2009-02-10 15:34:25 +01:00
|
|
|
// Find MSVC path
|
|
|
|
|
|
2010-02-01 12:43:56 +01:00
|
|
|
path += QLatin1Char('/');
|
2009-02-10 15:34:25 +01:00
|
|
|
|
|
|
|
|
// Find Platform name
|
|
|
|
|
CeSdkHandler cesdkhandler;
|
|
|
|
|
cesdkhandler.parse(path);
|
|
|
|
|
cesdkhandler.find(m_platform).addToEnvironment(env);
|
|
|
|
|
}
|