diff options
author | mtklein <mtklein@chromium.org> | 2016-08-25 14:50:44 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-25 14:50:44 -0700 |
commit | 7d6fb2c92d096ac3630e23d561a4077a974a815c (patch) | |
tree | 73f270ac1a7fb82e00ef08b3f5615a46b99bf312 /gn | |
parent | 44df651ebefc284acc2f66425dff3ea0b0e14b36 (diff) |
GN: Android
Once you have downloaded an android NDK, you can set the ndk GN arg to use it.
E.g. my gn.args looks like:
is_debug = false
ndk = "/opt/android-ndk"
This should be enough to get you going for an arm64 build. You ought to be able to tweak that to other architectures by changing target_cpu to "arm", "x86", "x86-64", etc. That won't quite work until I follow this up a bit, but the skeleton is there.
This is enough to get me compiled, linked, and running to completion on my N5x.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2275983004
Review-Url: https://codereview.chromium.org/2275983004
Diffstat (limited to 'gn')
-rw-r--r-- | gn/BUILD.gn | 40 | ||||
-rw-r--r-- | gn/BUILDCONFIG.gn | 23 |
2 files changed, 63 insertions, 0 deletions
diff --git a/gn/BUILD.gn b/gn/BUILD.gn index fecca8efe8..0a56fa206f 100644 --- a/gn/BUILD.gn +++ b/gn/BUILD.gn @@ -7,6 +7,11 @@ declare_args() { cc = "cc" cxx = "c++" + if (is_android) { + cc = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang" + cxx = "$ndk/toolchains/llvm/prebuilt/$ndk_host/bin/clang++" + } + extra_cflags = "" extra_cflags_c = "" extra_cflags_cc = "" @@ -42,6 +47,41 @@ config("default") { "-Wnon-virtual-dtor", ] + if (current_cpu == "arm") { + cflags += [ "-mfpu=neon" ] + } + + if (is_android) { + asmflags = [ "--target=$ndk_target" ] + cflags += [ + "--sysroot=$ndk/platforms/$ndk_platform", + "--target=$ndk_target", + ] + cflags_cc += [ + "-isystem$ndk/sources/android/support/include", + "-isystem$ndk/sources/cxx-stl/llvm-libc++/libcxx/include", + ] + ldflags = [ + "--sysroot=$ndk/platforms/$ndk_platform", + "--target=$ndk_target", + "-B$ndk/toolchains/$ndk_target-4.9/prebuilt/$ndk_host/$ndk_target/bin", + "-pie", + ] + lib_dirs = [ + "$ndk/sources/cxx-stl/llvm-libc++/libs/$ndk_stdlib", + "$ndk/toolchains/$ndk_target-4.9/prebuilt/$ndk_host/lib/gcc/$ndk_target/4.9.x", + ] + libs = [ + # Order matters here! Keep these three in exactly this order. + "c++_static", + "c++abi", + "android_support", + ] + } + + if (is_linux) { + libs = [ "pthread" ] + } } config("release") { diff --git a/gn/BUILDCONFIG.gn b/gn/BUILDCONFIG.gn index d6833571c8..6aa4451e59 100644 --- a/gn/BUILDCONFIG.gn +++ b/gn/BUILDCONFIG.gn @@ -8,11 +8,15 @@ declare_args() { is_debug = true is_component_build = false + ndk = "" } # Platform detection if (target_os == "") { target_os = host_os + if (ndk != "") { + target_os = "android" + } } if (current_os == "") { current_os = target_os @@ -20,6 +24,9 @@ if (current_os == "") { if (target_cpu == "") { target_cpu = host_cpu + if (ndk != "") { + target_cpu = "arm64" + } } if (current_cpu == "") { current_cpu = target_cpu @@ -34,6 +41,22 @@ is_win = current_os == "win" is_posix = !is_win +if (is_android) { + ndk_host = "" + ndk_target = "" + ndk_platform = "" + ndk_stdlib = "" + + if (host_os == "linux" && host_cpu == "x64") { + ndk_host = "linux-x86_64" + } + if (target_cpu == "arm64") { + ndk_target = "aarch64-linux-android" + ndk_platform = "android-21/arch-arm64" + ndk_stdlib = "arm64-v8a" + } +} + # A component is either a static or a shared library. template("component") { _component_mode = "static_library" |