r260662 - [CMake] Add option to switch default C++ stdlib
Jonas Hahnfeld via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 11 23:48:38 PST 2016
Author: hahnfeld
Date: Fri Feb 12 01:48:37 2016
New Revision: 260662
URL: http://llvm.org/viewvc/llvm-project?rev=260662&view=rev
Log:
[CMake] Add option to switch default C++ stdlib
With this option one can optionally override the architecture dependent
default library to use if no -stdlib= is provided on compiler invocation.
Differential Revision: http://reviews.llvm.org/D15920
Modified:
cfe/trunk/CMakeLists.txt
cfe/trunk/include/clang/Config/config.h.cmake
cfe/trunk/include/clang/Config/config.h.in
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h
Modified: cfe/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=260662&r1=260661&r2=260662&view=diff
==============================================================================
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Fri Feb 12 01:48:37 2016
@@ -197,6 +197,15 @@ set(GCC_INSTALL_PREFIX "" CACHE PATH "Di
set(DEFAULT_SYSROOT "" CACHE PATH
"Default <path> to all compiler invocations for --sysroot=<path>." )
+set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING
+ "Default C++ stdlib to use (empty for architecture default, \"libstdc++\" or \"libc++\"")
+if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR
+ CLANG_DEFAULT_CXX_STDLIB STREQUAL "libstdc++" OR
+ CLANG_DEFAULT_CXX_STDLIB STREQUAL "libc++"))
+ message(WARNING "Resetting default C++ stdlib to use architecture default")
+ set(CLANG_DEFAULT_CXX_STDLIB "")
+endif()
+
set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
"Default OpenMP runtime used by -fopenmp.")
Modified: cfe/trunk/include/clang/Config/config.h.cmake
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Config/config.h.cmake?rev=260662&r1=260661&r2=260662&view=diff
==============================================================================
--- cfe/trunk/include/clang/Config/config.h.cmake (original)
+++ cfe/trunk/include/clang/Config/config.h.cmake Fri Feb 12 01:48:37 2016
@@ -8,6 +8,9 @@
/* Bug report URL. */
#define BUG_REPORT_URL "${BUG_REPORT_URL}"
+/* Default C++ stdlib to use. */
+#define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
+
/* Default OpenMP runtime used by -fopenmp. */
#define CLANG_DEFAULT_OPENMP_RUNTIME "${CLANG_DEFAULT_OPENMP_RUNTIME}"
Modified: cfe/trunk/include/clang/Config/config.h.in
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Config/config.h.in?rev=260662&r1=260661&r2=260662&view=diff
==============================================================================
--- cfe/trunk/include/clang/Config/config.h.in (original)
+++ cfe/trunk/include/clang/Config/config.h.in Fri Feb 12 01:48:37 2016
@@ -8,6 +8,9 @@
/* Bug report URL. */
#undef BUG_REPORT_URL
+/* Default C++ stdlib to use. */
+#undef CLANG_DEFAULT_CXX_STDLIB
+
/* Default OpenMP runtime used by -fopenmp. */
#undef CLANG_DEFAULT_OPENMP_RUNTIME
Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=260662&r1=260661&r2=260662&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Fri Feb 12 01:48:37 2016
@@ -256,6 +256,10 @@ public:
return ToolChain::RLT_Libgcc;
}
+ virtual CXXStdlibType GetDefaultCXXStdlibType() const {
+ return ToolChain::CST_Libstdcxx;
+ }
+
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
StringRef Component,
bool Shared = false) const;
Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=260662&r1=260661&r2=260662&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Fri Feb 12 01:48:37 2016
@@ -9,6 +9,7 @@
#include "Tools.h"
#include "clang/Basic/ObjCRuntime.h"
+#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
@@ -533,18 +534,34 @@ ToolChain::RuntimeLibType ToolChain::Get
return GetDefaultRuntimeLibType();
}
+static bool ParseCXXStdlibType(const StringRef& Name,
+ ToolChain::CXXStdlibType& Type) {
+ if (Name == "libc++")
+ Type = ToolChain::CST_Libcxx;
+ else if (Name == "libstdc++")
+ Type = ToolChain::CST_Libstdcxx;
+ else
+ return false;
+
+ return true;
+}
+
ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
- if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
- StringRef Value = A->getValue();
- if (Value == "libc++")
- return ToolChain::CST_Libcxx;
- if (Value == "libstdc++")
- return ToolChain::CST_Libstdcxx;
- getDriver().Diag(diag::err_drv_invalid_stdlib_name)
- << A->getAsString(Args);
+ ToolChain::CXXStdlibType Type;
+ bool HasValidType = false;
+
+ const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
+ if (A) {
+ HasValidType = ParseCXXStdlibType(A->getValue(), Type);
+ if (!HasValidType)
+ getDriver().Diag(diag::err_drv_invalid_stdlib_name)
+ << A->getAsString(Args);
}
- return ToolChain::CST_Libstdcxx;
+ if (!HasValidType && !ParseCXXStdlibType(CLANG_DEFAULT_CXX_STDLIB, Type))
+ Type = GetDefaultCXXStdlibType();
+
+ return Type;
}
/// \brief Utility function to add a system include directory to CC1 arguments.
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=260662&r1=260661&r2=260662&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Fri Feb 12 01:48:37 2016
@@ -65,6 +65,16 @@ types::ID MachO::LookupTypeForExtension(
bool MachO::HasNativeLLVMSupport() const { return true; }
+ToolChain::CXXStdlibType Darwin::GetDefaultCXXStdlibType() const {
+ // Default to use libc++ on OS X 10.9+ and iOS 7+.
+ if ((isTargetMacOS() && !isMacosxVersionLT(10, 9)) ||
+ (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) ||
+ isTargetWatchOSBased())
+ return ToolChain::CST_Libcxx;
+
+ return ToolChain::CST_Libstdcxx;
+}
+
/// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0.
ObjCRuntime Darwin::getDefaultObjCRuntime(bool isNonFragile) const {
if (isTargetWatchOSBased())
@@ -1020,7 +1030,6 @@ DerivedArgList *Darwin::TranslateArgs(co
const char *BoundArch) const {
// First get the generic Apple args, before moving onto Darwin-specific ones.
DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch);
- const OptTable &Opts = getDriver().getOpts();
// If no architecture is bound, none of the translations here are relevant.
if (!BoundArch)
@@ -1051,14 +1060,6 @@ DerivedArgList *Darwin::TranslateArgs(co
}
}
- // Default to use libc++ on OS X 10.9+ and iOS 7+.
- if (((isTargetMacOS() && !isMacosxVersionLT(10, 9)) ||
- (isTargetIOSBased() && !isIPhoneOSVersionLT(7, 0)) ||
- isTargetWatchOSBased()) &&
- !Args.getLastArg(options::OPT_stdlib_EQ))
- DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_stdlib_EQ),
- "libc++");
-
// Validate the C++ standard library choice.
CXXStdlibType Type = GetCXXStdlibType(*DAL);
if (Type == ToolChain::CST_Libcxx) {
@@ -3027,16 +3028,7 @@ Tool *Bitrig::buildAssembler() const {
Tool *Bitrig::buildLinker() const { return new tools::bitrig::Linker(*this); }
-ToolChain::CXXStdlibType Bitrig::GetCXXStdlibType(const ArgList &Args) const {
- if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
- StringRef Value = A->getValue();
- if (Value == "libstdc++")
- return ToolChain::CST_Libstdcxx;
- if (Value == "libc++")
- return ToolChain::CST_Libcxx;
-
- getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args);
- }
+ToolChain::CXXStdlibType Bitrig::GetDefaultCXXStdlibType() const {
return ToolChain::CST_Libcxx;
}
Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=260662&r1=260661&r2=260662&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Fri Feb 12 01:48:37 2016
@@ -512,6 +512,7 @@ public:
TranslateArgs(const llvm::opt::DerivedArgList &Args,
const char *BoundArch) const override;
+ CXXStdlibType GetDefaultCXXStdlibType() const override;
ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
bool hasBlocksRuntime() const override;
@@ -699,7 +700,7 @@ public:
bool IsMathErrnoDefault() const override { return false; }
bool IsObjCNonFragileABIDefault() const override { return true; }
- CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
+ CXXStdlibType GetDefaultCXXStdlibType() const override;
void AddClangCXXStdlibIncludeArgs(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
More information about the cfe-commits
mailing list