Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 1 | //===--- ToolChains.cpp - ToolChain Implementations -----------------------===// |
| 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 | #include "ToolChains.h" |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 11 | #include "clang/Basic/CharInfo.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 12 | #include "clang/Basic/Version.h" |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Compilation.h" |
| 14 | #include "clang/Driver/Driver.h" |
Rafael Espindola | 7976446 | 2013-03-24 15:06:53 +0000 | [diff] [blame] | 15 | #include "clang/Driver/DriverDiagnostic.h" |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 16 | #include "clang/Driver/Options.h" |
Alp Toker | f1ffc84 | 2014-06-22 04:31:15 +0000 | [diff] [blame] | 17 | #include "llvm/Config/llvm-config.h" |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 18 | #include "llvm/Option/Arg.h" |
| 19 | #include "llvm/Option/ArgList.h" |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ErrorHandling.h" |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Path.h" |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 22 | |
| 23 | // Include the necessary headers to interface with the Windows registry and |
| 24 | // environment. |
Alp Toker | f1ffc84 | 2014-06-22 04:31:15 +0000 | [diff] [blame] | 25 | #if defined(LLVM_ON_WIN32) |
Alp Toker | fcce183 | 2014-06-22 03:27:45 +0000 | [diff] [blame] | 26 | #define USE_WIN32 |
| 27 | #endif |
| 28 | |
| 29 | #ifdef USE_WIN32 |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 30 | #define WIN32_LEAN_AND_MEAN |
| 31 | #define NOGDI |
| 32 | #define NOMINMAX |
Logan Chien | 733e3c6 | 2014-06-24 16:18:10 +0000 | [diff] [blame] | 33 | #include <windows.h> |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
| 36 | using namespace clang::driver; |
| 37 | using namespace clang::driver::toolchains; |
| 38 | using namespace clang; |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 39 | using namespace llvm::opt; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 40 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 41 | MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple& Triple, |
| 42 | const ArgList &Args) |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 43 | : ToolChain(D, Triple, Args) { |
| 44 | } |
| 45 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 46 | Tool *MSVCToolChain::buildLinker() const { |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 47 | return new tools::visualstudio::Link(*this); |
| 48 | } |
| 49 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 50 | Tool *MSVCToolChain::buildAssembler() const { |
Saleem Abdulrasool | 377066a | 2014-03-27 22:50:18 +0000 | [diff] [blame] | 51 | if (getTriple().isOSBinFormatMachO()) |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 52 | return new tools::darwin::Assemble(*this); |
Alp Toker | c8d4f0f | 2013-11-22 08:27:46 +0000 | [diff] [blame] | 53 | getDriver().Diag(clang::diag::err_no_external_assembler); |
Craig Topper | 92fc2df | 2014-05-17 16:56:41 +0000 | [diff] [blame] | 54 | return nullptr; |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 57 | bool MSVCToolChain::IsIntegratedAssemblerDefault() const { |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 58 | return true; |
| 59 | } |
| 60 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 61 | bool MSVCToolChain::IsUnwindTablesDefault() const { |
Reid Kleckner | 6b3a940 | 2014-09-04 18:13:12 +0000 | [diff] [blame] | 62 | // Emit unwind tables by default on Win64. All non-x86_32 Windows platforms |
| 63 | // such as ARM and PPC actually require unwind tables, but LLVM doesn't know |
| 64 | // how to generate them yet. |
| 65 | return getArch() == llvm::Triple::x86_64; |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 68 | bool MSVCToolChain::isPICDefault() const { |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 69 | return getArch() == llvm::Triple::x86_64; |
| 70 | } |
| 71 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 72 | bool MSVCToolChain::isPIEDefault() const { |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 76 | bool MSVCToolChain::isPICDefaultForced() const { |
Hans Wennborg | 1cc6cce | 2013-08-30 09:42:06 +0000 | [diff] [blame] | 77 | return getArch() == llvm::Triple::x86_64; |
| 78 | } |
| 79 | |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 80 | /// \brief Read registry string. |
| 81 | /// This also supports a means to look for high-versioned keys by use |
| 82 | /// of a $VERSION placeholder in the key path. |
| 83 | /// $VERSION in the key path is a placeholder for the version number, |
| 84 | /// causing the highest value path to be searched for and used. |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 85 | /// I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION". |
| 86 | /// There can be additional characters in the component. Only the numberic |
| 87 | /// characters are compared. |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 88 | static bool getSystemRegistryString(const char *keyPath, const char *valueName, |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 89 | char *value, size_t maxLength) { |
Alp Toker | fcce183 | 2014-06-22 03:27:45 +0000 | [diff] [blame] | 90 | #ifndef USE_WIN32 |
| 91 | return false; |
| 92 | #else |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 93 | HKEY hRootKey = NULL; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 94 | HKEY hKey = NULL; |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 95 | const char* subKey = NULL; |
| 96 | DWORD valueType; |
| 97 | DWORD valueSize = maxLength - 1; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 98 | long lResult; |
| 99 | bool returnValue = false; |
| 100 | |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 101 | if (strncmp(keyPath, "HKEY_CLASSES_ROOT\\", 18) == 0) { |
| 102 | hRootKey = HKEY_CLASSES_ROOT; |
| 103 | subKey = keyPath + 18; |
| 104 | } else if (strncmp(keyPath, "HKEY_USERS\\", 11) == 0) { |
| 105 | hRootKey = HKEY_USERS; |
| 106 | subKey = keyPath + 11; |
| 107 | } else if (strncmp(keyPath, "HKEY_LOCAL_MACHINE\\", 19) == 0) { |
| 108 | hRootKey = HKEY_LOCAL_MACHINE; |
| 109 | subKey = keyPath + 19; |
| 110 | } else if (strncmp(keyPath, "HKEY_CURRENT_USER\\", 18) == 0) { |
| 111 | hRootKey = HKEY_CURRENT_USER; |
| 112 | subKey = keyPath + 18; |
| 113 | } else { |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | const char *placeHolder = strstr(subKey, "$VERSION"); |
| 118 | char bestName[256]; |
| 119 | bestName[0] = '\0'; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 120 | // If we have a $VERSION placeholder, do the highest-version search. |
| 121 | if (placeHolder) { |
| 122 | const char *keyEnd = placeHolder - 1; |
| 123 | const char *nextKey = placeHolder; |
| 124 | // Find end of previous key. |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 125 | while ((keyEnd > subKey) && (*keyEnd != '\\')) |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 126 | keyEnd--; |
| 127 | // Find end of key containing $VERSION. |
| 128 | while (*nextKey && (*nextKey != '\\')) |
| 129 | nextKey++; |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 130 | size_t partialKeyLength = keyEnd - subKey; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 131 | char partialKey[256]; |
| 132 | if (partialKeyLength > sizeof(partialKey)) |
| 133 | partialKeyLength = sizeof(partialKey); |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 134 | strncpy(partialKey, subKey, partialKeyLength); |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 135 | partialKey[partialKeyLength] = '\0'; |
| 136 | HKEY hTopKey = NULL; |
Hans Wennborg | 935d01d | 2013-10-09 23:41:48 +0000 | [diff] [blame] | 137 | lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ | KEY_WOW64_32KEY, |
| 138 | &hTopKey); |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 139 | if (lResult == ERROR_SUCCESS) { |
| 140 | char keyName[256]; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 141 | double bestValue = 0.0; |
| 142 | DWORD index, size = sizeof(keyName) - 1; |
| 143 | for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL, |
| 144 | NULL, NULL, NULL) == ERROR_SUCCESS; index++) { |
| 145 | const char *sp = keyName; |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 146 | while (*sp && !isDigit(*sp)) |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 147 | sp++; |
| 148 | if (!*sp) |
| 149 | continue; |
| 150 | const char *ep = sp + 1; |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 151 | while (*ep && (isDigit(*ep) || (*ep == '.'))) |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 152 | ep++; |
| 153 | char numBuf[32]; |
| 154 | strncpy(numBuf, sp, sizeof(numBuf) - 1); |
| 155 | numBuf[sizeof(numBuf) - 1] = '\0'; |
Hans Wennborg | d219231 | 2013-10-10 18:03:08 +0000 | [diff] [blame] | 156 | double dvalue = strtod(numBuf, NULL); |
| 157 | if (dvalue > bestValue) { |
| 158 | // Test that InstallDir is indeed there before keeping this index. |
| 159 | // Open the chosen key path remainder. |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 160 | strcpy(bestName, keyName); |
Hans Wennborg | d219231 | 2013-10-10 18:03:08 +0000 | [diff] [blame] | 161 | // Append rest of key. |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 162 | strncat(bestName, nextKey, sizeof(bestName) - 1); |
| 163 | bestName[sizeof(bestName) - 1] = '\0'; |
| 164 | lResult = RegOpenKeyEx(hTopKey, bestName, 0, |
Hans Wennborg | d219231 | 2013-10-10 18:03:08 +0000 | [diff] [blame] | 165 | KEY_READ | KEY_WOW64_32KEY, &hKey); |
| 166 | if (lResult == ERROR_SUCCESS) { |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 167 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 168 | (LPBYTE)value, &valueSize); |
Hans Wennborg | d219231 | 2013-10-10 18:03:08 +0000 | [diff] [blame] | 169 | if (lResult == ERROR_SUCCESS) { |
Hans Wennborg | d219231 | 2013-10-10 18:03:08 +0000 | [diff] [blame] | 170 | bestValue = dvalue; |
| 171 | returnValue = true; |
| 172 | } |
| 173 | RegCloseKey(hKey); |
| 174 | } |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 175 | } |
| 176 | size = sizeof(keyName) - 1; |
| 177 | } |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 178 | RegCloseKey(hTopKey); |
| 179 | } |
| 180 | } else { |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 181 | lResult = RegOpenKeyEx(hRootKey, subKey, 0, KEY_READ | KEY_WOW64_32KEY, |
| 182 | &hKey); |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 183 | if (lResult == ERROR_SUCCESS) { |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 184 | lResult = RegQueryValueEx(hKey, valueName, NULL, &valueType, |
| 185 | (LPBYTE)value, &valueSize); |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 186 | if (lResult == ERROR_SUCCESS) |
| 187 | returnValue = true; |
| 188 | RegCloseKey(hKey); |
| 189 | } |
| 190 | } |
| 191 | return returnValue; |
Alp Toker | fcce183 | 2014-06-22 03:27:45 +0000 | [diff] [blame] | 192 | #endif // USE_WIN32 |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /// \brief Get Windows SDK installation directory. |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 196 | static bool getWindowsSDKDir(std::string &path) { |
| 197 | char windowsSDKInstallDir[256]; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 198 | // Try the Windows registry. |
| 199 | bool hasSDKDir = getSystemRegistryString( |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 200 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION", |
| 201 | "InstallationFolder", |
| 202 | windowsSDKInstallDir, |
| 203 | sizeof(windowsSDKInstallDir) - 1); |
| 204 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 205 | if (hasSDKDir && windowsSDKInstallDir[0]) { |
| 206 | path = windowsSDKInstallDir; |
| 207 | return true; |
| 208 | } |
| 209 | return false; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Alp Toker | fcce183 | 2014-06-22 03:27:45 +0000 | [diff] [blame] | 212 | // Get Visual Studio installation directory. |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 213 | static bool getVisualStudioDir(std::string &path) { |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 214 | // First check the environment variables that vsvars32.bat sets. |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 215 | const char* vcinstalldir = getenv("VCINSTALLDIR"); |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 216 | if (vcinstalldir) { |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 217 | char *p = const_cast<char *>(strstr(vcinstalldir, "\\VC")); |
| 218 | if (p) |
| 219 | *p = '\0'; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 220 | path = vcinstalldir; |
| 221 | return true; |
| 222 | } |
| 223 | |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 224 | char vsIDEInstallDir[256]; |
| 225 | char vsExpressIDEInstallDir[256]; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 226 | // Then try the windows registry. |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 227 | bool hasVCDir = getSystemRegistryString( |
| 228 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\$VERSION", |
| 229 | "InstallDir", vsIDEInstallDir, sizeof(vsIDEInstallDir) - 1); |
| 230 | bool hasVCExpressDir = getSystemRegistryString( |
| 231 | "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\$VERSION", |
| 232 | "InstallDir", vsExpressIDEInstallDir, sizeof(vsExpressIDEInstallDir) - 1); |
| 233 | // If we have both vc80 and vc90, pick version we were compiled with. |
| 234 | if (hasVCDir && vsIDEInstallDir[0]) { |
| 235 | char *p = (char*)strstr(vsIDEInstallDir, "\\Common7\\IDE"); |
| 236 | if (p) |
| 237 | *p = '\0'; |
| 238 | path = vsIDEInstallDir; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 239 | return true; |
| 240 | } |
| 241 | |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 242 | if (hasVCExpressDir && vsExpressIDEInstallDir[0]) { |
| 243 | char *p = (char*)strstr(vsExpressIDEInstallDir, "\\Common7\\IDE"); |
| 244 | if (p) |
| 245 | *p = '\0'; |
| 246 | path = vsExpressIDEInstallDir; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 247 | return true; |
| 248 | } |
| 249 | |
| 250 | // Try the environment. |
| 251 | const char *vs100comntools = getenv("VS100COMNTOOLS"); |
| 252 | const char *vs90comntools = getenv("VS90COMNTOOLS"); |
| 253 | const char *vs80comntools = getenv("VS80COMNTOOLS"); |
Alp Toker | fcce183 | 2014-06-22 03:27:45 +0000 | [diff] [blame] | 254 | |
| 255 | const char *vscomntools = nullptr; |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 256 | |
Alp Toker | a207440 | 2014-06-22 03:27:52 +0000 | [diff] [blame] | 257 | // Find any version we can |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 258 | if (vs100comntools) |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 259 | vscomntools = vs100comntools; |
| 260 | else if (vs90comntools) |
| 261 | vscomntools = vs90comntools; |
| 262 | else if (vs80comntools) |
| 263 | vscomntools = vs80comntools; |
| 264 | |
| 265 | if (vscomntools && *vscomntools) { |
| 266 | const char *p = strstr(vscomntools, "\\Common7\\Tools"); |
| 267 | path = p ? std::string(vscomntools, p) : vscomntools; |
| 268 | return true; |
| 269 | } |
| 270 | return false; |
| 271 | } |
| 272 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 273 | void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, |
| 274 | ArgStringList &CC1Args) const { |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 275 | if (DriverArgs.hasArg(options::OPT_nostdinc)) |
| 276 | return; |
| 277 | |
| 278 | if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { |
Rafael Espindola | 76565f0 | 2013-06-26 03:39:10 +0000 | [diff] [blame] | 279 | SmallString<128> P(getDriver().ResourceDir); |
| 280 | llvm::sys::path::append(P, "include"); |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 281 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 282 | } |
| 283 | |
| 284 | if (DriverArgs.hasArg(options::OPT_nostdlibinc)) |
| 285 | return; |
| 286 | |
Joao Matos | 792d7af | 2012-09-04 17:29:52 +0000 | [diff] [blame] | 287 | // Honor %INCLUDE%. It should know essential search paths with vcvarsall.bat. |
| 288 | if (const char *cl_include_dir = getenv("INCLUDE")) { |
| 289 | SmallVector<StringRef, 8> Dirs; |
Reid Kleckner | 77b45ba | 2014-04-23 00:15:01 +0000 | [diff] [blame] | 290 | StringRef(cl_include_dir) |
| 291 | .split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 292 | for (StringRef Dir : Dirs) |
| 293 | addSystemInclude(DriverArgs, CC1Args, Dir); |
| 294 | if (!Dirs.empty()) |
| 295 | return; |
Joao Matos | 792d7af | 2012-09-04 17:29:52 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | std::string VSDir; |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 299 | std::string WindowsSDKDir; |
Joao Matos | 792d7af | 2012-09-04 17:29:52 +0000 | [diff] [blame] | 300 | |
| 301 | // When built with access to the proper Windows APIs, try to actually find |
| 302 | // the correct include paths first. |
| 303 | if (getVisualStudioDir(VSDir)) { |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 304 | SmallString<128> P; |
| 305 | P = VSDir; |
| 306 | llvm::sys::path::append(P, "VC\\include"); |
| 307 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
| 308 | if (getWindowsSDKDir(WindowsSDKDir)) { |
| 309 | P = WindowsSDKDir; |
| 310 | llvm::sys::path::append(P, "include"); |
| 311 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Reid Kleckner | 77b45ba | 2014-04-23 00:15:01 +0000 | [diff] [blame] | 312 | } else { |
Hans Wennborg | e6b994e | 2014-10-20 23:26:03 +0000 | [diff] [blame] | 313 | P = VSDir; |
| 314 | llvm::sys::path::append(P, "VC\\PlatformSDK\\Include"); |
| 315 | addSystemInclude(DriverArgs, CC1Args, P.str()); |
Reid Kleckner | 77b45ba | 2014-04-23 00:15:01 +0000 | [diff] [blame] | 316 | } |
Joao Matos | 792d7af | 2012-09-04 17:29:52 +0000 | [diff] [blame] | 317 | return; |
| 318 | } |
Joao Matos | 792d7af | 2012-09-04 17:29:52 +0000 | [diff] [blame] | 319 | |
| 320 | // As a fallback, select default install paths. |
Alp Toker | fcce183 | 2014-06-22 03:27:45 +0000 | [diff] [blame] | 321 | // FIXME: Don't guess drives and paths like this on Windows. |
Joao Matos | 792d7af | 2012-09-04 17:29:52 +0000 | [diff] [blame] | 322 | const StringRef Paths[] = { |
| 323 | "C:/Program Files/Microsoft Visual Studio 10.0/VC/include", |
| 324 | "C:/Program Files/Microsoft Visual Studio 9.0/VC/include", |
| 325 | "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include", |
| 326 | "C:/Program Files/Microsoft Visual Studio 8/VC/include", |
| 327 | "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include" |
| 328 | }; |
| 329 | addSystemIncludes(DriverArgs, CC1Args, Paths); |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Saleem Abdulrasool | 819f391 | 2014-10-22 02:37:29 +0000 | [diff] [blame^] | 332 | void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, |
| 333 | ArgStringList &CC1Args) const { |
Chandler Carruth | 1fc603e | 2011-12-17 23:10:01 +0000 | [diff] [blame] | 334 | // FIXME: There should probably be logic here to find libc++ on Windows. |
| 335 | } |