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