diff options
author | Mike Stump <mrs@apple.com> | 2009-10-08 23:29:47 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2009-10-08 23:29:47 +0000 |
commit | 43d8176d2e8e304b2d419fb0fe139cc07af80dea (patch) | |
tree | 3f7b30a5b649d744f2efc93c01cec29407e2fdad /lib/Frontend/InitHeaderSearch.cpp | |
parent | 76bee4b756badefda61ce867c757cc31b7afa12f (diff) |
Set up include paths for VC++ and Cygwin headers, along with the
existing MinGW headers, plus the newer 4.4.0 version. Patch by John
Thompson.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83594 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/InitHeaderSearch.cpp')
-rw-r--r-- | lib/Frontend/InitHeaderSearch.cpp | 329 |
1 files changed, 249 insertions, 80 deletions
diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp index b56e3a8a98..05855cf65e 100644 --- a/lib/Frontend/InitHeaderSearch.cpp +++ b/lib/Frontend/InitHeaderSearch.cpp @@ -99,100 +99,269 @@ void InitHeaderSearch::AddEnvVarPaths(const char *Name) { } void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(std::string base, - std::string arch) { + std::string arch) { AddPath(base, System, true, false, false); AddPath(base + "/" + arch, System, true, false, false); AddPath(base + "/backward", System, true, false, false); } -void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang) { - // FIXME: temporary hack: hard-coded paths. - // FIXME: get these from the target? - -#ifdef LLVM_ON_WIN32 - if (Lang.CPlusPlus) { - // Mingw32 GCC version 4 - AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++", - System, true, false, false); - AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/mingw32", - System, true, false, false); - AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/backward", - System, true, false, false); +#if defined(LLVM_ON_WIN32) + +#if 0 // Yikes! Can't include windows.h. + #if LLVM_ON_WIN32 + #define WIN32_LEAN_AND_MEAN 1 + #include <windows.h> + #endif + + // Read Windows registry string. +bool getWindowsRegistryString(const char *keyPath, const char *valueName, + char *value, size_t maxLength) { + HKEY hRootKey = NULL; + HKEY hKey = NULL; + const char* subKey = NULL; + DWORD valueType; + DWORD valueSize = maxLength - 1; + bool returnValue = false; + if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { + hRootKey = HKEY_CLASSES_ROOT; + subKey = keyPath + 18; + } + else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { + hRootKey = HKEY_USERS; + subKey = keyPath + 11; + } + else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { + hRootKey = HKEY_LOCAL_MACHINE; + subKey = keyPath + 19; + } + else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { + hRootKey = HKEY_CURRENT_USER; + subKey = keyPath + 18; + } + else + return(false); + long lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ, &hKey); + if (lResult == ERROR_SUCCESS) { + lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, (LPBYTE)value, + &valueSize); + if (lResult == ERROR_SUCCESS) + returnValue = true; + RegCloseKey(kKey); } + return(returnValue); +} - // Mingw32 GCC version 4 - AddPath("C:/mingw/include", System, false, false, false); + // Get Visual Studio installation directory. +bool getVisualStudioDir(std::string &path) { + char vs80comntools[256]; + char vs90comntools[256]; + const char* vscomntools = NULL; + bool has80 = getWindowsRegistryString( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0", + "InstallDir", vs80comntools, sizeof(vs80comntools) - 1); + bool has90 = getWindowsRegistryString( + "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0", + "InstallDir", vs90comntools, sizeof(vs90comntools) - 1); + // If we have both vc80 and vc90, pick version we were compiled with. + if (has80 && has90) { + #ifdef _MSC_VER + #if (_MSC_VER >= 1500) // VC90 + vscomntools = vs90comntools; + #elif (_MSC_VER == 1400) // VC80 + vscomntools = vs80comntools; + #else + vscomntools = vs90comntools; + #endif + #else + vscomntools = vs90comntools; + #endif + } + else if (has90) + vscomntools = vs90comntools; + else if (has80) + vscomntools = vs80comntools; + else + return(false); + char *p = strstr(vscomntools, "\\Common7\\ide"); + if (p) + *p = '\0'; + path = vscomntools; + return(true); +} #else - if (Lang.CPlusPlus) { - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", - "i686-apple-darwin10"); - - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", "i686-apple-darwin8"); - - // Ubuntu 7.10 - Gutsy Gibbon - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3", "i486-linux-gnu"); - - // Ubuntu 9.04 - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3", "x86_64-linux-gnu"); - - // Fedora 8 - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", "i386-redhat-linux"); - - // Fedora 9 - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", "i386-redhat-linux"); - - // Fedora 10 - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", "i386-redhat-linux"); - - // openSUSE 11.1 - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", "i586-suse-linux"); - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", "x86_64-suse-linux"); - - // openSUSE 11.2 - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", "i586-suse-linux"); - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", "x86_64-suse-linux"); - - // Arch Linux 2008-06-24 - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", "i686-pc-linux-gnu"); - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", - "x86_64-unknown-linux-gnu"); - - // Gentoo x86 2009.0 stable - AddGnuCPlusPlusIncludePaths( - "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", - "i686-pc-linux-gnu"); - - // Gentoo x86 2008.0 stable - AddGnuCPlusPlusIncludePaths( - "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", - "i686-pc-linux-gnu"); - - // Ubuntu 8.10 - AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", "i486-pc-linux-gnu"); + // Get Visual Studio installation directory. +bool getVisualStudioDir(std::string &path) { + const char* vs90comntools = getenv("VS90COMNTOOLS"); + const char* vs80comntools = getenv("VS80COMNTOOLS"); + const char* vscomntools = NULL; + // If we have both vc80 and vc90, pick version we were compiled with. + if (vs90comntools && vs80comntools) { + #if (_MSC_VER >= 1500) // VC90 + vscomntools = vs90comntools; + #elif (_MSC_VER == 1400) // VC80 + vscomntools = vs80comntools; + #else + vscomntools = vs90comntools; + #endif + } + else if (vs90comntools) + vscomntools = vs90comntools; + else if (vs80comntools) + vscomntools = vs80comntools; + else + return(false); + char *p = (char*)strstr(vscomntools, "\\Common7\\Tools"); + if (p) + *p = '\0'; + path = vscomntools; + return(true); +} +#endif - // Gentoo amd64 stable - AddGnuCPlusPlusIncludePaths( - "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", - "i686-pc-linux-gnu"); +#endif // LLVM_ON_WIN32 - // DragonFly - AddPath("/usr/include/c++/4.1", System, true, false, false); +void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang, + llvm::Triple &triple) { + // FIXME: temporary hack: hard-coded paths. + llvm::Triple::OSType os = triple.getOS(); + + switch (os) { + case llvm::Triple::Win32: + { + #if defined(_MSC_VER) + std::string VSDir; + if (getVisualStudioDir(VSDir)) { + VSDir += "\\VC\\include"; + AddPath(VSDir, System, false, false, false); + } + else { + // Default install paths. + AddPath("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\include", + System, false, false, false); + AddPath("C:\\Program Files\\Microsoft Visual Studio 8\\VC\\include", + System, false, false, false); + // For some clang developers. + AddPath("G:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\include", + System, false, false, false); + } + #else + // Default install paths. + AddPath("/Program Files/Microsoft Visual Studio 9.0/VC/include", + System, false, false, false); + AddPath("/Program Files/Microsoft Visual Studio 8/VC/include", + System, false, false, false); + #endif + } + break; + case llvm::Triple::Cygwin: + if (Lang.CPlusPlus) { + AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include", System, false, false, + false); + AddPath("/lib/gcc/i686-pc-cygwin/3.4.4/include/c++", System, false, false, + false); + } + AddPath("/usr/include", System, false, false, false); + break; + case llvm::Triple::MinGW32: + case llvm::Triple::MinGW64: + if (Lang.CPlusPlus) { + // Try gcc 4.4.0 + AddPath("c:/mingw/lib/gcc/mingw32/4.4.0/include/c++", + System, true, false, false); + AddPath("c:/mingw/lib/gcc/mingw32/4.4.0/include/c++/mingw32", + System, true, false, false); + AddPath("c:/mingw/lib/gcc/mingw32/4.4.0/include/c++/backward", + System, true, false, false); + // Try gcc 4.3.0 + AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++", + System, true, false, false); + AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/mingw32", + System, true, false, false); + AddPath("c:/mingw/lib/gcc/mingw32/4.3.0/include/c++/backward", + System, true, false, false); + } + AddPath("c:/mingw/include", System, true, false, false); + break; + default: + if (Lang.CPlusPlus) { + switch (os) { + case llvm::Triple::Darwin: + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1", + "i686-apple-darwin10"); + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0", + "i686-apple-darwin8"); + break; + case llvm::Triple::Linux: + // Ubuntu 7.10 - Gutsy Gibbon + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.3", + "i486-linux-gnu"); + // Ubuntu 9.04 + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.3", + "x86_64-linux-gnu"); + // Fedora 8 + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.1.2", + "i386-redhat-linux"); + // Fedora 9 + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.0", + "i386-redhat-linux"); + // Fedora 10 + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.2", + "i386-redhat-linux"); + // openSUSE 11.1 + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", + "i586-suse-linux"); + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", + "x86_64-suse-linux"); + // openSUSE 11.2 + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", + "i586-suse-linux"); + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.4", + "x86_64-suse-linux"); + // Arch Linux 2008-06-24 + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", + "i686-pc-linux-gnu"); + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3.1", + "x86_64-unknown-linux-gnu"); + // Gentoo x86 2009.0 stable + AddGnuCPlusPlusIncludePaths( + "/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4", + "i686-pc-linux-gnu"); + // Gentoo x86 2008.0 stable + AddGnuCPlusPlusIncludePaths( + "/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4", + "i686-pc-linux-gnu"); + // Ubuntu 8.10 + AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", + "i486-pc-linux-gnu"); + // Gentoo amd64 stable + AddGnuCPlusPlusIncludePaths( + "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4", + "i686-pc-linux-gnu"); + break; + case llvm::Triple::FreeBSD: + // DragonFly + AddPath("/usr/include/c++/4.1", System, true, false, false); + // FreeBSD + AddPath("/usr/include/c++/4.2", System, true, false, false); + break; + case llvm::Triple::Solaris: + // AuroraUX + AddGnuCPlusPlusIncludePaths("/Opt/gcc4/include/c++/4.2.4", + "i386-pc-solaris2.11"); + break; + default: + break; + } + } - // FreeBSD - AddPath("/usr/include/c++/4.2", System, true, false, false); + AddPath("/usr/local/include", System, false, false, false); - // AuroraUX - AddGnuCPlusPlusIncludePaths("/Opt/gcc4/include/c++/4.2.4", - "i386-pc-solaris2.11"); + AddPath("/usr/include", System, false, false, false); + AddPath("/System/Library/Frameworks", System, true, false, true); + AddPath("/Library/Frameworks", System, true, false, true); + break; } - - AddPath("/usr/local/include", System, false, false, false); - - AddPath("/usr/include", System, false, false, false); - AddPath("/System/Library/Frameworks", System, true, false, true); - AddPath("/Library/Frameworks", System, true, false, true); -#endif } void InitHeaderSearch::AddDefaultEnvVarPaths(const LangOptions &Lang) { |