Browse Source

Better detection of Clang builtin headers location.

pull/513/merge
João Matos 11 years ago
parent
commit
0d7c7efd43
  1. 44
      src/CppParser/Parser.cpp

44
src/CppParser/Parser.cpp

@ -44,6 +44,15 @@
#include <CodeGen/CGCall.h> #include <CodeGen/CGCall.h>
#include <CodeGen/CGCXXABI.h> #include <CodeGen/CGCXXABI.h>
#if defined(__APPLE__) || defined(__linux__)
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <dlfcn.h>
#define HAVE_DLFCN
#endif
using namespace CppSharp::CppParser; using namespace CppSharp::CppParser;
// We use this as a placeholder for pointer values that should be ignored. // We use this as a placeholder for pointer values that should be ignored.
@ -57,7 +66,18 @@ Parser::Parser(ParserOptions* Opts) : Lib(Opts->ASTContext), Opts(Opts), Index(0
//-----------------------------------// //-----------------------------------//
static std::string GetClangResourceDir(const std::string& Dir) std::string GetCurrentLibraryDir()
{
#ifdef HAVE_DLFCN
Dl_info dl_info;
dladdr((void *)GetCurrentLibraryDir, &dl_info);
return dl_info.dli_fname;
#else
return ".";
#endif
}
static std::string GetClangResourceDir()
{ {
using namespace llvm; using namespace llvm;
using namespace clang; using namespace clang;
@ -65,7 +85,8 @@ static std::string GetClangResourceDir(const std::string& Dir)
// Compute the path to the resource directory. // Compute the path to the resource directory.
StringRef ClangResourceDir(CLANG_RESOURCE_DIR); StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
SmallString<128> P(Dir); SmallString<128> P(GetCurrentLibraryDir());
llvm::sys::path::remove_filename(P);
if (ClangResourceDir != "") if (ClangResourceDir != "")
llvm::sys::path::append(P, ClangResourceDir); llvm::sys::path::append(P, ClangResourceDir);
@ -75,16 +96,6 @@ static std::string GetClangResourceDir(const std::string& Dir)
return P.str(); return P.str();
} }
static std::string GetClangBuiltinIncludeDir()
{
using namespace llvm;
SmallString<128> P( GetClangResourceDir(".") );
llvm::sys::path::append(P, "include");
return P.str();
}
//-----------------------------------// //-----------------------------------//
static clang::TargetCXXABI::Kind static clang::TargetCXXABI::Kind
@ -219,9 +230,12 @@ void Parser::SetupHeader()
} }
// Initialize the default platform headers. // Initialize the default platform headers.
HSOpts.ResourceDir = GetClangResourceDir("."); HSOpts.ResourceDir = GetClangResourceDir();
HSOpts.AddPath(GetClangBuiltinIncludeDir(), clang::frontend::System,
/*IsFramework=*/false, /*IgnoreSysRoot=*/false); llvm::SmallString<128> ResourceDir(HSOpts.ResourceDir);
llvm::sys::path::append(ResourceDir, "include");
HSOpts.AddPath(ResourceDir.str(), clang::frontend::System, /*IsFramework=*/false,
/*IgnoreSysRoot=*/false);
#ifdef _MSC_VER #ifdef _MSC_VER
if (Opts->MicrosoftMode) if (Opts->MicrosoftMode)

Loading…
Cancel
Save