blob: d7c3439b001193c3f78bc01ec006b95bd6ce536c [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
Mike Klein3669a822017-03-03 10:55:02 -05006is_skia_standalone = true
7
mtklein7fbfbbe2016-07-21 12:25:45 -07008# It's best to keep the names and defaults of is_foo flags consistent with Chrome.
9
10declare_args() {
mtklein88a7ac02016-09-14 11:16:49 -070011 is_official_build = false
mtklein7fbfbbe2016-07-21 12:25:45 -070012 is_component_build = false
mtklein7d6fb2c2016-08-25 14:50:44 -070013 ndk = ""
Mike Klein9c1c8922017-11-28 14:31:14 -050014
15 # It's nice to keep ndk_api set to what Clank targets, but probably no big deal if we can't.
Mike Kleinf32b27d2017-12-05 08:50:20 -050016 if (target_cpu == "x86" || target_cpu == "arm") {
Mike Klein9c1c8922017-11-28 14:31:14 -050017 ndk_api = 16
Mike Kleinb7ce80b2016-12-14 13:17:53 -050018 } else {
19 ndk_api = 21
20 }
Mike Klein9c1c8922017-11-28 14:31:14 -050021
mtklein2b3c2a32016-09-08 08:39:34 -070022 sanitize = ""
Ethan Nicholas762466e2017-06-29 10:03:38 -040023
24 ar = "ar"
25 cc = "cc"
26 cxx = "c++"
27
Brian Osman852ca312017-12-07 16:16:21 -050028 win_sdk = "C:/Program Files (x86)/Windows Kits/10"
29 win_sdk_version = ""
30
31 win_vc = ""
32 win_toolchain_version = ""
33
Mike Kleinc722f792017-07-31 11:57:21 -040034 clang_win = ""
mtklein7fbfbbe2016-07-21 12:25:45 -070035}
mtklein88a7ac02016-09-14 11:16:49 -070036declare_args() {
37 is_debug = !is_official_build
38}
39
40assert(!(is_debug && is_official_build))
mtklein7fbfbbe2016-07-21 12:25:45 -070041
Kevin Lubickebf648e2017-09-21 13:45:16 -040042if (target_cpu == "wasm") {
43 target_os = "wasm"
44}
45
mtklein7fbfbbe2016-07-21 12:25:45 -070046# Platform detection
47if (target_os == "") {
48 target_os = host_os
mtklein7d6fb2c2016-08-25 14:50:44 -070049 if (ndk != "") {
50 target_os = "android"
51 }
mtklein7fbfbbe2016-07-21 12:25:45 -070052}
53if (current_os == "") {
54 current_os = target_os
55}
56
57is_android = current_os == "android"
58is_fuchsia = current_os == "fuchsia"
Matthew Leibowitz3150ec62017-03-14 16:22:32 -040059is_ios = current_os == "ios" || current_os == "tvos"
60is_tvos = current_os == "tvos"
mtklein7fbfbbe2016-07-21 12:25:45 -070061is_linux = current_os == "linux"
62is_mac = current_os == "mac"
63is_win = current_os == "win"
64
mtklein349cece2016-08-26 08:13:04 -070065if (target_cpu == "") {
66 target_cpu = host_cpu
Mike Klein7d302882016-11-03 14:06:31 -040067 if (is_android || is_ios) {
mtklein349cece2016-08-26 08:13:04 -070068 target_cpu = "arm64"
69 }
70}
Mike Kleinb48fd3c2017-01-23 11:58:53 -050071if (target_cpu == "x86_64") {
72 target_cpu = "x64"
73}
mtklein349cece2016-08-26 08:13:04 -070074if (current_cpu == "") {
75 current_cpu = target_cpu
76}
mtklein7fbfbbe2016-07-21 12:25:45 -070077
Kevin Lubickebf648e2017-09-21 13:45:16 -040078is_clang = is_android || is_ios || is_mac ||
79 (cc == "clang" && cxx == "clang++") || clang_win != ""
Mike Kleinc722f792017-07-31 11:57:21 -040080if (!is_clang && !is_win) {
81 is_clang = exec_script("gn/is_clang.py",
82 [
83 cc,
84 cxx,
85 ],
86 "value")
87}
88
mtklein7d6fb2c2016-08-25 14:50:44 -070089if (is_android) {
90 ndk_host = ""
91 ndk_target = ""
92 ndk_platform = ""
93 ndk_stdlib = ""
mtklein6ef69992016-09-14 06:12:09 -070094 ndk_gccdir = ""
Derek Sollenberger70120c72017-01-05 11:39:04 -050095 ndk_gdbserver = ""
mtklein6ef69992016-09-14 06:12:09 -070096
mtklein349cece2016-08-26 08:13:04 -070097 if (host_os == "linux") {
mtklein7d6fb2c2016-08-25 14:50:44 -070098 ndk_host = "linux-x86_64"
mtklein349cece2016-08-26 08:13:04 -070099 } else if (host_os == "mac") {
100 ndk_host = "darwin-x86_64"
Mike Klein82364ba2016-10-24 16:49:15 -0400101 } else if (host_os == "win") {
102 ndk_host = "windows-x86_64"
mtklein7d6fb2c2016-08-25 14:50:44 -0700103 }
mtklein349cece2016-08-26 08:13:04 -0700104
mtklein7d6fb2c2016-08-25 14:50:44 -0700105 if (target_cpu == "arm64") {
106 ndk_target = "aarch64-linux-android"
mtklein6ef69992016-09-14 06:12:09 -0700107 ndk_platform = "android-${ndk_api}/arch-arm64"
mtklein7d6fb2c2016-08-25 14:50:44 -0700108 ndk_stdlib = "arm64-v8a"
mtklein349cece2016-08-26 08:13:04 -0700109 ndk_gccdir = ndk_target
Derek Sollenberger70120c72017-01-05 11:39:04 -0500110 ndk_gdbserver = "prebuilt/android-arm64/gdbserver/gdbserver"
mtklein349cece2016-08-26 08:13:04 -0700111 } else if (target_cpu == "arm") {
112 ndk_target = "arm-linux-androideabi"
mtklein6ef69992016-09-14 06:12:09 -0700113 ndk_platform = "android-${ndk_api}/arch-arm"
mtklein349cece2016-08-26 08:13:04 -0700114 ndk_stdlib = "armeabi-v7a"
115 ndk_gccdir = ndk_target
Derek Sollenberger70120c72017-01-05 11:39:04 -0500116 ndk_gdbserver = "prebuilt/android-arm/gdbserver/gdbserver"
mtklein349cece2016-08-26 08:13:04 -0700117 } else if (target_cpu == "x64") {
118 ndk_target = "x86_64-linux-android"
mtklein6ef69992016-09-14 06:12:09 -0700119 ndk_platform = "android-${ndk_api}/arch-x86_64"
mtklein349cece2016-08-26 08:13:04 -0700120 ndk_stdlib = "x86_64"
121 ndk_gccdir = ndk_stdlib
Derek Sollenberger70120c72017-01-05 11:39:04 -0500122 ndk_gdbserver = "prebuilt/android-x86_64/gdbserver/gdbserver"
mtklein349cece2016-08-26 08:13:04 -0700123 } else if (target_cpu == "x86") {
124 ndk_target = "i686-linux-android"
mtklein6ef69992016-09-14 06:12:09 -0700125 ndk_platform = "android-${ndk_api}/arch-x86"
mtklein349cece2016-08-26 08:13:04 -0700126 ndk_stdlib = "x86"
127 ndk_gccdir = ndk_stdlib
Derek Sollenberger70120c72017-01-05 11:39:04 -0500128 ndk_gdbserver = "prebuilt/android-x86/gdbserver/gdbserver"
mtklein7d6fb2c2016-08-25 14:50:44 -0700129 }
130}
131
Brian Osman852ca312017-12-07 16:16:21 -0500132msvc = ""
133if (target_os == "win") {
Brian Osmanc50f8e02018-02-08 10:24:09 -0500134 # By default we look for 2017 (Pro & Community), then 2015. If MSVC is installed in a
135 # non-default location, you can set win_vc to inform us where it is.
136 vc_2017_pro_default =
Brian Osman852ca312017-12-07 16:16:21 -0500137 "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC"
Brian Osmanc50f8e02018-02-08 10:24:09 -0500138 vc_2017_com_default =
139 "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC"
Hal Canary28728e42018-02-14 11:25:31 -0500140 vc_2017_bt_default =
141 "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC"
Brian Osman852ca312017-12-07 16:16:21 -0500142 vc_2015_default = "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC"
143
144 if (win_vc == "") {
Brian Osmanc50f8e02018-02-08 10:24:09 -0500145 if ("True" == exec_script("//gn/checkdir.py",
146 [ "$vc_2017_pro_default" ],
147 "trim string")) {
148 win_vc = vc_2017_pro_default
149 msvc = 2017
150 } else if ("True" == exec_script("//gn/checkdir.py",
151 [ "$vc_2017_com_default" ],
152 "trim string")) {
153 win_vc = vc_2017_com_default
Brian Osman852ca312017-12-07 16:16:21 -0500154 msvc = 2017
155 } else if ("True" == exec_script("//gn/checkdir.py",
Hal Canary28728e42018-02-14 11:25:31 -0500156 [ "$vc_2017_bt_default" ],
157 "trim string")) {
158 win_vc = vc_2017_bt_default
159 msvc = 2017
160 } else if ("True" == exec_script("//gn/checkdir.py",
Brian Osman852ca312017-12-07 16:16:21 -0500161 [ "$vc_2015_default" ],
162 "trim string")) {
163 win_vc = vc_2015_default
164 msvc = 2015
165 }
166 }
167 assert(win_vc != "") # Could not find VC installation. Set win_vc to your VC directory.
168
169 if (msvc == "") {
170 if ("True" ==
171 exec_script("//gn/checkdir.py", [ "$win_vc/Tools" ], "trim string")) {
172 msvc = 2017
173 } else {
174 msvc = 2015
175 }
176 }
177}
178
Mike Klein409506c2017-12-06 16:47:41 -0500179if (target_os == "win") {
180 if (msvc == 2017 && win_toolchain_version == "") {
181 win_toolchain_version = exec_script("//gn/highest_version_dir.py",
Brian Osman5c548922017-12-11 14:59:03 -0500182 [
183 "$win_vc/Tools/MSVC",
184 "[0-9]{2}\.[0-9]{2}\.[0-9]{5}",
185 ],
Mike Klein409506c2017-12-06 16:47:41 -0500186 "trim string")
187 }
188 if (win_sdk_version == "") {
189 win_sdk_version = exec_script("//gn/highest_version_dir.py",
Brian Osman5c548922017-12-11 14:59:03 -0500190 [
191 "$win_sdk/Include",
192 "[0-9]{2}\.[0-9]\.[0-9]{5}\.[0-9]",
193 ],
Mike Klein409506c2017-12-06 16:47:41 -0500194 "trim string")
195 }
196}
197
mtklein5db44aa2016-07-29 09:10:31 -0700198# A component is either a static or a shared library.
mtklein7fbfbbe2016-07-21 12:25:45 -0700199template("component") {
mtklein5db44aa2016-07-29 09:10:31 -0700200 _component_mode = "static_library"
mtklein7fbfbbe2016-07-21 12:25:45 -0700201 if (is_component_build) {
202 _component_mode = "shared_library"
203 }
204
205 target(_component_mode, target_name) {
206 forward_variables_from(invoker, "*")
207 }
208}
209
210# Default configs
halcanary19a97202016-08-03 15:08:04 -0700211default_configs = [
212 "//gn:default",
Mike Klein6e55fef2016-10-26 11:41:47 -0400213 "//gn:no_exceptions",
halcanary19a97202016-08-03 15:08:04 -0700214 "//gn:no_rtti",
Mike Kleinc7165c22016-10-12 23:58:06 -0400215 "//gn:warnings",
Mike Klein50500ad2016-11-16 12:13:44 -0500216 "//gn:warnings_except_public_headers",
halcanary19a97202016-08-03 15:08:04 -0700217]
Mike Klein09008ff2017-01-21 15:35:10 +0000218if (!is_debug) {
halcanary19a97202016-08-03 15:08:04 -0700219 default_configs += [ "//gn:release" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700220}
mtklein88a7ac02016-09-14 11:16:49 -0700221if (!is_official_build) {
222 default_configs += [ "//gn:debug_symbols" ]
223}
Mike Klein121563e2016-10-04 17:09:13 -0400224default_configs += [ "//gn:extra_flags" ]
mtklein7fbfbbe2016-07-21 12:25:45 -0700225
226set_defaults("executable") {
Mike Klein121563e2016-10-04 17:09:13 -0400227 configs = [ "//gn:executable" ] + default_configs
mtklein7fbfbbe2016-07-21 12:25:45 -0700228}
229
230set_defaults("source_set") {
halcanary19a97202016-08-03 15:08:04 -0700231 configs = default_configs
mtklein7fbfbbe2016-07-21 12:25:45 -0700232}
233
234set_defaults("static_library") {
halcanary19a97202016-08-03 15:08:04 -0700235 configs = default_configs
mtklein7fbfbbe2016-07-21 12:25:45 -0700236}
237
238set_defaults("shared_library") {
halcanary19a97202016-08-03 15:08:04 -0700239 configs = default_configs
mtklein7fbfbbe2016-07-21 12:25:45 -0700240}
241
242set_defaults("component") {
halcanary19a97202016-08-03 15:08:04 -0700243 configs = default_configs
mtklein9b8583d2016-08-24 17:32:30 -0700244 if (!is_component_build) {
245 complete_static_lib = true
246 }
mtklein7fbfbbe2016-07-21 12:25:45 -0700247}
248
herbb6318bf2016-09-16 13:29:57 -0700249if (is_win) {
250 # Windows tool chain
Ethan Nicholas762466e2017-06-29 10:03:38 -0400251 set_default_toolchain("//gn/toolchain:msvc")
252 default_toolchain_name = "msvc"
253 host_toolchain = "msvc"
herbb6318bf2016-09-16 13:29:57 -0700254} else {
255 # GCC-like toolchains, including Clang.
Ethan Nicholas762466e2017-06-29 10:03:38 -0400256 set_default_toolchain("//gn/toolchain:gcc_like")
257 default_toolchain_name = "gcc_like"
258 host_toolchain = "gcc_like_host"
herbb6318bf2016-09-16 13:29:57 -0700259}