[cfe-commits] r83302 - /cfe/trunk/tools/clang-cc/clang-cc.cpp

Rafael Espindola rafael.espindola at gmail.com
Mon Oct 5 06:12:17 PDT 2009


Author: rafael
Date: Mon Oct  5 08:12:17 2009
New Revision: 83302

URL: http://llvm.org/viewvc/llvm-project?rev=83302&view=rev
Log:
Add a -nostdclanginc flag to clang-cc that prevents it from searching
its own binary-relative headers. Useful when using clang's preprocessor
with gcc.


Modified:
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=83302&r1=83301&r2=83302&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Mon Oct  5 08:12:17 2009
@@ -1098,6 +1098,10 @@
 static llvm::cl::opt<bool>
 nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
 
+static llvm::cl::opt<bool>
+nostdclanginc("nostdclanginc",
+	      llvm::cl::desc("Disable standard clang #include directories"));
+
 // Various command line options.  These four add directories to each chain.
 static llvm::cl::list<std::string>
 F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
@@ -1133,6 +1137,32 @@
 
 // Finally, implement the code that groks the options above.
 
+// Add the clang headers, which are relative to the clang binary.
+void AddClangIncludePaths(const char *Argv0, InitHeaderSearch *Init) {
+  if (nostdclanginc)
+    return;
+
+  llvm::sys::Path MainExecutablePath =
+     llvm::sys::Path::GetMainExecutable(Argv0,
+                                    (void*)(intptr_t)AddClangIncludePaths);
+  if (MainExecutablePath.isEmpty())
+    return;
+
+  MainExecutablePath.eraseComponent();  // Remove /clang from foo/bin/clang
+  MainExecutablePath.eraseComponent();  // Remove /bin   from foo/bin
+
+  // Get foo/lib/clang/<version>/include
+  MainExecutablePath.appendComponent("lib");
+  MainExecutablePath.appendComponent("clang");
+  MainExecutablePath.appendComponent(CLANG_VERSION_STRING);
+  MainExecutablePath.appendComponent("include");
+
+  // We pass true to ignore sysroot so that we *always* look for clang headers
+  // relative to our executable, never relative to -isysroot.
+  Init->AddPath(MainExecutablePath.c_str(), InitHeaderSearch::System,
+		false, false, false, true /*ignore sysroot*/);
+}
+
 /// InitializeIncludePaths - Process the -I options and set them in the
 /// HeaderSearch object.
 void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers,
@@ -1212,25 +1242,7 @@
 
   Init.AddDefaultEnvVarPaths(Lang);
 
-  // Add the clang headers, which are relative to the clang binary.
-  llvm::sys::Path MainExecutablePath =
-     llvm::sys::Path::GetMainExecutable(Argv0,
-                                    (void*)(intptr_t)InitializeIncludePaths);
-  if (!MainExecutablePath.isEmpty()) {
-    MainExecutablePath.eraseComponent();  // Remove /clang from foo/bin/clang
-    MainExecutablePath.eraseComponent();  // Remove /bin   from foo/bin
-
-    // Get foo/lib/clang/<version>/include
-    MainExecutablePath.appendComponent("lib");
-    MainExecutablePath.appendComponent("clang");
-    MainExecutablePath.appendComponent(CLANG_VERSION_STRING);
-    MainExecutablePath.appendComponent("include");
-
-    // We pass true to ignore sysroot so that we *always* look for clang headers
-    // relative to our executable, never relative to -isysroot.
-    Init.AddPath(MainExecutablePath.c_str(), InitHeaderSearch::System,
-                 false, false, false, true /*ignore sysroot*/);
-  }
+  AddClangIncludePaths(Argv0, &Init);
 
   if (!nostdinc)
     Init.AddDefaultSystemIncludePaths(Lang);





More information about the cfe-commits mailing list