Eliminate CIndexer::getClangPath(), since libclang no longer depends
on the presence of a 'clang' executable. Simplify
CIndexer::getClangResourcesPath() a bit.

Patch up the CMake makefiles to install headers into two locations in
the build tree, for those silly cases where 'clang' will end up
looking into the wrong build directory for headers.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116260 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndexer.cpp b/tools/libclang/CIndexer.cpp
index cdf6c61..b328d5c 100644
--- a/tools/libclang/CIndexer.cpp
+++ b/tools/libclang/CIndexer.cpp
@@ -39,59 +39,39 @@
 
 using namespace clang;
 
-const llvm::sys::Path& CIndexer::getClangPath() {
+std::string CIndexer::getClangResourcesPath() {
   // Did we already compute the path?
-  if (!ClangPath.empty())
-    return ClangPath;
-
-  // Find the location where this library lives (libCIndex.dylib).
+  if (!ResourcesPath.empty())
+    return ResourcesPath.str();
+  
+  // Find the location where this library lives (libclang.dylib).
 #ifdef LLVM_ON_WIN32
   MEMORY_BASIC_INFORMATION mbi;
   char path[MAX_PATH];
   VirtualQuery((void *)(uintptr_t)clang_createTranslationUnit, &mbi,
                sizeof(mbi));
   GetModuleFileNameA((HINSTANCE)mbi.AllocationBase, path, MAX_PATH);
-
-  llvm::sys::Path CIndexPath(path);
-
-  CIndexPath.eraseComponent();
-  CIndexPath.appendComponent("clang");
-  CIndexPath.appendSuffix("exe");
-  CIndexPath.makeAbsolute();
+  
+  llvm::sys::Path LibClangPath(path);
+  LibClangPath.eraseComponent();
 #else
   // This silly cast below avoids a C++ warning.
   Dl_info info;
   if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) == 0)
     assert(0 && "Call to dladdr() failed");
-
-  llvm::sys::Path CIndexPath(info.dli_fname);
-
+  
+  llvm::sys::Path LibClangPath(info.dli_fname);
+  
   // We now have the CIndex directory, locate clang relative to it.
-  CIndexPath.eraseComponent();
-  CIndexPath.appendComponent("..");
-  CIndexPath.appendComponent("bin");
-  CIndexPath.appendComponent("clang");
+  LibClangPath.eraseComponent();
 #endif
+  
+  LibClangPath.appendComponent("clang");
+  LibClangPath.appendComponent(CLANG_VERSION_STRING);
 
   // Cache our result.
-  ClangPath = CIndexPath;
-  return ClangPath;
-}
-
-std::string CIndexer::getClangResourcesPath() {
-  llvm::sys::Path P = getClangPath();
-
-  if (!P.empty()) {
-    P.eraseComponent();  // Remove /clang from foo/bin/clang
-    P.eraseComponent();  // Remove /bin   from foo/bin
-
-    // Get foo/lib/clang/<version>/include
-    P.appendComponent("lib");
-    P.appendComponent("clang");
-    P.appendComponent(CLANG_VERSION_STRING);
-  }
-
-  return P.str();
+  ResourcesPath = LibClangPath;
+  return LibClangPath.str();
 }
 
 static llvm::sys::Path GetTemporaryPath() {
diff --git a/tools/libclang/CIndexer.h b/tools/libclang/CIndexer.h
index 6ef8b40..89b0987 100644
--- a/tools/libclang/CIndexer.h
+++ b/tools/libclang/CIndexer.h
@@ -31,7 +31,7 @@
   bool OnlyLocalDecls;
   bool DisplayDiagnostics;
 
-  llvm::sys::Path ClangPath;
+  llvm::sys::Path ResourcesPath;
   
 public:
  CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false) { }
@@ -47,9 +47,6 @@
     DisplayDiagnostics = Display;
   }
 
-  /// \brief Get the path of the clang binary.
-  const llvm::sys::Path& getClangPath();
-  
   /// \brief Get the path of the clang resource files.
   std::string getClangResourcesPath();
 };