From fcce183a383d66b0056150a924210d3d1001a16c Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Sun, 22 Jun 2014 03:27:45 +0000 Subject: [PATCH] Make WindowsToolChain portable De-conditionalize as much as possible so we can start to fix this code. No change in functionality. llvm-svn: 211458 --- clang/lib/Driver/WindowsToolChain.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/clang/lib/Driver/WindowsToolChain.cpp b/clang/lib/Driver/WindowsToolChain.cpp index 5d4bbb5..20333e8 100644 --- a/clang/lib/Driver/WindowsToolChain.cpp +++ b/clang/lib/Driver/WindowsToolChain.cpp @@ -21,7 +21,12 @@ // Include the necessary headers to interface with the Windows registry and // environment. -#ifdef _MSC_VER +// TODO: Investigate enabling this with __MINGW32__. +#if defined(_MSC_VER) +#define USE_WIN32 +#endif + +#ifdef USE_WIN32 #define WIN32_LEAN_AND_MEAN #define NOGDI #define NOMINMAX @@ -69,9 +74,6 @@ bool Windows::isPICDefaultForced() const { return getArch() == llvm::Triple::x86_64; } -// FIXME: This probably should goto to some platform utils place. -#ifdef _MSC_VER - /// \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. @@ -82,6 +84,9 @@ bool Windows::isPICDefaultForced() const { /// characters are compared. static bool getSystemRegistryString(const char *keyPath, const char *valueName, char *value, size_t maxLength) { +#ifndef USE_WIN32 + return false; +#else HKEY hRootKey = NULL; HKEY hKey = NULL; const char* subKey = NULL; @@ -183,6 +188,7 @@ static bool getSystemRegistryString(const char *keyPath, const char *valueName, } } return returnValue; +#endif // USE_WIN32 } /// \brief Get Windows SDK installation directory. @@ -202,7 +208,7 @@ static bool getWindowsSDKDir(std::string &path) { return false; } - // Get Visual Studio installation directory. +// Get Visual Studio installation directory. static bool getVisualStudioDir(std::string &path) { // First check the environment variables that vsvars32.bat sets. const char* vcinstalldir = getenv("VCINSTALLDIR"); @@ -244,7 +250,8 @@ static bool getVisualStudioDir(std::string &path) { const char *vs100comntools = getenv("VS100COMNTOOLS"); const char *vs90comntools = getenv("VS90COMNTOOLS"); const char *vs80comntools = getenv("VS80COMNTOOLS"); - const char *vscomntools = NULL; + + const char *vscomntools = nullptr; // Try to find the version that we were compiled with if(false) {} @@ -277,8 +284,6 @@ static bool getVisualStudioDir(std::string &path) { return false; } -#endif // _MSC_VER - void Windows::AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const { if (DriverArgs.hasArg(options::OPT_nostdinc)) @@ -293,7 +298,11 @@ void Windows::AddClangSystemIncludeArgs(const ArgList &DriverArgs, if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; -#ifdef _MSC_VER +// TODO: This code path is portable. Conditionalize on LLVM_ON_WIN32 instead? +#ifndef USE_WIN32 + return; +#endif + // Honor %INCLUDE%. It should know essential search paths with vcvarsall.bat. if (const char *cl_include_dir = getenv("INCLUDE")) { SmallVector Dirs; @@ -328,6 +337,7 @@ void Windows::AddClangSystemIncludeArgs(const ArgList &DriverArgs, } // As a fallback, select default install paths. + // FIXME: Don't guess drives and paths like this on Windows. const StringRef Paths[] = { "C:/Program Files/Microsoft Visual Studio 10.0/VC/include", "C:/Program Files/Microsoft Visual Studio 9.0/VC/include", @@ -336,7 +346,6 @@ void Windows::AddClangSystemIncludeArgs(const ArgList &DriverArgs, "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include" }; addSystemIncludes(DriverArgs, CC1Args, Paths); -#endif // _MSC_VER } void Windows::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, -- 2.7.4