[cfe-commits] r83594 - in /cfe/trunk: include/clang/Frontend/InitHeaderSearch.h lib/Frontend/InitHeaderSearch.cpp tools/clang-cc/clang-cc.cpp

Mike Stump mrs at apple.com
Thu Oct 8 16:29:47 PDT 2009


Author: mrs
Date: Thu Oct  8 18:29:47 2009
New Revision: 83594

URL: http://llvm.org/viewvc/llvm-project?rev=83594&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Frontend/InitHeaderSearch.h
    cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Frontend/InitHeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/InitHeaderSearch.h?rev=83594&r1=83593&r2=83594&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/InitHeaderSearch.h (original)
+++ cfe/trunk/include/clang/Frontend/InitHeaderSearch.h Thu Oct  8 18:29:47 2009
@@ -16,6 +16,7 @@
 
 #include "clang/Lex/DirectoryLookup.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
 #include <string>
 #include <vector>
 
@@ -66,7 +67,7 @@
 
   /// AddDefaultSystemIncludePaths - Adds the default system include paths so
   ///  that e.g. stdio.h is found.
-  void AddDefaultSystemIncludePaths(const LangOptions &Lang);
+  void AddDefaultSystemIncludePaths(const LangOptions &Lang, llvm::Triple &triple);
 
   /// Realize - Merges all search path lists into one list and send it to
   /// HeaderSearch.

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=83594&r1=83593&r2=83594&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Thu Oct  8 18:29:47 2009
@@ -99,100 +99,269 @@
 }
 
 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?
+#if defined(LLVM_ON_WIN32)
 
-#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 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");
+  // 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
 
-    // Ubuntu 8.10
-    AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.3", "i486-pc-linux-gnu");
+#endif // LLVM_ON_WIN32
 
-    // Gentoo amd64 stable
-    AddGnuCPlusPlusIncludePaths(
-        "/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4",
-	"i686-pc-linux-gnu");
+void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
+                                                    llvm::Triple &triple) {
+  // FIXME: temporary hack: hard-coded paths.
+  llvm::Triple::OSType os = triple.getOS();
 
-    // DragonFly
-    AddPath("/usr/include/c++/4.1", System, true, false, false);
+  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) {

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=83594&r1=83593&r2=83594&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Thu Oct  8 18:29:47 2009
@@ -1166,7 +1166,8 @@
 /// InitializeIncludePaths - Process the -I options and set them in the
 /// HeaderSearch object.
 void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers,
-                            FileManager &FM, const LangOptions &Lang) {
+                            FileManager &FM, const LangOptions &Lang,
+                            llvm::Triple &triple) {
   InitHeaderSearch Init(Headers, Verbose, isysroot);
 
   // Handle -I... and -F... options, walking the lists in parallel.
@@ -1245,7 +1246,7 @@
   AddClangIncludePaths(Argv0, &Init);
 
   if (!nostdinc)
-    Init.AddDefaultSystemIncludePaths(Lang);
+    Init.AddDefaultSystemIncludePaths(Lang, triple);
 
   // Now that we have collected all of the include paths, merge them all
   // together and tell the preprocessor about them.
@@ -2410,7 +2411,7 @@
     HeaderSearch HeaderInfo(FileMgr);
 
 
-    InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo);
+    InitializeIncludePaths(argv[0], HeaderInfo, FileMgr, LangInfo, Triple);
 
     // Set up the preprocessor with these options.
     DriverPreprocessorFactory PPFactory(Diags, LangInfo, *Target,





More information about the cfe-commits mailing list