InitHeaderSearch.cpp revision 4c2bcad7b843c10fd4a2ffd43da40bfefb4dc8ba
10fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber//===--- InitHeaderSearch.cpp - Initialize header search paths ----------*-===// 20fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 30fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// The LLVM Compiler Infrastructure 40fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 50fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// This file is distributed under the University of Illinois Open Source 60fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// License. See LICENSE.TXT for details. 70fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 80fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber//===----------------------------------------------------------------------===// 90fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 100fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// This file implements the InitHeaderSearch class. 110fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber// 120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber//===----------------------------------------------------------------------===// 130fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 142cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar#include "clang/Frontend/Utils.h" 150fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "clang/Basic/FileManager.h" 160fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "clang/Basic/LangOptions.h" 1763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "clang/Frontend/HeaderSearchOptions.h" 1863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "clang/Lex/HeaderSearch.h" 190fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "llvm/ADT/SmallString.h" 200fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "llvm/ADT/SmallPtrSet.h" 21aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola#include "llvm/ADT/SmallVector.h" 22f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola#include "llvm/ADT/StringExtras.h" 232cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar#include "llvm/ADT/Triple.h" 24e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer#include "llvm/ADT/Twine.h" 25d57a7ef9252964bc6c8471451d7bd395b0520cb8Chris Lattner#include "llvm/Support/raw_ostream.h" 260fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber#include "llvm/System/Path.h" 27121e3c207415fb4c105d690de384d8f3d49b0f2dArgyrios Kyrtzidis#include "llvm/Config/config.h" 28620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#ifdef _MSC_VER 29620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #define WIN32_LEAN_AND_MEAN 1 30620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #include <windows.h> 31620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#endif 320fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weberusing namespace clang; 332cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarusing namespace clang::frontend; 342cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 352cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarnamespace { 362cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 372cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// InitHeaderSearch - This class makes it easier to set the search paths of 382cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// a HeaderSearch object. InitHeaderSearch stores several search path lists 392cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar/// internally, which can be sent to a HeaderSearch object in one swoop. 402cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarclass InitHeaderSearch { 412cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar std::vector<DirectoryLookup> IncludeGroup[4]; 422cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar HeaderSearch& Headers; 432cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool Verbose; 442cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar std::string isysroot; 452cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 462cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarpublic: 472cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 482cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar InitHeaderSearch(HeaderSearch &HS, 492cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool verbose = false, const std::string &iSysroot = "") 502cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar : Headers(HS), Verbose(verbose), isysroot(iSysroot) {} 512cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 522cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddPath - Add the specified path to the specified group list. 53e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer void AddPath(const llvm::Twine &Path, IncludeDirGroup Group, 542cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool isCXXAware, bool isUserSupplied, 552cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar bool isFramework, bool IgnoreSysRoot = false); 562cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 572cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddGnuCPlusPlusIncludePaths - Add the necessary paths to suport a gnu 582cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// libstdc++. 59e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer void AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, 60e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef ArchDir, 61e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef Dir32, 62e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef Dir64, 632cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar const llvm::Triple &triple); 642cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 652cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to suport a MinGW 662cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// libstdc++. 67e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, 68e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef Arch, 69e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef Version); 702cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 712cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddDelimitedPaths - Add a list of paths delimited by the system PATH 722cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// separator. The processing follows that of the CPATH variable for gcc. 739e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer void AddDelimitedPaths(llvm::StringRef String); 742cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 752cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // AddDefaultCIncludePaths - Add paths that should always be searched. 762cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddDefaultCIncludePaths(const llvm::Triple &triple); 772cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 782cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when 792cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar // compiling c++. 802cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple); 812cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 822cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// AddDefaultSystemIncludePaths - Adds the default system include paths so 832cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// that e.g. stdio.h is found. 842cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void AddDefaultSystemIncludePaths(const LangOptions &Lang, 854c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor const llvm::Triple &triple, 864c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor bool UseStandardCXXIncludes); 872cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 882cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// Realize - Merges all search path lists into one list and send it to 892cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// HeaderSearch. 902cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar void Realize(); 912cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar}; 922cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 932cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar} 940fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 95e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramervoid InitHeaderSearch::AddPath(const llvm::Twine &Path, 96458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer IncludeDirGroup Group, bool isCXXAware, 97458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer bool isUserSupplied, bool isFramework, 98458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer bool IgnoreSysRoot) { 99e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer assert(!Path.isTriviallyEmpty() && "can't handle empty path here"); 1000fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber FileManager &FM = Headers.getFileMgr(); 1011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1020fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Compute the actual path, taking into consideration -isysroot. 103e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::SmallString<256> MappedPathStr; 104e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::raw_svector_ostream MappedPath(MappedPathStr); 1051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1060fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Handle isysroot. 1076858dd3fcc2d3ac6a706a0294be1d3ac51849022Chris Lattner if (Group == System && !IgnoreSysRoot) { 1080fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // FIXME: Portability. This should be a sys::Path interface, this doesn't 1090fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // handle things like C:\ right, nor win32 \\network\device\blah. 1100fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (isysroot.size() != 1 || isysroot[0] != '/') // Add isysroot if present. 111e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer MappedPath << isysroot; 1120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer Path.print(MappedPath); 1150fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1160fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Compute the DirectoryLookup type. 1179d72851fec9e9c62570a027d42701562bbf29751Chris Lattner SrcMgr::CharacteristicKind Type; 1180fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (Group == Quoted || Group == Angled) 1190b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_User; 1200fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else if (isCXXAware) 1210b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_System; 1220fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else 1230b9e736308af5397f558ffc8e780c438c2fdb563Chris Lattner Type = SrcMgr::C_ExternCSystem; 1241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1260fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If the directory exists, add it. 127458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer if (const DirectoryEntry *DE = FM.getDirectory(MappedPath.str())) { 1280fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[Group].push_back(DirectoryLookup(DE, Type, isUserSupplied, 1290fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber isFramework)); 1300fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber return; 1310fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1330fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Check to see if this is an apple-style headermap (which are not allowed to 1340fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // be frameworks). 1350fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (!isFramework) { 136458fb10ef5ba2d7b375c6c64095c1458af0a5be3Benjamin Kramer if (const FileEntry *FE = FM.getFile(MappedPath.str())) { 1370fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) { 1380fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // It is a headermap, add it to the search path. 1390fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[Group].push_back(DirectoryLookup(HM, Type,isUserSupplied)); 1400fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber return; 1410fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1420fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1430fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1450fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (Verbose) 1467765934ad7e157b5fcf925792a38e01b1edbcf8aDaniel Dunbar llvm::errs() << "ignoring nonexistent directory \"" 1477765934ad7e157b5fcf925792a38e01b1edbcf8aDaniel Dunbar << MappedPath.str() << "\"\n"; 1480fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 1490fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1500fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1519e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramervoid InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) { 1529e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer if (at.empty()) // Empty string should not add '.' path. 1530fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber return; 1540fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 1559e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer llvm::StringRef::size_type delim; 1569e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) { 1579e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer if (delim == 0) 1580fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber AddPath(".", Angled, false, true, false); 1590fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else 1609e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer AddPath(at.substr(0, delim), Angled, false, true, false); 1619e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer at = at.substr(delim + 1); 1620fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 1639e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer 1649e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer if (at.empty()) 1650fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber AddPath(".", Angled, false, true, false); 1660fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else 1670fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber AddPath(at, Angled, false, true, false); 1680fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 1690fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 170e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramervoid InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base, 171e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef ArchDir, 172e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef Dir32, 173e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef Dir64, 17431b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola const llvm::Triple &triple) { 1756ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola // Add the base dir 176ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddPath(Base, System, true, false, false); 177ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola 178ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola // Add the multilib dirs 17931b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola llvm::Triple::ArchType arch = triple.getArch(); 18031b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola bool is64bit = arch == llvm::Triple::ppc64 || arch == llvm::Triple::x86_64; 18131b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola if (is64bit) 182ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddPath(Base + "/" + ArchDir + "/" + Dir64, System, true, false, false); 18331b63beefa058aa42a12a1c2b72b43a4ba21f7f1Rafael Espindola else 184ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddPath(Base + "/" + ArchDir + "/" + Dir32, System, true, false, false); 1856ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola 1866ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola // Add the backward dir 1876ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola AddPath(Base + "/backward", System, true, false, false); 1882e9f652d53346bf7e64c8a12a9ff06b004a3e489Rafael Espindola} 1890fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 190e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramervoid InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base, 191e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef Arch, 192e89ba59005479529f5567f12b436617a2ca73ec2Benjamin Kramer llvm::StringRef Version) { 193ab8ae19ea4285a15ca43123e8e218e401dc5cb5aBenjamin Kramer AddPath(Base + "/" + Arch + "/" + Version + "/include", 194ab8ae19ea4285a15ca43123e8e218e401dc5cb5aBenjamin Kramer System, true, false, false); 195ab8ae19ea4285a15ca43123e8e218e401dc5cb5aBenjamin Kramer AddPath(Base + "/" + Arch + "/" + Version + "/include/c++", 196ab8ae19ea4285a15ca43123e8e218e401dc5cb5aBenjamin Kramer System, true, false, false); 197ab8ae19ea4285a15ca43123e8e218e401dc5cb5aBenjamin Kramer AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/backward", 198ab8ae19ea4285a15ca43123e8e218e401dc5cb5aBenjamin Kramer System, true, false, false); 199620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump} 20043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump 201620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // FIXME: This probably should goto to some platform utils place. 202620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#ifdef _MSC_VER 20375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson 204620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // Read registry string. 20575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // This also supports a means to look for high-versioned keys by use 20675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // of a $VERSION placeholder in the key path. 20775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // $VERSION in the key path is a placeholder for the version number, 20875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // causing the highest value path to be searched for and used. 20975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". 21075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // There can be additional characters in the component. Only the numberic 21175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // characters are compared. 2126cd5216bb61e6165d8f6e8fb781d45c035bd4e00Benjamin Kramerstatic bool getSystemRegistryString(const char *keyPath, const char *valueName, 2136cd5216bb61e6165d8f6e8fb781d45c035bd4e00Benjamin Kramer char *value, size_t maxLength) { 21443d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump HKEY hRootKey = NULL; 21543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump HKEY hKey = NULL; 21643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump const char* subKey = NULL; 21743d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump DWORD valueType; 21843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump DWORD valueSize = maxLength - 1; 21975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson long lResult; 22043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump bool returnValue = false; 22143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { 22243d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump hRootKey = HKEY_CLASSES_ROOT; 22343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump subKey = keyPath + 18; 22443d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 22543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { 22643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump hRootKey = HKEY_USERS; 22743d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump subKey = keyPath + 11; 22843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 22943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { 23043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump hRootKey = HKEY_LOCAL_MACHINE; 23143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump subKey = keyPath + 19; 232121e3c207415fb4c105d690de384d8f3d49b0f2dArgyrios Kyrtzidis } 23343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { 23443d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump hRootKey = HKEY_CURRENT_USER; 23543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump subKey = keyPath + 18; 23643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 23743d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump else 23843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump return(false); 23975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson const char *placeHolder = strstr(subKey, "$VERSION"); 24075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char bestName[256]; 24175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson bestName[0] = '\0'; 24275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // If we have a $VERSION placeholder, do the highest-version search. 24375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (placeHolder) { 24475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson const char *keyEnd = placeHolder - 1; 24575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson const char *nextKey = placeHolder; 24675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Find end of previous key. 24775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson while ((keyEnd > subKey) && (*keyEnd != '\\')) 24875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson keyEnd--; 24975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Find end of key containing $VERSION. 25075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson while (*nextKey && (*nextKey != '\\')) 25175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson nextKey++; 25275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson size_t partialKeyLength = keyEnd - subKey; 25375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char partialKey[256]; 25475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (partialKeyLength > sizeof(partialKey)) 25575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson partialKeyLength = sizeof(partialKey); 25675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson strncpy(partialKey, subKey, partialKeyLength); 25775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson partialKey[partialKeyLength] = '\0'; 25875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson HKEY hTopKey = NULL; 25975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ, &hTopKey); 26075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) { 26175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char keyName[256]; 26275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson int bestIndex = -1; 26375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson double bestValue = 0.0; 26475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson DWORD index, size = sizeof(keyName) - 1; 26533cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, 26633cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes NULL, NULL, NULL) == ERROR_SUCCESS; index++) { 26733cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes const char *sp = keyName; 26833cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes while (*sp && !isdigit(*sp)) 26933cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes sp++; 27033cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes if (!*sp) 27133cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes continue; 27233cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes const char *ep = sp + 1; 27333cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes while (*ep && (isdigit(*ep) || (*ep == '.'))) 27433cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes ep++; 27533cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes char numBuf[32]; 27633cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes strncpy(numBuf, sp, sizeof(numBuf) - 1); 27733cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes numBuf[sizeof(numBuf) - 1] = '\0'; 27833cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes double value = strtod(numBuf, NULL); 27933cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes if (value > bestValue) { 28033cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes bestIndex = (int)index; 28133cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes bestValue = value; 28233cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes strcpy(bestName, keyName); 28333cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes } 28475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson size = sizeof(keyName) - 1; 28575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 28675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // If we found the highest versioned key, open the key and get the value. 28775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (bestIndex != -1) { 28875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Append rest of key. 28975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson strncat(bestName, nextKey, sizeof(bestName) - 1); 29075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson bestName[sizeof(bestName) - 1] = '\0'; 29175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Open the chosen key path remainder. 29275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegOpenKeyEx(hTopKey, bestName, 0, KEY_READ, &hKey); 29375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) { 29475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, 29575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson (LPBYTE)value, &valueSize); 29675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) 29775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson returnValue = true; 29875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson RegCloseKey(hKey); 29975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 30075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 30175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson RegCloseKey(hTopKey); 30275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 30375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 30475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson else { 30575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); 30675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) { 30775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, 30875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson (LPBYTE)value, &valueSize); 30975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (lResult == ERROR_SUCCESS) 31075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson returnValue = true; 31175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson RegCloseKey(hKey); 31275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 31343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 31443d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump return(returnValue); 31543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump} 316620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#else // _MSC_VER 317620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // Read registry string. 3186cd5216bb61e6165d8f6e8fb781d45c035bd4e00Benjamin Kramerstatic bool getSystemRegistryString(const char*, const char*, char*, size_t) { 319620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(false); 320620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump} 321620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump#endif // _MSC_VER 322121e3c207415fb4c105d690de384d8f3d49b0f2dArgyrios Kyrtzidis 32343d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump // Get Visual Studio installation directory. 3246cd5216bb61e6165d8f6e8fb781d45c035bd4e00Benjamin Kramerstatic bool getVisualStudioDir(std::string &path) { 32575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char vsIDEInstallDir[256]; 326620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // Try the Windows registry first. 32775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson bool hasVCDir = getSystemRegistryString( 32875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", 32975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1); 33043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump // If we have both vc80 and vc90, pick version we were compiled with. 33175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (hasVCDir && vsIDEInstallDir[0]) { 332620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); 333620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (p) 334620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump *p = '\0'; 335620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump path = vsIDEInstallDir; 336620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(true); 33743d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 338620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump else { 339620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // Try the environment. 340620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump const char* vs90comntools = getenv("VS90COMNTOOLS"); 341620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump const char* vs80comntools = getenv("VS80COMNTOOLS"); 342620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump const char* vscomntools = NULL; 343620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump // If we have both vc80 and vc90, pick version we were compiled with. 344620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (vs90comntools && vs80comntools) { 345620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #if (_MSC_VER >= 1500) // VC90 346620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs90comntools; 347620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #elif (_MSC_VER == 1400) // VC80 348620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs80comntools; 349620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #else 350620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs90comntools; 351620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump #endif 352620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump } 353620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump else if (vs90comntools) 354620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs90comntools; 355620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump else if (vs80comntools) 356620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump vscomntools = vs80comntools; 357620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (vscomntools && *vscomntools) { 358620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump char *p = (char*)strstr(vscomntools, "\\Common7\\Tools"); 359620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (p) 360620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump *p = '\0'; 361620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump path = vscomntools; 362620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(true); 363620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump } 364620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump else 365620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(false); 366620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump } 367620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump return(false); 36843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump} 3694d374d4a4832a01d5d3b75c59cb1567e60df41e7Sebastian Redl 37075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Get Windows SDK installation directory. 3716cd5216bb61e6165d8f6e8fb781d45c035bd4e00Benjamin Kramerstatic bool getWindowsSDKDir(std::string &path) { 37275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson char windowsSDKInstallDir[256]; 37375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // Try the Windows registry. 37475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson bool hasSDKDir = getSystemRegistryString( 37575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", 37675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson "InstallationFolder", windowsSDKInstallDir, sizeof(windowsSDKInstallDir) - 1); 37775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson // If we have both vc80 and vc90, pick version we were compiled with. 37875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (hasSDKDir && windowsSDKInstallDir[0]) { 37975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson path = windowsSDKInstallDir; 38075ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson return(true); 38175ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson } 38275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson return(false); 38375ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson} 38475ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson 385e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindolavoid InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple) { 38643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump // FIXME: temporary hack: hard-coded paths. 387c706468b1e00bab49ca92eb500a39657f530f828Daniel Dunbar llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS); 388c706468b1e00bab49ca92eb500a39657f530f828Daniel Dunbar if (CIncludeDirs != "") { 389aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola llvm::SmallVector<llvm::StringRef, 5> dirs; 390aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola CIncludeDirs.split(dirs, ":"); 391aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin(); 392aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola i != dirs.end(); 393aadd7a48453b4f58bd8e1e9eb670918ee7d6a711Rafael Espindola ++i) 394f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola AddPath(*i, System, false, false, false); 395f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola return; 396f0a2f51be576089e1a84cd677c09156dae067b6aRafael Espindola } 39743d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump llvm::Triple::OSType os = triple.getOS(); 39843d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump switch (os) { 39943d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump case llvm::Triple::Win32: 40043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump { 401620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump std::string VSDir; 40275ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson std::string WindowsSDKDir; 403620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump if (getVisualStudioDir(VSDir)) { 404620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump AddPath(VSDir + "\\VC\\include", System, false, false, false); 40575ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson if (getWindowsSDKDir(WindowsSDKDir)) 40675ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson AddPath(WindowsSDKDir, System, false, false, false); 40775ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson else 40875ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson AddPath(VSDir + "\\VC\\PlatformSDK\\Include", 40975ee3bd6e7ed2b4286d5e717ae7b94411f90b3b9John Thompson System, false, false, false); 410620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump } 4119319f02dea2449caf5c7a0d07c596ca324e43574John Thompson else { 4129319f02dea2449caf5c7a0d07c596ca324e43574John Thompson // Default install paths. 4139319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath("C:/Program Files/Microsoft Visual Studio 9.0/VC/include", 4149319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4159319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath( 4169319f02dea2449caf5c7a0d07c596ca324e43574John Thompson "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", 4179319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4189319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath("C:/Program Files/Microsoft Visual Studio 8/VC/include", 4199319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4209319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath( 4219319f02dea2449caf5c7a0d07c596ca324e43574John Thompson "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include", 4229319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4239319f02dea2449caf5c7a0d07c596ca324e43574John Thompson // For some clang developers. 4249319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath("G:/Program Files/Microsoft Visual Studio 9.0/VC/include", 4259319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4269319f02dea2449caf5c7a0d07c596ca324e43574John Thompson AddPath( 4279319f02dea2449caf5c7a0d07c596ca324e43574John Thompson "G:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", 4289319f02dea2449caf5c7a0d07c596ca324e43574John Thompson System, false, false, false); 4299319f02dea2449caf5c7a0d07c596ca324e43574John Thompson } 43043d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump } 43143d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump break; 43243d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump case llvm::Triple::MinGW64: 433620d57a293143e3f07d6e4f5ba50020a80f45564Mike Stump case llvm::Triple::MinGW32: 43443d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump AddPath("c:/mingw/include", System, true, false, false); 43543d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump break; 43643d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump default: 43743d8176d2e8e304b2d419fb0fe139cc07af80deaMike Stump break; 4380fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 439d3f88343af2dec3459493fafa22532317321eaf0John Thompson 440fc904d5b8bfa8fccca0ead0051e3f9e4374f6e7aChris Lattner AddPath("/usr/local/include", System, true, false, false); 441d3f88343af2dec3459493fafa22532317321eaf0John Thompson AddPath("/usr/include", System, false, false, false); 442e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 443e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 444e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindolavoid InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) { 445e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola llvm::Triple::OSType os = triple.getOS(); 446ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT); 447ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola if (CxxIncludeRoot != "") { 448ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH); 449ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola if (CxxIncludeArch == "") 450ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(), 451ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple); 452ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola else 453ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, CXX_INCLUDE_ARCH, 454ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR, triple); 455ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola return; 456ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola } 457e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // FIXME: temporary hack: hard-coded paths. 458e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola switch (os) { 459e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Cygwin: 460e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include", 461e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola System, true, false, false); 462e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++", 463e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola System, true, false, false); 464e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 465e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::MinGW64: 466e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Try gcc 4.4.0 467e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.4.0"); 468e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Try gcc 4.3.0 469e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw64", "4.3.0"); 470e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Fall through. 471e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::MinGW32: 472e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Try gcc 4.4.0 473e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0"); 474e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Try gcc 4.3.0 475e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0"); 476e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 477e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Darwin: 478e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", 479ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-apple-darwin10", "", "x86_64", triple); 480e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", 481ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-apple-darwin8", "", "", triple); 482e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 4837a7ca281bcf50b34de1ce067d3c55879b81722aeChris Lattner case llvm::Triple::DragonFly: 4847a7ca281bcf50b34de1ce067d3c55879b81722aeChris Lattner AddPath("/usr/include/c++/4.1", System, true, false, false); 4857a7ca281bcf50b34de1ce067d3c55879b81722aeChris Lattner break; 486e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Linux: 4870db3d725ece8c0796905843d5392c8667d3706c1Benjamin Kramer // Exherbo (2010-01-25) 4880db3d725ece8c0796905843d5392c8667d3706c1Benjamin Kramer AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", 489fc4b899563f70b2b1fc45948ebf7451f16ccfc09Torok Edwin "x86_64-pc-linux-gnu", "32", "", triple); 4900db3d725ece8c0796905843d5392c8667d3706c1Benjamin Kramer AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", 491fc4b899563f70b2b1fc45948ebf7451f16ccfc09Torok Edwin "i686-pc-linux-gnu", "", "", triple); 492331e8010aed1c2175328ed470aea75e93ff70b32Torok Edwin // Debian sid 493e69f047a6c882ce36bd260a8fed0ae31114a5a7eNick Lewycky AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 494331e8010aed1c2175328ed470aea75e93ff70b32Torok Edwin "x86_64-linux-gnu", "32", "", triple); 495e69f047a6c882ce36bd260a8fed0ae31114a5a7eNick Lewycky AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 496e69f047a6c882ce36bd260a8fed0ae31114a5a7eNick Lewycky "i486-linux-gnu", "64", "", triple); 497e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Ubuntu 7.10 - Gutsy Gibbon 498e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3", 499ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i486-linux-gnu", "", "", triple); 500e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Ubuntu 9.04 501e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3", 502ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-linux-gnu","32", "", triple); 5035114ecab149ab91d13d3f7fd165dbe0839c1f2e8Sebastian Redl // Ubuntu 9.10 5045114ecab149ab91d13d3f7fd165dbe0839c1f2e8Sebastian Redl AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", 505ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-linux-gnu", "32", "", triple); 506e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Fedora 8 507e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", 508ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-redhat-linux", "", "", triple); 509e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Fedora 9 510e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", 511ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-redhat-linux", "", "", triple); 512e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Fedora 10 513e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", 514ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-redhat-linux","", "", triple); 515189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes 5160720b5159010479c08f8264a8a209037ecf55922Chris Lattner // Fedora 10 x86_64 5170720b5159010479c08f8264a8a209037ecf55922Chris Lattner AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", 5180720b5159010479c08f8264a8a209037ecf55922Chris Lattner "x86_64-redhat-linux", "32", "", triple); 5190720b5159010479c08f8264a8a209037ecf55922Chris Lattner 520189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes // Fedora 11 521189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.1", 522189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes "i586-redhat-linux","", "", triple); 523189a14869a36ecf8bd5edc94255a34061044efe2Nuno Lopes 52433cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes // Fedora 12 52533cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.2", 52633cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes "i686-redhat-linux","", "", triple); 52733cc2437ae3a609cdc44179931a2909eb48a8200Nuno Lopes 5280edeca592f71e520d00dc09e74b829e8f7805d0bChris Lattner // Fedora 12 (February-2010+) 5290edeca592f71e520d00dc09e74b829e8f7805d0bChris Lattner AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4.3", 5300edeca592f71e520d00dc09e74b829e8f7805d0bChris Lattner "i686-redhat-linux","", "", triple); 5310edeca592f71e520d00dc09e74b829e8f7805d0bChris Lattner 532e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // openSUSE 11.1 32 bit 533e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 534ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i586-suse-linux", "", "", triple); 535e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // openSUSE 11.1 64 bit 536e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 537ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-suse-linux", "32", "", triple); 538e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // openSUSE 11.2 539e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 540ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i586-suse-linux", "", "", triple); 541e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", 542ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-suse-linux", "", "", triple); 543e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Arch Linux 2008-06-24 544e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", 545ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 546e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", 547ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "x86_64-unknown-linux-gnu", "", "", triple); 548e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Gentoo x86 2009.1 stable 549e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths( 55040d1bb6383c14d5f8249d0640e8088a91b694c66John Thompson "/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4", 551ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 552e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Gentoo x86 2009.0 stable 553e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths( 55440d1bb6383c14d5f8249d0640e8088a91b694c66John Thompson "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", 555ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 556e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Gentoo x86 2008.0 stable 557e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths( 55840d1bb6383c14d5f8249d0640e8088a91b694c66John Thompson "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", 559ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 560e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Ubuntu 8.10 561e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 562ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i486-pc-linux-gnu", "", "", triple); 563e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Ubuntu 9.04 564e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", 565ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i486-linux-gnu","", "", triple); 566e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Gentoo amd64 stable 567e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths( 568e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", 569ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i686-pc-linux-gnu", "", "", triple); 57070d9d4196e6531926ca18b2ca850eb218041488dEric Christopher 57170d9d4196e6531926ca18b2ca850eb218041488dEric Christopher // Gentoo amd64 gcc 4.3.2 57270d9d4196e6531926ca18b2ca850eb218041488dEric Christopher AddGnuCPlusPlusIncludePaths( 57370d9d4196e6531926ca18b2ca850eb218041488dEric Christopher "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4", 57470d9d4196e6531926ca18b2ca850eb218041488dEric Christopher "x86_64-pc-linux-gnu", "", "", triple); 57570d9d4196e6531926ca18b2ca850eb218041488dEric Christopher 57670d9d4196e6531926ca18b2ca850eb218041488dEric Christopher // Gentoo amd64 gcc 4.4.3 57770d9d4196e6531926ca18b2ca850eb218041488dEric Christopher AddGnuCPlusPlusIncludePaths( 57870d9d4196e6531926ca18b2ca850eb218041488dEric Christopher "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4", 57970d9d4196e6531926ca18b2ca850eb218041488dEric Christopher "x86_64-pc-linux-gnu", "32", "", triple); 58070d9d4196e6531926ca18b2ca850eb218041488dEric Christopher 581e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 582e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::FreeBSD: 583afe859a9a6217f177daf42ebab294a90bfe8a6abNuno Lopes AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2", "", "", "", triple); 584e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 585e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::Solaris: 586e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // Solaris - Fall though.. 587e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola case llvm::Triple::AuroraUX: 588e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola // AuroraUX 589e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddGnuCPlusPlusIncludePaths("/opt/gcc4/include/c++/4.2.4", 590ab7ae95c46f288ac52974aa60334a9575f9a850cRafael Espindola "i386-pc-solaris2.11", "", "", triple); 591e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 592e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola default: 593e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola break; 594e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola } 595e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 596e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 597e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindolavoid InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, 5984c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor const llvm::Triple &triple, 5994c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor bool UseStandardCXXIncludes) { 6004c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor if (Lang.CPlusPlus && UseStandardCXXIncludes) 6016ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola AddDefaultCPlusPlusIncludePaths(triple); 6026ec18a3f86c702004af66cce6ff979999a736898Rafael Espindola 603e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola AddDefaultCIncludePaths(triple); 604e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar 605e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar // Add the default framework include paths on Darwin. 606e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar if (triple.getOS() == llvm::Triple::Darwin) { 607e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar AddPath("/System/Library/Frameworks", System, true, false, true); 608e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar AddPath("/Library/Frameworks", System, true, false, true); 609e166582f8f36f4db8f4ea157538fab7fe6bf2658Daniel Dunbar } 610e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola} 611e4b255c80a786c6f16d3f0362ecb7e1b1e959f63Rafael Espindola 6120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber/// RemoveDuplicates - If there are duplicate directory entries in the specified 6130fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber/// search list, remove the later (dead) ones. 6140fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weberstatic void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList, 6150fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber bool Verbose) { 6160fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs; 6170fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs; 6180fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps; 6190fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber for (unsigned i = 0; i != SearchList.size(); ++i) { 6207a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner unsigned DirToRemove = i; 6211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62243eee07270bf1966ea7289310066aa670c4b647fChris Lattner const DirectoryLookup &CurEntry = SearchList[i]; 6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62443eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.isNormalDir()) { 6250fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this dir, remove it. 62643eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenDirs.insert(CurEntry.getDir())) 6270fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 62843eee07270bf1966ea7289310066aa670c4b647fChris Lattner } else if (CurEntry.isFramework()) { 6290fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this framework dir, remove it. 63043eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenFrameworkDirs.insert(CurEntry.getFrameworkDir())) 6310fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 6320fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } else { 63343eee07270bf1966ea7289310066aa670c4b647fChris Lattner assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 6340fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If this isn't the first time we've seen this headermap, remove it. 63543eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SeenHeaderMaps.insert(CurEntry.getHeaderMap())) 6360fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber continue; 63730f05b553db067c994966daca37e75324ee7b424Chris Lattner } 6381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63930f05b553db067c994966daca37e75324ee7b424Chris Lattner // If we have a normal #include dir/framework/headermap that is shadowed 64030f05b553db067c994966daca37e75324ee7b424Chris Lattner // later in the chain by a system include location, we actually want to 64130f05b553db067c994966daca37e75324ee7b424Chris Lattner // ignore the user's request and drop the user dir... keeping the system 64230f05b553db067c994966daca37e75324ee7b424Chris Lattner // dir. This is weird, but required to emulate GCC's search path correctly. 64330f05b553db067c994966daca37e75324ee7b424Chris Lattner // 64430f05b553db067c994966daca37e75324ee7b424Chris Lattner // Since dupes of system dirs are rare, just rescan to find the original 64530f05b553db067c994966daca37e75324ee7b424Chris Lattner // that we're nuking instead of using a DenseMap. 64643eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) { 64730f05b553db067c994966daca37e75324ee7b424Chris Lattner // Find the dir that this is the same of. 64830f05b553db067c994966daca37e75324ee7b424Chris Lattner unsigned FirstDir; 64930f05b553db067c994966daca37e75324ee7b424Chris Lattner for (FirstDir = 0; ; ++FirstDir) { 65030f05b553db067c994966daca37e75324ee7b424Chris Lattner assert(FirstDir != i && "Didn't find dupe?"); 6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65243eee07270bf1966ea7289310066aa670c4b647fChris Lattner const DirectoryLookup &SearchEntry = SearchList[FirstDir]; 65343eee07270bf1966ea7289310066aa670c4b647fChris Lattner 65430f05b553db067c994966daca37e75324ee7b424Chris Lattner // If these are different lookup types, then they can't be the dupe. 65543eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (SearchEntry.getLookupType() != CurEntry.getLookupType()) 65630f05b553db067c994966daca37e75324ee7b424Chris Lattner continue; 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65830f05b553db067c994966daca37e75324ee7b424Chris Lattner bool isSame; 65943eee07270bf1966ea7289310066aa670c4b647fChris Lattner if (CurEntry.isNormalDir()) 66043eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getDir() == CurEntry.getDir(); 66143eee07270bf1966ea7289310066aa670c4b647fChris Lattner else if (CurEntry.isFramework()) 66243eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getFrameworkDir() == CurEntry.getFrameworkDir(); 66330f05b553db067c994966daca37e75324ee7b424Chris Lattner else { 66443eee07270bf1966ea7289310066aa670c4b647fChris Lattner assert(CurEntry.isHeaderMap() && "Not a headermap or normal dir?"); 66543eee07270bf1966ea7289310066aa670c4b647fChris Lattner isSame = SearchEntry.getHeaderMap() == CurEntry.getHeaderMap(); 66630f05b553db067c994966daca37e75324ee7b424Chris Lattner } 6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66830f05b553db067c994966daca37e75324ee7b424Chris Lattner if (isSame) 66930f05b553db067c994966daca37e75324ee7b424Chris Lattner break; 67030f05b553db067c994966daca37e75324ee7b424Chris Lattner } 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67230f05b553db067c994966daca37e75324ee7b424Chris Lattner // If the first dir in the search path is a non-system dir, zap it 67330f05b553db067c994966daca37e75324ee7b424Chris Lattner // instead of the system one. 67430f05b553db067c994966daca37e75324ee7b424Chris Lattner if (SearchList[FirstDir].getDirCharacteristic() == SrcMgr::C_User) 67530f05b553db067c994966daca37e75324ee7b424Chris Lattner DirToRemove = FirstDir; 67630f05b553db067c994966daca37e75324ee7b424Chris Lattner } 67730f05b553db067c994966daca37e75324ee7b424Chris Lattner 67830f05b553db067c994966daca37e75324ee7b424Chris Lattner if (Verbose) { 679e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "ignoring duplicate directory \"" 680e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar << CurEntry.getName() << "\"\n"; 68130f05b553db067c994966daca37e75324ee7b424Chris Lattner if (DirToRemove != i) 682e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << " as it is a non-system directory that duplicates " 683e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar << "a system directory\n"; 6840fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 6851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6867a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner // This is reached if the current entry is a duplicate. Remove the 6877a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner // DirToRemove (usually the current dir). 6887a739401983eb9bc25c9b4b25177e116f5e5ba92Chris Lattner SearchList.erase(SearchList.begin()+DirToRemove); 6890fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber --i; 6900fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 6910fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 6920fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 6930fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 6940fca022d77b89100e746f4d659b84ed5b1ee0158Nico Webervoid InitHeaderSearch::Realize() { 6950fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList. 6960fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber std::vector<DirectoryLookup> SearchList; 6970fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber SearchList = IncludeGroup[Angled]; 6980fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber SearchList.insert(SearchList.end(), IncludeGroup[System].begin(), 6990fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[System].end()); 7000fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber SearchList.insert(SearchList.end(), IncludeGroup[After].begin(), 7010fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[After].end()); 7020fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber RemoveDuplicates(SearchList, Verbose); 7030fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber RemoveDuplicates(IncludeGroup[Quoted], Verbose); 7041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7050fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // Prepend QUOTED list on the search list. 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SearchList.insert(SearchList.begin(), IncludeGroup[Quoted].begin(), 7070fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber IncludeGroup[Quoted].end()); 7081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7090fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 7100fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber bool DontSearchCurDir = false; // TODO: set to true if -I- is set? 7110fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Headers.SetSearchPaths(SearchList, IncludeGroup[Quoted].size(), 7120fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber DontSearchCurDir); 7130fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber 7140fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber // If verbose, print the list of directories that will be searched. 7150fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (Verbose) { 716e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "#include \"...\" search starts here:\n"; 7170fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber unsigned QuotedIdx = IncludeGroup[Quoted].size(); 7180fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber for (unsigned i = 0, e = SearchList.size(); i != e; ++i) { 7190fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (i == QuotedIdx) 720e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "#include <...> search starts here:\n"; 7210fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber const char *Name = SearchList[i].getName(); 7220fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber const char *Suffix; 7230fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber if (SearchList[i].isNormalDir()) 7240fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = ""; 7250fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else if (SearchList[i].isFramework()) 7260fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = " (framework directory)"; 7270fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber else { 7280fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber assert(SearchList[i].isHeaderMap() && "Unknown DirectoryLookup"); 7290fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber Suffix = " (headermap)"; 7300fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 731e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << " " << Name << Suffix << "\n"; 7320fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 733e7cb7e4570842297f698bd7fd8d85520fc008acdDaniel Dunbar llvm::errs() << "End of search list.\n"; 7340fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber } 7350fca022d77b89100e746f4d659b84ed5b1ee0158Nico Weber} 73663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 7375814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbarvoid clang::ApplyHeaderSearchOptions(HeaderSearch &HS, 7385814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbar const HeaderSearchOptions &HSOpts, 7395814e657c9ad9ef6049a2a4af0d2aad248a8a15cDaniel Dunbar const LangOptions &Lang, 74063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar const llvm::Triple &Triple) { 74163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); 74263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 74363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // Add the user defined entries. 74463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar for (unsigned i = 0, e = HSOpts.UserEntries.size(); i != e; ++i) { 74563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar const HeaderSearchOptions::Entry &E = HSOpts.UserEntries[i]; 7461b483e70ad3f670f6dd0bc62dbe0921a28195f24Daniel Dunbar Init.AddPath(E.Path, E.Group, false, E.IsUserSupplied, E.IsFramework, 7471b483e70ad3f670f6dd0bc62dbe0921a28195f24Daniel Dunbar false); 74863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar } 74963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 75063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // Add entries from CPATH and friends. 7519e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer Init.AddDelimitedPaths(HSOpts.EnvIncPath); 752c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar if (Lang.CPlusPlus && Lang.ObjC1) 7539e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath); 754c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar else if (Lang.CPlusPlus) 7559e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath); 756c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar else if (Lang.ObjC1) 7579e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath); 758c363cb1929c7908c8c8c4b77d025c2ccb09284aeDaniel Dunbar else 7599e9ddf6100fd50ca2f9f9d0106b856e20b43300fBenjamin Kramer Init.AddDelimitedPaths(HSOpts.CEnvIncPath); 76063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 7611e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar if (HSOpts.UseBuiltinIncludes) { 76263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // Ignore the sys root, we *always* look for clang headers relative to 76363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar // supplied path. 7648b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar llvm::sys::Path P(HSOpts.ResourceDir); 7658b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar P.appendComponent("include"); 7668b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar Init.AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true); 76763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar } 76863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 769dd35ce9a783dea7e6660f9cb1d973742f3b3c73fDaniel Dunbar if (HSOpts.UseStandardIncludes) 7704c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor Init.AddDefaultSystemIncludePaths(Lang, Triple, 7714c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor HSOpts.UseStandardCXXIncludes); 77263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 77363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar Init.Realize(); 77463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar} 775