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" |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame^] | 21 | #include "llvm/ADT/Triple.h" |
Chris Lattner | d57a7ef | 2009-08-23 22:45:33 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 23 | #include "llvm/System/Path.h" |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 24 | #include "llvm/Config/config.h" |
Chris Lattner | 3daed52 | 2009-03-02 22:20:04 +0000 | [diff] [blame] | 25 | #include <cstdio> |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 26 | #ifdef _MSC_VER |
| 27 | #define WIN32_LEAN_AND_MEAN 1 |
| 28 | #include <windows.h> |
| 29 | #endif |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 30 | using namespace clang; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame^] | 31 | using namespace clang::frontend; |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | /// InitHeaderSearch - This class makes it easier to set the search paths of |
| 36 | /// a HeaderSearch object. InitHeaderSearch stores several search path lists |
| 37 | /// internally, which can be sent to a HeaderSearch object in one swoop. |
| 38 | class InitHeaderSearch { |
| 39 | std::vector<DirectoryLookup> IncludeGroup[4]; |
| 40 | HeaderSearch& Headers; |
| 41 | bool Verbose; |
| 42 | std::string isysroot; |
| 43 | |
| 44 | public: |
| 45 | |
| 46 | InitHeaderSearch(HeaderSearch &HS, |
| 47 | bool verbose = false, const std::string &iSysroot = "") |
| 48 | : Headers(HS), Verbose(verbose), isysroot(iSysroot) {} |
| 49 | |
| 50 | /// AddPath - Add the specified path to the specified group list. |
| 51 | void AddPath(const llvm::StringRef &Path, IncludeDirGroup Group, |
| 52 | bool isCXXAware, bool isUserSupplied, |
| 53 | bool isFramework, bool IgnoreSysRoot = false); |
| 54 | |
| 55 | /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to suport a gnu |
| 56 | /// libstdc++. |
| 57 | void AddGnuCPlusPlusIncludePaths(const std::string &Base, const char *Dir32, |
| 58 | const char *Dir64, |
| 59 | const llvm::Triple &triple); |
| 60 | |
| 61 | /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to suport a MinGW |
| 62 | /// libstdc++. |
| 63 | void AddMinGWCPlusPlusIncludePaths(const std::string &Base, |
| 64 | const char *Arch, |
| 65 | const char *Version); |
| 66 | |
| 67 | /// AddDelimitedPaths - Add a list of paths delimited by the system PATH |
| 68 | /// separator. The processing follows that of the CPATH variable for gcc. |
| 69 | void AddDelimitedPaths(const char *String); |
| 70 | |
| 71 | // AddDefaultCIncludePaths - Add paths that should always be searched. |
| 72 | void AddDefaultCIncludePaths(const llvm::Triple &triple); |
| 73 | |
| 74 | // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when |
| 75 | // compiling c++. |
| 76 | void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple); |
| 77 | |
| 78 | /// AddDefaultSystemIncludePaths - Adds the default system include paths so |
| 79 | /// that e.g. stdio.h is found. |
| 80 | void AddDefaultSystemIncludePaths(const LangOptions &Lang, |
| 81 | const llvm::Triple &triple); |
| 82 | |
| 83 | /// Realize - Merges all search path lists into one list and send it to |
| 84 | /// HeaderSearch. |
| 85 | void Realize(); |
| 86 | }; |
| 87 | |
| 88 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 89 | |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 90 | void InitHeaderSearch::AddPath(const llvm::StringRef &Path, |
| 91 | IncludeDirGroup Group, bool isCXXAware, |
| 92 | bool isUserSupplied, bool isFramework, |
| 93 | bool IgnoreSysRoot) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 94 | assert(!Path.empty() && "can't handle empty path here"); |
| 95 | FileManager &FM = Headers.getFileMgr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 97 | // Compute the actual path, taking into consideration -isysroot. |
| 98 | llvm::SmallString<256> MappedPath; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 99 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 100 | // Handle isysroot. |
Chris Lattner | 6858dd3 | 2009-02-19 06:48:28 +0000 | [diff] [blame] | 101 | if (Group == System && !IgnoreSysRoot) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 102 | // FIXME: Portability. This should be a sys::Path interface, this doesn't |
| 103 | // handle things like C:\ right, nor win32 \\network\device\blah. |
| 104 | if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present. |
| 105 | MappedPath.append(isysroot.begin(), isysroot.end()); |
| 106 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 108 | MappedPath.append(Path.begin(), Path.end()); |
| 109 | |
| 110 | // Compute the DirectoryLookup type. |
Chris Lattner | 9d72851 | 2008-10-27 01:19:25 +0000 | [diff] [blame] | 111 | SrcMgr::CharacteristicKind Type; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 112 | if (Group == Quoted || Group == Angled) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 113 | Type = SrcMgr::C_User; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 114 | else if (isCXXAware) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 115 | Type = SrcMgr::C_System; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 116 | else |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 117 | Type = SrcMgr::C_ExternCSystem; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 | |
| 119 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 120 | // If the directory exists, add it. |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 121 | if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 122 | IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied, |
| 123 | isFramework)); |
| 124 | return; |
| 125 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 126 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 127 | // Check to see if this is an apple-style headermap (which are not allowed to |
| 128 | // be frameworks). |
| 129 | if (!isFramework) { |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 130 | if (const FileEntry *FE = FM.getFile(MappedPath.str())) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 131 | if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { |
| 132 | // It is a headermap, add it to the search path. |
| 133 | IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied)); |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 139 | if (Verbose) |
Daniel Dunbar | 7765934 | 2009-08-19 20:04:03 +0000 | [diff] [blame] | 140 | llvm::errs() << "ignoring nonexistent directory \"" |
| 141 | << MappedPath.str() << "\"\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 145 | void InitHeaderSearch::AddDelimitedPaths(const char *at) { |
| 146 | if (*at == 0) // Empty string should not add '.' path. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 147 | return; |
| 148 | |
| 149 | const char* delim = strchr(at, llvm::sys::PathSeparator); |
| 150 | while (delim != 0) { |
| 151 | if (delim-at == 0) |
| 152 | AddPath(".", Angled, false, true, false); |
| 153 | else |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 154 | AddPath(llvm::StringRef(at, delim-at), Angled, false, true, false); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 155 | at = delim + 1; |
| 156 | delim = strchr(at, llvm::sys::PathSeparator); |
| 157 | } |
| 158 | if (*at == 0) |
| 159 | AddPath(".", Angled, false, true, false); |
| 160 | else |
| 161 | AddPath(at, Angled, false, true, false); |
| 162 | } |
| 163 | |
Mike Stump | ec05766 | 2009-10-09 20:16:49 +0000 | [diff] [blame] | 164 | void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(const std::string &Base, |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 165 | const char *Dir32, |
| 166 | const char *Dir64, |
| 167 | const llvm::Triple &triple) { |
| 168 | llvm::Triple::ArchType arch = triple.getArch(); |
| 169 | bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; |
| 170 | |
| 171 | AddPath(Base, System, true, false, false); |
| 172 | if (is64bit) |
| 173 | AddPath(Base + "/" + Dir64, System, true, false, false); |
| 174 | else |
| 175 | AddPath(Base + "/" + Dir32, System, true, false, false); |
| 176 | AddPath(Base + "/backward", System, true, false, false); |
Rafael Espindola | 2e9f652 | 2009-10-06 01:33:02 +0000 | [diff] [blame] | 177 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 178 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 179 | void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(const std::string &Base, |
| 180 | const char *Arch, |
| 181 | const char *Version) { |
Daniel Dunbar | 5c5758b | 2009-11-07 04:20:25 +0000 | [diff] [blame] | 182 | std::string localBase = Base + "/" + Arch + "/" + Version + "/include"; |
| 183 | AddPath(localBase, System, true, false, false); |
| 184 | AddPath(localBase + "/c++", System, true, false, false); |
| 185 | AddPath(localBase + "/c++/backward", System, true, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 186 | } |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 187 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 188 | // FIXME: This probably should goto to some platform utils place. |
| 189 | #ifdef _MSC_VER |
| 190 | // Read registry string. |
| 191 | bool getSystemRegistryString(const char *keyPath, const char *valueName, |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 192 | char *value, size_t maxLength) { |
| 193 | HKEY hRootKey = NULL; |
| 194 | HKEY hKey = NULL; |
| 195 | const char* subKey = NULL; |
| 196 | DWORD valueType; |
| 197 | DWORD valueSize = maxLength - 1; |
| 198 | bool returnValue = false; |
| 199 | if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { |
| 200 | hRootKey = HKEY_CLASSES_ROOT; |
| 201 | subKey = keyPath + 18; |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 202 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 203 | else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { |
| 204 | hRootKey = HKEY_USERS; |
| 205 | subKey = keyPath + 11; |
| 206 | } |
| 207 | else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { |
| 208 | hRootKey = HKEY_LOCAL_MACHINE; |
| 209 | subKey = keyPath + 19; |
| 210 | } |
| 211 | else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { |
| 212 | hRootKey = HKEY_CURRENT_USER; |
| 213 | subKey = keyPath + 18; |
| 214 | } |
| 215 | else |
| 216 | return(false); |
| 217 | long lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); |
| 218 | if (lResult == ERROR_SUCCESS) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 219 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 220 | (LPBYTE)value, &valueSize); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 221 | if (lResult == ERROR_SUCCESS) |
| 222 | returnValue = true; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 223 | RegCloseKey(hKey); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 224 | } |
| 225 | return(returnValue); |
| 226 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 227 | #else // _MSC_VER |
| 228 | // Read registry string. |
| 229 | bool getSystemRegistryString(const char *, const char *, char *, size_t) { |
| 230 | return(false); |
| 231 | } |
| 232 | #endif // _MSC_VER |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 233 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 234 | // Get Visual Studio installation directory. |
| 235 | bool getVisualStudioDir(std::string &path) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 236 | // Try the Windows registry first. |
| 237 | char vs80IDEInstallDir[256]; |
| 238 | char vs90IDEInstallDir[256]; |
| 239 | const char* vsIDEInstallDir = NULL; |
| 240 | bool has80 = getSystemRegistryString( |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 241 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0", |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 242 | "InstallDir", vs80IDEInstallDir, sizeof(vs80IDEInstallDir) - 1); |
| 243 | bool has90 = getSystemRegistryString( |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 244 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0", |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 245 | "InstallDir", vs90IDEInstallDir, sizeof(vs90IDEInstallDir) - 1); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 246 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 247 | if (has80 && has90) { |
| 248 | #ifdef _MSC_VER |
| 249 | #if (_MSC_VER >= 1500) // VC90 |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 250 | vsIDEInstallDir = vs90IDEInstallDir; |
| 251 | #elif (_MSC_VER == 1400) // VC80 |
| 252 | vsIDEInstallDir = vs80IDEInstallDir; |
| 253 | #else |
| 254 | vsIDEInstallDir = vs90IDEInstallDir; |
| 255 | #endif |
| 256 | #else |
| 257 | vsIDEInstallDir = vs90IDEInstallDir; |
| 258 | #endif |
| 259 | } |
| 260 | else if (has90) |
| 261 | vsIDEInstallDir = vs90IDEInstallDir; |
| 262 | else if (has80) |
| 263 | vsIDEInstallDir = vs80IDEInstallDir; |
| 264 | if (vsIDEInstallDir && *vsIDEInstallDir) { |
| 265 | char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); |
| 266 | if (p) |
| 267 | *p = '\0'; |
| 268 | path = vsIDEInstallDir; |
| 269 | return(true); |
| 270 | } |
| 271 | else { |
| 272 | // Try the environment. |
| 273 | const char* vs90comntools = getenv("VS90COMNTOOLS"); |
| 274 | const char* vs80comntools = getenv("VS80COMNTOOLS"); |
| 275 | const char* vscomntools = NULL; |
| 276 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 277 | if (vs90comntools && vs80comntools) { |
| 278 | #if (_MSC_VER >= 1500) // VC90 |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 279 | vscomntools = vs90comntools; |
| 280 | #elif (_MSC_VER == 1400) // VC80 |
| 281 | vscomntools = vs80comntools; |
| 282 | #else |
| 283 | vscomntools = vs90comntools; |
| 284 | #endif |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 285 | } |
| 286 | else if (vs90comntools) |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 287 | vscomntools = vs90comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 288 | else if (vs80comntools) |
| 289 | vscomntools = vs80comntools; |
| 290 | if (vscomntools && *vscomntools) { |
| 291 | char *p = (char*)strstr(vscomntools, "\\Common7\\Tools"); |
| 292 | if (p) |
| 293 | *p = '\0'; |
| 294 | path = vscomntools; |
| 295 | return(true); |
| 296 | } |
| 297 | else |
| 298 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 299 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 300 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 301 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 302 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 303 | void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 304 | // FIXME: temporary hack: hard-coded paths. |
| 305 | llvm::Triple::OSType os = triple.getOS(); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 306 | switch (os) { |
| 307 | case llvm::Triple::Win32: |
| 308 | { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 309 | std::string VSDir; |
| 310 | if (getVisualStudioDir(VSDir)) { |
| 311 | AddPath(VSDir + "\\VC\\include", System, false, false, false); |
| 312 | AddPath(VSDir + "\\VC\\PlatformSDK\\Include", |
| 313 | System, false, false, false); |
| 314 | } |
| 315 | else { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 316 | // Default install paths. |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 317 | AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 318 | System, false, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 319 | AddPath( |
| 320 | "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 321 | System, false, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 322 | AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", |
| 323 | System, false, false, false); |
| 324 | AddPath( |
| 325 | "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", |
| 326 | System, false, false, false); |
| 327 | // For some clang developers. |
| 328 | AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 329 | System, false, false, false); |
| 330 | AddPath( |
| 331 | "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
| 332 | System, false, false, false); |
| 333 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 334 | } |
| 335 | break; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 336 | case llvm::Triple::MinGW64: |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 337 | case llvm::Triple::MinGW32: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 338 | AddPath("c:/mingw/include", System, true, false, false); |
| 339 | break; |
| 340 | default: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 341 | break; |
| 342 | } |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 343 | |
| 344 | AddPath("/usr/local/include", System, false, false, false); |
| 345 | AddPath("/usr/include", System, false, false, false); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) { |
| 349 | llvm::Triple::OSType os = triple.getOS(); |
| 350 | // FIXME: temporary hack: hard-coded paths. |
| 351 | switch (os) { |
| 352 | case llvm::Triple::Cygwin: |
| 353 | AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include", |
| 354 | System, true, false, false); |
| 355 | AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++", |
| 356 | System, true, false, false); |
| 357 | break; |
| 358 | case llvm::Triple::MinGW64: |
| 359 | // Try gcc 4.4.0 |
| 360 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0"); |
| 361 | // Try gcc 4.3.0 |
| 362 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0"); |
| 363 | // Fall through. |
| 364 | case llvm::Triple::MinGW32: |
| 365 | // Try gcc 4.4.0 |
| 366 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); |
| 367 | // Try gcc 4.3.0 |
| 368 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); |
| 369 | break; |
| 370 | case llvm::Triple::Darwin: |
| 371 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 372 | "i686-apple-darwin10", |
| 373 | "i686-apple-darwin10/x86_64", |
| 374 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 375 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 376 | "i686-apple-darwin8", |
| 377 | "i686-apple-darwin8", |
| 378 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 379 | break; |
| 380 | case llvm::Triple::Linux: |
| 381 | // Ubuntu 7.10 - Gutsy Gibbon |
| 382 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 383 | "i486-linux-gnu", |
| 384 | "i486-linux-gnu", |
| 385 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 386 | // Ubuntu 9.04 |
| 387 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 388 | "x86_64-linux-gnu/32", |
| 389 | "x86_64-linux-gnu", |
| 390 | triple); |
Sebastian Redl | 5114eca | 2009-11-05 17:44:49 +0000 | [diff] [blame] | 391 | // Ubuntu 9.10 |
| 392 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 393 | "x86_64-linux-gnu/32", |
| 394 | "x86_64-linux-gnu", |
| 395 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 396 | // Fedora 8 |
| 397 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 398 | "i386-redhat-linux", |
| 399 | "i386-redhat-linux", |
| 400 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 401 | // Fedora 9 |
| 402 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 403 | "i386-redhat-linux", |
| 404 | "i386-redhat-linux", |
| 405 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 406 | // Fedora 10 |
| 407 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 408 | "i386-redhat-linux", |
| 409 | "i386-redhat-linux", |
| 410 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 411 | // openSUSE 11.1 32 bit |
| 412 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 413 | "i586-suse-linux", |
| 414 | "i586-suse-linux", |
| 415 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 416 | // openSUSE 11.1 64 bit |
| 417 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 418 | "x86_64-suse-linux/32", |
| 419 | "x86_64-suse-linux", |
| 420 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 421 | // openSUSE 11.2 |
| 422 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 423 | "i586-suse-linux", |
| 424 | "i586-suse-linux", |
| 425 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 426 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 427 | "x86_64-suse-linux", |
| 428 | "x86_64-suse-linux", |
| 429 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 430 | // Arch Linux 2008-06-24 |
| 431 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 432 | "i686-pc-linux-gnu", |
| 433 | "i686-pc-linux-gnu", |
| 434 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 435 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 436 | "x86_64-unknown-linux-gnu", |
| 437 | "x86_64-unknown-linux-gnu", |
| 438 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 439 | // Gentoo x86 2009.1 stable |
| 440 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 441 | "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4", |
| 442 | "i686-pc-linux-gnu", |
| 443 | "i686-pc-linux-gnu", |
| 444 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 445 | // Gentoo x86 2009.0 stable |
| 446 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 447 | "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", |
| 448 | "i686-pc-linux-gnu", |
| 449 | "i686-pc-linux-gnu", |
| 450 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 451 | // Gentoo x86 2008.0 stable |
| 452 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 453 | "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", |
| 454 | "i686-pc-linux-gnu", |
| 455 | "i686-pc-linux-gnu", |
| 456 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 457 | // Ubuntu 8.10 |
| 458 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 459 | "i486-pc-linux-gnu", |
| 460 | "i486-pc-linux-gnu", |
| 461 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 462 | // Ubuntu 9.04 |
| 463 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 464 | "i486-linux-gnu", |
| 465 | "i486-linux-gnu", |
| 466 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 467 | // Gentoo amd64 stable |
| 468 | AddGnuCPlusPlusIncludePaths( |
| 469 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", |
| 470 | "i686-pc-linux-gnu", |
| 471 | "i686-pc-linux-gnu", |
| 472 | triple); |
Benjamin Kramer | 5d7a188 | 2009-10-30 12:57:13 +0000 | [diff] [blame] | 473 | // Exherbo (2009-10-26) |
| 474 | AddGnuCPlusPlusIncludePaths( |
| 475 | "/usr/include/c++/4.4.2", |
| 476 | "x86_64-pc-linux-gnu/32", |
| 477 | "x86_64-pc-linux-gnu", |
| 478 | triple); |
| 479 | AddGnuCPlusPlusIncludePaths( |
| 480 | "/usr/include/c++/4.4.2", |
| 481 | "i686-pc-linux-gnu", |
| 482 | "i686-pc-linux-gnu", |
| 483 | triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 484 | break; |
| 485 | case llvm::Triple::FreeBSD: |
| 486 | // DragonFly |
| 487 | AddPath("/usr/include/c++/4.1", System, true, false, false); |
| 488 | // FreeBSD |
| 489 | AddPath("/usr/include/c++/4.2", System, true, false, false); |
| 490 | break; |
| 491 | case llvm::Triple::Solaris: |
| 492 | // Solaris - Fall though.. |
| 493 | case llvm::Triple::AuroraUX: |
| 494 | // AuroraUX |
| 495 | AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", |
| 496 | "i386-pc-solaris2.11", |
| 497 | "i386-pc-solaris2.11", |
| 498 | triple); |
| 499 | break; |
| 500 | default: |
| 501 | break; |
| 502 | } |
| 503 | } |
| 504 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 505 | void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, |
| 506 | const llvm::Triple &triple) { |
| 507 | AddDefaultCIncludePaths(triple); |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 508 | |
| 509 | // Add the default framework include paths on Darwin. |
| 510 | if (triple.getOS() == llvm::Triple::Darwin) { |
| 511 | AddPath("/System/Library/Frameworks", System, true, false, true); |
| 512 | AddPath("/Library/Frameworks", System, true, false, true); |
| 513 | } |
| 514 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 515 | if (Lang.CPlusPlus) |
| 516 | AddDefaultCPlusPlusIncludePaths(triple); |
| 517 | } |
| 518 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 519 | /// RemoveDuplicates - If there are duplicate directory entries in the specified |
| 520 | /// search list, remove the later (dead) ones. |
| 521 | static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
| 522 | bool Verbose) { |
| 523 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 524 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 525 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
| 526 | for (unsigned i = 0; i != SearchList.size(); ++i) { |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 527 | unsigned DirToRemove = i; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 529 | const DirectoryLookup &CurEntry = SearchList[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 530 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 531 | if (CurEntry.isNormalDir()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 532 | // 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] | 533 | if (SeenDirs.insert(CurEntry.getDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 534 | continue; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 535 | } else if (CurEntry.isFramework()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 536 | // 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] | 537 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 538 | continue; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 539 | } else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 540 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 541 | // 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] | 542 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 543 | continue; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 544 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 545 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 546 | // If we have a normal #include dir/framework/headermap that is shadowed |
| 547 | // later in the chain by a system include location, we actually want to |
| 548 | // ignore the user's request and drop the user dir... keeping the system |
| 549 | // dir. This is weird, but required to emulate GCC's search path correctly. |
| 550 | // |
| 551 | // Since dupes of system dirs are rare, just rescan to find the original |
| 552 | // that we're nuking instead of using a DenseMap. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 553 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 554 | // Find the dir that this is the same of. |
| 555 | unsigned FirstDir; |
| 556 | for (FirstDir = 0; ; ++FirstDir) { |
| 557 | assert(FirstDir != i && "Didn't find dupe?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 558 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 559 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 560 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 561 | // 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] | 562 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 563 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 565 | bool isSame; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 566 | if (CurEntry.isNormalDir()) |
| 567 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 568 | else if (CurEntry.isFramework()) |
| 569 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 570 | else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 571 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 572 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 573 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 575 | if (isSame) |
| 576 | break; |
| 577 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 579 | // If the first dir in the search path is a non-system dir, zap it |
| 580 | // instead of the system one. |
| 581 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 582 | DirToRemove = FirstDir; |
| 583 | } |
| 584 | |
| 585 | if (Verbose) { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 586 | fprintf(stderr, "ignoring duplicate directory \"%s\"\n", |
| 587 | CurEntry.getName()); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 588 | if (DirToRemove != i) |
| 589 | fprintf(stderr, " as it is a non-system directory that duplicates" |
| 590 | " a system directory\n"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 591 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 592 | |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 593 | // This is reached if the current entry is a duplicate. Remove the |
| 594 | // DirToRemove (usually the current dir). |
| 595 | SearchList.erase(SearchList.begin()+DirToRemove); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 596 | --i; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | |
| 601 | void InitHeaderSearch::Realize() { |
| 602 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. |
| 603 | std::vector<DirectoryLookup> SearchList; |
| 604 | SearchList = IncludeGroup[Angled]; |
| 605 | SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), |
| 606 | IncludeGroup[System].end()); |
| 607 | SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), |
| 608 | IncludeGroup[After].end()); |
| 609 | RemoveDuplicates(SearchList, Verbose); |
| 610 | RemoveDuplicates(IncludeGroup[Quoted], Verbose); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 611 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 612 | // Prepend QUOTED list on the search list. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 613 | SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 614 | IncludeGroup[Quoted].end()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 615 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 616 | |
| 617 | bool DontSearchCurDir = false; // TODO: set to true if -I- is set? |
| 618 | Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), |
| 619 | DontSearchCurDir); |
| 620 | |
| 621 | // If verbose, print the list of directories that will be searched. |
| 622 | if (Verbose) { |
| 623 | fprintf(stderr, "#include \"...\" search starts here:\n"); |
| 624 | unsigned QuotedIdx = IncludeGroup[Quoted].size(); |
| 625 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
| 626 | if (i == QuotedIdx) |
| 627 | fprintf(stderr, "#include <...> search starts here:\n"); |
| 628 | const char *Name = SearchList[i].getName(); |
| 629 | const char *Suffix; |
| 630 | if (SearchList[i].isNormalDir()) |
| 631 | Suffix = ""; |
| 632 | else if (SearchList[i].isFramework()) |
| 633 | Suffix = " (framework directory)"; |
| 634 | else { |
| 635 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 636 | Suffix = " (headermap)"; |
| 637 | } |
| 638 | fprintf(stderr, " %s%s\n", Name, Suffix); |
| 639 | } |
| 640 | fprintf(stderr, "End of search list.\n"); |
| 641 | } |
| 642 | } |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 643 | |
| 644 | void clang::ApplyHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 645 | HeaderSearch &HS, const LangOptions &Lang, |
| 646 | const llvm::Triple &Triple) { |
| 647 | InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); |
| 648 | |
| 649 | // Add the user defined entries. |
| 650 | for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { |
| 651 | const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; |
| 652 | Init.AddPath(E.Path, E.Group, E.IsCXXAware, E.IsUserSupplied, E.IsFramework, |
| 653 | E.IgnoreSysRoot); |
| 654 | } |
| 655 | |
| 656 | // Add entries from CPATH and friends. |
| 657 | Init.AddDelimitedPaths(HSOpts.EnvIncPath.c_str()); |
| 658 | Init.AddDelimitedPaths(HSOpts.LangEnvIncPath.c_str()); |
| 659 | |
| 660 | if (!HSOpts.BuiltinIncludePath.empty()) { |
| 661 | // Ignore the sys root, we *always* look for clang headers relative to |
| 662 | // supplied path. |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame^] | 663 | Init.AddPath(HSOpts.BuiltinIncludePath, System, |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 664 | false, false, false, /*IgnoreSysRoot=*/ true); |
| 665 | } |
| 666 | |
Daniel Dunbar | dd35ce9 | 2009-11-07 04:58:12 +0000 | [diff] [blame] | 667 | if (HSOpts.UseStandardIncludes) |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 668 | Init.AddDefaultSystemIncludePaths(Lang, Triple); |
| 669 | |
| 670 | Init.Realize(); |
| 671 | } |