Nick Lewycky | df22c2c | 2010-07-25 03:12:58 +0000 | [diff] [blame] | 1 | //===--- InitHeaderSearch.cpp - Initialize header search paths ------------===// |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 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 | |
mike-m | a608737 | 2010-05-05 17:00:31 +0000 | [diff] [blame] | 57 | /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 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. |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 76 | void AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 77 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 78 | |
| 79 | // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when |
| 80 | // compiling c++. |
| 81 | void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple); |
| 82 | |
| 83 | /// AddDefaultSystemIncludePaths - Adds the default system include paths so |
| 84 | /// that e.g. stdio.h is found. |
| 85 | void AddDefaultSystemIncludePaths(const LangOptions &Lang, |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 86 | const llvm::Triple &triple, |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 87 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 88 | |
| 89 | /// Realize - Merges all search path lists into one list and send it to |
| 90 | /// HeaderSearch. |
| 91 | void Realize(); |
| 92 | }; |
| 93 | |
| 94 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 95 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 96 | void InitHeaderSearch::AddPath(const llvm::Twine &Path, |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 97 | IncludeDirGroup Group, bool isCXXAware, |
| 98 | bool isUserSupplied, bool isFramework, |
| 99 | bool IgnoreSysRoot) { |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 100 | assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 101 | FileManager &FM = Headers.getFileMgr(); |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 102 | const FileSystemOptions &FSOpts = Headers.getFileSystemOpts(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 104 | // Compute the actual path, taking into consideration -isysroot. |
Chandler Carruth | 5853b0f | 2010-11-15 00:05:18 +0000 | [diff] [blame^] | 105 | llvm::SmallString<256> MappedPathStorage; |
| 106 | llvm::StringRef MappedPath = Path.toStringRef(MappedPathStorage); |
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 | // Handle isysroot. |
Chandler Carruth | 5853b0f | 2010-11-15 00:05:18 +0000 | [diff] [blame^] | 109 | if (Group == System && !IgnoreSysRoot && MappedPath[0] == '/') { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 110 | // FIXME: Portability. This should be a sys::Path interface, this doesn't |
| 111 | // handle things like C:\ right, nor win32 \\network\device\blah. |
| 112 | if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present. |
Chandler Carruth | 5853b0f | 2010-11-15 00:05:18 +0000 | [diff] [blame^] | 113 | MappedPath = (isysroot + Path).toStringRef(MappedPathStorage); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 114 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 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. |
Chandler Carruth | 5853b0f | 2010-11-15 00:05:18 +0000 | [diff] [blame^] | 127 | if (const DirectoryEntry *DE = FM.getDirectory(MappedPath, FSOpts)) { |
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) { |
Chandler Carruth | 5853b0f | 2010-11-15 00:05:18 +0000 | [diff] [blame^] | 136 | if (const FileEntry *FE = FM.getFile(MappedPath, FSOpts)) { |
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) |
Chandler Carruth | 5853b0f | 2010-11-15 00:05:18 +0000 | [diff] [blame^] | 146 | llvm::errs() << "ignoring nonexistent directory \"" << MappedPath << "\"\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 150 | void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) { |
| 151 | if (at.empty()) // Empty string should not add '.' path. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 152 | return; |
| 153 | |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 154 | llvm::StringRef::size_type delim; |
| 155 | while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) { |
| 156 | if (delim == 0) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 157 | AddPath(".", Angled, false, true, false); |
| 158 | else |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 159 | AddPath(at.substr(0, delim), Angled, false, true, false); |
| 160 | at = at.substr(delim + 1); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 161 | } |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 162 | |
| 163 | if (at.empty()) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 164 | AddPath(".", Angled, false, true, false); |
| 165 | else |
| 166 | AddPath(at, Angled, false, true, false); |
| 167 | } |
| 168 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 169 | void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, |
| 170 | llvm::StringRef ArchDir, |
| 171 | llvm::StringRef Dir32, |
| 172 | llvm::StringRef Dir64, |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 173 | const llvm::Triple &triple) { |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 174 | // Add the base dir |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 175 | AddPath(Base, System, true, false, false); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 176 | |
| 177 | // Add the multilib dirs |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 178 | llvm::Triple::ArchType arch = triple.getArch(); |
| 179 | bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 180 | if (is64bit) |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 181 | AddPath(Base + "/" + ArchDir + "/" + Dir64, System, true, false, false); |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 182 | else |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 183 | AddPath(Base + "/" + ArchDir + "/" + Dir32, System, true, false, false); |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 184 | |
| 185 | // Add the backward dir |
| 186 | AddPath(Base + "/backward", System, true, false, false); |
Rafael Espindola | 2e9f652 | 2009-10-06 01:33:02 +0000 | [diff] [blame] | 187 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 188 | |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 189 | void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, |
| 190 | llvm::StringRef Arch, |
| 191 | llvm::StringRef Version) { |
Benjamin Kramer | ab8ae19 | 2010-01-20 16:18:11 +0000 | [diff] [blame] | 192 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", |
| 193 | System, true, false, false); |
Chris Lattner | 8e9006b | 2010-09-03 16:45:53 +0000 | [diff] [blame] | 194 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, |
| 195 | System, true, false, false); |
Benjamin Kramer | ab8ae19 | 2010-01-20 16:18:11 +0000 | [diff] [blame] | 196 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", |
| 197 | System, true, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 198 | } |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 199 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 200 | // FIXME: This probably should goto to some platform utils place. |
| 201 | #ifdef _MSC_VER |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 202 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 203 | // Read registry string. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 204 | // This also supports a means to look for high-versioned keys by use |
| 205 | // of a $VERSION placeholder in the key path. |
| 206 | // $VERSION in the key path is a placeholder for the version number, |
| 207 | // causing the highest value path to be searched for and used. |
| 208 | // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". |
| 209 | // There can be additional characters in the component. Only the numberic |
| 210 | // characters are compared. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 211 | static bool getSystemRegistryString(const char *keyPath, const char *valueName, |
| 212 | char *value, size_t maxLength) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 213 | HKEY hRootKey = NULL; |
| 214 | HKEY hKey = NULL; |
| 215 | const char* subKey = NULL; |
| 216 | DWORD valueType; |
| 217 | DWORD valueSize = maxLength - 1; |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 218 | long lResult; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 219 | bool returnValue = false; |
| 220 | if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { |
| 221 | hRootKey = HKEY_CLASSES_ROOT; |
| 222 | subKey = keyPath + 18; |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 223 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 224 | else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { |
| 225 | hRootKey = HKEY_USERS; |
| 226 | subKey = keyPath + 11; |
| 227 | } |
| 228 | else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { |
| 229 | hRootKey = HKEY_LOCAL_MACHINE; |
| 230 | subKey = keyPath + 19; |
| 231 | } |
| 232 | else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { |
| 233 | hRootKey = HKEY_CURRENT_USER; |
| 234 | subKey = keyPath + 18; |
| 235 | } |
| 236 | else |
| 237 | return(false); |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 238 | const char *placeHolder = strstr(subKey, "$VERSION"); |
| 239 | char bestName[256]; |
| 240 | bestName[0] = '\0'; |
| 241 | // If we have a $VERSION placeholder, do the highest-version search. |
| 242 | if (placeHolder) { |
| 243 | const char *keyEnd = placeHolder - 1; |
| 244 | const char *nextKey = placeHolder; |
| 245 | // Find end of previous key. |
| 246 | while ((keyEnd > subKey) && (*keyEnd != '\\')) |
| 247 | keyEnd--; |
| 248 | // Find end of key containing $VERSION. |
| 249 | while (*nextKey && (*nextKey != '\\')) |
| 250 | nextKey++; |
| 251 | size_t partialKeyLength = keyEnd - subKey; |
| 252 | char partialKey[256]; |
| 253 | if (partialKeyLength > sizeof(partialKey)) |
| 254 | partialKeyLength = sizeof(partialKey); |
| 255 | strncpy(partialKey, subKey, partialKeyLength); |
| 256 | partialKey[partialKeyLength] = '\0'; |
| 257 | HKEY hTopKey = NULL; |
| 258 | lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey); |
| 259 | if (lResult == ERROR_SUCCESS) { |
| 260 | char keyName[256]; |
| 261 | int bestIndex = -1; |
| 262 | double bestValue = 0.0; |
| 263 | DWORD index, size = sizeof(keyName) - 1; |
Nuno Lopes | 33cc243 | 2009-12-07 17:18:48 +0000 | [diff] [blame] | 264 | for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, |
| 265 | NULL, NULL, NULL) == ERROR_SUCCESS; index++) { |
| 266 | const char *sp = keyName; |
| 267 | while (*sp && !isdigit(*sp)) |
| 268 | sp++; |
| 269 | if (!*sp) |
| 270 | continue; |
| 271 | const char *ep = sp + 1; |
| 272 | while (*ep && (isdigit(*ep) || (*ep == '.'))) |
| 273 | ep++; |
| 274 | char numBuf[32]; |
| 275 | strncpy(numBuf, sp, sizeof(numBuf) - 1); |
| 276 | numBuf[sizeof(numBuf) - 1] = '\0'; |
| 277 | double value = strtod(numBuf, NULL); |
| 278 | if (value > bestValue) { |
| 279 | bestIndex = (int)index; |
| 280 | bestValue = value; |
| 281 | strcpy(bestName, keyName); |
| 282 | } |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 283 | size = sizeof(keyName) - 1; |
| 284 | } |
| 285 | // If we found the highest versioned key, open the key and get the value. |
| 286 | if (bestIndex != -1) { |
| 287 | // Append rest of key. |
| 288 | strncat(bestName, nextKey, sizeof(bestName) - 1); |
| 289 | bestName[sizeof(bestName) - 1] = '\0'; |
| 290 | // Open the chosen key path remainder. |
| 291 | lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey); |
| 292 | if (lResult == ERROR_SUCCESS) { |
| 293 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 294 | (LPBYTE)value, &valueSize); |
| 295 | if (lResult == ERROR_SUCCESS) |
| 296 | returnValue = true; |
| 297 | RegCloseKey(hKey); |
| 298 | } |
| 299 | } |
| 300 | RegCloseKey(hTopKey); |
| 301 | } |
| 302 | } |
| 303 | else { |
| 304 | lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); |
| 305 | if (lResult == ERROR_SUCCESS) { |
| 306 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 307 | (LPBYTE)value, &valueSize); |
| 308 | if (lResult == ERROR_SUCCESS) |
| 309 | returnValue = true; |
| 310 | RegCloseKey(hKey); |
| 311 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 312 | } |
| 313 | return(returnValue); |
| 314 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 315 | #else // _MSC_VER |
| 316 | // Read registry string. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 317 | static bool getSystemRegistryString(const char*, const char*, char*, size_t) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 318 | return(false); |
| 319 | } |
| 320 | #endif // _MSC_VER |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 321 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 322 | // Get Visual Studio installation directory. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 323 | static bool getVisualStudioDir(std::string &path) { |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 324 | // First check the environment variables that vsvars32.bat sets. |
| 325 | const char* vcinstalldir = getenv("VCINSTALLDIR"); |
| 326 | if(vcinstalldir) { |
| 327 | char *p = const_cast<char *>(strstr(vcinstalldir, "\\VC")); |
| 328 | if (p) |
| 329 | *p = '\0'; |
| 330 | path = vcinstalldir; |
| 331 | return(true); |
| 332 | } |
| 333 | |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 334 | char vsIDEInstallDir[256]; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 335 | char vsExpressIDEInstallDir[256]; |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 336 | // Then try the windows registry. |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 337 | bool hasVCDir = getSystemRegistryString( |
| 338 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", |
| 339 | "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1); |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 340 | bool hasVCExpressDir = getSystemRegistryString( |
| 341 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION", |
| 342 | "InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 343 | // 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] | 344 | if (hasVCDir && vsIDEInstallDir[0]) { |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 345 | char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); |
| 346 | if (p) |
| 347 | *p = '\0'; |
| 348 | path = vsIDEInstallDir; |
| 349 | return(true); |
| 350 | } |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 351 | else if (hasVCExpressDir && vsExpressIDEInstallDir[0]) { |
| 352 | char *p = (char*)strstr(vsExpressIDEInstallDir, "\\Common7\\IDE"); |
| 353 | if (p) |
| 354 | *p = '\0'; |
| 355 | path = vsExpressIDEInstallDir; |
| 356 | return(true); |
| 357 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 358 | else { |
| 359 | // Try the environment. |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 360 | const char* vs100comntools = getenv("VS100COMNTOOLS"); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 361 | const char* vs90comntools = getenv("VS90COMNTOOLS"); |
| 362 | const char* vs80comntools = getenv("VS80COMNTOOLS"); |
| 363 | const char* vscomntools = NULL; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 364 | |
| 365 | // Try to find the version that we were compiled with |
| 366 | if(false) {} |
| 367 | #if (_MSC_VER >= 1600) // VC100 |
| 368 | else if(vs100comntools) { |
| 369 | vscomntools = vs100comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 370 | } |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 371 | #elif (_MSC_VER == 1500) // VC80 |
| 372 | else if(vs90comntools) { |
| 373 | vscomntools = vs90comntools; |
| 374 | } |
| 375 | #elif (_MSC_VER == 1400) // VC80 |
| 376 | else if(vs80comntools) { |
| 377 | vscomntools = vs80comntools; |
| 378 | } |
| 379 | #endif |
| 380 | // Otherwise find any version we can |
| 381 | else if (vs100comntools) |
| 382 | vscomntools = vs100comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 383 | else if (vs90comntools) |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 384 | vscomntools = vs90comntools; |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 385 | else if (vs80comntools) |
| 386 | vscomntools = vs80comntools; |
Douglas Gregor | 80f93d9 | 2010-05-18 05:47:04 +0000 | [diff] [blame] | 387 | |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 388 | if (vscomntools && *vscomntools) { |
Dan Gohman | cb421fa | 2010-04-19 16:39:44 +0000 | [diff] [blame] | 389 | char *p = const_cast<char *>(strstr(vscomntools, "\\Common7\\Tools")); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 390 | if (p) |
| 391 | *p = '\0'; |
| 392 | path = vscomntools; |
| 393 | return(true); |
| 394 | } |
| 395 | else |
| 396 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 397 | } |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 398 | return(false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 399 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 400 | |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 401 | // Get Windows SDK installation directory. |
Benjamin Kramer | 6cd5216 | 2010-01-20 16:21:40 +0000 | [diff] [blame] | 402 | static bool getWindowsSDKDir(std::string &path) { |
John Thompson | 75ee3bd | 2009-11-21 00:15:52 +0000 | [diff] [blame] | 403 | char windowsSDKInstallDir[256]; |
| 404 | // Try the Windows registry. |
| 405 | bool hasSDKDir = getSystemRegistryString( |
| 406 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", |
| 407 | "InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1); |
| 408 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 409 | if (hasSDKDir && windowsSDKInstallDir[0]) { |
| 410 | path = windowsSDKInstallDir; |
| 411 | return(true); |
| 412 | } |
| 413 | return(false); |
| 414 | } |
| 415 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 416 | void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 417 | const HeaderSearchOptions &HSOpts) { |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 418 | // FIXME: temporary hack: hard-coded paths. |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 419 | AddPath("/usr/local/include", System, true, false, false); |
| 420 | |
| 421 | // Builtin includes use #include_next directives and should be positioned |
| 422 | // just prior C include dirs. |
| 423 | if (HSOpts.UseBuiltinIncludes) { |
| 424 | // Ignore the sys root, we *always* look for clang headers relative to |
| 425 | // supplied path. |
| 426 | llvm::sys::Path P(HSOpts.ResourceDir); |
| 427 | P.appendComponent("include"); |
| 428 | AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true); |
| 429 | } |
| 430 | |
| 431 | // Add dirs specified via 'configure --with-c-include-dirs'. |
Daniel Dunbar | c706468 | 2009-11-12 07:28:29 +0000 | [diff] [blame] | 432 | llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); |
| 433 | if (CIncludeDirs != "") { |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 434 | llvm::SmallVector<llvm::StringRef, 5> dirs; |
| 435 | CIncludeDirs.split(dirs, ":"); |
| 436 | for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin(); |
| 437 | i != dirs.end(); |
| 438 | ++i) |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 439 | AddPath(*i, System, false, false, false); |
| 440 | return; |
| 441 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 442 | llvm::Triple::OSType os = triple.getOS(); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 443 | switch (os) { |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 444 | case llvm::Triple::Win32: { |
| 445 | std::string VSDir; |
| 446 | std::string WindowsSDKDir; |
| 447 | if (getVisualStudioDir(VSDir)) { |
| 448 | AddPath(VSDir + "\\VC\\include", System, false, false, false); |
| 449 | if (getWindowsSDKDir(WindowsSDKDir)) |
| 450 | AddPath(WindowsSDKDir + "\\include", System, false, false, false); |
| 451 | else |
| 452 | AddPath(VSDir + "\\VC\\PlatformSDK\\Include", |
| 453 | System, false, false, false); |
| 454 | } else { |
| 455 | // Default install paths. |
| 456 | AddPath("C:/Program Files/Microsoft Visual Studio 10.0/VC/include", |
| 457 | System, false, false, false); |
| 458 | AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 459 | System, false, false, false); |
| 460 | AddPath( |
John Thompson | 9319f02 | 2009-11-23 17:49:27 +0000 | [diff] [blame] | 461 | "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 462 | System, false, false, false); |
| 463 | AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", |
| 464 | System, false, false, false); |
| 465 | AddPath( |
John Thompson | 9319f02 | 2009-11-23 17:49:27 +0000 | [diff] [blame] | 466 | "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 467 | System, false, false, false); |
| 468 | // For some clang developers. |
| 469 | AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 470 | System, false, false, false); |
| 471 | AddPath( |
John Thompson | 9319f02 | 2009-11-23 17:49:27 +0000 | [diff] [blame] | 472 | "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 473 | System, false, false, false); |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 474 | } |
| 475 | break; |
Daniel Dunbar | d11ee7f | 2010-09-09 17:38:18 +0000 | [diff] [blame] | 476 | } |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 477 | case llvm::Triple::Haiku: |
| 478 | AddPath("/boot/common/include", System, true, false, false); |
| 479 | AddPath("/boot/develop/headers/os", System, true, false, false); |
| 480 | AddPath("/boot/develop/headers/os/app", System, true, false, false); |
| 481 | AddPath("/boot/develop/headers/os/arch", System, true, false, false); |
| 482 | AddPath("/boot/develop/headers/os/device", System, true, false, false); |
| 483 | AddPath("/boot/develop/headers/os/drivers", System, true, false, false); |
| 484 | AddPath("/boot/develop/headers/os/game", System, true, false, false); |
| 485 | AddPath("/boot/develop/headers/os/interface", System, true, false, false); |
| 486 | AddPath("/boot/develop/headers/os/kernel", System, true, false, false); |
| 487 | AddPath("/boot/develop/headers/os/locale", System, true, false, false); |
| 488 | AddPath("/boot/develop/headers/os/mail", System, true, false, false); |
| 489 | AddPath("/boot/develop/headers/os/media", System, true, false, false); |
| 490 | AddPath("/boot/develop/headers/os/midi", System, true, false, false); |
| 491 | AddPath("/boot/develop/headers/os/midi2", System, true, false, false); |
| 492 | AddPath("/boot/develop/headers/os/net", System, true, false, false); |
| 493 | AddPath("/boot/develop/headers/os/storage", System, true, false, false); |
| 494 | AddPath("/boot/develop/headers/os/support", System, true, false, false); |
| 495 | AddPath("/boot/develop/headers/os/translation", |
| 496 | System, true, false, false); |
| 497 | AddPath("/boot/develop/headers/os/add-ons/graphics", |
| 498 | System, true, false, false); |
| 499 | AddPath("/boot/develop/headers/os/add-ons/input_server", |
| 500 | System, true, false, false); |
| 501 | AddPath("/boot/develop/headers/os/add-ons/screen_saver", |
| 502 | System, true, false, false); |
| 503 | AddPath("/boot/develop/headers/os/add-ons/tracker", |
| 504 | System, true, false, false); |
| 505 | AddPath("/boot/develop/headers/os/be_apps/Deskbar", |
| 506 | System, true, false, false); |
| 507 | AddPath("/boot/develop/headers/os/be_apps/NetPositive", |
| 508 | System, true, false, false); |
| 509 | AddPath("/boot/develop/headers/os/be_apps/Tracker", |
| 510 | System, true, false, false); |
| 511 | AddPath("/boot/develop/headers/cpp", System, true, false, false); |
| 512 | AddPath("/boot/develop/headers/cpp/i586-pc-haiku", |
| 513 | System, true, false, false); |
| 514 | AddPath("/boot/develop/headers/3rdparty", System, true, false, false); |
| 515 | AddPath("/boot/develop/headers/bsd", System, true, false, false); |
| 516 | AddPath("/boot/develop/headers/glibc", System, true, false, false); |
| 517 | AddPath("/boot/develop/headers/posix", System, true, false, false); |
| 518 | AddPath("/boot/develop/headers", System, true, false, false); |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 519 | break; |
NAKAMURA Takumi | 32df002 | 2010-10-11 02:27:37 +0000 | [diff] [blame] | 520 | case llvm::Triple::Cygwin: |
| 521 | AddPath("/usr/include/w32api", System, true, false, false); |
| 522 | break; |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 523 | case llvm::Triple::MinGW64: |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 524 | case llvm::Triple::MinGW32: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 525 | AddPath("c:/mingw/include", System, true, false, false); |
| 526 | break; |
| 527 | default: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 528 | break; |
| 529 | } |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 530 | |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 531 | AddPath("/usr/include", System, false, false, false); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 534 | void InitHeaderSearch:: |
| 535 | AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) { |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 536 | llvm::Triple::OSType os = triple.getOS(); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 537 | llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); |
| 538 | if (CxxIncludeRoot != "") { |
| 539 | llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); |
| 540 | if (CxxIncludeArch == "") |
| 541 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 542 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, |
| 543 | triple); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 544 | else |
| 545 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 546 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, |
| 547 | triple); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 548 | return; |
| 549 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 550 | // FIXME: temporary hack: hard-coded paths. |
| 551 | switch (os) { |
| 552 | case llvm::Triple::Cygwin: |
NAKAMURA Takumi | 32df002 | 2010-10-11 02:27:37 +0000 | [diff] [blame] | 553 | // Cygwin-1.7 |
| 554 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4"); |
| 555 | // g++-4 / Cygwin-1.5 |
| 556 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); |
| 557 | // FIXME: Do we support g++-3.4.4? |
| 558 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4"); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 559 | break; |
| 560 | case llvm::Triple::MinGW64: |
Chris Lattner | 6a08140 | 2010-09-01 15:51:58 +0000 | [diff] [blame] | 561 | // Try gcc 4.5.0 |
| 562 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.5.0"); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 563 | // Try gcc 4.4.0 |
| 564 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0"); |
| 565 | // Try gcc 4.3.0 |
| 566 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0"); |
| 567 | // Fall through. |
| 568 | case llvm::Triple::MinGW32: |
Chris Lattner | 6a08140 | 2010-09-01 15:51:58 +0000 | [diff] [blame] | 569 | // Try gcc 4.5.0 |
| 570 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0"); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 571 | // Try gcc 4.4.0 |
| 572 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); |
| 573 | // Try gcc 4.3.0 |
| 574 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); |
| 575 | break; |
| 576 | case llvm::Triple::Darwin: |
Daniel Dunbar | f2070b3 | 2010-05-28 01:54:31 +0000 | [diff] [blame] | 577 | switch (triple.getArch()) { |
| 578 | default: break; |
| 579 | |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 580 | case llvm::Triple::ppc: |
| 581 | case llvm::Triple::ppc64: |
Douglas Gregor | 616d436 | 2010-05-29 01:21:11 +0000 | [diff] [blame] | 582 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 583 | "powerpc-apple-darwin10", "", "ppc64", |
| 584 | triple); |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 585 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
| 586 | "powerpc-apple-darwin10", "", "ppc64", |
| 587 | triple); |
| 588 | break; |
| 589 | |
Daniel Dunbar | f2070b3 | 2010-05-28 01:54:31 +0000 | [diff] [blame] | 590 | case llvm::Triple::x86: |
| 591 | case llvm::Triple::x86_64: |
| 592 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 593 | "i686-apple-darwin10", "", "x86_64", triple); |
| 594 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
| 595 | "i686-apple-darwin8", "", "", triple); |
| 596 | break; |
| 597 | |
| 598 | case llvm::Triple::arm: |
| 599 | case llvm::Triple::thumb: |
| 600 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 601 | "arm-apple-darwin10", "v7", "", triple); |
| 602 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 603 | "arm-apple-darwin10", "v6", "", triple); |
| 604 | break; |
| 605 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 606 | break; |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 607 | case llvm::Triple::DragonFly: |
| 608 | AddPath("/usr/include/c++/4.1", System, true, false, false); |
| 609 | break; |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 610 | case llvm::Triple::Linux: |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 611 | //===------------------------------------------------------------------===// |
| 612 | // Debian based distros. |
| 613 | // Note: these distros symlink /usr/include/c++/X.Y.Z -> X.Y |
| 614 | //===------------------------------------------------------------------===// |
| 615 | // Ubuntu 10.04 LTS "Lucid Lynx" -- gcc-4.4.3 |
| 616 | // Ubuntu 9.10 "Karmic Koala" -- gcc-4.4.1 |
| 617 | // Debian 6.0 "squeeze" -- gcc-4.4.2 |
| 618 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 619 | "x86_64-linux-gnu", "32", "", triple); |
| 620 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
| 621 | "i486-linux-gnu", "", "64", triple); |
| 622 | // Ubuntu 9.04 "Jaunty Jackalope" -- gcc-4.3.3 |
| 623 | // Ubuntu 8.10 "Intrepid Ibex" -- gcc-4.3.2 |
| 624 | // Debian 5.0 "lenny" -- gcc-4.3.2 |
| 625 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
| 626 | "x86_64-linux-gnu", "32", "", triple); |
| 627 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
| 628 | "i486-linux-gnu", "", "64", triple); |
Rafael Espindola | e7d6c2c | 2010-06-04 14:28:10 +0000 | [diff] [blame] | 629 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
| 630 | "arm-linux-gnueabi", "", "", triple); |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 631 | // Ubuntu 8.04.4 LTS "Hardy Heron" -- gcc-4.2.4 |
| 632 | // Ubuntu 8.04.[0-3] LTS "Hardy Heron" -- gcc-4.2.3 |
| 633 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", |
| 634 | "x86_64-linux-gnu", "32", "", triple); |
| 635 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", |
| 636 | "i486-linux-gnu", "", "64", triple); |
| 637 | // Ubuntu 7.10 "Gutsy Gibbon" -- gcc-4.1.3 |
| 638 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1", |
| 639 | "x86_64-linux-gnu", "32", "", triple); |
| 640 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1", |
| 641 | "i486-linux-gnu", "", "64", triple); |
| 642 | |
| 643 | //===------------------------------------------------------------------===// |
| 644 | // Redhat based distros. |
| 645 | //===------------------------------------------------------------------===// |
Rafael Espindola | 6638b3a | 2010-11-02 18:39:34 +0000 | [diff] [blame] | 646 | // Fedora 14 |
| 647 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1", |
| 648 | "x86_64-redhat-linux", "32", "", triple); |
| 649 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.1", |
| 650 | "i686-redhat-linux", "", "", triple); |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 651 | // Fedora 13 |
Chris Lattner | 4336e19 | 2010-05-29 01:01:38 +0000 | [diff] [blame] | 652 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", |
| 653 | "x86_64-redhat-linux", "32", "", triple); |
| 654 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.4", |
| 655 | "i686-redhat-linux","", "", triple); |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 656 | // Fedora 12 |
| 657 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
| 658 | "x86_64-redhat-linux", "32", "", triple); |
| 659 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
| 660 | "i686-redhat-linux","", "", triple); |
| 661 | // Fedora 12 (pre-FEB-2010) |
| 662 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 663 | "x86_64-redhat-linux", "32", "", triple); |
| 664 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", |
| 665 | "i686-redhat-linux","", "", triple); |
| 666 | // Fedora 11 |
| 667 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
| 668 | "x86_64-redhat-linux", "32", "", triple); |
| 669 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", |
| 670 | "i586-redhat-linux","", "", triple); |
| 671 | // Fedora 10 |
| 672 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
| 673 | "x86_64-redhat-linux", "32", "", triple); |
| 674 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", |
| 675 | "i386-redhat-linux","", "", triple); |
| 676 | // Fedora 9 |
| 677 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
| 678 | "x86_64-redhat-linux", "32", "", triple); |
| 679 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", |
| 680 | "i386-redhat-linux", "", "", triple); |
| 681 | // Fedora 8 |
| 682 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
| 683 | "x86_64-redhat-linux", "", "", triple); |
| 684 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", |
| 685 | "i386-redhat-linux", "", "", triple); |
| 686 | |
| 687 | //===------------------------------------------------------------------===// |
| 688 | |
Benjamin Kramer | 0db3d72 | 2010-01-25 12:20:15 +0000 | [diff] [blame] | 689 | // Exherbo (2010-01-25) |
| 690 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
Torok Edwin | fc4b899 | 2009-12-18 17:29:14 +0000 | [diff] [blame] | 691 | "x86_64-pc-linux-gnu", "32", "", triple); |
Benjamin Kramer | 0db3d72 | 2010-01-25 12:20:15 +0000 | [diff] [blame] | 692 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", |
Torok Edwin | fc4b899 | 2009-12-18 17:29:14 +0000 | [diff] [blame] | 693 | "i686-pc-linux-gnu", "", "", triple); |
Chris Lattner | ea00f84 | 2010-04-23 15:55:20 +0000 | [diff] [blame] | 694 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 695 | // openSUSE 11.1 32 bit |
| 696 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 697 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 698 | // openSUSE 11.1 64 bit |
| 699 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 700 | "x86_64-suse-linux", "32", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 701 | // openSUSE 11.2 |
| 702 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 703 | "i586-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 704 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 705 | "x86_64-suse-linux", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 706 | // Arch Linux 2008-06-24 |
| 707 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 708 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 709 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 710 | "x86_64-unknown-linux-gnu", "", "", triple); |
Nuno Lopes | 0d155a5 | 2010-09-11 17:51:45 +0000 | [diff] [blame] | 711 | // Gentoo x86 2010.0 stable |
| 712 | AddGnuCPlusPlusIncludePaths( |
| 713 | "/usr/lib/gcc/i686-pc-linux-gnu/4.4.3/include/g++-v4", |
| 714 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 715 | // Gentoo x86 2009.1 stable |
| 716 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 717 | "/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] | 718 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 719 | // Gentoo x86 2009.0 stable |
| 720 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 721 | "/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] | 722 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 723 | // Gentoo x86 2008.0 stable |
| 724 | AddGnuCPlusPlusIncludePaths( |
John Thompson | 40d1bb6 | 2009-11-05 22:03:02 +0000 | [diff] [blame] | 725 | "/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] | 726 | "i686-pc-linux-gnu", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 727 | // Gentoo amd64 stable |
| 728 | AddGnuCPlusPlusIncludePaths( |
| 729 | "/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] | 730 | "i686-pc-linux-gnu", "", "", triple); |
Eric Christopher | 70d9d41 | 2010-03-03 21:41:50 +0000 | [diff] [blame] | 731 | |
| 732 | // Gentoo amd64 gcc 4.3.2 |
| 733 | AddGnuCPlusPlusIncludePaths( |
| 734 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4", |
| 735 | "x86_64-pc-linux-gnu", "", "", triple); |
| 736 | |
| 737 | // Gentoo amd64 gcc 4.4.3 |
| 738 | AddGnuCPlusPlusIncludePaths( |
| 739 | "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4", |
| 740 | "x86_64-pc-linux-gnu", "32", "", triple); |
Nick Lewycky | 6693534 | 2010-07-24 21:33:13 +0000 | [diff] [blame] | 741 | |
| 742 | // Gentoo amd64 llvm-gcc trunk |
| 743 | AddGnuCPlusPlusIncludePaths( |
| 744 | "/usr/lib/llvm-gcc-4.2-9999/include/c++/4.2.1", |
| 745 | "x86_64-pc-linux-gnu", "", "", triple); |
Eric Christopher | 70d9d41 | 2010-03-03 21:41:50 +0000 | [diff] [blame] | 746 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 747 | break; |
| 748 | case llvm::Triple::FreeBSD: |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 749 | // FreeBSD 8.0 |
| 750 | // FreeBSD 7.3 |
Nuno Lopes | afe859a | 2010-01-17 00:00:11 +0000 | [diff] [blame] | 751 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 752 | break; |
Anton Korobeynikov | ab07941 | 2010-08-31 22:39:50 +0000 | [diff] [blame] | 753 | case llvm::Triple::NetBSD: |
| 754 | AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple); |
| 755 | break; |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 756 | case llvm::Triple::OpenBSD: { |
| 757 | std::string t = triple.getTriple(); |
| 758 | if (t.substr(0, 6) == "x86_64") |
| 759 | t.replace(0, 6, "amd64"); |
| 760 | AddGnuCPlusPlusIncludePaths("/usr/include/g++", |
| 761 | t, "", "", triple); |
| 762 | break; |
| 763 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 764 | case llvm::Triple::Minix: |
| 765 | AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3", |
| 766 | "", "", "", triple); |
| 767 | break; |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 768 | case llvm::Triple::Solaris: |
| 769 | // Solaris - Fall though.. |
| 770 | case llvm::Triple::AuroraUX: |
| 771 | // AuroraUX |
| 772 | AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 773 | "i386-pc-solaris2.11", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 774 | break; |
| 775 | default: |
| 776 | break; |
| 777 | } |
| 778 | } |
| 779 | |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 780 | void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 781 | const llvm::Triple &triple, |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 782 | const HeaderSearchOptions &HSOpts) { |
Daniel Dunbar | 80c26f4 | 2010-09-09 17:38:22 +0000 | [diff] [blame] | 783 | if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes) { |
| 784 | if (!HSOpts.CXXSystemIncludes.empty()) { |
| 785 | for (unsigned i = 0, e = HSOpts.CXXSystemIncludes.size(); i != e; ++i) |
| 786 | AddPath(HSOpts.CXXSystemIncludes[i], System, true, false, false); |
| 787 | } else |
| 788 | AddDefaultCPlusPlusIncludePaths(triple); |
| 789 | } |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 790 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 791 | AddDefaultCIncludePaths(triple, HSOpts); |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 792 | |
| 793 | // Add the default framework include paths on Darwin. |
| 794 | if (triple.getOS() == llvm::Triple::Darwin) { |
| 795 | AddPath("/System/Library/Frameworks", System, true, false, true); |
| 796 | AddPath("/Library/Frameworks", System, true, false, true); |
| 797 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 800 | /// RemoveDuplicates - If there are duplicate directory entries in the specified |
| 801 | /// search list, remove the later (dead) ones. |
| 802 | static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
| 803 | bool Verbose) { |
| 804 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 805 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 806 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
| 807 | for (unsigned i = 0; i != SearchList.size(); ++i) { |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 808 | unsigned DirToRemove = i; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 809 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 810 | const DirectoryLookup &CurEntry = SearchList[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 811 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 812 | if (CurEntry.isNormalDir()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 813 | // 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] | 814 | if (SeenDirs.insert(CurEntry.getDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 815 | continue; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 816 | } else if (CurEntry.isFramework()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 817 | // 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] | 818 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 819 | continue; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 820 | } else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 821 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 822 | // 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] | 823 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 824 | continue; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 825 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 826 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 827 | // If we have a normal #include dir/framework/headermap that is shadowed |
| 828 | // later in the chain by a system include location, we actually want to |
| 829 | // ignore the user's request and drop the user dir... keeping the system |
| 830 | // dir. This is weird, but required to emulate GCC's search path correctly. |
| 831 | // |
| 832 | // Since dupes of system dirs are rare, just rescan to find the original |
| 833 | // that we're nuking instead of using a DenseMap. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 834 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 835 | // Find the dir that this is the same of. |
| 836 | unsigned FirstDir; |
| 837 | for (FirstDir = 0; ; ++FirstDir) { |
| 838 | assert(FirstDir != i && "Didn't find dupe?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 840 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 841 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 842 | // 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] | 843 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 844 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 846 | bool isSame; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 847 | if (CurEntry.isNormalDir()) |
| 848 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 849 | else if (CurEntry.isFramework()) |
| 850 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 851 | else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 852 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 853 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 854 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 855 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 856 | if (isSame) |
| 857 | break; |
| 858 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 859 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 860 | // If the first dir in the search path is a non-system dir, zap it |
| 861 | // instead of the system one. |
| 862 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 863 | DirToRemove = FirstDir; |
| 864 | } |
| 865 | |
| 866 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 867 | llvm::errs() << "ignoring duplicate directory \"" |
| 868 | << CurEntry.getName() << "\"\n"; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 869 | if (DirToRemove != i) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 870 | llvm::errs() << " as it is a non-system directory that duplicates " |
| 871 | << "a system directory\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 872 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 873 | |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 874 | // This is reached if the current entry is a duplicate. Remove the |
| 875 | // DirToRemove (usually the current dir). |
| 876 | SearchList.erase(SearchList.begin()+DirToRemove); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 877 | --i; |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | |
| 882 | void InitHeaderSearch::Realize() { |
| 883 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. |
| 884 | std::vector<DirectoryLookup> SearchList; |
| 885 | SearchList = IncludeGroup[Angled]; |
| 886 | SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), |
| 887 | IncludeGroup[System].end()); |
| 888 | SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), |
| 889 | IncludeGroup[After].end()); |
| 890 | RemoveDuplicates(SearchList, Verbose); |
| 891 | RemoveDuplicates(IncludeGroup[Quoted], Verbose); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 893 | // Prepend QUOTED list on the search list. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 895 | IncludeGroup[Quoted].end()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 896 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 897 | |
| 898 | bool DontSearchCurDir = false; // TODO: set to true if -I- is set? |
| 899 | Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), |
| 900 | DontSearchCurDir); |
| 901 | |
| 902 | // If verbose, print the list of directories that will be searched. |
| 903 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 904 | llvm::errs() << "#include \"...\" search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 905 | unsigned QuotedIdx = IncludeGroup[Quoted].size(); |
| 906 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
| 907 | if (i == QuotedIdx) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 908 | llvm::errs() << "#include <...> search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 909 | const char *Name = SearchList[i].getName(); |
| 910 | const char *Suffix; |
| 911 | if (SearchList[i].isNormalDir()) |
| 912 | Suffix = ""; |
| 913 | else if (SearchList[i].isFramework()) |
| 914 | Suffix = " (framework directory)"; |
| 915 | else { |
| 916 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 917 | Suffix = " (headermap)"; |
| 918 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 919 | llvm::errs() << " " << Name << Suffix << "\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 920 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 921 | llvm::errs() << "End of search list.\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 922 | } |
| 923 | } |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 924 | |
Daniel Dunbar | 5814e65 | 2009-11-11 21:44:21 +0000 | [diff] [blame] | 925 | void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, |
| 926 | const HeaderSearchOptions &HSOpts, |
| 927 | const LangOptions &Lang, |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 928 | const llvm::Triple &Triple) { |
| 929 | InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); |
| 930 | |
| 931 | // Add the user defined entries. |
| 932 | for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { |
| 933 | const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; |
Daniel Dunbar | 1b483e7 | 2009-11-17 05:04:15 +0000 | [diff] [blame] | 934 | Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework, |
Chris Lattner | 23637be | 2010-08-24 22:27:37 +0000 | [diff] [blame] | 935 | !E.IsSysRootRelative); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | // Add entries from CPATH and friends. |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 939 | Init.AddDelimitedPaths(HSOpts.EnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 940 | if (Lang.CPlusPlus && Lang.ObjC1) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 941 | Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 942 | else if (Lang.CPlusPlus) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 943 | Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 944 | else if (Lang.ObjC1) |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 945 | Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath); |
Daniel Dunbar | c363cb1 | 2009-11-16 22:38:40 +0000 | [diff] [blame] | 946 | else |
Benjamin Kramer | 9e9ddf6 | 2009-12-08 12:11:06 +0000 | [diff] [blame] | 947 | Init.AddDelimitedPaths(HSOpts.CEnvIncPath); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 948 | |
Daniel Dunbar | dd35ce9 | 2009-11-07 04:58:12 +0000 | [diff] [blame] | 949 | if (HSOpts.UseStandardIncludes) |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 950 | Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 951 | |
| 952 | Init.Realize(); |
| 953 | } |