diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-09-22 21:41:16 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-09-22 21:41:16 +0000 |
commit | 47adebef0df6dce752fe9a45e9190e8005b5d07c (patch) | |
tree | 096b430ad15076f1b5170b72de873de8ad45e207 /lib/Driver/Tools.cpp | |
parent | 4cd06348a8c7b3559e9f437439dfc75ff7a04e88 (diff) |
Add support for CPATH and friends.
This moves the existing code for CPATH into the driver and adds the environment lookup and path splitting there.
The paths are then passed down to cc1 with -I options (CPATH), added after the normal user-specified include dirs.
Language specific paths are passed via -LANG-isystem and the actual filtering is performed in the frontend.
I tried to match GCC's behavior as close as possible
Fixes PR8971.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140341 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Tools.cpp')
-rw-r--r-- | lib/Driver/Tools.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 840e4c2734..c3c07f412f 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -183,6 +183,38 @@ static void addProfileRT(const ToolChain &TC, const ArgList &Args, CmdArgs.push_back(Args.MakeArgString(ProfileRT)); } +static void AddIncludeDirectoryList(const ArgList &Args, + ArgStringList &CmdArgs, + const char *ArgName, + const char *DirList) { + if (!DirList) + return; // Nothing to do. + + StringRef Dirs(DirList); + if (Dirs.empty()) // Empty string should not add '.'. + return; + + StringRef::size_type Delim; + while ((Delim = Dirs.find(llvm::sys::PathSeparator)) != StringRef::npos) { + if (Delim == 0) { // Leading colon. + CmdArgs.push_back(ArgName); + CmdArgs.push_back("."); + } else { + CmdArgs.push_back(ArgName); + CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim))); + } + Dirs = Dirs.substr(Delim + 1); + } + + if (Dirs.empty()) { // Trailing colon. + CmdArgs.push_back(ArgName); + CmdArgs.push_back("."); + } else { // Add the last path. + CmdArgs.push_back(ArgName); + CmdArgs.push_back(Args.MakeArgString(Dirs)); + } +} + void Clang::AddPreprocessingOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, @@ -391,6 +423,23 @@ void Clang::AddPreprocessingOptions(const Driver &D, } Args.AddAllArgs(CmdArgs, options::OPT_fauto_module_import); + + // Parse additional include paths from environment variables. + // CPATH - included following the user specified includes (but prior to + // builtin and standard includes). + AddIncludeDirectoryList(Args, CmdArgs, "-I", ::getenv("CPATH")); + // C_INCLUDE_PATH - system includes enabled when compiling C. + AddIncludeDirectoryList(Args, CmdArgs, "-c-isystem", + ::getenv("C_INCLUDE_PATH")); + // CPLUS_INCLUDE_PATH - system includes enabled when compiling C++. + AddIncludeDirectoryList(Args, CmdArgs, "-cxx-isystem", + ::getenv("CPLUS_INCLUDE_PATH")); + // OBJC_INCLUDE_PATH - system includes enabled when compiling ObjC. + AddIncludeDirectoryList(Args, CmdArgs, "-objc-isystem", + ::getenv("OBJC_INCLUDE_PATH")); + // OBJCPLUS_INCLUDE_PATH - system includes enabled when compiling ObjC++. + AddIncludeDirectoryList(Args, CmdArgs, "-objcxx-isystem", + ::getenv("OBJCPLUS_INCLUDE_PATH")); } /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting. |