[PATCH] D12646: Add libc++ header path for DarwinClang builds

don hinton via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 4 13:50:20 PDT 2015


hintonda created this revision.
hintonda added a reviewer: rsmith.
hintonda added a subscriber: cfe-commits.

Current behavior doesn't add c++ header path if libc++ wasn't installed via macports in /usr.  This change will try to locate c++ headers from various locations, including in tree, via macports, sysroot, and default Xcode location -- which is how my configuration finds it.

This probably needs a bit of work, especially wrt other configurations, so feedback would be appreciated..

http://reviews.llvm.org/D12646

Files:
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h

Index: lib/Driver/ToolChains.h
===================================================================
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -475,6 +475,9 @@
 
   void AddLinkARCArgs(const llvm::opt::ArgList &Args,
                       llvm::opt::ArgStringList &CmdArgs) const override;
+
+  void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+                                    llvm::opt::ArgStringList &CC1Args) const override;
   /// }
 
 private:
Index: lib/Driver/ToolChains.cpp
===================================================================
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -264,6 +264,43 @@
   CmdArgs.push_back(Args.MakeArgString(P));
 }
 
+void DarwinClang::AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+                                               llvm::opt::ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+      DriverArgs.hasArg(options::OPT_nostdincxx))
+    return;
+
+  DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
+
+  // Check if libc++ has been enabled and provide its include paths if so.
+  if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) {
+    const std::string LibCXXIncludePathCandidates[] = {
+        // The primary location is within the Clang installation.
+        // FIXME: We shouldn't hard code 'v1' here to make Clang future proof to
+        // newer ABI versions.
+        getDriver().Dir + "/../include/c++/v1",
+
+        // Try sysroot, e.g., DEFAULT_SYSROOT, if set
+        getDriver().SysRoot + "/usr/include/c++/v1",
+
+        // libc++ was installed via macports
+        "/usr/include/c++/v1",
+
+        // libc++ was installed as part of Xcode
+        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"
+    };
+    for (const auto &IncludePath : LibCXXIncludePathCandidates) {
+      if (!llvm::sys::fs::exists(IncludePath))
+        continue;
+      // Add the first candidate that exists.
+      addSystemInclude(DriverArgs, CC1Args, IncludePath);
+      break;
+    }
+    return;
+  }
+}
+
+
 void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
                               StringRef DarwinLibName, bool AlwaysLink,
                               bool IsEmbedded, bool AddRPath) const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12646.34072.patch
Type: text/x-patch
Size: 2375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150904/f6c0be19/attachment.bin>


More information about the cfe-commits mailing list