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 | |
Oscar Fuentes | 2100fe9 | 2011-02-03 22:48:20 +0000 | [diff] [blame] | 14 | #ifdef HAVE_CLANG_CONFIG_H |
| 15 | # include "clang/Config/config.h" |
| 16 | #endif |
| 17 | |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 19 | #include "clang/Basic/FileManager.h" |
| 20 | #include "clang/Basic/LangOptions.h" |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 21 | #include "clang/Frontend/HeaderSearchOptions.h" |
| 22 | #include "clang/Lex/HeaderSearch.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallString.h" |
| 24 | #include "llvm/ADT/SmallPtrSet.h" |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallVector.h" |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Triple.h" |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/Twine.h" |
Chris Lattner | d57a7ef | 2009-08-23 22:45:33 +0000 | [diff] [blame] | 29 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | ca23419 | 2011-11-04 23:49:05 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Path.h" |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 32 | #include "llvm/Config/config.h" |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 33 | using namespace clang; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 34 | using namespace clang::frontend; |
| 35 | |
| 36 | namespace { |
| 37 | |
| 38 | /// InitHeaderSearch - This class makes it easier to set the search paths of |
| 39 | /// a HeaderSearch object. InitHeaderSearch stores several search path lists |
| 40 | /// internally, which can be sent to a HeaderSearch object in one swoop. |
| 41 | class InitHeaderSearch { |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 42 | std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath; |
| 43 | typedef std::vector<std::pair<IncludeDirGroup, |
| 44 | DirectoryLookup> >::const_iterator path_iterator; |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 45 | HeaderSearch &Headers; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 46 | bool Verbose; |
Michael J. Spencer | af6530c | 2010-12-25 20:09:27 +0000 | [diff] [blame] | 47 | std::string IncludeSysroot; |
| 48 | bool IsNotEmptyOrRoot; |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 49 | |
| 50 | public: |
| 51 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 52 | InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot) |
Michael J. Spencer | af6530c | 2010-12-25 20:09:27 +0000 | [diff] [blame] | 53 | : Headers(HS), Verbose(verbose), IncludeSysroot(sysroot), |
| 54 | IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) { |
Chandler Carruth | c09265a | 2010-11-15 07:15:26 +0000 | [diff] [blame] | 55 | } |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 56 | |
| 57 | /// AddPath - Add the specified path to the specified group list. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 58 | void AddPath(const Twine &Path, IncludeDirGroup Group, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 59 | bool isCXXAware, bool isUserSupplied, |
| 60 | bool isFramework, bool IgnoreSysRoot = false); |
| 61 | |
mike-m | a608737 | 2010-05-05 17:00:31 +0000 | [diff] [blame] | 62 | /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 63 | /// libstdc++. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 64 | void AddGnuCPlusPlusIncludePaths(StringRef Base, |
| 65 | StringRef ArchDir, |
| 66 | StringRef Dir32, |
| 67 | StringRef Dir64, |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 68 | const llvm::Triple &triple); |
| 69 | |
Michael J. Spencer | 06a8dc6 | 2010-12-21 16:45:42 +0000 | [diff] [blame] | 70 | /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 71 | /// libstdc++. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 72 | void AddMinGWCPlusPlusIncludePaths(StringRef Base, |
| 73 | StringRef Arch, |
| 74 | StringRef Version); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 75 | |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 76 | /// AddMinGW64CXXPaths - Add the necessary paths to support |
| 77 | /// libstdc++ of x86_64-w64-mingw32 aka mingw-w64. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 78 | void AddMinGW64CXXPaths(StringRef Base, |
| 79 | StringRef Version); |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 80 | |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 81 | // AddDefaultCIncludePaths - Add paths that should always be searched. |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 82 | void AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 83 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 84 | |
| 85 | // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when |
| 86 | // compiling c++. |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 87 | void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, |
| 88 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 89 | |
| 90 | /// AddDefaultSystemIncludePaths - Adds the default system include paths so |
| 91 | /// that e.g. stdio.h is found. |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 92 | void AddDefaultIncludePaths(const LangOptions &Lang, |
| 93 | const llvm::Triple &triple, |
| 94 | const HeaderSearchOptions &HSOpts); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 95 | |
| 96 | /// Realize - Merges all search path lists into one list and send it to |
| 97 | /// HeaderSearch. |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 98 | void Realize(const LangOptions &Lang); |
Daniel Dunbar | 2cdafa8 | 2009-11-09 23:02:47 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 101 | } // end anonymous namespace. |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 103 | void InitHeaderSearch::AddPath(const Twine &Path, |
Benjamin Kramer | 458fb10 | 2009-09-05 09:49:39 +0000 | [diff] [blame] | 104 | IncludeDirGroup Group, bool isCXXAware, |
| 105 | bool isUserSupplied, bool isFramework, |
| 106 | bool IgnoreSysRoot) { |
Benjamin Kramer | e89ba59 | 2009-12-08 12:38:20 +0000 | [diff] [blame] | 107 | assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 108 | FileManager &FM = Headers.getFileMgr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 110 | // Compute the actual path, taking into consideration -isysroot. |
Chandler Carruth | 5853b0f | 2010-11-15 00:05:18 +0000 | [diff] [blame] | 111 | llvm::SmallString<256> MappedPathStorage; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 112 | StringRef MappedPathStr = Path.toStringRef(MappedPathStorage); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 113 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 114 | // Handle isysroot. |
Rafael Espindola | 9a7e09d | 2011-03-02 21:30:07 +0000 | [diff] [blame] | 115 | if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot && |
NAKAMURA Takumi | 0f0cdab | 2011-05-02 04:50:10 +0000 | [diff] [blame] | 116 | #if defined(_WIN32) |
| 117 | !MappedPathStr.empty() && |
| 118 | llvm::sys::path::is_separator(MappedPathStr[0]) && |
| 119 | #else |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 120 | llvm::sys::path::is_absolute(MappedPathStr) && |
NAKAMURA Takumi | 0f0cdab | 2011-05-02 04:50:10 +0000 | [diff] [blame] | 121 | #endif |
Michael J. Spencer | af6530c | 2010-12-25 20:09:27 +0000 | [diff] [blame] | 122 | IsNotEmptyOrRoot) { |
Chandler Carruth | 5619ae5 | 2010-11-15 09:28:23 +0000 | [diff] [blame] | 123 | MappedPathStorage.clear(); |
Chandler Carruth | c09265a | 2010-11-15 07:15:26 +0000 | [diff] [blame] | 124 | MappedPathStr = |
Michael J. Spencer | af6530c | 2010-12-25 20:09:27 +0000 | [diff] [blame] | 125 | (IncludeSysroot + Path).toStringRef(MappedPathStorage); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 126 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 127 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 128 | // Compute the DirectoryLookup type. |
Chris Lattner | 9d72851 | 2008-10-27 01:19:25 +0000 | [diff] [blame] | 129 | SrcMgr::CharacteristicKind Type; |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 130 | if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 131 | Type = SrcMgr::C_User; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 132 | else if (isCXXAware) |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 133 | Type = SrcMgr::C_System; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 134 | else |
Chris Lattner | 0b9e736 | 2008-09-26 21:18:42 +0000 | [diff] [blame] | 135 | Type = SrcMgr::C_ExternCSystem; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 136 | |
| 137 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 138 | // If the directory exists, add it. |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 139 | if (const DirectoryEntry *DE = FM.getDirectory(MappedPathStr)) { |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 140 | IncludePath.push_back(std::make_pair(Group, DirectoryLookup(DE, Type, |
| 141 | isUserSupplied, isFramework))); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 142 | return; |
| 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 | // Check to see if this is an apple-style headermap (which are not allowed to |
| 146 | // be frameworks). |
| 147 | if (!isFramework) { |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 148 | if (const FileEntry *FE = FM.getFile(MappedPathStr)) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 149 | if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { |
| 150 | // It is a headermap, add it to the search path. |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 151 | IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type, |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 152 | isUserSupplied, Group == IndexHeaderMap))); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 153 | return; |
| 154 | } |
| 155 | } |
| 156 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 158 | if (Verbose) |
Chandler Carruth | f372145 | 2010-11-15 00:48:13 +0000 | [diff] [blame] | 159 | llvm::errs() << "ignoring nonexistent directory \"" |
| 160 | << MappedPathStr << "\"\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 163 | void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base, |
| 164 | StringRef ArchDir, |
| 165 | StringRef Dir32, |
| 166 | StringRef Dir64, |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 167 | const llvm::Triple &triple) { |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 168 | // Add the base dir |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 169 | AddPath(Base, CXXSystem, true, false, false); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 170 | |
| 171 | // Add the multilib dirs |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 172 | llvm::Triple::ArchType arch = triple.getArch(); |
| 173 | bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 174 | if (is64bit) |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 175 | AddPath(Base + "/" + ArchDir + "/" + Dir64, CXXSystem, true, false, false); |
Rafael Espindola | 31b63be | 2009-10-14 17:09:44 +0000 | [diff] [blame] | 176 | else |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 177 | AddPath(Base + "/" + ArchDir + "/" + Dir32, CXXSystem, true, false, false); |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 178 | |
| 179 | // Add the backward dir |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 180 | AddPath(Base + "/backward", CXXSystem, true, false, false); |
Rafael Espindola | 2e9f652 | 2009-10-06 01:33:02 +0000 | [diff] [blame] | 181 | } |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 182 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 183 | void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base, |
| 184 | StringRef Arch, |
| 185 | StringRef Version) { |
Benjamin Kramer | ab8ae19 | 2010-01-20 16:18:11 +0000 | [diff] [blame] | 186 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 187 | CXXSystem, true, false, false); |
Chris Lattner | 8e9006b | 2010-09-03 16:45:53 +0000 | [diff] [blame] | 188 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch, |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 189 | CXXSystem, true, false, false); |
Benjamin Kramer | ab8ae19 | 2010-01-20 16:18:11 +0000 | [diff] [blame] | 190 | AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 191 | CXXSystem, true, false, false); |
Mike Stump | 620d57a | 2009-10-12 20:50:45 +0000 | [diff] [blame] | 192 | } |
Argyrios Kyrtzidis | 121e3c2 | 2008-09-05 09:41:20 +0000 | [diff] [blame] | 193 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 194 | void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base, |
| 195 | StringRef Version) { |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 196 | // Assumes Base is HeaderSearchOpts' ResourceDir |
| 197 | AddPath(Base + "/../../../include/c++/" + Version, |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 198 | CXXSystem, true, false, false); |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 199 | AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32", |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 200 | CXXSystem, true, false, false); |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 201 | AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32", |
| 202 | CXXSystem, true, false, false); |
| 203 | AddPath(Base + "/../../../include/c++/" + Version + "/backward", |
NAKAMURA Takumi | 9db4846 | 2011-03-15 02:32:36 +0000 | [diff] [blame] | 204 | CXXSystem, true, false, false); |
| 205 | } |
| 206 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 207 | void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple, |
| 208 | const HeaderSearchOptions &HSOpts) { |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 209 | llvm::Triple::OSType os = triple.getOS(); |
| 210 | |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 211 | if (HSOpts.UseStandardSystemIncludes) { |
| 212 | switch (os) { |
| 213 | case llvm::Triple::FreeBSD: |
| 214 | case llvm::Triple::NetBSD: |
| 215 | break; |
| 216 | default: |
| 217 | // FIXME: temporary hack: hard-coded paths. |
| 218 | AddPath("/usr/local/include", System, true, false, false); |
| 219 | break; |
| 220 | } |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 221 | } |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 222 | |
| 223 | // Builtin includes use #include_next directives and should be positioned |
| 224 | // just prior C include dirs. |
| 225 | if (HSOpts.UseBuiltinIncludes) { |
| 226 | // Ignore the sys root, we *always* look for clang headers relative to |
| 227 | // supplied path. |
| 228 | llvm::sys::Path P(HSOpts.ResourceDir); |
| 229 | P.appendComponent("include"); |
| 230 | AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true); |
| 231 | } |
| 232 | |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 233 | // All remaining additions are for system include directories, early exit if |
| 234 | // we aren't using them. |
| 235 | if (!HSOpts.UseStandardSystemIncludes) |
| 236 | return; |
| 237 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 238 | // Add dirs specified via 'configure --with-c-include-dirs'. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 239 | StringRef CIncludeDirs(C_INCLUDE_DIRS); |
Daniel Dunbar | c706468 | 2009-11-12 07:28:29 +0000 | [diff] [blame] | 240 | if (CIncludeDirs != "") { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 241 | SmallVector<StringRef, 5> dirs; |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 242 | CIncludeDirs.split(dirs, ":"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 243 | for (SmallVectorImpl<StringRef>::iterator i = dirs.begin(); |
Rafael Espindola | aadd7a4 | 2009-11-13 05:13:58 +0000 | [diff] [blame] | 244 | i != dirs.end(); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 245 | ++i) |
Rafael Espindola | f0a2f51 | 2009-11-12 05:48:41 +0000 | [diff] [blame] | 246 | AddPath(*i, System, false, false, false); |
| 247 | return; |
| 248 | } |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 249 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 250 | switch (os) { |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 251 | case llvm::Triple::Linux: |
Chandler Carruth | ca23419 | 2011-11-04 23:49:05 +0000 | [diff] [blame] | 252 | case llvm::Triple::Win32: |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 253 | llvm_unreachable("Include management is handled in the driver."); |
Chandler Carruth | ca23419 | 2011-11-04 23:49:05 +0000 | [diff] [blame] | 254 | |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 255 | case llvm::Triple::Haiku: |
| 256 | AddPath("/boot/common/include", System, true, false, false); |
| 257 | AddPath("/boot/develop/headers/os", System, true, false, false); |
| 258 | AddPath("/boot/develop/headers/os/app", System, true, false, false); |
| 259 | AddPath("/boot/develop/headers/os/arch", System, true, false, false); |
| 260 | AddPath("/boot/develop/headers/os/device", System, true, false, false); |
| 261 | AddPath("/boot/develop/headers/os/drivers", System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 262 | AddPath("/boot/develop/headers/os/game", System, true, false, false); |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 263 | AddPath("/boot/develop/headers/os/interface", System, true, false, false); |
| 264 | AddPath("/boot/develop/headers/os/kernel", System, true, false, false); |
| 265 | AddPath("/boot/develop/headers/os/locale", System, true, false, false); |
| 266 | AddPath("/boot/develop/headers/os/mail", System, true, false, false); |
| 267 | AddPath("/boot/develop/headers/os/media", System, true, false, false); |
| 268 | AddPath("/boot/develop/headers/os/midi", System, true, false, false); |
| 269 | AddPath("/boot/develop/headers/os/midi2", System, true, false, false); |
| 270 | AddPath("/boot/develop/headers/os/net", System, true, false, false); |
| 271 | AddPath("/boot/develop/headers/os/storage", System, true, false, false); |
| 272 | AddPath("/boot/develop/headers/os/support", System, true, false, false); |
| 273 | AddPath("/boot/develop/headers/os/translation", |
| 274 | System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 275 | AddPath("/boot/develop/headers/os/add-ons/graphics", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 276 | System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 277 | AddPath("/boot/develop/headers/os/add-ons/input_server", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 278 | System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 279 | AddPath("/boot/develop/headers/os/add-ons/screen_saver", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 280 | System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 281 | AddPath("/boot/develop/headers/os/add-ons/tracker", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 282 | System, true, false, false); |
| 283 | AddPath("/boot/develop/headers/os/be_apps/Deskbar", |
| 284 | System, true, false, false); |
| 285 | AddPath("/boot/develop/headers/os/be_apps/NetPositive", |
| 286 | System, true, false, false); |
| 287 | AddPath("/boot/develop/headers/os/be_apps/Tracker", |
| 288 | System, true, false, false); |
| 289 | AddPath("/boot/develop/headers/cpp", System, true, false, false); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 290 | AddPath("/boot/develop/headers/cpp/i586-pc-haiku", |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 291 | System, true, false, false); |
| 292 | AddPath("/boot/develop/headers/3rdparty", System, true, false, false); |
| 293 | AddPath("/boot/develop/headers/bsd", System, true, false, false); |
| 294 | AddPath("/boot/develop/headers/glibc", System, true, false, false); |
| 295 | AddPath("/boot/develop/headers/posix", System, true, false, false); |
| 296 | AddPath("/boot/develop/headers", System, true, false, false); |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 297 | break; |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 298 | case llvm::Triple::RTEMS: |
| 299 | break; |
NAKAMURA Takumi | 32df002 | 2010-10-11 02:27:37 +0000 | [diff] [blame] | 300 | case llvm::Triple::Cygwin: |
| 301 | AddPath("/usr/include/w32api", System, true, false, false); |
| 302 | break; |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 303 | case llvm::Triple::MinGW32: { |
| 304 | // mingw-w64 crt include paths |
| 305 | llvm::sys::Path P(HSOpts.ResourceDir); |
| 306 | P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include |
| 307 | AddPath(P.str(), System, true, false, false); |
| 308 | P = llvm::sys::Path(HSOpts.ResourceDir); |
| 309 | P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include |
| 310 | AddPath(P.str(), System, true, false, false); |
| 311 | // mingw.org crt include paths |
| 312 | P = llvm::sys::Path(HSOpts.ResourceDir); |
| 313 | P.appendComponent("../../../include"); // <sysroot>/include |
| 314 | AddPath(P.str(), System, true, false, false); |
| 315 | AddPath("/mingw/include", System, true, false, false); |
| 316 | AddPath("c:/mingw/include", System, true, false, false); |
| 317 | } |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 318 | break; |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 319 | |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 320 | default: |
Mike Stump | 43d8176 | 2009-10-08 23:29:47 +0000 | [diff] [blame] | 321 | break; |
| 322 | } |
John Thompson | d3f8834 | 2009-10-13 18:51:32 +0000 | [diff] [blame] | 323 | |
Douglas Gregor | dca5226 | 2011-07-01 22:41:14 +0000 | [diff] [blame] | 324 | if ( os != llvm::Triple::RTEMS ) |
| 325 | AddPath("/usr/include", System, false, false, false); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 328 | void InitHeaderSearch:: |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 329 | AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) { |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 330 | llvm::Triple::OSType os = triple.getOS(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 331 | StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 332 | if (CxxIncludeRoot != "") { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 333 | StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 334 | if (CxxIncludeArch == "") |
| 335 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 336 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, |
| 337 | triple); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 338 | else |
| 339 | AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, |
Chris Lattner | 0e3cc05 | 2010-05-05 05:28:39 +0000 | [diff] [blame] | 340 | CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, |
| 341 | triple); |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 342 | return; |
| 343 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 344 | // FIXME: temporary hack: hard-coded paths. |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 345 | |
| 346 | if (triple.isOSDarwin()) { |
Daniel Dunbar | f2070b3 | 2010-05-28 01:54:31 +0000 | [diff] [blame] | 347 | switch (triple.getArch()) { |
| 348 | default: break; |
| 349 | |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 350 | case llvm::Triple::ppc: |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 351 | case llvm::Triple::ppc64: |
Douglas Gregor | 616d436 | 2010-05-29 01:21:11 +0000 | [diff] [blame] | 352 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 353 | "powerpc-apple-darwin10", "", "ppc64", |
Douglas Gregor | 616d436 | 2010-05-29 01:21:11 +0000 | [diff] [blame] | 354 | triple); |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 355 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 356 | "powerpc-apple-darwin10", "", "ppc64", |
Douglas Gregor | 582c301 | 2010-05-29 01:15:12 +0000 | [diff] [blame] | 357 | triple); |
| 358 | break; |
| 359 | |
Daniel Dunbar | f2070b3 | 2010-05-28 01:54:31 +0000 | [diff] [blame] | 360 | case llvm::Triple::x86: |
| 361 | case llvm::Triple::x86_64: |
| 362 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 363 | "i686-apple-darwin10", "", "x86_64", triple); |
| 364 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", |
| 365 | "i686-apple-darwin8", "", "", triple); |
| 366 | break; |
| 367 | |
| 368 | case llvm::Triple::arm: |
| 369 | case llvm::Triple::thumb: |
| 370 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 371 | "arm-apple-darwin10", "v7", "", triple); |
| 372 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", |
| 373 | "arm-apple-darwin10", "v6", "", triple); |
| 374 | break; |
| 375 | } |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 376 | return; |
| 377 | } |
| 378 | |
| 379 | switch (os) { |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 380 | case llvm::Triple::Linux: |
| 381 | case llvm::Triple::Win32: |
| 382 | llvm_unreachable("Include management is handled in the driver."); |
| 383 | |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 384 | case llvm::Triple::Cygwin: |
| 385 | // Cygwin-1.7 |
| 386 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.4"); |
| 387 | // g++-4 / Cygwin-1.5 |
| 388 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "4.3.2"); |
| 389 | // FIXME: Do we support g++-3.4.4? |
| 390 | AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4"); |
| 391 | break; |
| 392 | case llvm::Triple::MinGW32: |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 393 | // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32) |
| 394 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0"); |
| 395 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1"); |
| 396 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2"); |
| 397 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3"); |
Eli Friedman | a74ec5c | 2011-11-28 23:58:55 +0000 | [diff] [blame^] | 398 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4"); |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 399 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0"); |
| 400 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1"); |
Douglas Gregor | f732f2b | 2011-07-05 14:16:05 +0000 | [diff] [blame] | 401 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2"); |
Eli Friedman | a74ec5c | 2011-11-28 23:58:55 +0000 | [diff] [blame^] | 402 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3"); |
Douglas Gregor | f732f2b | 2011-07-05 14:16:05 +0000 | [diff] [blame] | 403 | AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0"); |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 404 | // mingw.org C++ include paths |
| 405 | AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 406 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0"); |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 407 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 408 | AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 409 | break; |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 410 | case llvm::Triple::DragonFly: |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 411 | AddPath("/usr/include/c++/4.1", CXXSystem, true, false, false); |
Chris Lattner | 7a7ca28 | 2010-01-09 05:41:14 +0000 | [diff] [blame] | 412 | break; |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 413 | case llvm::Triple::FreeBSD: |
mike-m | ac78b7a | 2010-05-06 14:11:13 +0000 | [diff] [blame] | 414 | // FreeBSD 8.0 |
| 415 | // FreeBSD 7.3 |
Nuno Lopes | afe859a | 2010-01-17 00:00:11 +0000 | [diff] [blame] | 416 | AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 417 | break; |
Anton Korobeynikov | ab07941 | 2010-08-31 22:39:50 +0000 | [diff] [blame] | 418 | case llvm::Triple::NetBSD: |
| 419 | AddGnuCPlusPlusIncludePaths("/usr/include/g++", "", "", "", triple); |
| 420 | break; |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 421 | case llvm::Triple::OpenBSD: { |
| 422 | std::string t = triple.getTriple(); |
| 423 | if (t.substr(0, 6) == "x86_64") |
| 424 | t.replace(0, 6, "amd64"); |
| 425 | AddGnuCPlusPlusIncludePaths("/usr/include/g++", |
| 426 | t, "", "", triple); |
| 427 | break; |
| 428 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 429 | case llvm::Triple::Minix: |
| 430 | AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3", |
| 431 | "", "", "", triple); |
| 432 | break; |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 433 | case llvm::Triple::Solaris: |
| 434 | // Solaris - Fall though.. |
| 435 | case llvm::Triple::AuroraUX: |
| 436 | // AuroraUX |
| 437 | AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", |
Rafael Espindola | ab7ae95 | 2009-11-16 19:49:37 +0000 | [diff] [blame] | 438 | "i386-pc-solaris2.11", "", "", triple); |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 439 | break; |
| 440 | default: |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 445 | void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang, |
| 446 | const llvm::Triple &triple, |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 447 | const HeaderSearchOptions &HSOpts) { |
Chandler Carruth | ca23419 | 2011-11-04 23:49:05 +0000 | [diff] [blame] | 448 | // NB: This code path is going away. All of the logic is moving into the |
| 449 | // driver which has the information necessary to do target-specific |
| 450 | // selections of default include paths. Each target which moves there will be |
| 451 | // exempted from this logic here until we can delete the entire pile of code. |
| 452 | switch (triple.getOS()) { |
| 453 | default: |
| 454 | break; // Everything else continues to use this routine's logic. |
| 455 | |
Chandler Carruth | 7d7e9f9 | 2011-11-05 20:17:13 +0000 | [diff] [blame] | 456 | case llvm::Triple::Linux: |
Chandler Carruth | ca23419 | 2011-11-04 23:49:05 +0000 | [diff] [blame] | 457 | case llvm::Triple::Win32: |
| 458 | return; |
| 459 | } |
| 460 | |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 461 | if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes && |
| 462 | HSOpts.UseStandardSystemIncludes) { |
Douglas Gregor | baf41f1 | 2011-07-29 20:21:18 +0000 | [diff] [blame] | 463 | if (HSOpts.UseLibcxx) { |
| 464 | if (triple.isOSDarwin()) { |
| 465 | // On Darwin, libc++ may be installed alongside the compiler in |
| 466 | // lib/c++/v1. |
| 467 | llvm::sys::Path P(HSOpts.ResourceDir); |
| 468 | if (!P.isEmpty()) { |
| 469 | P.eraseComponent(); // Remove version from foo/lib/clang/version |
| 470 | P.eraseComponent(); // Remove clang from foo/lib/clang |
| 471 | |
| 472 | // Get foo/lib/c++/v1 |
| 473 | P.appendComponent("c++"); |
| 474 | P.appendComponent("v1"); |
| 475 | AddPath(P.str(), CXXSystem, true, false, false, true); |
| 476 | } |
| 477 | } |
| 478 | |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 479 | AddPath("/usr/include/c++/v1", CXXSystem, true, false, false); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 480 | } else { |
Douglas Gregor | d944a9b | 2011-06-27 15:47:15 +0000 | [diff] [blame] | 481 | AddDefaultCPlusPlusIncludePaths(triple, HSOpts); |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 482 | } |
Bob Wilson | 13c4f21 | 2011-06-21 21:12:29 +0000 | [diff] [blame] | 483 | } |
Rafael Espindola | 6ec18a3 | 2009-11-23 16:31:19 +0000 | [diff] [blame] | 484 | |
mike-m | 79bc57c | 2010-05-16 19:03:52 +0000 | [diff] [blame] | 485 | AddDefaultCIncludePaths(triple, HSOpts); |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 486 | |
| 487 | // Add the default framework include paths on Darwin. |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 488 | if (HSOpts.UseStandardSystemIncludes) { |
| 489 | if (triple.isOSDarwin()) { |
| 490 | AddPath("/System/Library/Frameworks", System, true, false, true); |
| 491 | AddPath("/Library/Frameworks", System, true, false, true); |
| 492 | } |
Daniel Dunbar | e166582 | 2009-11-07 04:20:39 +0000 | [diff] [blame] | 493 | } |
Rafael Espindola | e4b255c | 2009-10-27 14:47:31 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 496 | /// RemoveDuplicates - If there are duplicate directory entries in the specified |
Chad Rosier | e305e81 | 2011-10-10 18:44:24 +0000 | [diff] [blame] | 497 | /// search list, remove the later (dead) ones. Returns the number of non-system |
| 498 | /// headers removed, which is used to update NumAngled. |
| 499 | static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, |
| 500 | unsigned First, bool Verbose) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 501 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; |
| 502 | llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; |
| 503 | llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; |
Chad Rosier | e305e81 | 2011-10-10 18:44:24 +0000 | [diff] [blame] | 504 | unsigned NonSystemRemoved = 0; |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 505 | for (unsigned i = First; i != SearchList.size(); ++i) { |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 506 | unsigned DirToRemove = i; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 508 | const DirectoryLookup &CurEntry = SearchList[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 510 | if (CurEntry.isNormalDir()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 511 | // 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] | 512 | if (SeenDirs.insert(CurEntry.getDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 513 | continue; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 514 | } else if (CurEntry.isFramework()) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 515 | // 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] | 516 | if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 517 | continue; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 518 | } else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 519 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 520 | // 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] | 521 | if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 522 | continue; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 523 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 525 | // If we have a normal #include dir/framework/headermap that is shadowed |
| 526 | // later in the chain by a system include location, we actually want to |
| 527 | // ignore the user's request and drop the user dir... keeping the system |
| 528 | // dir. This is weird, but required to emulate GCC's search path correctly. |
| 529 | // |
| 530 | // Since dupes of system dirs are rare, just rescan to find the original |
| 531 | // that we're nuking instead of using a DenseMap. |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 532 | if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 533 | // Find the dir that this is the same of. |
| 534 | unsigned FirstDir; |
| 535 | for (FirstDir = 0; ; ++FirstDir) { |
| 536 | assert(FirstDir != i && "Didn't find dupe?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 538 | const DirectoryLookup &SearchEntry = SearchList[FirstDir]; |
| 539 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 540 | // 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] | 541 | if (SearchEntry.getLookupType() != CurEntry.getLookupType()) |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 542 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 544 | bool isSame; |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 545 | if (CurEntry.isNormalDir()) |
| 546 | isSame = SearchEntry.getDir() == CurEntry.getDir(); |
| 547 | else if (CurEntry.isFramework()) |
| 548 | isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 549 | else { |
Chris Lattner | 43eee07 | 2009-02-08 01:00:10 +0000 | [diff] [blame] | 550 | assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); |
| 551 | isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 552 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 553 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 554 | if (isSame) |
| 555 | break; |
| 556 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 557 | |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 558 | // If the first dir in the search path is a non-system dir, zap it |
| 559 | // instead of the system one. |
| 560 | if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) |
| 561 | DirToRemove = FirstDir; |
| 562 | } |
| 563 | |
| 564 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 565 | llvm::errs() << "ignoring duplicate directory \"" |
| 566 | << CurEntry.getName() << "\"\n"; |
Chris Lattner | 30f05b5 | 2009-02-08 00:55:22 +0000 | [diff] [blame] | 567 | if (DirToRemove != i) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 568 | llvm::errs() << " as it is a non-system directory that duplicates " |
| 569 | << "a system directory\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 570 | } |
Chad Rosier | e305e81 | 2011-10-10 18:44:24 +0000 | [diff] [blame] | 571 | if (DirToRemove != i) |
| 572 | ++NonSystemRemoved; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
Chris Lattner | 7a73940 | 2008-09-26 17:46:45 +0000 | [diff] [blame] | 574 | // This is reached if the current entry is a duplicate. Remove the |
| 575 | // DirToRemove (usually the current dir). |
| 576 | SearchList.erase(SearchList.begin()+DirToRemove); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 577 | --i; |
| 578 | } |
Chad Rosier | e305e81 | 2011-10-10 18:44:24 +0000 | [diff] [blame] | 579 | return NonSystemRemoved; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 583 | void InitHeaderSearch::Realize(const LangOptions &Lang) { |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 584 | // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. |
| 585 | std::vector<DirectoryLookup> SearchList; |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 586 | SearchList.reserve(IncludePath.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 587 | |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 588 | // Quoted arguments go first. |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 589 | for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); |
| 590 | it != ie; ++it) { |
| 591 | if (it->first == Quoted) |
| 592 | SearchList.push_back(it->second); |
| 593 | } |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 594 | // Deduplicate and remember index. |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 595 | RemoveDuplicates(SearchList, 0, Verbose); |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 596 | unsigned NumQuoted = SearchList.size(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 597 | |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 598 | for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); |
| 599 | it != ie; ++it) { |
Douglas Gregor | 65e02fa | 2011-07-28 04:45:53 +0000 | [diff] [blame] | 600 | if (it->first == Angled || it->first == IndexHeaderMap) |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 601 | SearchList.push_back(it->second); |
| 602 | } |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 603 | |
| 604 | RemoveDuplicates(SearchList, NumQuoted, Verbose); |
| 605 | unsigned NumAngled = SearchList.size(); |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 606 | |
| 607 | for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); |
| 608 | it != ie; ++it) { |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 609 | if (it->first == System || |
| 610 | (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) || |
Benjamin Kramer | c535d97 | 2011-09-23 02:25:14 +0000 | [diff] [blame] | 611 | (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) || |
Benjamin Kramer | 47adebe | 2011-09-22 21:41:16 +0000 | [diff] [blame] | 612 | (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) || |
| 613 | (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem)) |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 614 | SearchList.push_back(it->second); |
| 615 | } |
| 616 | |
| 617 | for (path_iterator it = IncludePath.begin(), ie = IncludePath.end(); |
| 618 | it != ie; ++it) { |
| 619 | if (it->first == After) |
| 620 | SearchList.push_back(it->second); |
| 621 | } |
| 622 | |
Chris Lattner | 1d7f12b | 2011-06-16 22:58:10 +0000 | [diff] [blame] | 623 | // Remove duplicates across both the Angled and System directories. GCC does |
| 624 | // this and failing to remove duplicates across these two groups breaks |
| 625 | // #include_next. |
Chad Rosier | e305e81 | 2011-10-10 18:44:24 +0000 | [diff] [blame] | 626 | unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose); |
| 627 | NumAngled -= NonSystemRemoved; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 628 | |
| 629 | bool DontSearchCurDir = false; // TODO: set to true if -I- is set? |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 630 | Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir); |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 631 | |
| 632 | // If verbose, print the list of directories that will be searched. |
| 633 | if (Verbose) { |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 634 | llvm::errs() << "#include \"...\" search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 635 | for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { |
Chris Lattner | ebb6164 | 2011-06-16 22:56:45 +0000 | [diff] [blame] | 636 | if (i == NumQuoted) |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 637 | llvm::errs() << "#include <...> search starts here:\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 638 | const char *Name = SearchList[i].getName(); |
| 639 | const char *Suffix; |
| 640 | if (SearchList[i].isNormalDir()) |
| 641 | Suffix = ""; |
| 642 | else if (SearchList[i].isFramework()) |
| 643 | Suffix = " (framework directory)"; |
| 644 | else { |
| 645 | assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); |
| 646 | Suffix = " (headermap)"; |
| 647 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 648 | llvm::errs() << " " << Name << Suffix << "\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 649 | } |
Daniel Dunbar | e7cb7e4 | 2009-12-03 09:14:02 +0000 | [diff] [blame] | 650 | llvm::errs() << "End of search list.\n"; |
Nico Weber | 0fca022 | 2008-08-22 09:25:22 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 653 | |
Daniel Dunbar | 5814e65 | 2009-11-11 21:44:21 +0000 | [diff] [blame] | 654 | void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, |
| 655 | const HeaderSearchOptions &HSOpts, |
| 656 | const LangOptions &Lang, |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 657 | const llvm::Triple &Triple) { |
| 658 | InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); |
| 659 | |
| 660 | // Add the user defined entries. |
| 661 | for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { |
| 662 | const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; |
Chandler Carruth | ac2bc4d | 2011-11-05 08:30:29 +0000 | [diff] [blame] | 663 | Init.AddPath(E.Path, E.Group, !E.ImplicitExternC, E.IsUserSupplied, |
| 664 | E.IsFramework, E.IgnoreSysRoot); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Daniel Dunbar | a268fc0 | 2011-10-11 18:20:10 +0000 | [diff] [blame] | 667 | Init.AddDefaultIncludePaths(Lang, Triple, HSOpts); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 668 | |
Joerg Sonnenberger | 2df6647 | 2011-02-22 00:40:56 +0000 | [diff] [blame] | 669 | Init.Realize(Lang); |
Daniel Dunbar | 63c8b77 | 2009-11-07 04:20:50 +0000 | [diff] [blame] | 670 | } |