mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 1 | # 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 | |
| 8 | declare_args() { |
| 9 | is_debug = true |
| 10 | is_component_build = false |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 11 | ndk = "" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 12 | } |
| 13 | |
| 14 | # Platform detection |
| 15 | if (target_os == "") { |
| 16 | target_os = host_os |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 17 | if (ndk != "") { |
| 18 | target_os = "android" |
| 19 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 20 | } |
| 21 | if (current_os == "") { |
| 22 | current_os = target_os |
| 23 | } |
| 24 | |
| 25 | is_android = current_os == "android" |
| 26 | is_fuchsia = current_os == "fuchsia" |
| 27 | is_ios = current_os == "ios" |
| 28 | is_linux = current_os == "linux" |
| 29 | is_mac = current_os == "mac" |
| 30 | is_win = current_os == "win" |
| 31 | |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 32 | if (target_cpu == "") { |
| 33 | target_cpu = host_cpu |
| 34 | if (is_android) { |
| 35 | target_cpu = "arm64" |
| 36 | } |
| 37 | } |
| 38 | if (current_cpu == "") { |
| 39 | current_cpu = target_cpu |
| 40 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 41 | |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 42 | if (is_android) { |
| 43 | ndk_host = "" |
| 44 | ndk_target = "" |
| 45 | ndk_platform = "" |
| 46 | ndk_stdlib = "" |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 47 | nkd_gccdir = "" |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 48 | |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 49 | if (host_os == "linux") { |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 50 | ndk_host = "linux-x86_64" |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 51 | } else if (host_os == "mac") { |
| 52 | ndk_host = "darwin-x86_64" |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 53 | } |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 54 | |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 55 | if (target_cpu == "arm64") { |
| 56 | ndk_target = "aarch64-linux-android" |
| 57 | ndk_platform = "android-21/arch-arm64" |
| 58 | ndk_stdlib = "arm64-v8a" |
mtklein | 349cece | 2016-08-26 08:13:04 -0700 | [diff] [blame] | 59 | ndk_gccdir = ndk_target |
| 60 | } else if (target_cpu == "arm") { |
| 61 | ndk_target = "arm-linux-androideabi" |
| 62 | ndk_platform = "android-18/arch-arm" |
| 63 | ndk_stdlib = "armeabi-v7a" |
| 64 | ndk_gccdir = ndk_target |
| 65 | } else if (target_cpu == "mips64el") { |
| 66 | ndk_target = "mips64el-linux-android" |
| 67 | ndk_platform = "android-21/arch-mips64" |
| 68 | ndk_stdlib = "mips64" |
| 69 | ndk_gccdir = ndk_target |
| 70 | } else if (target_cpu == "mipsel") { |
| 71 | ndk_target = "mipsel-linux-android" |
| 72 | ndk_platform = "android-18/arch-mips" |
| 73 | ndk_stdlib = "mips" |
| 74 | ndk_gccdir = ndk_target |
| 75 | } else if (target_cpu == "x64") { |
| 76 | ndk_target = "x86_64-linux-android" |
| 77 | ndk_platform = "android-21/arch-x86_64" |
| 78 | ndk_stdlib = "x86_64" |
| 79 | ndk_gccdir = ndk_stdlib |
| 80 | } else if (target_cpu == "x86") { |
| 81 | ndk_target = "i686-linux-android" |
| 82 | ndk_platform = "android-18/arch-x86" |
| 83 | ndk_stdlib = "x86" |
| 84 | ndk_gccdir = ndk_stdlib |
mtklein | 7d6fb2c | 2016-08-25 14:50:44 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
mtklein | 5db44aa | 2016-07-29 09:10:31 -0700 | [diff] [blame] | 88 | # A component is either a static or a shared library. |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 89 | template("component") { |
mtklein | 5db44aa | 2016-07-29 09:10:31 -0700 | [diff] [blame] | 90 | _component_mode = "static_library" |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 91 | if (is_component_build) { |
| 92 | _component_mode = "shared_library" |
| 93 | } |
| 94 | |
| 95 | target(_component_mode, target_name) { |
| 96 | forward_variables_from(invoker, "*") |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | # Default configs |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 101 | default_configs = [ |
| 102 | "//gn:default", |
| 103 | "//gn:no_rtti", |
| 104 | ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 105 | if (!is_debug) { |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 106 | default_configs += [ "//gn:release" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | set_defaults("executable") { |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 110 | configs = default_configs + [ "//gn:executable" ] |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | set_defaults("source_set") { |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 114 | configs = default_configs |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | set_defaults("static_library") { |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 118 | configs = default_configs |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | set_defaults("shared_library") { |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 122 | configs = default_configs |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | set_defaults("component") { |
halcanary | 19a9720 | 2016-08-03 15:08:04 -0700 | [diff] [blame] | 126 | configs = default_configs |
mtklein | 9b8583d | 2016-08-24 17:32:30 -0700 | [diff] [blame] | 127 | if (!is_component_build) { |
| 128 | complete_static_lib = true |
| 129 | } |
mtklein | 7fbfbbe | 2016-07-21 12:25:45 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | # For now, we support GCC-like toolchains, including Clang. |
| 133 | set_default_toolchain("//gn:gcc_like") |