From: Rafael Espindola Date: Mon, 5 Oct 2009 13:12:17 +0000 (+0000) Subject: Add a -nostdclanginc flag to clang-cc that prevents it from searching X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1bb15a9afa73687225782ca6aa75c8530b4428fb;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83302 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 2d6fda0d45..19ea039835 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -1098,6 +1098,10 @@ RelocatablePCH("relocatable-pch", static llvm::cl::opt nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories")); +static llvm::cl::opt +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 F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix, @@ -1133,6 +1137,32 @@ isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"), // 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//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 @@ void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers, 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//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);