aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/Tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Driver/Tools.cpp')
-rw-r--r--lib/Driver/Tools.cpp49
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.