android_toolchain.gni 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (c) 2020 Project CHIP Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import("//build_overrides/build.gni")
  15. import("${build_root}/config/android/config.gni")
  16. import("${build_root}/toolchain/gcc_toolchain.gni")
  17. template("android_clang_toolchain") {
  18. _invoker_toolchain_args = invoker.toolchain_args
  19. if (_invoker_toolchain_args.current_cpu == "arm") {
  20. _tool_name_root = "armv7a-linux-androideabi${invoker.api_level}-"
  21. } else if (_invoker_toolchain_args.current_cpu == "arm64") {
  22. _tool_name_root = "aarch64-linux-android${invoker.api_level}-"
  23. } else if (_invoker_toolchain_args.current_cpu == "x64") {
  24. _tool_name_root = "x86_64-linux-android${invoker.api_level}-"
  25. } else if (_invoker_toolchain_args.current_cpu == "x86") {
  26. _tool_name_root = "i686-linux-android${invoker.api_level}-"
  27. } else {
  28. assert(
  29. false,
  30. "Unknown/invalid current_cpu value in toolchain_args::current_cpu for android_clang_toolchain")
  31. }
  32. _android_toolchain_args = {
  33. current_os = "android"
  34. is_clang = true
  35. forward_variables_from(_invoker_toolchain_args, "*")
  36. }
  37. _ndk_prefix = ""
  38. if (android_ndk_root != "") {
  39. _ndk_host_os = ""
  40. if (host_os == "linux") {
  41. _ndk_host_os = "linux"
  42. } else if (host_os == "mac") {
  43. _ndk_host_os = "darwin"
  44. } else if (host_os == "win") {
  45. _ndk_host_os = "windows"
  46. }
  47. _ndk_host_cpu = ""
  48. if (host_cpu == "x64") {
  49. _ndk_host_cpu = "-x86_64"
  50. } else if (host_cpu == "arm64") {
  51. # until NDK 24.0.7856742-beta1, the host cpu on apple silicon is x86_64
  52. _ndk_host_cpu = "-x86_64"
  53. }
  54. _ndk_host = _ndk_host_os + _ndk_host_cpu
  55. _ndk_prefix =
  56. "${android_ndk_root}/toolchains/llvm/prebuilt/${_ndk_host}/bin/"
  57. }
  58. gcc_toolchain(target_name) {
  59. toolchain_args = _android_toolchain_args
  60. ar = _ndk_prefix + "llvm-ar"
  61. cc = _ndk_prefix + _tool_name_root + "clang"
  62. cxx = _ndk_prefix + _tool_name_root + "clang++"
  63. link_generate_map_file = false
  64. }
  65. }