Commit 75c36c9b authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Gcc: Support -stdlib=whatever arguments for the code model



Switching the stdlib implementation is possible with clang and results
in different include pathes being used (and potentially different defines).

Change-Id: I9c856256f51ceded9dc7892c1dde2bcc8c1b024c
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 22c3bd24
......@@ -408,18 +408,21 @@ void AutotoolsProject::updateCppCodeModel()
QStringList allFrameworkPaths;
QByteArray macros;
QStringList cxxflags; // FIXME: Autotools should be able to do better than this!
if (activeTarget()) {
ProjectExplorer::Kit *k = activeTarget()->kit();
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
if (tc) {
const QList<HeaderPath> allHeaderPaths = tc->systemHeaderPaths(SysRootKitInformation::sysRoot(k));
const QList<HeaderPath> allHeaderPaths = tc->systemHeaderPaths(cxxflags,
SysRootKitInformation::sysRoot(k));
foreach (const HeaderPath &headerPath, allHeaderPaths) {
if (headerPath.kind() == HeaderPath::FrameworkHeaderPath)
allFrameworkPaths.append(headerPath.path());
else
allIncludePaths.append(headerPath.path());
}
macros = tc->predefinedMacros(QStringList());
macros = tc->predefinedMacros(cxxflags);
macros += '\n';
}
}
......
......@@ -303,13 +303,15 @@ bool CMakeProject::parseCMakeLists()
allIncludePaths.append(projectDirectory());
allIncludePaths.append(cbpparser.includeFiles());
QStringList cxxflags; // FIXME: We should do better than this!
QByteArray allDefines;
allDefines.append(tc->predefinedMacros(QStringList()));
allDefines.append(tc->predefinedMacros(cxxflags));
allDefines.append(cbpparser.defines());
QStringList allFrameworkPaths;
QList<ProjectExplorer::HeaderPath> allHeaderPaths;
allHeaderPaths = tc->systemHeaderPaths(SysRootKitInformation::sysRoot(k));
allHeaderPaths = tc->systemHeaderPaths(cxxflags, SysRootKitInformation::sysRoot(k));
foreach (const ProjectExplorer::HeaderPath &headerPath, allHeaderPaths) {
if (headerPath.kind() == ProjectExplorer::HeaderPath::FrameworkHeaderPath)
allFrameworkPaths.append(headerPath.path());
......
......@@ -250,10 +250,11 @@ void GenericProject::refresh(RefreshOptions options)
Kit *k = activeTarget() ? activeTarget()->kit() : KitManager::instance()->defaultKit();
ToolChain *tc = k ? ToolChainKitInformation::toolChain(k) : 0;
if (tc) {
part->defines = tc->predefinedMacros(QStringList());
QStringList cxxflags; // FIXME: Can we do better?
part->defines = tc->predefinedMacros(cxxflags);
part->defines += '\n';
foreach (const HeaderPath &headerPath, tc->systemHeaderPaths(SysRootKitInformation::sysRoot(k))) {
foreach (const HeaderPath &headerPath, tc->systemHeaderPaths(cxxflags, SysRootKitInformation::sysRoot(k))) {
if (headerPath.kind() == HeaderPath::FrameworkHeaderPath)
part->frameworkPaths.append(headerPath.path());
else
......
......@@ -105,8 +105,9 @@ ToolChain::CompilerFlags AbstractMsvcToolChain::compilerFlags(const QStringList
}
}
QList<HeaderPath> AbstractMsvcToolChain::systemHeaderPaths(const Utils::FileName &sysRoot) const
QList<HeaderPath> AbstractMsvcToolChain::systemHeaderPaths(const QStringList &cxxflags, const Utils::FileName &sysRoot) const
{
Q_UNUSED(cxxflags);
Q_UNUSED(sysRoot);
if (m_headerPaths.isEmpty()) {
Utils::Environment env(m_lastEnvironment);
......
......@@ -50,7 +50,7 @@ public:
QByteArray predefinedMacros(const QStringList &cxxflags) const;
CompilerFlags compilerFlags(const QStringList &cxxflags) const;
QList<HeaderPath> systemHeaderPaths(const Utils::FileName &sysRoot) const;
QList<HeaderPath> systemHeaderPaths(const QStringList &cxxflags, const Utils::FileName &sysRoot) const;
void addToEnvironment(Utils::Environment &env) const;
QString makeCommand(const Utils::Environment &environment) const;
......
......@@ -122,7 +122,8 @@ static QByteArray gccPredefinedMacros(const FileName &gcc, const QStringList &ar
|| a == QLatin1String("-O2") || a == QLatin1String("-O3")
|| a == QLatin1String("-ffinite-math-only") || a == QLatin1String("-fshort-double")
|| a == QLatin1String("-fshort-wchar") || a == QLatin1String("-fsignaling-nans")
|| a.startsWith(QLatin1String("-std=")) || a.startsWith(QLatin1String("-specs="))
|| a.startsWith(QLatin1String("-std=")) || a.startsWith(QLatin1String("-stdlib="))
|| a.startsWith(QLatin1String("-specs="))
|| a == QLatin1String("-ansi")
|| a.startsWith(QLatin1String("-D")) || a.startsWith(QLatin1String("-U"))
|| a == QLatin1String("-undef"))
......@@ -148,12 +149,18 @@ static QByteArray gccPredefinedMacros(const FileName &gcc, const QStringList &ar
return predefinedMacros;
}
QList<HeaderPath> GccToolChain::gccHeaderPaths(const FileName &gcc, const QStringList &env, const FileName &sysrootPath)
QList<HeaderPath> GccToolChain::gccHeaderPaths(const FileName &gcc, const QStringList &args,
const QStringList &env, const FileName &sysrootPath)
{
QList<HeaderPath> systemHeaderPaths;
QStringList arguments;
if (!sysrootPath.isEmpty())
arguments.append(QString::fromLatin1("--sysroot=%1").arg(sysrootPath.toString()));
foreach (const QString &a, args) {
if (a.startsWith(QLatin1String("-stdlib=")))
arguments << a;
}
arguments << QLatin1String("-xc++")
<< QLatin1String("-E")
<< QLatin1String("-v")
......@@ -393,13 +400,13 @@ ToolChain::CompilerFlags GccToolChain::compilerFlags(const QStringList &cxxflags
return NO_FLAGS;
}
QList<HeaderPath> GccToolChain::systemHeaderPaths(const Utils::FileName &sysRoot) const
QList<HeaderPath> GccToolChain::systemHeaderPaths(const QStringList &cxxflags, const Utils::FileName &sysRoot) const
{
if (m_headerPaths.isEmpty()) {
// Using a clean environment breaks ccache/distcc/etc.
Environment env = Environment::systemEnvironment();
addToEnvironment(env);
m_headerPaths = gccHeaderPaths(m_compilerCommand, env.toStringList(), sysRoot);
m_headerPaths = gccHeaderPaths(m_compilerCommand, cxxflags, env.toStringList(), sysRoot);
}
return m_headerPaths;
}
......
......@@ -63,7 +63,7 @@ public:
QByteArray predefinedMacros(const QStringList &cxxflags) const;
CompilerFlags compilerFlags(const QStringList &cxxflags) const;
QList<HeaderPath> systemHeaderPaths(const Utils::FileName &sysRoot) const;
QList<HeaderPath> systemHeaderPaths(const QStringList &cxxflags, const Utils::FileName &sysRoot) const;
void addToEnvironment(Utils::Environment &env) const;
QString makeCommand(const Utils::Environment &environment) const;
QList<Utils::FileName> suggestedMkspecList() const;
......@@ -90,7 +90,7 @@ protected:
virtual QList<Abi> detectSupportedAbis() const;
virtual QString detectVersion() const;
static QList<HeaderPath> gccHeaderPaths(const Utils::FileName &gcc, const QStringList &env, const Utils::FileName &sysrootPath);
static QList<HeaderPath> gccHeaderPaths(const Utils::FileName &gcc, const QStringList &args, const QStringList &env, const Utils::FileName &sysrootPath);
mutable QByteArray m_predefinedMacros;
......
......@@ -87,7 +87,8 @@ public:
STD_CXX11 = 1
};
virtual CompilerFlags compilerFlags(const QStringList &cxxflags) const = 0;
virtual QList<HeaderPath> systemHeaderPaths(const Utils::FileName &sysRoot) const = 0;
virtual QList<HeaderPath> systemHeaderPaths(const QStringList &cxxflags,
const Utils::FileName &sysRoot) const = 0;
virtual void addToEnvironment(Utils::Environment &env) const = 0;
virtual QString makeCommand(const Utils::Environment &env) const = 0;
......
......@@ -541,9 +541,11 @@ void Qt4Project::updateCppCodeModel()
ProjectPart::Ptr part(new ProjectPart);
part->qtVersion = qtVersionForPart;
QStringList cxxflags = pro->variableValue(CppFlagsVar);
// part->defines
if (tc)
part->defines = tc->predefinedMacros(pro->variableValue(CppFlagsVar));
part->defines = tc->predefinedMacros(cxxflags);
part->defines += pro->cxxDefines();
// part->includePaths
......@@ -551,7 +553,7 @@ void Qt4Project::updateCppCodeModel()
QList<HeaderPath> headers;
if (tc)
headers = tc->systemHeaderPaths(SysRootKitInformation::sysRoot(k)); // todo pass cxxflags?
headers = tc->systemHeaderPaths(cxxflags, SysRootKitInformation::sysRoot(k));
if (qtVersion) {
headers.append(qtVersion->systemHeaderPathes(k));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment