2011-12-18 07:10:01 +08:00
|
|
|
//===--- ToolChains.cpp - ToolChain Implementations -----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ToolChains.h"
|
2015-06-08 08:22:46 +08:00
|
|
|
#include "Tools.h"
|
2013-02-09 06:30:41 +08:00
|
|
|
#include "clang/Basic/CharInfo.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
2011-12-18 07:10:01 +08:00
|
|
|
#include "clang/Driver/Compilation.h"
|
|
|
|
#include "clang/Driver/Driver.h"
|
2013-03-24 23:06:53 +08:00
|
|
|
#include "clang/Driver/DriverDiagnostic.h"
|
2011-12-18 07:10:01 +08:00
|
|
|
#include "clang/Driver/Options.h"
|
2014-10-23 04:40:28 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2014-06-22 12:31:15 +08:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2013-06-15 01:17:23 +08:00
|
|
|
#include "llvm/Option/Arg.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
2011-12-18 07:10:01 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2014-10-23 04:40:28 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Process.h"
|
2015-01-24 03:16:25 +08:00
|
|
|
#include <cstdio>
|
|
|
|
|
2011-12-18 07:10:01 +08:00
|
|
|
// Include the necessary headers to interface with the Windows registry and
|
|
|
|
// environment.
|
2014-06-22 12:31:15 +08:00
|
|
|
#if defined(LLVM_ON_WIN32)
|
2014-06-22 11:27:45 +08:00
|
|
|
#define USE_WIN32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_WIN32
|
2011-12-18 07:10:01 +08:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define NOGDI
|
2014-12-05 05:46:50 +08:00
|
|
|
#ifndef NOMINMAX
|
|
|
|
#define NOMINMAX
|
|
|
|
#endif
|
2014-06-25 00:18:10 +08:00
|
|
|
#include <windows.h>
|
2011-12-18 07:10:01 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace clang::driver;
|
|
|
|
using namespace clang::driver::toolchains;
|
|
|
|
using namespace clang;
|
2013-06-15 01:17:23 +08:00
|
|
|
using namespace llvm::opt;
|
2011-12-18 07:10:01 +08:00
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple& Triple,
|
|
|
|
const ArgList &Args)
|
2013-08-30 17:42:06 +08:00
|
|
|
: ToolChain(D, Triple, Args) {
|
2014-12-02 07:06:47 +08:00
|
|
|
getProgramPaths().push_back(getDriver().getInstalledDir());
|
|
|
|
if (getDriver().getInstalledDir() != getDriver().Dir)
|
|
|
|
getProgramPaths().push_back(getDriver().Dir);
|
2013-08-30 17:42:06 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
Tool *MSVCToolChain::buildLinker() const {
|
2013-08-30 17:42:06 +08:00
|
|
|
return new tools::visualstudio::Link(*this);
|
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
Tool *MSVCToolChain::buildAssembler() const {
|
2014-03-28 06:50:18 +08:00
|
|
|
if (getTriple().isOSBinFormatMachO())
|
2013-08-30 17:42:06 +08:00
|
|
|
return new tools::darwin::Assemble(*this);
|
2013-11-22 16:27:46 +08:00
|
|
|
getDriver().Diag(clang::diag::err_no_external_assembler);
|
2014-05-18 00:56:41 +08:00
|
|
|
return nullptr;
|
2013-08-30 17:42:06 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
bool MSVCToolChain::IsIntegratedAssemblerDefault() const {
|
2013-08-30 17:42:06 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
bool MSVCToolChain::IsUnwindTablesDefault() const {
|
2014-09-05 02:13:12 +08:00
|
|
|
// Emit unwind tables by default on Win64. All non-x86_32 Windows platforms
|
|
|
|
// such as ARM and PPC actually require unwind tables, but LLVM doesn't know
|
|
|
|
// how to generate them yet.
|
|
|
|
return getArch() == llvm::Triple::x86_64;
|
2013-08-30 17:42:06 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
bool MSVCToolChain::isPICDefault() const {
|
2013-08-30 17:42:06 +08:00
|
|
|
return getArch() == llvm::Triple::x86_64;
|
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
bool MSVCToolChain::isPIEDefault() const {
|
2013-08-30 17:42:06 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
bool MSVCToolChain::isPICDefaultForced() const {
|
2013-08-30 17:42:06 +08:00
|
|
|
return getArch() == llvm::Triple::x86_64;
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:40:28 +08:00
|
|
|
#ifdef USE_WIN32
|
|
|
|
static bool readFullStringValue(HKEY hkey, const char *valueName,
|
|
|
|
std::string &value) {
|
|
|
|
// FIXME: We should be using the W versions of the registry functions, but
|
|
|
|
// doing so requires UTF8 / UTF16 conversions similar to how we handle command
|
|
|
|
// line arguments. The UTF8 conversion functions are not exposed publicly
|
|
|
|
// from LLVM though, so in order to do this we will probably need to create
|
|
|
|
// a registry abstraction in LLVMSupport that is Windows only.
|
|
|
|
DWORD result = 0;
|
|
|
|
DWORD valueSize = 0;
|
|
|
|
DWORD type = 0;
|
|
|
|
// First just query for the required size.
|
|
|
|
result = RegQueryValueEx(hkey, valueName, NULL, &type, NULL, &valueSize);
|
|
|
|
if (result != ERROR_SUCCESS || type != REG_SZ)
|
|
|
|
return false;
|
|
|
|
std::vector<BYTE> buffer(valueSize);
|
|
|
|
result = RegQueryValueEx(hkey, valueName, NULL, NULL, &buffer[0], &valueSize);
|
|
|
|
if (result == ERROR_SUCCESS)
|
|
|
|
value.assign(reinterpret_cast<const char *>(buffer.data()));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-18 07:10:01 +08:00
|
|
|
/// \brief Read registry string.
|
|
|
|
/// This also supports a means to look for high-versioned keys by use
|
|
|
|
/// of a $VERSION placeholder in the key path.
|
|
|
|
/// $VERSION in the key path is a placeholder for the version number,
|
|
|
|
/// causing the highest value path to be searched for and used.
|
2014-10-23 04:40:28 +08:00
|
|
|
/// I.e. "SOFTWARE\\Microsoft\\VisualStudio\\$VERSION".
|
|
|
|
/// There can be additional characters in the component. Only the numeric
|
|
|
|
/// characters are compared. This function only searches HKLM.
|
2011-12-18 07:10:01 +08:00
|
|
|
static bool getSystemRegistryString(const char *keyPath, const char *valueName,
|
2014-10-23 04:40:28 +08:00
|
|
|
std::string &value, std::string *phValue) {
|
2014-06-22 11:27:45 +08:00
|
|
|
#ifndef USE_WIN32
|
|
|
|
return false;
|
|
|
|
#else
|
2014-10-23 04:40:28 +08:00
|
|
|
HKEY hRootKey = HKEY_LOCAL_MACHINE;
|
2011-12-18 07:10:01 +08:00
|
|
|
HKEY hKey = NULL;
|
|
|
|
long lResult;
|
|
|
|
bool returnValue = false;
|
|
|
|
|
2014-10-23 04:40:28 +08:00
|
|
|
const char *placeHolder = strstr(keyPath, "$VERSION");
|
|
|
|
std::string bestName;
|
2011-12-18 07:10:01 +08:00
|
|
|
// If we have a $VERSION placeholder, do the highest-version search.
|
|
|
|
if (placeHolder) {
|
|
|
|
const char *keyEnd = placeHolder - 1;
|
|
|
|
const char *nextKey = placeHolder;
|
|
|
|
// Find end of previous key.
|
2014-10-23 04:40:28 +08:00
|
|
|
while ((keyEnd > keyPath) && (*keyEnd != '\\'))
|
2011-12-18 07:10:01 +08:00
|
|
|
keyEnd--;
|
|
|
|
// Find end of key containing $VERSION.
|
|
|
|
while (*nextKey && (*nextKey != '\\'))
|
|
|
|
nextKey++;
|
2014-10-23 04:40:28 +08:00
|
|
|
size_t partialKeyLength = keyEnd - keyPath;
|
2011-12-18 07:10:01 +08:00
|
|
|
char partialKey[256];
|
|
|
|
if (partialKeyLength > sizeof(partialKey))
|
|
|
|
partialKeyLength = sizeof(partialKey);
|
2014-10-23 04:40:28 +08:00
|
|
|
strncpy(partialKey, keyPath, partialKeyLength);
|
2011-12-18 07:10:01 +08:00
|
|
|
partialKey[partialKeyLength] = '\0';
|
|
|
|
HKEY hTopKey = NULL;
|
2013-10-10 07:41:48 +08:00
|
|
|
lResult = RegOpenKeyEx(hRootKey, partialKey, 0, KEY_READ | KEY_WOW64_32KEY,
|
|
|
|
&hTopKey);
|
2011-12-18 07:10:01 +08:00
|
|
|
if (lResult == ERROR_SUCCESS) {
|
|
|
|
char keyName[256];
|
|
|
|
double bestValue = 0.0;
|
|
|
|
DWORD index, size = sizeof(keyName) - 1;
|
|
|
|
for (index = 0; RegEnumKeyEx(hTopKey, index, keyName, &size, NULL,
|
|
|
|
NULL, NULL, NULL) == ERROR_SUCCESS; index++) {
|
|
|
|
const char *sp = keyName;
|
2013-02-09 06:30:41 +08:00
|
|
|
while (*sp && !isDigit(*sp))
|
2011-12-18 07:10:01 +08:00
|
|
|
sp++;
|
|
|
|
if (!*sp)
|
|
|
|
continue;
|
|
|
|
const char *ep = sp + 1;
|
2013-02-09 06:30:41 +08:00
|
|
|
while (*ep && (isDigit(*ep) || (*ep == '.')))
|
2011-12-18 07:10:01 +08:00
|
|
|
ep++;
|
|
|
|
char numBuf[32];
|
|
|
|
strncpy(numBuf, sp, sizeof(numBuf) - 1);
|
|
|
|
numBuf[sizeof(numBuf) - 1] = '\0';
|
2013-10-11 02:03:08 +08:00
|
|
|
double dvalue = strtod(numBuf, NULL);
|
|
|
|
if (dvalue > bestValue) {
|
|
|
|
// Test that InstallDir is indeed there before keeping this index.
|
|
|
|
// Open the chosen key path remainder.
|
2014-10-23 04:40:28 +08:00
|
|
|
bestName = keyName;
|
2013-10-11 02:03:08 +08:00
|
|
|
// Append rest of key.
|
2014-10-23 04:40:28 +08:00
|
|
|
bestName.append(nextKey);
|
|
|
|
lResult = RegOpenKeyEx(hTopKey, bestName.c_str(), 0,
|
2013-10-11 02:03:08 +08:00
|
|
|
KEY_READ | KEY_WOW64_32KEY, &hKey);
|
|
|
|
if (lResult == ERROR_SUCCESS) {
|
2014-10-23 04:40:28 +08:00
|
|
|
lResult = readFullStringValue(hKey, valueName, value);
|
2013-10-11 02:03:08 +08:00
|
|
|
if (lResult == ERROR_SUCCESS) {
|
|
|
|
bestValue = dvalue;
|
2014-10-23 04:40:28 +08:00
|
|
|
if (phValue)
|
|
|
|
*phValue = bestName;
|
2013-10-11 02:03:08 +08:00
|
|
|
returnValue = true;
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
2011-12-18 07:10:01 +08:00
|
|
|
}
|
|
|
|
size = sizeof(keyName) - 1;
|
|
|
|
}
|
|
|
|
RegCloseKey(hTopKey);
|
|
|
|
}
|
|
|
|
} else {
|
2014-10-23 04:40:28 +08:00
|
|
|
lResult =
|
|
|
|
RegOpenKeyEx(hRootKey, keyPath, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
|
2011-12-18 07:10:01 +08:00
|
|
|
if (lResult == ERROR_SUCCESS) {
|
2014-10-23 04:40:28 +08:00
|
|
|
lResult = readFullStringValue(hKey, valueName, value);
|
2011-12-18 07:10:01 +08:00
|
|
|
if (lResult == ERROR_SUCCESS)
|
|
|
|
returnValue = true;
|
2014-10-23 04:40:28 +08:00
|
|
|
if (phValue)
|
|
|
|
phValue->clear();
|
2011-12-18 07:10:01 +08:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnValue;
|
2014-06-22 11:27:45 +08:00
|
|
|
#endif // USE_WIN32
|
2011-12-18 07:10:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Get Windows SDK installation directory.
|
2014-10-23 04:40:28 +08:00
|
|
|
bool MSVCToolChain::getWindowsSDKDir(std::string &path, int &major,
|
|
|
|
int &minor) const {
|
|
|
|
std::string sdkVersion;
|
2011-12-18 07:10:01 +08:00
|
|
|
// Try the Windows registry.
|
|
|
|
bool hasSDKDir = getSystemRegistryString(
|
2014-10-23 04:40:28 +08:00
|
|
|
"SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
|
|
|
|
"InstallationFolder", path, &sdkVersion);
|
|
|
|
if (!sdkVersion.empty())
|
2015-01-24 03:16:25 +08:00
|
|
|
std::sscanf(sdkVersion.c_str(), "v%d.%d", &major, &minor);
|
2014-10-23 04:40:28 +08:00
|
|
|
return hasSDKDir && !path.empty();
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:40:43 +08:00
|
|
|
// Gets the library path required to link against the Windows SDK.
|
|
|
|
bool MSVCToolChain::getWindowsSDKLibraryPath(std::string &path) const {
|
|
|
|
std::string sdkPath;
|
|
|
|
int sdkMajor = 0;
|
|
|
|
int sdkMinor = 0;
|
|
|
|
|
|
|
|
path.clear();
|
|
|
|
if (!getWindowsSDKDir(sdkPath, sdkMajor, sdkMinor))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
llvm::SmallString<128> libPath(sdkPath);
|
|
|
|
llvm::sys::path::append(libPath, "Lib");
|
|
|
|
if (sdkMajor <= 7) {
|
|
|
|
switch (getArch()) {
|
|
|
|
// In Windows SDK 7.x, x86 libraries are directly in the Lib folder.
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
break;
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
llvm::sys::path::append(libPath, "x64");
|
|
|
|
break;
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
// It is not necessary to link against Windows SDK 7.x when targeting ARM.
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Windows SDK 8.x installs libraries in a folder whose names depend on the
|
|
|
|
// version of the OS you're targeting. By default choose the newest, which
|
|
|
|
// usually corresponds to the version of the OS you've installed the SDK on.
|
2014-10-23 05:48:56 +08:00
|
|
|
const char *tests[] = {"winv6.3", "win8", "win7"};
|
2014-10-23 04:40:43 +08:00
|
|
|
bool found = false;
|
2014-10-23 05:48:56 +08:00
|
|
|
for (const char *test : tests) {
|
2014-10-23 04:40:43 +08:00
|
|
|
llvm::SmallString<128> testPath(libPath);
|
|
|
|
llvm::sys::path::append(testPath, test);
|
|
|
|
if (llvm::sys::fs::exists(testPath.c_str())) {
|
|
|
|
libPath = testPath;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
llvm::sys::path::append(libPath, "um");
|
|
|
|
switch (getArch()) {
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
llvm::sys::path::append(libPath, "x86");
|
|
|
|
break;
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
llvm::sys::path::append(libPath, "x64");
|
|
|
|
break;
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
llvm::sys::path::append(libPath, "arm");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path = libPath.str();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:40:28 +08:00
|
|
|
// Get the location to use for Visual Studio binaries. The location priority
|
|
|
|
// is: %VCINSTALLDIR% > %PATH% > newest copy of Visual Studio installed on
|
|
|
|
// system (as reported by the registry).
|
|
|
|
bool MSVCToolChain::getVisualStudioBinariesFolder(const char *clangProgramPath,
|
|
|
|
std::string &path) const {
|
|
|
|
path.clear();
|
|
|
|
|
|
|
|
SmallString<128> BinDir;
|
|
|
|
|
|
|
|
// First check the environment variables that vsvars32.bat sets.
|
|
|
|
llvm::Optional<std::string> VcInstallDir =
|
|
|
|
llvm::sys::Process::GetEnv("VCINSTALLDIR");
|
|
|
|
if (VcInstallDir.hasValue()) {
|
|
|
|
BinDir = VcInstallDir.getValue();
|
|
|
|
llvm::sys::path::append(BinDir, "bin");
|
|
|
|
} else {
|
|
|
|
// Next walk the PATH, trying to find a cl.exe in the path. If we find one,
|
|
|
|
// use that. However, make sure it's not clang's cl.exe.
|
|
|
|
llvm::Optional<std::string> OptPath = llvm::sys::Process::GetEnv("PATH");
|
|
|
|
if (OptPath.hasValue()) {
|
|
|
|
const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
|
|
|
|
SmallVector<StringRef, 8> PathSegments;
|
|
|
|
llvm::SplitString(OptPath.getValue(), PathSegments, EnvPathSeparatorStr);
|
|
|
|
|
|
|
|
for (StringRef PathSegment : PathSegments) {
|
|
|
|
if (PathSegment.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SmallString<128> FilePath(PathSegment);
|
|
|
|
llvm::sys::path::append(FilePath, "cl.exe");
|
|
|
|
if (llvm::sys::fs::can_execute(FilePath.c_str()) &&
|
|
|
|
!llvm::sys::fs::equivalent(FilePath.c_str(), clangProgramPath)) {
|
|
|
|
// If we found it on the PATH, use it exactly as is with no
|
|
|
|
// modifications.
|
|
|
|
path = PathSegment;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string installDir;
|
|
|
|
// With no VCINSTALLDIR and nothing on the PATH, if we can't find it in the
|
|
|
|
// registry then we have no choice but to fail.
|
|
|
|
if (!getVisualStudioInstallDir(installDir))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Regardless of what binary we're ultimately trying to find, we make sure
|
|
|
|
// that this is a Visual Studio directory by checking for cl.exe. We use
|
|
|
|
// cl.exe instead of other binaries like link.exe because programs such as
|
|
|
|
// GnuWin32 also have a utility called link.exe, so cl.exe is the least
|
|
|
|
// ambiguous.
|
|
|
|
BinDir = installDir;
|
|
|
|
llvm::sys::path::append(BinDir, "VC", "bin");
|
|
|
|
SmallString<128> ClPath(BinDir);
|
|
|
|
llvm::sys::path::append(ClPath, "cl.exe");
|
|
|
|
|
|
|
|
if (!llvm::sys::fs::can_execute(ClPath.c_str()))
|
|
|
|
return false;
|
2014-10-21 07:26:03 +08:00
|
|
|
}
|
2014-10-23 04:40:28 +08:00
|
|
|
|
|
|
|
if (BinDir.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (getArch()) {
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
break;
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
llvm::sys::path::append(BinDir, "amd64");
|
|
|
|
break;
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
llvm::sys::path::append(BinDir, "arm");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Whatever this is, Visual Studio doesn't have a toolchain for it.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
path = BinDir.str();
|
|
|
|
return true;
|
2011-12-18 07:10:01 +08:00
|
|
|
}
|
|
|
|
|
2014-06-22 11:27:45 +08:00
|
|
|
// Get Visual Studio installation directory.
|
2014-10-23 04:40:28 +08:00
|
|
|
bool MSVCToolChain::getVisualStudioInstallDir(std::string &path) const {
|
2011-12-18 07:10:01 +08:00
|
|
|
// First check the environment variables that vsvars32.bat sets.
|
2014-10-23 04:40:28 +08:00
|
|
|
const char *vcinstalldir = getenv("VCINSTALLDIR");
|
2011-12-18 07:10:01 +08:00
|
|
|
if (vcinstalldir) {
|
|
|
|
path = vcinstalldir;
|
2014-10-23 04:40:28 +08:00
|
|
|
path = path.substr(0, path.find("\\VC"));
|
2011-12-18 07:10:01 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:40:28 +08:00
|
|
|
std::string vsIDEInstallDir;
|
|
|
|
std::string vsExpressIDEInstallDir;
|
2011-12-18 07:10:01 +08:00
|
|
|
// Then try the windows registry.
|
2014-10-23 04:40:28 +08:00
|
|
|
bool hasVCDir =
|
|
|
|
getSystemRegistryString("SOFTWARE\\Microsoft\\VisualStudio\\$VERSION",
|
|
|
|
"InstallDir", vsIDEInstallDir, nullptr);
|
|
|
|
if (hasVCDir && !vsIDEInstallDir.empty()) {
|
|
|
|
path = vsIDEInstallDir.substr(0, vsIDEInstallDir.find("\\Common7\\IDE"));
|
2011-12-18 07:10:01 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:40:28 +08:00
|
|
|
bool hasVCExpressDir =
|
|
|
|
getSystemRegistryString("SOFTWARE\\Microsoft\\VCExpress\\$VERSION",
|
|
|
|
"InstallDir", vsExpressIDEInstallDir, nullptr);
|
|
|
|
if (hasVCExpressDir && !vsExpressIDEInstallDir.empty()) {
|
|
|
|
path = vsExpressIDEInstallDir.substr(
|
|
|
|
0, vsIDEInstallDir.find("\\Common7\\IDE"));
|
2011-12-18 07:10:01 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try the environment.
|
2014-10-23 04:40:28 +08:00
|
|
|
const char *vs120comntools = getenv("VS120COMNTOOLS");
|
2011-12-18 07:10:01 +08:00
|
|
|
const char *vs100comntools = getenv("VS100COMNTOOLS");
|
|
|
|
const char *vs90comntools = getenv("VS90COMNTOOLS");
|
|
|
|
const char *vs80comntools = getenv("VS80COMNTOOLS");
|
2014-06-22 11:27:45 +08:00
|
|
|
|
|
|
|
const char *vscomntools = nullptr;
|
2011-12-18 07:10:01 +08:00
|
|
|
|
2014-06-22 11:27:52 +08:00
|
|
|
// Find any version we can
|
2014-10-23 04:40:28 +08:00
|
|
|
if (vs120comntools)
|
|
|
|
vscomntools = vs120comntools;
|
|
|
|
else if (vs100comntools)
|
2011-12-18 07:10:01 +08:00
|
|
|
vscomntools = vs100comntools;
|
|
|
|
else if (vs90comntools)
|
|
|
|
vscomntools = vs90comntools;
|
|
|
|
else if (vs80comntools)
|
|
|
|
vscomntools = vs80comntools;
|
|
|
|
|
|
|
|
if (vscomntools && *vscomntools) {
|
|
|
|
const char *p = strstr(vscomntools, "\\Common7\\Tools");
|
|
|
|
path = p ? std::string(vscomntools, p) : vscomntools;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-23 04:40:28 +08:00
|
|
|
void MSVCToolChain::AddSystemIncludeWithSubfolder(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args,
|
|
|
|
const std::string &folder,
|
|
|
|
const char *subfolder) const {
|
|
|
|
llvm::SmallString<128> path(folder);
|
|
|
|
llvm::sys::path::append(path, subfolder);
|
2015-03-18 18:17:07 +08:00
|
|
|
addSystemInclude(DriverArgs, CC1Args, path);
|
2014-10-23 04:40:28 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
2012-09-05 01:29:52 +08:00
|
|
|
if (DriverArgs.hasArg(options::OPT_nostdinc))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
|
2013-06-26 11:39:10 +08:00
|
|
|
SmallString<128> P(getDriver().ResourceDir);
|
|
|
|
llvm::sys::path::append(P, "include");
|
2015-03-18 18:17:07 +08:00
|
|
|
addSystemInclude(DriverArgs, CC1Args, P);
|
2012-09-05 01:29:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DriverArgs.hasArg(options::OPT_nostdlibinc))
|
|
|
|
return;
|
2011-12-18 07:10:01 +08:00
|
|
|
|
2012-03-13 08:02:21 +08:00
|
|
|
// Honor %INCLUDE%. It should know essential search paths with vcvarsall.bat.
|
|
|
|
if (const char *cl_include_dir = getenv("INCLUDE")) {
|
|
|
|
SmallVector<StringRef, 8> Dirs;
|
2014-04-23 08:15:01 +08:00
|
|
|
StringRef(cl_include_dir)
|
|
|
|
.split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
|
|
|
|
for (StringRef Dir : Dirs)
|
|
|
|
addSystemInclude(DriverArgs, CC1Args, Dir);
|
|
|
|
if (!Dirs.empty())
|
|
|
|
return;
|
2012-03-13 08:02:21 +08:00
|
|
|
}
|
|
|
|
|
2011-12-18 07:10:01 +08:00
|
|
|
std::string VSDir;
|
|
|
|
|
|
|
|
// When built with access to the proper Windows APIs, try to actually find
|
|
|
|
// the correct include paths first.
|
2014-10-23 04:40:28 +08:00
|
|
|
if (getVisualStudioInstallDir(VSDir)) {
|
|
|
|
AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, VSDir, "VC\\include");
|
|
|
|
|
|
|
|
std::string WindowsSDKDir;
|
|
|
|
int major, minor;
|
|
|
|
if (getWindowsSDKDir(WindowsSDKDir, major, minor)) {
|
|
|
|
if (major >= 8) {
|
|
|
|
AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
|
|
|
|
"include\\shared");
|
|
|
|
AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
|
|
|
|
"include\\um");
|
|
|
|
AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
|
|
|
|
"include\\winrt");
|
|
|
|
} else {
|
|
|
|
AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, WindowsSDKDir,
|
|
|
|
"include");
|
|
|
|
}
|
2014-04-23 08:15:01 +08:00
|
|
|
} else {
|
2014-10-23 04:40:28 +08:00
|
|
|
addSystemInclude(DriverArgs, CC1Args, VSDir);
|
2014-04-23 08:15:01 +08:00
|
|
|
}
|
2012-09-05 01:29:52 +08:00
|
|
|
return;
|
2011-12-18 07:10:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// As a fallback, select default install paths.
|
2014-06-22 11:27:45 +08:00
|
|
|
// FIXME: Don't guess drives and paths like this on Windows.
|
2012-09-05 01:29:52 +08:00
|
|
|
const StringRef Paths[] = {
|
2011-12-18 07:10:01 +08:00
|
|
|
"C:/Program Files/Microsoft Visual Studio 10.0/VC/include",
|
|
|
|
"C:/Program Files/Microsoft Visual Studio 9.0/VC/include",
|
|
|
|
"C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include",
|
|
|
|
"C:/Program Files/Microsoft Visual Studio 8/VC/include",
|
|
|
|
"C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
|
|
|
|
};
|
2012-09-05 01:29:52 +08:00
|
|
|
addSystemIncludes(DriverArgs, CC1Args, Paths);
|
2011-12-18 07:10:01 +08:00
|
|
|
}
|
|
|
|
|
2014-10-22 10:37:29 +08:00
|
|
|
void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
|
|
|
|
ArgStringList &CC1Args) const {
|
2011-12-18 07:10:01 +08:00
|
|
|
// FIXME: There should probably be logic here to find libc++ on Windows.
|
|
|
|
}
|
2015-06-08 08:22:46 +08:00
|
|
|
|
|
|
|
std::string
|
|
|
|
MSVCToolChain::ComputeEffectiveClangTriple(const ArgList &Args,
|
|
|
|
types::ID InputType) const {
|
|
|
|
std::string TripleStr =
|
|
|
|
ToolChain::ComputeEffectiveClangTriple(Args, InputType);
|
|
|
|
llvm::Triple Triple(TripleStr);
|
|
|
|
VersionTuple MSVT =
|
|
|
|
tools::visualstudio::getMSVCVersion(/*D=*/nullptr, Triple, Args,
|
|
|
|
/*IsWindowsMSVC=*/true);
|
|
|
|
if (MSVT.empty())
|
|
|
|
return TripleStr;
|
|
|
|
|
|
|
|
MSVT = VersionTuple(MSVT.getMajor(), MSVT.getMinor().getValueOr(0),
|
|
|
|
MSVT.getSubminor().getValueOr(0));
|
|
|
|
|
2015-06-09 14:30:01 +08:00
|
|
|
if (Triple.getEnvironment() == llvm::Triple::MSVC) {
|
|
|
|
StringRef ObjFmt = Triple.getEnvironmentName().split('-').second;
|
|
|
|
if (ObjFmt.empty())
|
|
|
|
Triple.setEnvironmentName((Twine("msvc") + MSVT.getAsString()).str());
|
|
|
|
else
|
|
|
|
Triple.setEnvironmentName(
|
|
|
|
(Twine("msvc") + MSVT.getAsString() + Twine('-') + ObjFmt).str());
|
|
|
|
}
|
2015-06-08 08:22:46 +08:00
|
|
|
return Triple.getTriple();
|
|
|
|
}
|
2015-06-20 05:36:47 +08:00
|
|
|
|
|
|
|
SanitizerMask MSVCToolChain::getSupportedSanitizers() const {
|
|
|
|
SanitizerMask Res = ToolChain::getSupportedSanitizers();
|
|
|
|
Res |= SanitizerKind::Address;
|
|
|
|
// CFI checks are not implemented for MSVC ABI for now.
|
|
|
|
Res &= ~SanitizerKind::CFI;
|
|
|
|
Res &= ~SanitizerKind::CFICastStrict;
|
|
|
|
return Res;
|
|
|
|
}
|