blob: e294854aa7c4bc6fe772fd53d90d9b01b52bac27 [file] [log] [blame]
mtklein7fbfbbe2016-07-21 12:25:45 -07001# Copyright 2016 Google Inc.
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# It's best to keep the names and defaults of is_foo flags consistent with Chrome.
7
8declare_args() {
mtklein88a7ac02016-09-14 11:16:49 -07009 is_official_build = false
mtklein7fbfbbe2016-07-21 12:25:45 -070010 is_component_build = false
mtklein7d6fb2c2016-08-25 14:50:44 -070011 ndk = ""
mtklein6ef69992016-09-14 06:12:09 -070012 ndk_api = 0 # 0 == picked automatically for target_cpu.
mtklein2b3c2a32016-09-08 08:39:34 -070013 sanitize = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070014}
mtklein88a7ac02016-09-14 11:16:49 -070015declare_args() {
16 is_debug = !is_official_build
17}
18
19assert(!(is_debug && is_official_build))
mtklein7fbfbbe2016-07-21 12:25:45 -070020
21# Platform detection
22if (target_os == "") {
23 target_os = host_os
mtklein7d6fb2c2016-08-25 14:50:44 -070024 if (ndk != "") {
25 target_os = "android"
26 }
mtklein7fbfbbe2016-07-21 12:25:45 -070027}
28if (current_os == "") {
29 current_os = target_os
30}
31
32is_android = current_os == "android"
33is_fuchsia = current_os == "fuchsia"
34is_ios = current_os == "ios"
35is_linux = current_os == "linux"
36is_mac = current_os == "mac"
37is_win = current_os == "win"
38
mtklein349cece2016-08-26 08:13:04 -070039if (target_cpu == "") {
40 target_cpu = host_cpu
41 if (is_android) {
42 target_cpu = "arm64"
43 }
44}
45if (current_cpu == "") {
46 current_cpu = target_cpu
47}
mtklein7fbfbbe2016-07-21 12:25:45 -070048
mtklein7d6fb2c2016-08-25 14:50:44 -070049if (is_android) {
50 ndk_host = ""
51 ndk_target = ""
52 ndk_platform = ""
53 ndk_stdlib = ""
mtklein6ef69992016-09-14 06:12:09 -070054 ndk_gccdir = ""
55
56 if (ndk_api == 0) {
57 ndk_api = 18
58 if (target_cpu == "arm64" || target_cpu == "mips64el" ||
59 target_cpu == "x64") {
60 ndk_api = 21
61 }
62 }
mtklein7d6fb2c2016-08-25 14:50:44 -070063
mtklein349cece2016-08-26 08:13:04 -070064 if (host_os == "linux") {
mtklein7d6fb2c2016-08-25 14:50:44 -070065 ndk_host = "linux-x86_64"
mtklein349cece2016-08-26 08:13:04 -070066 } else if (host_os == "mac") {
67 ndk_host = "darwin-x86_64"
mtklein7d6fb2c2016-08-25 14:50:44 -070068 }
mtklein349cece2016-08-26 08:13:04 -070069
mtklein7d6fb2c2016-08-25 14:50:44 -070070 if (target_cpu == "arm64") {
71 ndk_target = "aarch64-linux-android"
mtklein6ef69992016-09-14 06:12:09 -070072 ndk_platform = "android-${ndk_api}/arch-arm64"
mtklein7d6fb2c2016-08-25 14:50:44 -070073 ndk_stdlib = "arm64-v8a"
mtklein349cece2016-08-26 08:13:04 -070074 ndk_gccdir = ndk_target
75 } else if (target_cpu == "arm") {
76 ndk_target = "arm-linux-androideabi"
mtklein6ef69992016-09-14 06:12:09 -070077 ndk_platform = "android-${ndk_api}/arch-arm"
mtklein349cece2016-08-26 08:13:04 -070078 ndk_stdlib = "armeabi-v7a"
79 ndk_gccdir = ndk_target
80 } else if (target_cpu == "mips64el") {
81 ndk_target = "mips64el-linux-android"
mtklein6ef69992016-09-14 06:12:09 -070082 ndk_platform = "android-${ndk_api}/arch-mips64"
mtklein349cece2016-08-26 08:13:04 -070083 ndk_stdlib = "mips64"
84 ndk_gccdir = ndk_target
85 } else if (target_cpu == "mipsel") {
86 ndk_target = "mipsel-linux-android"
mtklein6ef69992016-09-14 06:12:09 -070087 ndk_platform = "android-${ndk_api}/arch-mips"
mtklein349cece2016-08-26 08:13:04 -070088 ndk_stdlib = "mips"
89 ndk_gccdir = ndk_target
90 } else if (target_cpu == "x64") {
91 ndk_target = "x86_64-linux-android"
mtklein6ef69992016-09-14 06:12:09 -070092 ndk_platform = "android-${ndk_api}/arch-x86_64"
mtklein349cece2016-08-26 08:13:04 -070093 ndk_stdlib = "x86_64"
94 ndk_gccdir = ndk_stdlib
95 } else if (target_cpu == "x86") {
96 ndk_target = "i686-linux-android"
mtklein6ef69992016-09-14 06:12:09 -070097 ndk_platform = "android-${ndk_api}/arch-x86"
mtklein349cece2016-08-26 08:13:04 -070098 ndk_stdlib = "x86"
99 ndk_gccdir = ndk_stdlib
mtklein7d6fb2c2016-08-25 14:50:44 -0700100 }
101}
102
mtklein5db44aa2016-07-29 09:10:31 -0700103# A component is either a static or a shared library.
mtklein7fbfbbe2016-07-21 12:25:45 -0700104template("component") {
mtklein5db44aa2016-07-29 09:10:31 -0700105 _component_mode = "static_library"
mtklein7fbfbbe2016-07-21 12:25:45 -0700106 if (is_component_build) {
107 _component_mode = "shared_library"
108 }
109
110 target(_component_mode, target_name) {
111 forward_variables_from(invoker, "*")
112 }
113}
114
115# Default configs
halcanary19a97202016-08-03 15:08:04 -0700116default_configs = [
117 "//gn:default",
118 "//gn:no_rtti",
119]
mtklein7fbfbbe2016-07-21 12:25:45 -0700120if (!is_debug) {
halcanary19a97202016-08-03 15:08:04 -0700121 default_configs += [ "//gn:release" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700122}
mtklein88a7ac02016-09-14 11:16:49 -0700123if (!is_official_build) {
124 default_configs += [ "//gn:debug_symbols" ]
125}
mtklein7fbfbbe2016-07-21 12:25:45 -0700126
127set_defaults("executable") {
halcanary19a97202016-08-03 15:08:04 -0700128 configs = default_configs + [ "//gn:executable" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700129}
130
131set_defaults("source_set") {
halcanary19a97202016-08-03 15:08:04 -0700132 configs = default_configs
mtklein7fbfbbe2016-07-21 12:25:45 -0700133}
134
135set_defaults("static_library") {
halcanary19a97202016-08-03 15:08:04 -0700136 configs = default_configs
mtklein7fbfbbe2016-07-21 12:25:45 -0700137}
138
139set_defaults("shared_library") {
halcanary19a97202016-08-03 15:08:04 -0700140 configs = default_configs
mtklein7fbfbbe2016-07-21 12:25:45 -0700141}
142
143set_defaults("component") {
halcanary19a97202016-08-03 15:08:04 -0700144 configs = default_configs
mtklein9b8583d2016-08-24 17:32:30 -0700145 if (!is_component_build) {
146 complete_static_lib = true
147 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700148}
149
herbb6318bf2016-09-16 13:29:57 -0700150if (is_win) {
151 # Windows tool chain
152 set_default_toolchain("//gn:msvc")
153} else {
154 # GCC-like toolchains, including Clang.
155 set_default_toolchain("//gn:gcc_like")
156}