Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 1 | //===--- 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 Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 14 | #include "clang/Frontend/Utils.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 15 | #include "clang/Basic/FileManager.h" |
| 16 | #include "clang/Basic/LangOptions.h" |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/HeaderSearchOptions.h" |
| 18 | #include "clang/Lex/HeaderSearch.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallString.h" |
| 20 | #include "llvm/ADT/SmallPtrSet.h" |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/Triple.h" |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Twine.h" |
Chris Lattner | d57a7ef | 2009-08-23 22:45:33 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 26 | #include "llvm/System/Path.h" |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 27 | #include "llvm/Config/config.h" |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 28 | #ifdef _MSC_VER |
| 29 | #define WIN32_LEAN_AND_MEAN 1 |
| 30 | #include <windows.h> |
| 31 | #endif |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 32 | using namespace clang; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 33 | using namespace clang::frontend; |
| 34 | |
| 35 | namespace { |
| 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. |
| 40 | class InitHeaderSearch { |
| 41 | std::vector<DirectoryLookup> IncludeGroup[4]; |
| 42 | HeaderSearch& Headers; |
| 43 | bool Verbose; |
| 44 | std::string isysroot; |
| 45 | |
| 46 | public: |
| 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 Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 53 | void AddPath(const llvm::Twine &Path, IncludeDirGroup Group, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 54 | bool isCXXAware, bool isUserSupplied, |
| 55 | bool isFramework, bool IgnoreSysRoot = false); |
| 56 | |
| 57 | /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to suport a gnu |
| 58 | /// libstdc++. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 59 | void AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, |
| 60 | llvm::StringRef ArchDir, |
| 61 | llvm::StringRef Dir32, |
| 62 | llvm::StringRef Dir64, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 63 | const llvm::Triple &triple); |
| 64 | |
| 65 | /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to suport a MinGW |
| 66 | /// libstdc++. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 67 | void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, |
| 68 | llvm::StringRef Arch, |
| 69 | llvm::StringRef Version); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 70 | |
| 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 Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 73 | void AddDelimitedPaths(llvm::StringRef String); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 74 | |
| 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, |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 85 | const llvm::Triple &triple, |
| 86 | bool UseStandardCXXIncludes); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 87 | |
| 88 | /// Realize - Merges all search path lists into one list and send it to |
| 89 | /// HeaderSearch. |
| 90 | void Realize(); |
| 91 | }; |
| 92 | |
| 93 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 94 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 95 | void InitHeaderSearch::AddPath(const llvm::Twine &Path, |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 96 | IncludeDirGroup Group, bool isCXXAware, |
| 97 | bool isUserSupplied, bool isFramework, |
| 98 | bool IgnoreSysRoot) { |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 99 | assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 100 | FileManager &FM = Headers.getFileMgr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 101 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 102 | // Compute the actual path, taking into consideration -isysroot. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 103 | llvm::SmallString<256> MappedPathStr; |
| 104 | llvm::raw_svector_ostream MappedPath(MappedPathStr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 105 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 106 | // Handle isysroot. |
Chris Lattner | 6858dd3 | 2009-02-19 06:48:28 +0000 | [diff] [blame] | 107 | if (Group == System && !IgnoreSysRoot) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 108 | // FIXME: Portability. This should be a sys::Path interface, this doesn't |
| 109 | // handle things like C:\ right, nor win32 \\network\device\blah. |
| 110 | if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present. |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 111 | MappedPath << isysroot; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 112 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 114 | Path.print(MappedPath); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 115 | |
| 116 | // Compute the DirectoryLookup type. |
Chris Lattner | 9d72851 | 2008-10-27 01:19:25 +0000 | [diff] [blame] | 117 | SrcMgr::CharacteristicKind Type; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 118 | if (Group == Quoted || Group == Angled) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 119 | Type = SrcMgr::C_User; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 120 | else if (isCXXAware) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 121 | Type = SrcMgr::C_System; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 122 | else |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 123 | Type = SrcMgr::C_ExternCSystem; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
| 125 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 126 | // If the directory exists, add it. |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 127 | if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 128 | IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied, |
| 129 | isFramework)); |
| 130 | return; |
| 131 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 133 | // Check to see if this is an apple-style headermap (which are not allowed to |
| 134 | // be frameworks). |
| 135 | if (!isFramework) { |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 136 | if (const FileEntry *FE = FM.getFile(MappedPath.str())) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 137 | if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { |
| 138 | // It is a headermap, add it to the search path. |
| 139 | IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied)); |
| 140 | return; |
| 141 | } |
| 142 | } |
| 143 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 144 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 145 | if (Verbose) |
Daniel Dunbar | 7765934 | 2009-08-19 20:04:03 +0000 | [diff] [blame] | 146 | llvm::errs() << "ignoring nonexistent directory \"" |
| 147 | << MappedPath.str() << "\"\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 151 | void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) { |
| 152 | if (at.empty()) // Empty string should not add '.' path. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 153 | return; |
| 154 | |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 155 | llvm::StringRef::size_type delim; |
| 156 | while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) { |
| 157 | if (delim == 0) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 158 | AddPath(".", Angled, false, true, false); |
| 159 | else |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 160 | AddPath(at.substr(0, delim), Angled, false, true, false); |
| 161 | at = at.substr(delim + 1); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 162 | } |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 163 | |
| 164 | if (at.empty()) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 165 | AddPath(".", Angled, false, true, false); |
| 166 | else |
| 167 | AddPath(at, Angled, false, true, false); |
| 168 | } |
| 169 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 170 | void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, |
| 171 | llvm::StringRef ArchDir, |
| 172 | llvm::StringRef Dir32, |
| 173 | llvm::StringRef Dir64, |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 174 | const llvm::Triple &triple) { |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 175 | // Add the base dir |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 176 | AddPath(Base, System, true, false, false); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 177 | |
| 178 | // Add the multilib dirs |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 179 | llvm::Triple::ArchType arch = triple.getArch(); |
| 180 | bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 181 | if (is64bit) |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 182 | AddPath(Base + "/" + ArchDir + "/" + Dir64, System, true, false, false); |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 183 | else |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 184 | AddPath(Base + "/" + ArchDir + "/" + Dir32, System, true, false, false); |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 185 | |
| 186 | // Add the backward dir |
| 187 | AddPath(Base + "/backward", System, true, false, false); |
Rafael Espindola | 2e9f652 | 2009-10-06 01:33:02 +0000 | [diff] [blame] | 188 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 189 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 190 | void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, |
| 191 | llvm::StringRef Arch, |
| 192 | llvm::StringRef Version) { |
Benjamin Kramer | ab8ae19 | 2010-01-20 16:18:11 +0000 | [diff] [blame] | 193 | AddPath(Base + "/" + Arch + "/" + Version + "/include", |
| 194 | System, true, false, false); |
| 195 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", |
| 196 | System, true, false, false); |
| 197 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", |
| 198 | System, true, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 199 | } |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 200 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 201 | // FIXME: This probably should goto to some platform utils place. |
| 202 | #ifdef _MSC_VER |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 203 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 204 | // Read registry string. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 205 | // This also supports a means to look for high-versioned keys by use |
| 206 | // of a $VERSION placeholder in the key path. |
| 207 | // $VERSION in the key path is a placeholder for the version number, |
| 208 | // causing the highest value path to be searched for and used. |
| 209 | // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". |
| 210 | // There can be additional characters in the component. Only the numberic |
| 211 | // characters are compared. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 212 | static bool getSystemRegistryString(const char *keyPath, const char *valueName, |
| 213 | char *value, size_t maxLength) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 214 | HKEY hRootKey = NULL; |
| 215 | HKEY hKey = NULL; |
| 216 | const char* subKey = NULL; |
| 217 | DWORD valueType; |
| 218 | DWORD valueSize = maxLength - 1; |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 219 | long lResult; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 220 | bool returnValue = false; |
| 221 | if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { |
| 222 | hRootKey = HKEY_CLASSES_ROOT; |
| 223 | subKey = keyPath + 18; |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 224 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 225 | else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { |
| 226 | hRootKey = HKEY_USERS; |
| 227 | subKey = keyPath + 11; |
| 228 | } |
| 229 | else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { |
| 230 | hRootKey = HKEY_LOCAL_MACHINE; |
| 231 | subKey = keyPath + 19; |
| 232 | } |
| 233 | else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { |
| 234 | hRootKey = HKEY_CURRENT_USER; |
| 235 | subKey = keyPath + 18; |
| 236 | } |
| 237 | else |
| 238 | return(false); |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 239 | const char *placeHolder = strstr(subKey, "$VERSION"); |
| 240 | char bestName[256]; |
| 241 | bestName[0] = '\0'; |
| 242 | // If we have a $VERSION placeholder, do the highest-version search. |
| 243 | if (placeHolder) { |
| 244 | const char *keyEnd = placeHolder - 1; |
| 245 | const char *nextKey = placeHolder; |
| 246 | // Find end of previous key. |
| 247 | while ((keyEnd > subKey) && (*keyEnd != '\\')) |
| 248 | keyEnd--; |
| 249 | // Find end of key containing $VERSION. |
| 250 | while (*nextKey && (*nextKey != '\\')) |
| 251 | nextKey++; |
| 252 | size_t partialKeyLength = keyEnd - subKey; |
| 253 | char partialKey[256]; |
| 254 | if (partialKeyLength > sizeof(partialKey)) |
| 255 | partialKeyLength = sizeof(partialKey); |
| 256 | strncpy(partialKey, subKey, partialKeyLength); |
| 257 | partialKey[partialKeyLength] = '\0'; |
| 258 | HKEY hTopKey = NULL; |
| 259 | lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey); |
| 260 | if (lResult == ERROR_SUCCESS) { |
| 261 | char keyName[256]; |
| 262 | int bestIndex = -1; |
| 263 | double bestValue = 0.0; |
| 264 | DWORD index, size = sizeof(keyName) - 1; |
Nuno Lopes | 33cc243 | 2009-12-07 17:18:48 +0000 | [diff] [blame] | 265 | for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, |
| 266 | NULL, NULL, NULL) == ERROR_SUCCESS; index++) { |
| 267 | const char *sp = keyName; |
| 268 | while (*sp && !isdigit(*sp)) |
| 269 | sp++; |
| 270 | if (!*sp) |
| 271 | continue; |
| 272 | const char *ep = sp + 1; |
| 273 | while (*ep && (isdigit(*ep) || (*ep == '.'))) |
| 274 | ep++; |
| 275 | char numBuf[32]; |
| 276 | strncpy(numBuf, sp, sizeof(numBuf) - 1); |
| 277 | numBuf[sizeof(numBuf) - 1] = '\0'; |
| 278 | double value = strtod(numBuf, NULL); |
| 279 | if (value > bestValue) { |
| 280 | bestIndex = (int)index; |
| 281 | bestValue = value; |
| 282 | strcpy(bestName, keyName); |
| 283 | } |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 284 | size = sizeof(keyName) - 1; |
| 285 | } |
| 286 | // If we found the highest versioned key, open the key and get the value. |
| 287 | if (bestIndex != -1) { |
| 288 | // Append rest of key. |
| 289 | strncat(bestName, nextKey, sizeof(bestName) - 1); |
| 290 | bestName[sizeof(bestName) - 1] = '\0'; |
| 291 | // Open the chosen key path remainder. |
| 292 | lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey); |
| 293 | if (lResult == ERROR_SUCCESS) { |
| 294 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 295 | (LPBYTE)value, &valueSize); |
| 296 | if (lResult == ERROR_SUCCESS) |
| 297 | returnValue = true; |
| 298 | RegCloseKey(hKey); |
| 299 | } |
| 300 | } |
| 301 | RegCloseKey(hTopKey); |
| 302 | } |
| 303 | } |
| 304 | else { |
| 305 | lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); |
| 306 | if (lResult == ERROR_SUCCESS) { |
| 307 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 308 | (LPBYTE)value, &valueSize); |
| 309 | if (lResult == ERROR_SUCCESS) |
| 310 | returnValue = true; |
| 311 | RegCloseKey(hKey); |
| 312 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 313 | } |
| 314 | return(returnValue); |
| 315 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 316 | #else // _MSC_VER |
| 317 | // Read registry string. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 318 | static bool getSystemRegistryString(const char*, const char*, char*, size_t) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 319 | return(false); |
| 320 | } |
| 321 | #endif // _MSC_VER |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 322 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 323 | // Get Visual Studio installation directory. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 324 | static bool getVisualStudioDir(std::string &path) { |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 325 | char vsIDEInstallDir[256]; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 326 | // Try the Windows registry first. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 327 | bool hasVCDir = getSystemRegistryString( |
| 328 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", |
| 329 | "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 330 | // If we have both vc80 and vc90, pick version we were compiled with. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 331 | if (hasVCDir && vsIDEInstallDir[0]) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 332 | char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); |
| 333 | if (p) |
| 334 | *p = '\0'; |
| 335 | path = vsIDEInstallDir; |
| 336 | return(true); |
| 337 | } |
| 338 | else { |
| 339 | // Try the environment. |
| 340 | const char* vs90comntools = getenv("VS90COMNTOOLS"); |
| 341 | const char* vs80comntools = getenv("VS80COMNTOOLS"); |
| 342 | const char* vscomntools = NULL; |
| 343 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 344 | if (vs90comntools && vs80comntools) { |
| 345 | #if (_MSC_VER >= 1500) // VC90 |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 346 | vscomntools = vs90comntools; |
| 347 | #elif (_MSC_VER == 1400) // VC80 |
| 348 | vscomntools = vs80comntools; |
| 349 | #else |
| 350 | vscomntools = vs90comntools; |
| 351 | #endif |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 352 | } |
| 353 | else if (vs90comntools) |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 354 | vscomntools = vs90comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 355 | else if (vs80comntools) |
| 356 | vscomntools = vs80comntools; |
| 357 | if (vscomntools && *vscomntools) { |
| 358 | char *p = (char*)strstr(vscomntools, "\\Common7\\Tools"); |
| 359 | if (p) |
| 360 | *p = '\0'; |
| 361 | path = vscomntools; |
| 362 | return(true); |
| 363 | } |
| 364 | else |
| 365 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 366 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 367 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 368 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 369 | |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 370 | // Get Windows SDK installation directory. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 371 | static bool getWindowsSDKDir(std::string &path) { |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 372 | char windowsSDKInstallDir[256]; |
| 373 | // Try the Windows registry. |
| 374 | bool hasSDKDir = getSystemRegistryString( |
| 375 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", |
| 376 | "InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1); |
| 377 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 378 | if (hasSDKDir && windowsSDKInstallDir[0]) { |
| 379 | path = windowsSDKInstallDir; |
| 380 | return(true); |
| 381 | } |
| 382 | return(false); |
| 383 | } |
| 384 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 385 | void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 386 | // FIXME: temporary hack: hard-coded paths. |
Daniel Dunbar | c706468 | 2009-11-12 07:28:29 +0000 | [diff] [blame] | 387 | llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 388 | if (CIncludeDirs != "") { |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 389 | llvm::SmallVector<llvm::StringRef, 5> dirs; |
| 390 | CIncludeDirs.split(dirs, ":"); |
| 391 | for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin(); |
| 392 | i != dirs.end(); |
| 393 | ++i) |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 394 | AddPath(*i, System, false, false, false); |
| 395 | return; |
| 396 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 397 | llvm::Triple::OSType os = triple.getOS(); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 398 | switch (os) { |
| 399 | case llvm::Triple::Win32: |
| 400 | { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 401 | std::string VSDir; |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 402 | std::string WindowsSDKDir; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 403 | if (getVisualStudioDir(VSDir)) { |
| 404 | AddPath(VSDir + "\\VC\\include", System, false, false, false); |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 405 | if (getWindowsSDKDir(WindowsSDKDir)) |
| 406 | AddPath(WindowsSDKDir, System, false, false, false); |
| 407 | else |
| 408 | AddPath(VSDir + "\\VC\\PlatformSDK\\Include", |
| 409 | System, false, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 410 | } |
John Thompson | 9319f02 | 2009-11-23 17:49:27 +0000 | [diff] [blame] | 411 | else { |
| 412 | // Default install paths. |
| 413 | AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 414 | System, false, false, false); |
| 415 | AddPath( |
| 416 | "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
| 417 | System, false, false, false); |
| 418 | AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", |
| 419 | System, false, false, false); |
| 420 | AddPath( |
| 421 | "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", |
| 422 | System, false, false, false); |
| 423 | // For some clang developers. |
| 424 | AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 425 | System, false, false, false); |
| 426 | AddPath( |
| 427 | "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
| 428 | System, false, false, false); |
| 429 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 430 | } |
| 431 | break; |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame^] | 432 | case llvm::Triple::Haiku: |
| 433 | AddPath("/boot/common/include", System, true, false, false); |
| 434 | AddPath("/boot/develop/headers/os", System, true, false, false); |
| 435 | AddPath("/boot/develop/headers/os/app", System, true, false, false); |
| 436 | AddPath("/boot/develop/headers/os/arch", System, true, false, false); |
| 437 | AddPath("/boot/develop/headers/os/device", System, true, false, false); |
| 438 | AddPath("/boot/develop/headers/os/drivers", System, true, false, false); |
| 439 | AddPath("/boot/develop/headers/os/game", System, true, false, false); |
| 440 | AddPath("/boot/develop/headers/os/interface", System, true, false, false); |
| 441 | AddPath("/boot/develop/headers/os/kernel", System, true, false, false); |
| 442 | AddPath("/boot/develop/headers/os/locale", System, true, false, false); |
| 443 | AddPath("/boot/develop/headers/os/mail", System, true, false, false); |
| 444 | AddPath("/boot/develop/headers/os/media", System, true, false, false); |
| 445 | AddPath("/boot/develop/headers/os/midi", System, true, false, false); |
| 446 | AddPath("/boot/develop/headers/os/midi2", System, true, false, false); |
| 447 | AddPath("/boot/develop/headers/os/net", System, true, false, false); |
| 448 | AddPath("/boot/develop/headers/os/storage", System, true, false, false); |
| 449 | AddPath("/boot/develop/headers/os/support", System, true, false, false); |
| 450 | AddPath("/boot/develop/headers/os/translation", |
| 451 | System, true, false, false); |
| 452 | AddPath("/boot/develop/headers/os/add-ons/graphics", |
| 453 | System, true, false, false); |
| 454 | AddPath("/boot/develop/headers/os/add-ons/input_server", |
| 455 | System, true, false, false); |
| 456 | AddPath("/boot/develop/headers/os/add-ons/screen_saver", |
| 457 | System, true, false, false); |
| 458 | AddPath("/boot/develop/headers/os/add-ons/tracker", |
| 459 | System, true, false, false); |
| 460 | AddPath("/boot/develop/headers/os/be_apps/Deskbar", |
| 461 | System, true, false, false); |
| 462 | AddPath("/boot/develop/headers/os/be_apps/NetPositive", |
| 463 | System, true, false, false); |
| 464 | AddPath("/boot/develop/headers/os/be_apps/Tracker", |
| 465 | System, true, false, false); |
| 466 | AddPath("/boot/develop/headers/cpp", System, true, false, false); |
| 467 | AddPath("/boot/develop/headers/cpp/i586-pc-haiku", |
| 468 | System, true, false, false); |
| 469 | AddPath("/boot/develop/headers/3rdparty", System, true, false, false); |
| 470 | AddPath("/boot/develop/headers/bsd", System, true, false, false); |
| 471 | AddPath("/boot/develop/headers/glibc", System, true, false, false); |
| 472 | AddPath("/boot/develop/headers/posix", System, true, false, false); |
| 473 | AddPath("/boot/develop/headers", System, true, false, false); |
| 474 | break; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 475 | case llvm::Triple::MinGW64: |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 476 | case llvm::Triple::MinGW32: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 477 | AddPath("c:/mingw/include", System, true, false, false); |
| 478 | break; |
| 479 | default: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 480 | break; |
| 481 | } |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 482 | |
Chris Lattner | fc904d5 | 2010-03-06 19:38:10 +0000 | [diff] [blame] | 483 | AddPath("/usr/local/include", System, true, false, false); |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 484 | AddPath("/usr/include", System, false, false, false); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) { |
| 488 | llvm::Triple::OSType os = triple.getOS(); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 489 | llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); |
| 490 | if (CxxIncludeRoot != "") { |
| 491 | llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); |
| 492 | if (CxxIncludeArch == "") |
| 493 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), |
| 494 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple); |
| 495 | else |
| 496 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, |
| 497 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple); |
| 498 | return; |
| 499 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 500 | // FIXME: temporary hack: hard-coded paths. |
| 501 | switch (os) { |
| 502 | case llvm::Triple::Cygwin: |
| 503 | AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include", |
| 504 | System, true, false, false); |
| 505 | AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++", |
| 506 | System, true, false, false); |
| 507 | break; |
| 508 | case llvm::Triple::MinGW64: |
| 509 | // Try gcc 4.4.0 |
| 510 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0"); |
| 511 | // Try gcc 4.3.0 |
| 512 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0"); |
| 513 | // Fall through. |
| 514 | case llvm::Triple::MinGW32: |
| 515 | // Try gcc 4.4.0 |
| 516 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); |
| 517 | // Try gcc 4.3.0 |
| 518 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); |
| 519 | break; |
| 520 | case llvm::Triple::Darwin: |
| 521 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 522 | "i686-apple-darwin10", "", "x86_64", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 523 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 524 | "i686-apple-darwin8", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 525 | break; |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 526 | case llvm::Triple::DragonFly: |
| 527 | AddPath("/usr/include/c++/4.1", System, true, false, false); |
| 528 | break; |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 529 | case llvm::Triple::Linux: |
Benjamin Kramer | 0db3d72 | 2010-01-25 12:20:15 +0000 | [diff] [blame] | 530 | // Exherbo (2010-01-25) |
| 531 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
Torok Edwin | fc4b899 | 2009-12-18 17:29:14 +0000 | [diff] [blame] | 532 | "x86_64-pc-linux-gnu", "32", "", triple); |
Benjamin Kramer | 0db3d72 | 2010-01-25 12:20:15 +0000 | [diff] [blame] | 533 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
Torok Edwin | fc4b899 | 2009-12-18 17:29:14 +0000 | [diff] [blame] | 534 | "i686-pc-linux-gnu", "", "", triple); |
Torok Edwin | 331e801 | 2009-12-18 17:43:54 +0000 | [diff] [blame] | 535 | // Debian sid |
Nick Lewycky | e69f047 | 2010-02-27 22:35:43 +0000 | [diff] [blame] | 536 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Torok Edwin | 331e801 | 2009-12-18 17:43:54 +0000 | [diff] [blame] | 537 | "x86_64-linux-gnu", "32", "", triple); |
Nick Lewycky | e69f047 | 2010-02-27 22:35:43 +0000 | [diff] [blame] | 538 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 539 | "i486-linux-gnu", "64", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 540 | // Ubuntu 7.10 - Gutsy Gibbon |
| 541 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 542 | "i486-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 543 | // Ubuntu 9.04 |
| 544 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 545 | "x86_64-linux-gnu","32", "", triple); |
Sebastian Redl | 5114eca | 2009-11-05 17:44:49 +0000 | [diff] [blame] | 546 | // Ubuntu 9.10 |
| 547 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 548 | "x86_64-linux-gnu", "32", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 549 | // Fedora 8 |
| 550 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 551 | "i386-redhat-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 552 | // Fedora 9 |
| 553 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 554 | "i386-redhat-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 555 | // Fedora 10 |
| 556 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 557 | "i386-redhat-linux","", "", triple); |
Nuno Lopes | 189a148 | 2009-11-17 15:28:35 +0000 | [diff] [blame] | 558 | |
Chris Lattner | 0720b51 | 2010-01-19 23:30:00 +0000 | [diff] [blame] | 559 | // Fedora 10 x86_64 |
| 560 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
| 561 | "x86_64-redhat-linux", "32", "", triple); |
| 562 | |
Nuno Lopes | 189a148 | 2009-11-17 15:28:35 +0000 | [diff] [blame] | 563 | // Fedora 11 |
| 564 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
| 565 | "i586-redhat-linux","", "", triple); |
| 566 | |
Nuno Lopes | 33cc243 | 2009-12-07 17:18:48 +0000 | [diff] [blame] | 567 | // Fedora 12 |
| 568 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 569 | "i686-redhat-linux","", "", triple); |
| 570 | |
Chris Lattner | 0edeca5 | 2010-02-13 19:18:26 +0000 | [diff] [blame] | 571 | // Fedora 12 (February-2010+) |
| 572 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
| 573 | "i686-redhat-linux","", "", triple); |
| 574 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 575 | // openSUSE 11.1 32 bit |
| 576 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 577 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 578 | // openSUSE 11.1 64 bit |
| 579 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 580 | "x86_64-suse-linux", "32", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 581 | // openSUSE 11.2 |
| 582 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 583 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 584 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 585 | "x86_64-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 586 | // Arch Linux 2008-06-24 |
| 587 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 588 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 589 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 590 | "x86_64-unknown-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 591 | // Gentoo x86 2009.1 stable |
| 592 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 593 | "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 594 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 595 | // Gentoo x86 2009.0 stable |
| 596 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 597 | "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 598 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 599 | // Gentoo x86 2008.0 stable |
| 600 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 601 | "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 602 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 603 | // Ubuntu 8.10 |
| 604 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 605 | "i486-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 606 | // Ubuntu 9.04 |
| 607 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 608 | "i486-linux-gnu","", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 609 | // Gentoo amd64 stable |
| 610 | AddGnuCPlusPlusIncludePaths( |
| 611 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 612 | "i686-pc-linux-gnu", "", "", triple); |
Eric Christopher | 70d9d41 | 2010-03-03 21:41:50 +0000 | [diff] [blame] | 613 | |
| 614 | // Gentoo amd64 gcc 4.3.2 |
| 615 | AddGnuCPlusPlusIncludePaths( |
| 616 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4", |
| 617 | "x86_64-pc-linux-gnu", "", "", triple); |
| 618 | |
| 619 | // Gentoo amd64 gcc 4.4.3 |
| 620 | AddGnuCPlusPlusIncludePaths( |
| 621 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4", |
| 622 | "x86_64-pc-linux-gnu", "32", "", triple); |
| 623 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 624 | break; |
| 625 | case llvm::Triple::FreeBSD: |
Nuno Lopes | afe859a | 2010-01-17 00:00:11 +0000 | [diff] [blame] | 626 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 627 | break; |
| 628 | case llvm::Triple::Solaris: |
| 629 | // Solaris - Fall though.. |
| 630 | case llvm::Triple::AuroraUX: |
| 631 | // AuroraUX |
| 632 | AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 633 | "i386-pc-solaris2.11", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 634 | break; |
| 635 | default: |
| 636 | break; |
| 637 | } |
| 638 | } |
| 639 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 640 | void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 641 | const llvm::Triple &triple, |
| 642 | bool UseStandardCXXIncludes) { |
| 643 | if (Lang.CPlusPlus && UseStandardCXXIncludes) |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 644 | AddDefaultCPlusPlusIncludePaths(triple); |
| 645 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 646 | AddDefaultCIncludePaths(triple); |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 647 | |
| 648 | // Add the default framework include paths on Darwin. |
| 649 | if (triple.getOS() == llvm::Triple::Darwin) { |
| 650 | AddPath("/System/Library/Frameworks", System, true, false, true); |
| 651 | AddPath("/Library/Frameworks", System, true, false, true); |
| 652 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 655 | /// RemoveDuplicates - If there are duplicate directory entries in the specified |
| 656 | /// search list, remove the later (dead) ones. |
| 657 | static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
| 658 | bool Verbose) { |
| 659 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 660 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 661 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
| 662 | for (unsigned i = 0; i != SearchList.size(); ++i) { |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 663 | unsigned DirToRemove = i; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 665 | const DirectoryLookup &CurEntry = SearchList[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 666 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 667 | if (CurEntry.isNormalDir()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 668 | // If this isn't the first time we've seen this dir, remove it. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 669 | if (SeenDirs.insert(CurEntry.getDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 670 | continue; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 671 | } else if (CurEntry.isFramework()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 672 | // If this isn't the first time we've seen this framework dir, remove it. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 673 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 674 | continue; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 675 | } else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 676 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 677 | // If this isn't the first time we've seen this headermap, remove it. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 678 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 679 | continue; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 680 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 681 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 682 | // If we have a normal #include dir/framework/headermap that is shadowed |
| 683 | // later in the chain by a system include location, we actually want to |
| 684 | // ignore the user's request and drop the user dir... keeping the system |
| 685 | // dir. This is weird, but required to emulate GCC's search path correctly. |
| 686 | // |
| 687 | // Since dupes of system dirs are rare, just rescan to find the original |
| 688 | // that we're nuking instead of using a DenseMap. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 689 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 690 | // Find the dir that this is the same of. |
| 691 | unsigned FirstDir; |
| 692 | for (FirstDir = 0; ; ++FirstDir) { |
| 693 | assert(FirstDir != i && "Didn't find dupe?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 694 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 695 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 696 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 697 | // If these are different lookup types, then they can't be the dupe. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 698 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 699 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 701 | bool isSame; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 702 | if (CurEntry.isNormalDir()) |
| 703 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 704 | else if (CurEntry.isFramework()) |
| 705 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 706 | else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 707 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 708 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 711 | if (isSame) |
| 712 | break; |
| 713 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 715 | // If the first dir in the search path is a non-system dir, zap it |
| 716 | // instead of the system one. |
| 717 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 718 | DirToRemove = FirstDir; |
| 719 | } |
| 720 | |
| 721 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 722 | llvm::errs() << "ignoring duplicate directory \"" |
| 723 | << CurEntry.getName() << "\"\n"; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 724 | if (DirToRemove != i) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 725 | llvm::errs() << " as it is a non-system directory that duplicates " |
| 726 | << "a system directory\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 727 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 729 | // This is reached if the current entry is a duplicate. Remove the |
| 730 | // DirToRemove (usually the current dir). |
| 731 | SearchList.erase(SearchList.begin()+DirToRemove); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 732 | --i; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | |
| 737 | void InitHeaderSearch::Realize() { |
| 738 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. |
| 739 | std::vector<DirectoryLookup> SearchList; |
| 740 | SearchList = IncludeGroup[Angled]; |
| 741 | SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), |
| 742 | IncludeGroup[System].end()); |
| 743 | SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), |
| 744 | IncludeGroup[After].end()); |
| 745 | RemoveDuplicates(SearchList, Verbose); |
| 746 | RemoveDuplicates(IncludeGroup[Quoted], Verbose); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 747 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 748 | // Prepend QUOTED list on the search list. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 | SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 750 | IncludeGroup[Quoted].end()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 752 | |
| 753 | bool DontSearchCurDir = false; // TODO: set to true if -I- is set? |
| 754 | Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), |
| 755 | DontSearchCurDir); |
| 756 | |
| 757 | // If verbose, print the list of directories that will be searched. |
| 758 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 759 | llvm::errs() << "#include \"...\" search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 760 | unsigned QuotedIdx = IncludeGroup[Quoted].size(); |
| 761 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
| 762 | if (i == QuotedIdx) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 763 | llvm::errs() << "#include <...> search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 764 | const char *Name = SearchList[i].getName(); |
| 765 | const char *Suffix; |
| 766 | if (SearchList[i].isNormalDir()) |
| 767 | Suffix = ""; |
| 768 | else if (SearchList[i].isFramework()) |
| 769 | Suffix = " (framework directory)"; |
| 770 | else { |
| 771 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 772 | Suffix = " (headermap)"; |
| 773 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 774 | llvm::errs() << " " << Name << Suffix << "\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 775 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 776 | llvm::errs() << "End of search list.\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 777 | } |
| 778 | } |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 779 | |
Daniel Dunbar | 5814e65 | 2009-11-11 21:44:21 +0000 | [diff] [blame] | 780 | void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, |
| 781 | const HeaderSearchOptions &HSOpts, |
| 782 | const LangOptions &Lang, |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 783 | const llvm::Triple &Triple) { |
| 784 | InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); |
| 785 | |
| 786 | // Add the user defined entries. |
| 787 | for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { |
| 788 | const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 789 | Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework, |
| 790 | false); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | // Add entries from CPATH and friends. |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 794 | Init.AddDelimitedPaths(HSOpts.EnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 795 | if (Lang.CPlusPlus && Lang.ObjC1) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 796 | Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 797 | else if (Lang.CPlusPlus) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 798 | Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 799 | else if (Lang.ObjC1) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 800 | Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 801 | else |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 802 | Init.AddDelimitedPaths(HSOpts.CEnvIncPath); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 803 | |
Daniel Dunbar | 1e69fe3 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 804 | if (HSOpts.UseBuiltinIncludes) { |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 805 | // Ignore the sys root, we *always* look for clang headers relative to |
| 806 | // supplied path. |
Daniel Dunbar | 8b9adfe | 2009-12-15 00:06:45 +0000 | [diff] [blame] | 807 | llvm::sys::Path P(HSOpts.ResourceDir); |
| 808 | P.appendComponent("include"); |
| 809 | Init.AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Daniel Dunbar | dd35ce9 | 2009-11-07 04:58:12 +0000 | [diff] [blame] | 812 | if (HSOpts.UseStandardIncludes) |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 813 | Init.AddDefaultSystemIncludePaths(Lang, Triple, |
| 814 | HSOpts.UseStandardCXXIncludes); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 815 | |
| 816 | Init.Realize(); |
| 817 | } |