blob: 6fceb98567b077609926b2233336354241ca2e19 [file] [log] [blame]
Nico Weber0fca0222008-08-22 09:25:22 +00001//===--- InitHeaderSearch.cpp - Initialize header search paths ----------*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the InitHeaderSearch class.
11//
12//===----------------------------------------------------------------------===//
13
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000014#include "clang/Frontend/Utils.h"
Nico Weber0fca0222008-08-22 09:25:22 +000015#include "clang/Basic/FileManager.h"
16#include "clang/Basic/LangOptions.h"
Daniel Dunbar63c8b772009-11-07 04:20:50 +000017#include "clang/Frontend/HeaderSearchOptions.h"
18#include "clang/Lex/HeaderSearch.h"
Nico Weber0fca0222008-08-22 09:25:22 +000019#include "llvm/ADT/SmallString.h"
20#include "llvm/ADT/SmallPtrSet.h"
Rafael Espindolaaadd7a42009-11-13 05:13:58 +000021#include "llvm/ADT/SmallVector.h"
Rafael Espindolaf0a2f512009-11-12 05:48:41 +000022#include "llvm/ADT/StringExtras.h"
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000023#include "llvm/ADT/Triple.h"
Benjamin Kramere89ba592009-12-08 12:38:20 +000024#include "llvm/ADT/Twine.h"
Chris Lattnerd57a7ef2009-08-23 22:45:33 +000025#include "llvm/Support/raw_ostream.h"
Nico Weber0fca0222008-08-22 09:25:22 +000026#include "llvm/System/Path.h"
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +000027#include "llvm/Config/config.h"
Mike Stump620d57a2009-10-12 20:50:45 +000028#ifdef _MSC_VER
29 #define WIN32_LEAN_AND_MEAN 1
30 #include <windows.h>
31#endif
Nico Weber0fca0222008-08-22 09:25:22 +000032using namespace clang;
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000033using namespace clang::frontend;
34
35namespace {
36
37/// InitHeaderSearch - This class makes it easier to set the search paths of
38/// a HeaderSearch object. InitHeaderSearch stores several search path lists
39/// internally, which can be sent to a HeaderSearch object in one swoop.
40class InitHeaderSearch {
41 std::vector<DirectoryLookup> IncludeGroup[4];
42 HeaderSearch& Headers;
43 bool Verbose;
44 std::string isysroot;
45
46public:
47
48 InitHeaderSearch(HeaderSearch &HS,
49 bool verbose = false, const std::string &iSysroot = "")
50 : Headers(HS), Verbose(verbose), isysroot(iSysroot) {}
51
52 /// AddPath - Add the specified path to the specified group list.
Benjamin Kramere89ba592009-12-08 12:38:20 +000053 void AddPath(const llvm::Twine &Path, IncludeDirGroup Group,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000054 bool isCXXAware, bool isUserSupplied,
55 bool isFramework, bool IgnoreSysRoot = false);
56
57 /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to suport a gnu
58 /// libstdc++.
Benjamin Kramere89ba592009-12-08 12:38:20 +000059 void AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
60 llvm::StringRef ArchDir,
61 llvm::StringRef Dir32,
62 llvm::StringRef Dir64,
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000063 const llvm::Triple &triple);
64
65 /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to suport a MinGW
66 /// libstdc++.
Benjamin Kramere89ba592009-12-08 12:38:20 +000067 void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
68 llvm::StringRef Arch,
69 llvm::StringRef Version);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000070
71 /// AddDelimitedPaths - Add a list of paths delimited by the system PATH
72 /// separator. The processing follows that of the CPATH variable for gcc.
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +000073 void AddDelimitedPaths(llvm::StringRef String);
Daniel Dunbar2cdafa82009-11-09 23:02:47 +000074
75 // AddDefaultCIncludePaths - Add paths that should always be searched.
76 void AddDefaultCIncludePaths(const llvm::Triple &triple);
77
78 // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
79 // compiling c++.
80 void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple);
81
82 /// AddDefaultSystemIncludePaths - Adds the default system include paths so
83 /// that e.g. stdio.h is found.
84 void AddDefaultSystemIncludePaths(const LangOptions &Lang,
85 const llvm::Triple &triple);
86
87 /// Realize - Merges all search path lists into one list and send it to
88 /// HeaderSearch.
89 void Realize();
90};
91
92}
Nico Weber0fca0222008-08-22 09:25:22 +000093
Benjamin Kramere89ba592009-12-08 12:38:20 +000094void InitHeaderSearch::AddPath(const llvm::Twine &Path,
Benjamin Kramer458fb102009-09-05 09:49:39 +000095 IncludeDirGroup Group, bool isCXXAware,
96 bool isUserSupplied, bool isFramework,
97 bool IgnoreSysRoot) {
Benjamin Kramere89ba592009-12-08 12:38:20 +000098 assert(!Path.isTriviallyEmpty() && "can't handle empty path here");
Nico Weber0fca0222008-08-22 09:25:22 +000099 FileManager &FM = Headers.getFileMgr();
Mike Stump1eb44332009-09-09 15:08:12 +0000100
Nico Weber0fca0222008-08-22 09:25:22 +0000101 // Compute the actual path, taking into consideration -isysroot.
Benjamin Kramere89ba592009-12-08 12:38:20 +0000102 llvm::SmallString<256> MappedPathStr;
103 llvm::raw_svector_ostream MappedPath(MappedPathStr);
Mike Stump1eb44332009-09-09 15:08:12 +0000104
Nico Weber0fca0222008-08-22 09:25:22 +0000105 // Handle isysroot.
Chris Lattner6858dd32009-02-19 06:48:28 +0000106 if (Group == System && !IgnoreSysRoot) {
Nico Weber0fca0222008-08-22 09:25:22 +0000107 // FIXME: Portability. This should be a sys::Path interface, this doesn't
108 // handle things like C:\ right, nor win32 \\network\device\blah.
109 if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present.
Benjamin Kramere89ba592009-12-08 12:38:20 +0000110 MappedPath << isysroot;
Nico Weber0fca0222008-08-22 09:25:22 +0000111 }
Mike Stump1eb44332009-09-09 15:08:12 +0000112
Benjamin Kramere89ba592009-12-08 12:38:20 +0000113 Path.print(MappedPath);
Nico Weber0fca0222008-08-22 09:25:22 +0000114
115 // Compute the DirectoryLookup type.
Chris Lattner9d728512008-10-27 01:19:25 +0000116 SrcMgr::CharacteristicKind Type;
Nico Weber0fca0222008-08-22 09:25:22 +0000117 if (Group == Quoted || Group == Angled)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000118 Type = SrcMgr::C_User;
Nico Weber0fca0222008-08-22 09:25:22 +0000119 else if (isCXXAware)
Chris Lattner0b9e7362008-09-26 21:18:42 +0000120 Type = SrcMgr::C_System;
Nico Weber0fca0222008-08-22 09:25:22 +0000121 else
Chris Lattner0b9e7362008-09-26 21:18:42 +0000122 Type = SrcMgr::C_ExternCSystem;
Mike Stump1eb44332009-09-09 15:08:12 +0000123
124
Nico Weber0fca0222008-08-22 09:25:22 +0000125 // If the directory exists, add it.
Benjamin Kramer458fb102009-09-05 09:49:39 +0000126 if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) {
Nico Weber0fca0222008-08-22 09:25:22 +0000127 IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied,
128 isFramework));
129 return;
130 }
Mike Stump1eb44332009-09-09 15:08:12 +0000131
Nico Weber0fca0222008-08-22 09:25:22 +0000132 // Check to see if this is an apple-style headermap (which are not allowed to
133 // be frameworks).
134 if (!isFramework) {
Benjamin Kramer458fb102009-09-05 09:49:39 +0000135 if (const FileEntry *FE = FM.getFile(MappedPath.str())) {
Nico Weber0fca0222008-08-22 09:25:22 +0000136 if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
137 // It is a headermap, add it to the search path.
138 IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied));
139 return;
140 }
141 }
142 }
Mike Stump1eb44332009-09-09 15:08:12 +0000143
Nico Weber0fca0222008-08-22 09:25:22 +0000144 if (Verbose)
Daniel Dunbar77659342009-08-19 20:04:03 +0000145 llvm::errs() << "ignoring nonexistent directory \""
146 << MappedPath.str() << "\"\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000147}
148
149
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000150void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) {
151 if (at.empty()) // Empty string should not add '.' path.
Nico Weber0fca0222008-08-22 09:25:22 +0000152 return;
153
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000154 llvm::StringRef::size_type delim;
155 while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) {
156 if (delim == 0)
Nico Weber0fca0222008-08-22 09:25:22 +0000157 AddPath(".", Angled, false, true, false);
158 else
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000159 AddPath(at.substr(0, delim), Angled, false, true, false);
160 at = at.substr(delim + 1);
Nico Weber0fca0222008-08-22 09:25:22 +0000161 }
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000162
163 if (at.empty())
Nico Weber0fca0222008-08-22 09:25:22 +0000164 AddPath(".", Angled, false, true, false);
165 else
166 AddPath(at, Angled, false, true, false);
167}
168
Benjamin Kramere89ba592009-12-08 12:38:20 +0000169void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
170 llvm::StringRef ArchDir,
171 llvm::StringRef Dir32,
172 llvm::StringRef Dir64,
Rafael Espindola31b63be2009-10-14 17:09:44 +0000173 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000174 // Add the base dir
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000175 AddPath(Base, System, true, false, false);
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000176
177 // Add the multilib dirs
Rafael Espindola31b63be2009-10-14 17:09:44 +0000178 llvm::Triple::ArchType arch = triple.getArch();
179 bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64;
Rafael Espindola31b63be2009-10-14 17:09:44 +0000180 if (is64bit)
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000181 AddPath(Base + "/" + ArchDir + "/" + Dir64, System, true, false, false);
Rafael Espindola31b63be2009-10-14 17:09:44 +0000182 else
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000183 AddPath(Base + "/" + ArchDir + "/" + Dir32, System, true, false, false);
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000184
185 // Add the backward dir
186 AddPath(Base + "/backward", System, true, false, false);
Rafael Espindola2e9f6522009-10-06 01:33:02 +0000187}
Nico Weber0fca0222008-08-22 09:25:22 +0000188
Benjamin Kramere89ba592009-12-08 12:38:20 +0000189void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
190 llvm::StringRef Arch,
191 llvm::StringRef Version) {
192 llvm::Twine localBase = Base + "/" + Arch + "/" + Version + "/include";
Daniel Dunbar5c5758b2009-11-07 04:20:25 +0000193 AddPath(localBase, System, true, false, false);
194 AddPath(localBase + "/c++", System, true, false, false);
195 AddPath(localBase + "/c++/backward", System, true, false, false);
Mike Stump620d57a2009-10-12 20:50:45 +0000196}
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000197
Mike Stump620d57a2009-10-12 20:50:45 +0000198 // FIXME: This probably should goto to some platform utils place.
199#ifdef _MSC_VER
John Thompson75ee3bd2009-11-21 00:15:52 +0000200
Mike Stump620d57a2009-10-12 20:50:45 +0000201 // Read registry string.
John Thompson75ee3bd2009-11-21 00:15:52 +0000202 // This also supports a means to look for high-versioned keys by use
203 // of a $VERSION placeholder in the key path.
204 // $VERSION in the key path is a placeholder for the version number,
205 // causing the highest value path to be searched for and used.
206 // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION".
207 // There can be additional characters in the component. Only the numberic
208 // characters are compared.
Mike Stump620d57a2009-10-12 20:50:45 +0000209bool getSystemRegistryString(const char *keyPath, const char *valueName,
Mike Stump43d81762009-10-08 23:29:47 +0000210 char *value, size_t maxLength) {
211 HKEY hRootKey = NULL;
212 HKEY hKey = NULL;
213 const char* subKey = NULL;
214 DWORD valueType;
215 DWORD valueSize = maxLength - 1;
John Thompson75ee3bd2009-11-21 00:15:52 +0000216 long lResult;
Mike Stump43d81762009-10-08 23:29:47 +0000217 bool returnValue = false;
218 if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) {
219 hRootKey = HKEY_CLASSES_ROOT;
220 subKey = keyPath + 18;
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000221 }
Mike Stump43d81762009-10-08 23:29:47 +0000222 else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) {
223 hRootKey = HKEY_USERS;
224 subKey = keyPath + 11;
225 }
226 else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) {
227 hRootKey = HKEY_LOCAL_MACHINE;
228 subKey = keyPath + 19;
229 }
230 else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) {
231 hRootKey = HKEY_CURRENT_USER;
232 subKey = keyPath + 18;
233 }
234 else
235 return(false);
John Thompson75ee3bd2009-11-21 00:15:52 +0000236 const char *placeHolder = strstr(subKey, "$VERSION");
237 char bestName[256];
238 bestName[0] = '\0';
239 // If we have a $VERSION placeholder, do the highest-version search.
240 if (placeHolder) {
241 const char *keyEnd = placeHolder - 1;
242 const char *nextKey = placeHolder;
243 // Find end of previous key.
244 while ((keyEnd > subKey) && (*keyEnd != '\\'))
245 keyEnd--;
246 // Find end of key containing $VERSION.
247 while (*nextKey && (*nextKey != '\\'))
248 nextKey++;
249 size_t partialKeyLength = keyEnd - subKey;
250 char partialKey[256];
251 if (partialKeyLength > sizeof(partialKey))
252 partialKeyLength = sizeof(partialKey);
253 strncpy(partialKey, subKey, partialKeyLength);
254 partialKey[partialKeyLength] = '\0';
255 HKEY hTopKey = NULL;
256 lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey);
257 if (lResult == ERROR_SUCCESS) {
258 char keyName[256];
259 int bestIndex = -1;
260 double bestValue = 0.0;
261 DWORD index, size = sizeof(keyName) - 1;
Nuno Lopes33cc2432009-12-07 17:18:48 +0000262 for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL,
263 NULL, NULL, NULL) == ERROR_SUCCESS; index++) {
264 const char *sp = keyName;
265 while (*sp && !isdigit(*sp))
266 sp++;
267 if (!*sp)
268 continue;
269 const char *ep = sp + 1;
270 while (*ep && (isdigit(*ep) || (*ep == '.')))
271 ep++;
272 char numBuf[32];
273 strncpy(numBuf, sp, sizeof(numBuf) - 1);
274 numBuf[sizeof(numBuf) - 1] = '\0';
275 double value = strtod(numBuf, NULL);
276 if (value > bestValue) {
277 bestIndex = (int)index;
278 bestValue = value;
279 strcpy(bestName, keyName);
280 }
John Thompson75ee3bd2009-11-21 00:15:52 +0000281 size = sizeof(keyName) - 1;
282 }
283 // If we found the highest versioned key, open the key and get the value.
284 if (bestIndex != -1) {
285 // Append rest of key.
286 strncat(bestName, nextKey, sizeof(bestName) - 1);
287 bestName[sizeof(bestName) - 1] = '\0';
288 // Open the chosen key path remainder.
289 lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey);
290 if (lResult == ERROR_SUCCESS) {
291 lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
292 (LPBYTE)value, &valueSize);
293 if (lResult == ERROR_SUCCESS)
294 returnValue = true;
295 RegCloseKey(hKey);
296 }
297 }
298 RegCloseKey(hTopKey);
299 }
300 }
301 else {
302 lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey);
303 if (lResult == ERROR_SUCCESS) {
304 lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType,
305 (LPBYTE)value, &valueSize);
306 if (lResult == ERROR_SUCCESS)
307 returnValue = true;
308 RegCloseKey(hKey);
309 }
Mike Stump43d81762009-10-08 23:29:47 +0000310 }
311 return(returnValue);
312}
Mike Stump620d57a2009-10-12 20:50:45 +0000313#else // _MSC_VER
314 // Read registry string.
315bool getSystemRegistryString(const char *, const char *, char *, size_t) {
316 return(false);
317}
318#endif // _MSC_VER
Argyrios Kyrtzidis121e3c22008-09-05 09:41:20 +0000319
Mike Stump43d81762009-10-08 23:29:47 +0000320 // Get Visual Studio installation directory.
321bool getVisualStudioDir(std::string &path) {
John Thompson75ee3bd2009-11-21 00:15:52 +0000322 char vsIDEInstallDir[256];
Mike Stump620d57a2009-10-12 20:50:45 +0000323 // Try the Windows registry first.
John Thompson75ee3bd2009-11-21 00:15:52 +0000324 bool hasVCDir = getSystemRegistryString(
325 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION",
326 "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1);
Mike Stump43d81762009-10-08 23:29:47 +0000327 // If we have both vc80 and vc90, pick version we were compiled with.
John Thompson75ee3bd2009-11-21 00:15:52 +0000328 if (hasVCDir && vsIDEInstallDir[0]) {
Mike Stump620d57a2009-10-12 20:50:45 +0000329 char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE");
330 if (p)
331 *p = '\0';
332 path = vsIDEInstallDir;
333 return(true);
334 }
335 else {
336 // Try the environment.
337 const char* vs90comntools = getenv("VS90COMNTOOLS");
338 const char* vs80comntools = getenv("VS80COMNTOOLS");
339 const char* vscomntools = NULL;
340 // If we have both vc80 and vc90, pick version we were compiled with.
341 if (vs90comntools && vs80comntools) {
342 #if (_MSC_VER >= 1500) // VC90
Mike Stump43d81762009-10-08 23:29:47 +0000343 vscomntools = vs90comntools;
344 #elif (_MSC_VER == 1400) // VC80
345 vscomntools = vs80comntools;
346 #else
347 vscomntools = vs90comntools;
348 #endif
Mike Stump620d57a2009-10-12 20:50:45 +0000349 }
350 else if (vs90comntools)
Mike Stump43d81762009-10-08 23:29:47 +0000351 vscomntools = vs90comntools;
Mike Stump620d57a2009-10-12 20:50:45 +0000352 else if (vs80comntools)
353 vscomntools = vs80comntools;
354 if (vscomntools && *vscomntools) {
355 char *p = (char*)strstr(vscomntools, "\\Common7\\Tools");
356 if (p)
357 *p = '\0';
358 path = vscomntools;
359 return(true);
360 }
361 else
362 return(false);
Mike Stump43d81762009-10-08 23:29:47 +0000363 }
Mike Stump620d57a2009-10-12 20:50:45 +0000364 return(false);
Mike Stump43d81762009-10-08 23:29:47 +0000365}
Mike Stump43d81762009-10-08 23:29:47 +0000366
John Thompson75ee3bd2009-11-21 00:15:52 +0000367 // Get Windows SDK installation directory.
368bool getWindowsSDKDir(std::string &path) {
369 char windowsSDKInstallDir[256];
370 // Try the Windows registry.
371 bool hasSDKDir = getSystemRegistryString(
372 "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
373 "InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1);
374 // If we have both vc80 and vc90, pick version we were compiled with.
375 if (hasSDKDir && windowsSDKInstallDir[0]) {
376 path = windowsSDKInstallDir;
377 return(true);
378 }
379 return(false);
380}
381
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000382void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple) {
Mike Stump43d81762009-10-08 23:29:47 +0000383 // FIXME: temporary hack: hard-coded paths.
Daniel Dunbarc7064682009-11-12 07:28:29 +0000384 llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS);
385 if (CIncludeDirs != "") {
Rafael Espindolaaadd7a42009-11-13 05:13:58 +0000386 llvm::SmallVector<llvm::StringRef, 5> dirs;
387 CIncludeDirs.split(dirs, ":");
388 for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin();
389 i != dirs.end();
390 ++i)
Rafael Espindolaf0a2f512009-11-12 05:48:41 +0000391 AddPath(*i, System, false, false, false);
392 return;
393 }
Mike Stump43d81762009-10-08 23:29:47 +0000394 llvm::Triple::OSType os = triple.getOS();
Mike Stump43d81762009-10-08 23:29:47 +0000395 switch (os) {
396 case llvm::Triple::Win32:
397 {
Mike Stump620d57a2009-10-12 20:50:45 +0000398 std::string VSDir;
John Thompson75ee3bd2009-11-21 00:15:52 +0000399 std::string WindowsSDKDir;
Mike Stump620d57a2009-10-12 20:50:45 +0000400 if (getVisualStudioDir(VSDir)) {
401 AddPath(VSDir + "\\VC\\include", System, false, false, false);
John Thompson75ee3bd2009-11-21 00:15:52 +0000402 if (getWindowsSDKDir(WindowsSDKDir))
403 AddPath(WindowsSDKDir, System, false, false, false);
404 else
405 AddPath(VSDir + "\\VC\\PlatformSDK\\Include",
406 System, false, false, false);
Mike Stump620d57a2009-10-12 20:50:45 +0000407 }
John Thompson9319f022009-11-23 17:49:27 +0000408 else {
409 // Default install paths.
410 AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
411 System, false, false, false);
412 AddPath(
413 "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
414 System, false, false, false);
415 AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include",
416 System, false, false, false);
417 AddPath(
418 "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include",
419 System, false, false, false);
420 // For some clang developers.
421 AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include",
422 System, false, false, false);
423 AddPath(
424 "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
425 System, false, false, false);
426 }
Mike Stump43d81762009-10-08 23:29:47 +0000427 }
428 break;
Mike Stump43d81762009-10-08 23:29:47 +0000429 case llvm::Triple::MinGW64:
Mike Stump620d57a2009-10-12 20:50:45 +0000430 case llvm::Triple::MinGW32:
Mike Stump43d81762009-10-08 23:29:47 +0000431 AddPath("c:/mingw/include", System, true, false, false);
432 break;
433 default:
Mike Stump43d81762009-10-08 23:29:47 +0000434 break;
435 }
John Thompsond3f88342009-10-13 18:51:32 +0000436
437 AddPath("/usr/local/include", System, false, false, false);
438 AddPath("/usr/include", System, false, false, false);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000439}
440
441void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
442 llvm::Triple::OSType os = triple.getOS();
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000443 llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT);
444 if (CxxIncludeRoot != "") {
445 llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH);
446 if (CxxIncludeArch == "")
447 AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(),
448 CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple);
449 else
450 AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH,
451 CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple);
452 return;
453 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000454 // FIXME: temporary hack: hard-coded paths.
455 switch (os) {
456 case llvm::Triple::Cygwin:
457 AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include",
458 System, true, false, false);
459 AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++",
460 System, true, false, false);
461 break;
462 case llvm::Triple::MinGW64:
463 // Try gcc 4.4.0
464 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0");
465 // Try gcc 4.3.0
466 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0");
467 // Fall through.
468 case llvm::Triple::MinGW32:
469 // Try gcc 4.4.0
470 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
471 // Try gcc 4.3.0
472 AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
473 break;
474 case llvm::Triple::Darwin:
475 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000476 "i686-apple-darwin10", "", "x86_64", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000477 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000478 "i686-apple-darwin8", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000479 break;
Chris Lattner7a7ca282010-01-09 05:41:14 +0000480 case llvm::Triple::DragonFly:
481 AddPath("/usr/include/c++/4.1", System, true, false, false);
482 break;
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000483 case llvm::Triple::Linux:
Torok Edwinfc4b8992009-12-18 17:29:14 +0000484 // Exherbo (2009-10-26)
485 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2",
486 "x86_64-pc-linux-gnu", "32", "", triple);
487 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2",
488 "i686-pc-linux-gnu", "", "", triple);
Torok Edwin331e8012009-12-18 17:43:54 +0000489 // Debian sid
490 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2",
491 "x86_64-linux-gnu", "32", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000492 // Ubuntu 7.10 - Gutsy Gibbon
493 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000494 "i486-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000495 // Ubuntu 9.04
496 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000497 "x86_64-linux-gnu","32", "", triple);
Sebastian Redl5114eca2009-11-05 17:44:49 +0000498 // Ubuntu 9.10
499 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000500 "x86_64-linux-gnu", "32", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000501 // Fedora 8
502 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000503 "i386-redhat-linux", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000504 // Fedora 9
505 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000506 "i386-redhat-linux", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000507 // Fedora 10
508 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000509 "i386-redhat-linux","", "", triple);
Nuno Lopes189a1482009-11-17 15:28:35 +0000510
511 // Fedora 11
512 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1",
513 "i586-redhat-linux","", "", triple);
514
Nuno Lopes33cc2432009-12-07 17:18:48 +0000515 // Fedora 12
516 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2",
517 "i686-redhat-linux","", "", triple);
518
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000519 // openSUSE 11.1 32 bit
520 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000521 "i586-suse-linux", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000522 // openSUSE 11.1 64 bit
523 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000524 "x86_64-suse-linux", "32", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000525 // openSUSE 11.2
526 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000527 "i586-suse-linux", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000528 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000529 "x86_64-suse-linux", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000530 // Arch Linux 2008-06-24
531 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000532 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000533 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000534 "x86_64-unknown-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000535 // Gentoo x86 2009.1 stable
536 AddGnuCPlusPlusIncludePaths(
John Thompson40d1bb62009-11-05 22:03:02 +0000537 "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000538 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000539 // Gentoo x86 2009.0 stable
540 AddGnuCPlusPlusIncludePaths(
John Thompson40d1bb62009-11-05 22:03:02 +0000541 "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000542 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000543 // Gentoo x86 2008.0 stable
544 AddGnuCPlusPlusIncludePaths(
John Thompson40d1bb62009-11-05 22:03:02 +0000545 "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000546 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000547 // Ubuntu 8.10
548 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000549 "i486-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000550 // Ubuntu 9.04
551 AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000552 "i486-linux-gnu","", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000553 // Gentoo amd64 stable
554 AddGnuCPlusPlusIncludePaths(
555 "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000556 "i686-pc-linux-gnu", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000557 break;
558 case llvm::Triple::FreeBSD:
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000559 AddPath("/usr/include/c++/4.2", System, true, false, false);
560 break;
561 case llvm::Triple::Solaris:
562 // Solaris - Fall though..
563 case llvm::Triple::AuroraUX:
564 // AuroraUX
565 AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4",
Rafael Espindolaab7ae952009-11-16 19:49:37 +0000566 "i386-pc-solaris2.11", "", "", triple);
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000567 break;
568 default:
569 break;
570 }
571}
572
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000573void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
574 const llvm::Triple &triple) {
Rafael Espindola6ec18a32009-11-23 16:31:19 +0000575 if (Lang.CPlusPlus)
576 AddDefaultCPlusPlusIncludePaths(triple);
577
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000578 AddDefaultCIncludePaths(triple);
Daniel Dunbare1665822009-11-07 04:20:39 +0000579
580 // Add the default framework include paths on Darwin.
581 if (triple.getOS() == llvm::Triple::Darwin) {
582 AddPath("/System/Library/Frameworks", System, true, false, true);
583 AddPath("/Library/Frameworks", System, true, false, true);
584 }
Rafael Espindolae4b255c2009-10-27 14:47:31 +0000585}
586
Nico Weber0fca0222008-08-22 09:25:22 +0000587/// RemoveDuplicates - If there are duplicate directory entries in the specified
588/// search list, remove the later (dead) ones.
589static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
590 bool Verbose) {
591 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
592 llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
593 llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
594 for (unsigned i = 0; i != SearchList.size(); ++i) {
Chris Lattner7a739402008-09-26 17:46:45 +0000595 unsigned DirToRemove = i;
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Chris Lattner43eee072009-02-08 01:00:10 +0000597 const DirectoryLookup &CurEntry = SearchList[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000598
Chris Lattner43eee072009-02-08 01:00:10 +0000599 if (CurEntry.isNormalDir()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000600 // If this isn't the first time we've seen this dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000601 if (SeenDirs.insert(CurEntry.getDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000602 continue;
Chris Lattner43eee072009-02-08 01:00:10 +0000603 } else if (CurEntry.isFramework()) {
Nico Weber0fca0222008-08-22 09:25:22 +0000604 // If this isn't the first time we've seen this framework dir, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000605 if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir()))
Nico Weber0fca0222008-08-22 09:25:22 +0000606 continue;
Nico Weber0fca0222008-08-22 09:25:22 +0000607 } else {
Chris Lattner43eee072009-02-08 01:00:10 +0000608 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
Nico Weber0fca0222008-08-22 09:25:22 +0000609 // If this isn't the first time we've seen this headermap, remove it.
Chris Lattner43eee072009-02-08 01:00:10 +0000610 if (SeenHeaderMaps.insert(CurEntry.getHeaderMap()))
Nico Weber0fca0222008-08-22 09:25:22 +0000611 continue;
Chris Lattner30f05b52009-02-08 00:55:22 +0000612 }
Mike Stump1eb44332009-09-09 15:08:12 +0000613
Chris Lattner30f05b52009-02-08 00:55:22 +0000614 // If we have a normal #include dir/framework/headermap that is shadowed
615 // later in the chain by a system include location, we actually want to
616 // ignore the user's request and drop the user dir... keeping the system
617 // dir. This is weird, but required to emulate GCC's search path correctly.
618 //
619 // Since dupes of system dirs are rare, just rescan to find the original
620 // that we're nuking instead of using a DenseMap.
Chris Lattner43eee072009-02-08 01:00:10 +0000621 if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
Chris Lattner30f05b52009-02-08 00:55:22 +0000622 // Find the dir that this is the same of.
623 unsigned FirstDir;
624 for (FirstDir = 0; ; ++FirstDir) {
625 assert(FirstDir != i && "Didn't find dupe?");
Mike Stump1eb44332009-09-09 15:08:12 +0000626
Chris Lattner43eee072009-02-08 01:00:10 +0000627 const DirectoryLookup &SearchEntry = SearchList[FirstDir];
628
Chris Lattner30f05b52009-02-08 00:55:22 +0000629 // If these are different lookup types, then they can't be the dupe.
Chris Lattner43eee072009-02-08 01:00:10 +0000630 if (SearchEntry.getLookupType() != CurEntry.getLookupType())
Chris Lattner30f05b52009-02-08 00:55:22 +0000631 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000632
Chris Lattner30f05b52009-02-08 00:55:22 +0000633 bool isSame;
Chris Lattner43eee072009-02-08 01:00:10 +0000634 if (CurEntry.isNormalDir())
635 isSame = SearchEntry.getDir() == CurEntry.getDir();
636 else if (CurEntry.isFramework())
637 isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir();
Chris Lattner30f05b52009-02-08 00:55:22 +0000638 else {
Chris Lattner43eee072009-02-08 01:00:10 +0000639 assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?");
640 isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap();
Chris Lattner30f05b52009-02-08 00:55:22 +0000641 }
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Chris Lattner30f05b52009-02-08 00:55:22 +0000643 if (isSame)
644 break;
645 }
Mike Stump1eb44332009-09-09 15:08:12 +0000646
Chris Lattner30f05b52009-02-08 00:55:22 +0000647 // If the first dir in the search path is a non-system dir, zap it
648 // instead of the system one.
649 if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User)
650 DirToRemove = FirstDir;
651 }
652
653 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000654 llvm::errs() << "ignoring duplicate directory \""
655 << CurEntry.getName() << "\"\n";
Chris Lattner30f05b52009-02-08 00:55:22 +0000656 if (DirToRemove != i)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000657 llvm::errs() << " as it is a non-system directory that duplicates "
658 << "a system directory\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000659 }
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Chris Lattner7a739402008-09-26 17:46:45 +0000661 // This is reached if the current entry is a duplicate. Remove the
662 // DirToRemove (usually the current dir).
663 SearchList.erase(SearchList.begin()+DirToRemove);
Nico Weber0fca0222008-08-22 09:25:22 +0000664 --i;
665 }
666}
667
668
669void InitHeaderSearch::Realize() {
670 // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
671 std::vector<DirectoryLookup> SearchList;
672 SearchList = IncludeGroup[Angled];
673 SearchList.insert(SearchList.end(), IncludeGroup[System].begin(),
674 IncludeGroup[System].end());
675 SearchList.insert(SearchList.end(), IncludeGroup[After].begin(),
676 IncludeGroup[After].end());
677 RemoveDuplicates(SearchList, Verbose);
678 RemoveDuplicates(IncludeGroup[Quoted], Verbose);
Mike Stump1eb44332009-09-09 15:08:12 +0000679
Nico Weber0fca0222008-08-22 09:25:22 +0000680 // Prepend QUOTED list on the search list.
Mike Stump1eb44332009-09-09 15:08:12 +0000681 SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(),
Nico Weber0fca0222008-08-22 09:25:22 +0000682 IncludeGroup[Quoted].end());
Mike Stump1eb44332009-09-09 15:08:12 +0000683
Nico Weber0fca0222008-08-22 09:25:22 +0000684
685 bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
686 Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(),
687 DontSearchCurDir);
688
689 // If verbose, print the list of directories that will be searched.
690 if (Verbose) {
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000691 llvm::errs() << "#include \"...\" search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000692 unsigned QuotedIdx = IncludeGroup[Quoted].size();
693 for (unsigned i = 0, e = SearchList.size(); i != e; ++i) {
694 if (i == QuotedIdx)
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000695 llvm::errs() << "#include <...> search starts here:\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000696 const char *Name = SearchList[i].getName();
697 const char *Suffix;
698 if (SearchList[i].isNormalDir())
699 Suffix = "";
700 else if (SearchList[i].isFramework())
701 Suffix = " (framework directory)";
702 else {
703 assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup");
704 Suffix = " (headermap)";
705 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000706 llvm::errs() << " " << Name << Suffix << "\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000707 }
Daniel Dunbare7cb7e42009-12-03 09:14:02 +0000708 llvm::errs() << "End of search list.\n";
Nico Weber0fca0222008-08-22 09:25:22 +0000709 }
710}
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000711
Daniel Dunbar5814e652009-11-11 21:44:21 +0000712void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
713 const HeaderSearchOptions &HSOpts,
714 const LangOptions &Lang,
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000715 const llvm::Triple &Triple) {
716 InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
717
718 // Add the user defined entries.
719 for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) {
720 const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i];
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000721 Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework,
722 false);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000723 }
724
725 // Add entries from CPATH and friends.
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000726 Init.AddDelimitedPaths(HSOpts.EnvIncPath);
Daniel Dunbarc363cb12009-11-16 22:38:40 +0000727 if (Lang.CPlusPlus && Lang.ObjC1)
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000728 Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath);
Daniel Dunbarc363cb12009-11-16 22:38:40 +0000729 else if (Lang.CPlusPlus)
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000730 Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath);
Daniel Dunbarc363cb12009-11-16 22:38:40 +0000731 else if (Lang.ObjC1)
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000732 Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath);
Daniel Dunbarc363cb12009-11-16 22:38:40 +0000733 else
Benjamin Kramer9e9ddf62009-12-08 12:11:06 +0000734 Init.AddDelimitedPaths(HSOpts.CEnvIncPath);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000735
Daniel Dunbar1e69fe32009-12-13 03:45:58 +0000736 if (HSOpts.UseBuiltinIncludes) {
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000737 // Ignore the sys root, we *always* look for clang headers relative to
738 // supplied path.
Daniel Dunbar8b9adfe2009-12-15 00:06:45 +0000739 llvm::sys::Path P(HSOpts.ResourceDir);
740 P.appendComponent("include");
741 Init.AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true);
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000742 }
743
Daniel Dunbardd35ce92009-11-07 04:58:12 +0000744 if (HSOpts.UseStandardIncludes)
Daniel Dunbar63c8b772009-11-07 04:20:50 +0000745 Init.AddDefaultSystemIncludePaths(Lang, Triple);
746
747 Init.Realize();
748}