[cfe-commits] r116260 - in /cfe/trunk: lib/Headers/CMakeLists.txt tools/libclang/CIndexer.cpp tools/libclang/CIndexer.h

Douglas Gregor dgregor at apple.com
Mon Oct 11 16:17:59 PDT 2010


Author: dgregor
Date: Mon Oct 11 18:17:59 2010
New Revision: 116260

URL: http://llvm.org/viewvc/llvm-project?rev=116260&view=rev
Log:
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.


Modified:
    cfe/trunk/lib/Headers/CMakeLists.txt
    cfe/trunk/tools/libclang/CIndexer.cpp
    cfe/trunk/tools/libclang/CIndexer.h

Modified: cfe/trunk/lib/Headers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/CMakeLists.txt?rev=116260&r1=116259&r2=116260&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/CMakeLists.txt (original)
+++ cfe/trunk/lib/Headers/CMakeLists.txt Mon Oct 11 18:17:59 2010
@@ -18,21 +18,20 @@
   tmmintrin.h
   xmmintrin.h)
 
-if (MSVC_IDE OR XCODE)
-  set(output_dir ${LLVM_BINARY_DIR}/bin/lib/clang/${CLANG_VERSION}/include)
-else ()
-  set(output_dir ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION}/include)
-endif ()
+set(output_dir ${LLVM_BINARY_DIR}/lib/${CMAKE_CFG_INTDIR}/clang/${CLANG_VERSION}/include)
+
+# If we are in an IDE that has a configuration directory, we need to
+# create a second copy of the headers so that 'clang' can find them if
+# it's run from the build directory.
+if(MSVC_IDE OR XCODE)
+   set(other_output_dir ${LLVM_BINARY_DIR}/bin/lib/clang/${CLANG_VERSION}/include)
+endif()
 
 # Generate arm_neon.h
 set(LLVM_TARGET_DEFINITIONS ${CLANG_SOURCE_DIR}/include/clang/Basic/arm_neon.td)
 tablegen(arm_neon.h.inc -gen-arm-neon)
 
-add_custom_command(OUTPUT ${output_dir}/arm_neon.h 
-  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h.inc
-  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h.inc ${output_dir}/arm_neon.h
-  COMMENT "Copying clang's arm_neon.h...")
-
+set(out_files)
 foreach( f ${files} )
   set( src ${CMAKE_CURRENT_SOURCE_DIR}/${f} )
   set( dst ${output_dir}/${f} )
@@ -40,10 +39,34 @@
     DEPENDS ${src}
     COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
     COMMENT "Copying clang's ${f}...")
+  list(APPEND out_files ${dst})
+
+  if(other_output_dir)
+   set(other_dst ${other_output_dir}/${f})
+    add_custom_command(OUTPUT ${other_dst}
+      DEPENDS ${src}
+      COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${other_dst}
+      COMMENT "Copying clang's ${f}...")    
+    list(APPEND out_files ${other_dst})
+  endif()
 endforeach( f )
 
-add_custom_target(clang-headers ALL
-  DEPENDS ${files} ${output_dir}/arm_neon.h)
+add_custom_command(OUTPUT ${output_dir}/arm_neon.h 
+  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h.inc
+  COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h.inc ${output_dir}/arm_neon.h
+  COMMENT "Copying clang's arm_neon.h...")
+list(APPEND out_files ${output_dir}/arm_neon.h)
+
+if (other_output_dir)
+    set(other_dst ${other_output_dir}/arm_neon.h)
+    add_custom_command(OUTPUT ${other_dst}
+      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h.inc
+      COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h.inc ${other_dst}
+      COMMENT "Copying clang's arm_neon.h...")
+    list(APPEND out_files ${other_dst})
+endif ()
+
+add_custom_target(clang-headers ALL DEPENDS ${out_files})
 
 install(FILES ${files} ${output_dir}/arm_neon.h
   PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ

Modified: cfe/trunk/tools/libclang/CIndexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.cpp?rev=116260&r1=116259&r2=116260&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexer.cpp Mon Oct 11 18:17:59 2010
@@ -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() {

Modified: cfe/trunk/tools/libclang/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.h?rev=116260&r1=116259&r2=116260&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.h (original)
+++ cfe/trunk/tools/libclang/CIndexer.h Mon Oct 11 18:17:59 2010
@@ -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();
 };





More information about the cfe-commits mailing list