forked from qt-creator/qt-creator
Clang: tune include paths used by clang
Do not search the standard system directories for include files, but do search compiler builtin include directories. To make sure that the include files for intrinsics are the ones clang can parse, put that path first on the command-line. Change-Id: I2ada992b58203d1c3dbd55851c5f195c12572943 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
@@ -44,6 +45,8 @@ using namespace ClangCodeModel::Internal;
|
||||
using namespace Core;
|
||||
using namespace CppTools;
|
||||
|
||||
static const bool BeVerbose = !qgetenv("QTC_CLANG_VERBOSE").isEmpty();
|
||||
|
||||
namespace ClangCodeModel {
|
||||
namespace Utils {
|
||||
|
||||
@@ -110,6 +113,7 @@ static QStringList buildDefines(const QByteArray &defines, bool toolchainDefines
|
||||
if (def.isEmpty())
|
||||
continue;
|
||||
|
||||
// TODO: verify if we can pass compiler-defined macros when also passing -undef.
|
||||
if (toolchainDefines) {
|
||||
//### FIXME: the next 3 check shouldn't be needed: we probably don't want to get the compiler-defined defines in.
|
||||
if (!def.startsWith("#define "))
|
||||
@@ -137,6 +141,15 @@ static QStringList buildDefines(const QByteArray &defines, bool toolchainDefines
|
||||
return result;
|
||||
}
|
||||
|
||||
static QString getResourceDir()
|
||||
{
|
||||
QDir dir(Core::ICore::instance()->resourcePath() + QLatin1String("/cplusplus/clang/") +
|
||||
QLatin1String(CLANG_VERSION) + QLatin1String("/include"));
|
||||
if (!dir.exists() || !QFileInfo(dir, QLatin1String("stdint.h")).exists())
|
||||
dir = QDir(QLatin1String(CLANG_RESOURCE_DIR));
|
||||
return dir.canonicalPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates list of command-line arguments required for correct parsing
|
||||
* @param pPart Null if file isn't part of any project
|
||||
@@ -169,9 +182,23 @@ QStringList createClangOptions(const ProjectPart::Ptr &pPart, ProjectFile::Kind
|
||||
if (pPart.isNull())
|
||||
return result;
|
||||
|
||||
result << QLatin1String("-nostdinc");
|
||||
static const QString resourceDir = getResourceDir();
|
||||
|
||||
result << buildDefines(pPart->toolchainDefines, true);
|
||||
if (BeVerbose)
|
||||
result << QLatin1String("-v");
|
||||
|
||||
if (!resourceDir.isEmpty()) {
|
||||
result << QLatin1String("-nostdlibinc");
|
||||
result << (QLatin1String("-I") + resourceDir);
|
||||
result << QLatin1String("-undef");
|
||||
}
|
||||
|
||||
result << QLatin1String("-fmessage-length=0");
|
||||
result << QLatin1String("-fdiagnostics-show-note-include-stack");
|
||||
result << QLatin1String("-fmacro-backtrace-limit=0");
|
||||
result << QLatin1String("-fretain-comments-from-system-headers");
|
||||
|
||||
result << buildDefines(pPart->toolchainDefines, false);
|
||||
result << buildDefines(pPart->projectDefines, false);
|
||||
|
||||
foreach (const QString &frameworkPath, pPart->frameworkPaths)
|
||||
|
||||
Reference in New Issue
Block a user