From: Daniel Dunbar Date: Tue, 14 Sep 2010 23:12:40 +0000 (+0000) Subject: Driver: Add a -stdlib= argument which can be used to select the C++ standard X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f16c959e30b7e7ba8e4b8d597c313fbe457206d;p=clang Driver: Add a -stdlib= argument which can be used to select the C++ standard library to use. - This is currently useful for testing libc++; you can now use 'clang++ -stdlib=libc++ t.cpp' to compile using it if installed. - In the future could also be used to select other standard library choices if alternatives become available (for example, to use an alternate C library). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113891 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/tools/clang.pod b/docs/tools/clang.pod index 032efcfcab..8284d319e7 100644 --- a/docs/tools/clang.pod +++ b/docs/tools/clang.pod @@ -14,6 +14,7 @@ B [B<-c>|B<-S>|B<-E>] B<-std=>I B<-g> B<-f>I B<-m>I B<-o> I + B<-stdlib=>I I =head1 DESCRIPTION @@ -130,6 +131,11 @@ Treat subsequent input files as having type I. Specify the language standard to compile for. +=item B<-stdlib>=I + +Specify the C++ standard library to use; supported options are libstdc++ and +libc++. + =item B<-ansi> Same as B<-std=c89>. diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 34cd6004ed..b6e89bd78b 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -16,6 +16,8 @@ def err_drv_unknown_stdin_type : Error< def err_drv_unknown_language : Error<"language not recognized: '%0'">; def err_drv_invalid_arch_name : Error< "invalid arch name '%0'">; +def err_drv_invalid_stdlib_name : Error< + "invalid library name in argument '%0'">; def err_drv_invalid_opt_with_multiple_archs : Error< "option '%0' cannot be used with multiple -arch options">; def err_drv_invalid_output_with_multiple_archs : Error< diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index c51d12a487..de8f1769a5 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -575,6 +575,7 @@ def static_libgcc : Flag<"-static-libgcc">; def static : Flag<"-static">, Flags<[NoArgumentUnused]>; def std_default_EQ : Joined<"-std-default=">; def std_EQ : Joined<"-std=">; +def stdlib_EQ : Joined<"-stdlib=">; def sub__library : JoinedOrSeparate<"-sub_library">; def sub__umbrella : JoinedOrSeparate<"-sub_umbrella">; def s : Flag<"-s">; @@ -719,6 +720,8 @@ def _specs : Separate<"--specs">, Alias; def _static : Flag<"--static">, Alias; def _std_EQ : Joined<"--std=">, Alias; def _std : Separate<"--std">, Alias; +def _stdlib_EQ : Joined<"--stdlib=">, Alias; +def _stdlib : Separate<"--stdlib">, Alias; def _sysroot_EQ : Joined<"--sysroot=">; def _sysroot : Separate<"--sysroot">, Alias<_sysroot_EQ>; def _target_help : Flag<"--target-help">; diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index e2d3b34b66..a9de09c9d5 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -34,6 +34,7 @@ public: typedef llvm::SmallVector path_list; enum CXXStdlibType { + CST_Libcxx, CST_Libstdcxx }; diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 0f63046409..337ea4e8f9 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -175,6 +175,16 @@ std::string ToolChain::ComputeEffectiveClangTriple(const ArgList &Args) const { } ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ + if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { + llvm::StringRef Value = A->getValue(Args); + if (Value == "libc++") + return ToolChain::CST_Libcxx; + if (Value == "libstdc++") + return ToolChain::CST_Libstdcxx; + getDriver().Diag(clang::diag::err_drv_invalid_stdlib_name) + << A->getAsString(Args); + } + return ToolChain::CST_Libstdcxx; } @@ -183,6 +193,11 @@ void ToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args, CXXStdlibType Type = GetCXXStdlibType(Args); switch (Type) { + case ToolChain::CST_Libcxx: + CmdArgs.push_back("-cxx-system-include"); + CmdArgs.push_back("/usr/include/c++/v1"); + break; + case ToolChain::CST_Libstdcxx: // Currently handled by the mass of goop in InitHeaderSearch. break; @@ -194,6 +209,10 @@ void ToolChain::AddClangCXXStdlibLibArgs(const ArgList &Args, CXXStdlibType Type = GetCXXStdlibType(Args); switch (Type) { + case ToolChain::CST_Libcxx: + CmdArgs.push_back("-lc++"); + break; + case ToolChain::CST_Libstdcxx: CmdArgs.push_back("-lstdc++"); break;