1 //===- CIndex.cpp - Clang-C Source Indexing Library -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Clang-C Source Indexing library.
12 //===----------------------------------------------------------------------===//
15 #include "clang/Basic/LLVM.h"
16 #include "clang/Basic/Version.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/Config/llvm-config.h"
19 #include "llvm/Support/Path.h"
20 #include "llvm/Support/Program.h"
24 #include <cygwin/version.h>
25 #include <sys/cygwin.h>
26 #define LLVM_ON_WIN32 1
35 using namespace clang;
37 const std::string &CIndexer::getClangResourcesPath() {
38 // Did we already compute the path?
39 if (!ResourcesPath.empty())
42 SmallString<128> LibClangPath;
44 // Find the location where this library lives (libclang.dylib).
46 MEMORY_BASIC_INFORMATION mbi;
48 VirtualQuery((void *)(uintptr_t)clang_createTranslationUnit, &mbi,
50 GetModuleFileNameA((HINSTANCE)mbi.AllocationBase, path, MAX_PATH);
53 char w32path[MAX_PATH];
54 strcpy(w32path, path);
55 #if CYGWIN_VERSION_API_MAJOR > 0 || CYGWIN_VERSION_API_MINOR >= 181
56 cygwin_conv_path(CCP_WIN_A_TO_POSIX, w32path, path, MAX_PATH);
58 cygwin_conv_to_full_posix_path(w32path, path);
62 LibClangPath += llvm::sys::path::parent_path(path);
64 // This silly cast below avoids a C++ warning.
66 if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) == 0)
67 llvm_unreachable("Call to dladdr() failed");
69 // We now have the CIndex directory, locate clang relative to it.
70 LibClangPath += llvm::sys::path::parent_path(info.dli_fname);
73 llvm::sys::path::append(LibClangPath, "clang", CLANG_VERSION_STRING);
76 ResourcesPath = LibClangPath.str();