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