mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:24:46 +01:00
[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 llvm-svn: 260662
This commit is contained in:
@@ -197,6 +197,15 @@ set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
|
||||
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.")
|
||||
|
||||
|
||||
@@ -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}"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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::GetRuntimeLibType(
|
||||
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.
|
||||
|
||||
@@ -65,6 +65,16 @@ types::ID MachO::LookupTypeForExtension(const char *Ext) const {
|
||||
|
||||
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(const DerivedArgList &Args,
|
||||
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(const DerivedArgList &Args,
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user