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:
Erik Verbruggen
2014-01-21 14:57:00 +01:00
parent 1838224277
commit 31d051a52a
2 changed files with 40 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
isEmpty(LLVM_INSTALL_DIR):LLVM_INSTALL_DIR=$$(LLVM_INSTALL_DIR) isEmpty(LLVM_INSTALL_DIR):LLVM_INSTALL_DIR=$$(LLVM_INSTALL_DIR)
LLVM_INSTALL_DIR ~= s,\\\\,/,g
DEFINES += CLANG_COMPLETION DEFINES += CLANG_COMPLETION
DEFINES += CLANG_HIGHLIGHTING DEFINES += CLANG_HIGHLIGHTING
@@ -50,16 +51,22 @@ win32 {
error("Cannot find Clang shared library!") error("Cannot find Clang shared library!")
} }
} }
LLVM_LIBDIR = $$LLVM_INSTALL_DIR/lib
LLVM_LIBS = \ LLVM_LIBS = \
-L$$LLVM_INSTALL_DIR/bin \ -L$$LLVM_INSTALL_DIR/bin \
-L$$LLVM_INSTALL_DIR/lib \ -L$$LLVM_LIBDIR \
-l$${CLANG_LIB} -l$${CLANG_LIB}
LLVM_LIBS += -ladvapi32 -lshell32 LLVM_LIBS += -ladvapi32 -lshell32
LLVM_VERSION = 3.4
} }
unix { unix {
LLVM_CONFIG = $$findLLVMConfig() LLVM_CONFIG = $$findLLVMConfig()
LLVM_VERSION = $$system($$LLVM_CONFIG --version)
LLVM_VERSION = $$replace(LLVM_VERSION, ^(\\d+\\.\\d+).*$, \\1)
message("... version $$LLVM_VERSION");
LLVM_INCLUDEPATH = $$system($$LLVM_CONFIG --includedir) LLVM_INCLUDEPATH = $$system($$LLVM_CONFIG --includedir)
isEmpty(LLVM_INCLUDEPATH):LLVM_INCLUDEPATH=$$LLVM_INSTALL_DIR/include isEmpty(LLVM_INCLUDEPATH):LLVM_INCLUDEPATH=$$LLVM_INSTALL_DIR/include
LLVM_LIBDIR = $$system($$LLVM_CONFIG --libdir) LLVM_LIBDIR = $$system($$LLVM_CONFIG --libdir)
@@ -87,3 +94,6 @@ unix {
LLVM_LIBS = -L$${LLVM_LIBDIR} LLVM_LIBS = -L$${LLVM_LIBDIR}
LLVM_LIBS += -l$${CLANG_LIB} LLVM_LIBS += -l$${CLANG_LIB}
} }
DEFINES += CLANG_VERSION=\\\"$${LLVM_VERSION}\\\"
DEFINES += "\"CLANG_RESOURCE_DIR=\\\"$${LLVM_LIBDIR}/clang/$${LLVM_VERSION}/include\\\"\""

View File

@@ -35,6 +35,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <QDir>
#include <QFile> #include <QFile>
#include <QSet> #include <QSet>
#include <QString> #include <QString>
@@ -44,6 +45,8 @@ using namespace ClangCodeModel::Internal;
using namespace Core; using namespace Core;
using namespace CppTools; using namespace CppTools;
static const bool BeVerbose = !qgetenv("QTC_CLANG_VERBOSE").isEmpty();
namespace ClangCodeModel { namespace ClangCodeModel {
namespace Utils { namespace Utils {
@@ -110,6 +113,7 @@ static QStringList buildDefines(const QByteArray &defines, bool toolchainDefines
if (def.isEmpty()) if (def.isEmpty())
continue; continue;
// TODO: verify if we can pass compiler-defined macros when also passing -undef.
if (toolchainDefines) { if (toolchainDefines) {
//### FIXME: the next 3 check shouldn't be needed: we probably don't want to get the compiler-defined defines in. //### 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 ")) if (!def.startsWith("#define "))
@@ -137,6 +141,15 @@ static QStringList buildDefines(const QByteArray &defines, bool toolchainDefines
return result; 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 * @brief Creates list of command-line arguments required for correct parsing
* @param pPart Null if file isn't part of any project * @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()) if (pPart.isNull())
return result; 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); result << buildDefines(pPart->projectDefines, false);
foreach (const QString &frameworkPath, pPart->frameworkPaths) foreach (const QString &frameworkPath, pPart->frameworkPaths)