Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / build / toolchain / android / android_toolchain.gni
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
15 import("//build_overrides/build.gni")
16
17 import("${build_root}/config/android/config.gni")
18 import("${build_root}/toolchain/gcc_toolchain.gni")
19
20 template("android_clang_toolchain") {
21   _invoker_toolchain_args = invoker.toolchain_args
22
23   if (_invoker_toolchain_args.current_cpu == "arm") {
24     _tool_name_root = "armv7a-linux-androideabi${invoker.api_level}-"
25   } else if (_invoker_toolchain_args.current_cpu == "arm64") {
26     _tool_name_root = "aarch64-linux-android${invoker.api_level}-"
27   } else if (_invoker_toolchain_args.current_cpu == "x64") {
28     _tool_name_root = "x86_64-linux-android${invoker.api_level}-"
29   } else if (_invoker_toolchain_args.current_cpu == "x86") {
30     _tool_name_root = "i686-linux-android${invoker.api_level}-"
31   } else {
32     assert(
33         false,
34         "Unknown/invalid current_cpu value in toolchain_args::current_cpu for android_clang_toolchain")
35   }
36
37   _android_toolchain_args = {
38     current_os = "android"
39     is_clang = true
40
41     forward_variables_from(_invoker_toolchain_args, "*")
42   }
43
44   _ndk_prefix = ""
45   if (android_ndk_root != "") {
46     _ndk_host_os = ""
47     if (host_os == "linux") {
48       _ndk_host_os = "linux"
49     } else if (host_os == "mac") {
50       _ndk_host_os = "darwin"
51     } else if (host_os == "win") {
52       _ndk_host_os = "windows"
53     }
54
55     _ndk_host_cpu = ""
56     if (host_cpu == "x64") {
57       _ndk_host_cpu = "-x86_64"
58     }
59
60     _ndk_host = _ndk_host_os + _ndk_host_cpu
61     _ndk_prefix =
62         "${android_ndk_root}/toolchains/llvm/prebuilt/${_ndk_host}/bin/"
63   }
64
65   gcc_toolchain(target_name) {
66     toolchain_args = _android_toolchain_args
67     ar = _ndk_prefix + "llvm-ar"
68     cc = _ndk_prefix + _tool_name_root + "clang"
69     cxx = _ndk_prefix + _tool_name_root + "clang++"
70   }
71 }