Make the Linux support for finding libc++ somewhat less braindead.
Now instead of just looking in the system root for it, we also look
relative to the clang binary's directory. This should "just work" in
almost all cases. I've added test cases accordingly.
This is probably *very* worthwhile to backport to the 3.4 branch so that
folks can check it out, build it, and use that as their host compiler
going forward.
llvm-svn: 199632
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp
index c056346..e364fa7 100644
--- a/clang/lib/Driver/ToolChains.cpp
+++ b/clang/lib/Driver/ToolChains.cpp
@@ -2945,9 +2945,24 @@
// Check if libc++ has been enabled and provide its include paths if so.
if (GetCXXStdlibType(DriverArgs) == ToolChain::CST_Libcxx) {
- // libc++ is always installed at a fixed path on Linux currently.
- addSystemInclude(DriverArgs, CC1Args,
- getDriver().SysRoot + "/usr/include/c++/v1");
+ 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",
+
+ // We also check the system as for a long time this is the only place Clang looked.
+ // FIXME: We should really remove this. It doesn't make any sense.
+ getDriver().SysRoot + "/usr/include/c++/v1"
+ };
+ for (unsigned i = 0; i < llvm::array_lengthof(LibCXXIncludePathCandidates);
+ ++i) {
+ if (!llvm::sys::fs::exists(LibCXXIncludePathCandidates[i]))
+ continue;
+ // Add the first candidate that exists.
+ addSystemInclude(DriverArgs, CC1Args, LibCXXIncludePathCandidates[i]);
+ break;
+ }
return;
}
@@ -2971,7 +2986,7 @@
MIPSABIDirSuffix, DriverArgs, CC1Args))
return;
- const std::string IncludePathCandidates[] = {
+ const std::string LibStdCXXIncludePathCandidates[] = {
// Gentoo is weird and places its headers inside the GCC install, so if the
// first attempt to find the headers fails, try these patterns.
InstallDir.str() + "/include/g++-v" + Version.MajorStr + "." +
@@ -2984,8 +2999,9 @@
LibDir.str() + "/../include/c++",
};
- for (unsigned i = 0; i < llvm::array_lengthof(IncludePathCandidates); ++i) {
- if (addLibStdCXXIncludePaths(IncludePathCandidates[i],
+ for (unsigned i = 0; i < llvm::array_lengthof(LibStdCXXIncludePathCandidates);
+ ++i) {
+ if (addLibStdCXXIncludePaths(LibStdCXXIncludePathCandidates[i],
TripleStr + MIPSABIDirSuffix + BiarchSuffix,
DriverArgs, CC1Args))
break;