Fix C++ on Darwin

Port of https://android-review.googlesource.com/207241

Change-Id: Idad81a528a2104579de0225b0724bb81293eea44
This commit is contained in:
Dan Willemsen 2016-03-09 10:30:22 -08:00
parent 71ea9c13c9
commit 282a4b0dda
3 changed files with 37 additions and 15 deletions

View File

@ -955,6 +955,10 @@ func (c *CCLinked) flags(ctx common.AndroidModuleContext, flags CCFlags) CCFlags
// Host builds will use GNU libstdc++.
if ctx.Device() {
flags.CFlags = append(flags.CFlags, "-I"+common.PathForSource(ctx, "bionic/libstdc++/include").String())
} else {
// Host builds will use the system C++. libc++ on Darwin, GNU libstdc++ everywhere else
flags.CppFlags = append(flags.CppFlags, flags.Toolchain.SystemCppCppflags())
flags.LdFlags = append(flags.LdFlags, flags.Toolchain.SystemCppLdflags())
}
case "ndk_system":
ndkSrcRoot := common.PathForSource(ctx, "prebuilts/ndk/current/sources/cxx-stl/system/include")

View File

@ -70,6 +70,9 @@ type Toolchain interface {
ShlibSuffix() string
ExecutableSuffix() string
SystemCppCppflags() string
SystemCppLdflags() string
}
type toolchainBase struct {
@ -117,6 +120,14 @@ func (toolchainBase) ClangAsflags() string {
return ""
}
func (toolchainBase) SystemCppCppflags() string {
return ""
}
func (toolchainBase) SystemCppLdflags() string {
return ""
}
type toolchain64Bit struct {
toolchainBase
}

View File

@ -32,16 +32,20 @@ var (
"-DMACOSX_DEPLOYMENT_TARGET=${macSdkVersion}",
}
darwinCppflags = []string{
"-isystem ${macToolchainRoot}/usr/include/c++/v1",
}
darwinLdflags = []string{
"-isysroot ${macSdkRoot}",
"-Wl,-syslibroot,${macSdkRoot}",
"-mmacosx-version-min=${macSdkVersion}",
}
darwinSystemCppCppflags = []string{
"-isystem ${macToolchainRoot}/usr/include/c++/v1",
}
darwinSystemCppLdflags = []string{
"-stdlib=libc++",
}
// Extended cflags
darwinX86Cflags = []string{
"-m32",
@ -74,8 +78,6 @@ var (
darwinX8664ClangLdflags = clangFilterUnknownCflags(darwinX8664Ldflags)
darwinClangCppflags = clangFilterUnknownCflags(darwinCppflags)
darwinSupportedSdkVersions = []string{
"macosx10.8",
"macosx10.9",
@ -113,11 +115,12 @@ func init() {
pctx.StaticVariable("darwinCflags", strings.Join(darwinCflags, " "))
pctx.StaticVariable("darwinLdflags", strings.Join(darwinLdflags, " "))
pctx.StaticVariable("darwinCppflags", strings.Join(darwinCppflags, " "))
pctx.StaticVariable("darwinClangCflags", strings.Join(darwinClangCflags, " "))
pctx.StaticVariable("darwinClangLdflags", strings.Join(darwinClangLdflags, " "))
pctx.StaticVariable("darwinClangCppflags", strings.Join(darwinClangCppflags, " "))
pctx.StaticVariable("darwinSystemCppCppflags", strings.Join(darwinSystemCppCppflags, " "))
pctx.StaticVariable("darwinSystemCppLdflags", strings.Join(darwinSystemCppLdflags, " "))
// Extended cflags
pctx.StaticVariable("darwinX86Cflags", strings.Join(darwinX86Cflags, " "))
@ -198,7 +201,7 @@ func (t *toolchainDarwinX8664) Cflags() string {
}
func (t *toolchainDarwin) Cppflags() string {
return "${darwinCppflags}"
return ""
}
func (t *toolchainDarwinX86) Ldflags() string {
@ -221,10 +224,6 @@ func (t *toolchainDarwinX86) ClangCflags() string {
return "${darwinClangCflags} ${darwinX86ClangCflags}"
}
func (t *toolchainDarwinX86) ClangCppflags() string {
return "${darwinClangCppflags}"
}
func (t *toolchainDarwinX8664) ClangTriple() string {
return "x86_64-darwin-gnu"
}
@ -233,8 +232,8 @@ func (t *toolchainDarwinX8664) ClangCflags() string {
return "${darwinClangCflags} ${darwinX8664ClangCflags}"
}
func (t *toolchainDarwinX8664) ClangCppflags() string {
return "${darwinClangCppflags}"
func (t *toolchainDarwin) ClangCppflags() string {
return ""
}
func (t *toolchainDarwinX86) ClangLdflags() string {
@ -249,6 +248,14 @@ func (t *toolchainDarwin) ShlibSuffix() string {
return ".dylib"
}
func (t *toolchainDarwin) SystemCppCppflags() string {
return "${darwinSystemCppCppflags}"
}
func (t *toolchainDarwin) SystemCppLdflags() string {
return "${darwinSystemCppLdflags}"
}
var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{}
var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}