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
6is_skia_standalone = true
7
8# It's best to keep the names and defaults of is_foo flags consistent with Chrome.
9
10declare_args() {
11  is_official_build = false
12  is_component_build = false
13  ndk = ""
14
15  # It's nice to keep ndk_api set to what Clank targets, but probably no big deal if we can't.
16  if (target_cpu == "x86" || target_cpu == "arm") {
17    ndk_api = 16
18  } else {
19    ndk_api = 21
20  }
21
22  sanitize = ""
23
24  ar = "ar"
25  cc = "cc"
26  cxx = "c++"
27
28  win_sdk = "C:/Program Files (x86)/Windows Kits/10"
29  win_sdk_version = ""
30
31  win_vc = ""
32  win_toolchain_version = ""
33
34  clang_win = ""
35
36  skia_moltenvk_path = ""
37}
38declare_args() {
39  is_debug = !is_official_build
40}
41
42assert(!(is_debug && is_official_build))
43
44if (target_cpu == "wasm") {
45  target_os = "wasm"
46}
47
48# Platform detection
49if (target_os == "") {
50  target_os = host_os
51  if (ndk != "") {
52    target_os = "android"
53  }
54}
55if (current_os == "") {
56  current_os = target_os
57}
58
59is_android = current_os == "android"
60is_fuchsia = current_os == "fuchsia"
61is_ios = current_os == "ios" || current_os == "tvos"
62is_tvos = current_os == "tvos"
63is_linux = current_os == "linux"
64is_mac = current_os == "mac"
65is_win = current_os == "win"
66
67if (target_cpu == "") {
68  target_cpu = host_cpu
69  if (is_android || is_ios) {
70    target_cpu = "arm64"
71  }
72}
73if (target_cpu == "x86_64") {
74  target_cpu = "x64"
75}
76if (current_cpu == "") {
77  current_cpu = target_cpu
78}
79
80is_clang = is_android || is_ios || is_mac ||
81           (cc == "clang" && cxx == "clang++") || clang_win != ""
82if (!is_clang && !is_win) {
83  is_clang = exec_script("gn/is_clang.py",
84                         [
85                           cc,
86                           cxx,
87                         ],
88                         "value")
89}
90
91if (is_android) {
92  ndk_host = ""
93  ndk_target = ""
94  ndk_platform = ""
95  ndk_stdlib = ""
96  ndk_gccdir = ""
97  ndk_gdbserver = ""
98
99  if (host_os == "linux") {
100    ndk_host = "linux-x86_64"
101  } else if (host_os == "mac") {
102    ndk_host = "darwin-x86_64"
103  } else if (host_os == "win") {
104    ndk_host = "windows-x86_64"
105  }
106
107  if (target_cpu == "arm64") {
108    ndk_target = "aarch64-linux-android"
109    ndk_platform = "android-${ndk_api}/arch-arm64"
110    ndk_stdlib = "arm64-v8a"
111    ndk_gccdir = ndk_target
112    ndk_gdbserver = "prebuilt/android-arm64/gdbserver/gdbserver"
113  } else if (target_cpu == "arm") {
114    ndk_target = "arm-linux-androideabi"
115    ndk_platform = "android-${ndk_api}/arch-arm"
116    ndk_stdlib = "armeabi-v7a"
117    ndk_gccdir = ndk_target
118    ndk_gdbserver = "prebuilt/android-arm/gdbserver/gdbserver"
119  } else if (target_cpu == "x64") {
120    ndk_target = "x86_64-linux-android"
121    ndk_platform = "android-${ndk_api}/arch-x86_64"
122    ndk_stdlib = "x86_64"
123    ndk_gccdir = ndk_stdlib
124    ndk_gdbserver = "prebuilt/android-x86_64/gdbserver/gdbserver"
125  } else if (target_cpu == "x86") {
126    ndk_target = "i686-linux-android"
127    ndk_platform = "android-${ndk_api}/arch-x86"
128    ndk_stdlib = "x86"
129    ndk_gccdir = ndk_stdlib
130    ndk_gdbserver = "prebuilt/android-x86/gdbserver/gdbserver"
131  }
132}
133
134msvc = ""
135if (target_os == "win") {
136  # By default we look for 2017 (Enterprise, Pro, and Community), then 2015. If MSVC is installed in a
137  # non-default location, you can set win_vc to inform us where it is.
138  vc_2017_ent_default =
139      "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC"
140  vc_2017_pro_default =
141      "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\VC"
142  vc_2017_com_default =
143      "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC"
144  vc_2017_bt_default =
145      "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC"
146  vc_2015_default = "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC"
147
148  if (win_vc == "") {
149    if ("True" == exec_script("//gn/checkdir.py",
150                              [ "$vc_2017_ent_default" ],
151                              "trim string")) {
152      win_vc = vc_2017_ent_default
153      msvc = 2017
154    } else if ("True" == exec_script("//gn/checkdir.py",
155                                     [ "$vc_2017_pro_default" ],
156                                     "trim string")) {
157      win_vc = vc_2017_pro_default
158      msvc = 2017
159    } else if ("True" == exec_script("//gn/checkdir.py",
160                                     [ "$vc_2017_com_default" ],
161                                     "trim string")) {
162      win_vc = vc_2017_com_default
163      msvc = 2017
164    } else if ("True" == exec_script("//gn/checkdir.py",
165                                     [ "$vc_2017_bt_default" ],
166                                     "trim string")) {
167      win_vc = vc_2017_bt_default
168      msvc = 2017
169    } else if ("True" == exec_script("//gn/checkdir.py",
170                                     [ "$vc_2015_default" ],
171                                     "trim string")) {
172      win_vc = vc_2015_default
173      msvc = 2015
174    }
175  }
176  assert(win_vc != "")  # Could not find VC installation. Set win_vc to your VC directory.
177
178  if (msvc == "") {
179    if ("True" ==
180        exec_script("//gn/checkdir.py", [ "$win_vc/Tools" ], "trim string")) {
181      msvc = 2017
182    } else {
183      msvc = 2015
184    }
185  }
186}
187
188if (target_os == "win") {
189  if (msvc == 2017 && win_toolchain_version == "") {
190    win_toolchain_version = exec_script("//gn/highest_version_dir.py",
191                                        [
192                                          "$win_vc/Tools/MSVC",
193                                          "[0-9]{2}\.[0-9]{2}\.[0-9]{5}",
194                                        ],
195                                        "trim string")
196  }
197  if (win_sdk_version == "") {
198    win_sdk_version = exec_script("//gn/highest_version_dir.py",
199                                  [
200                                    "$win_sdk/Include",
201                                    "[0-9]{2}\.[0-9]\.[0-9]{5}\.[0-9]",
202                                  ],
203                                  "trim string")
204  }
205}
206
207# A component is either a static or a shared library.
208template("component") {
209  _component_mode = "static_library"
210  if (is_component_build) {
211    _component_mode = "shared_library"
212  }
213
214  target(_component_mode, target_name) {
215    forward_variables_from(invoker, "*")
216  }
217}
218
219# Default configs
220default_configs = [
221  "//gn:default",
222  "//gn:no_exceptions",
223  "//gn:no_rtti",
224]
225if (!is_debug) {
226  default_configs += [
227    "//gn:optimize",
228    "//gn:NDEBUG",
229  ]
230}
231if (!is_official_build) {
232  default_configs += [
233    "//gn:debug_symbols",
234    "//gn:warnings",
235  ]
236}
237default_configs += [
238  "//gn:warnings_except_public_headers",
239  "//gn:extra_flags",
240]
241
242set_defaults("executable") {
243  configs = [ "//gn:executable" ] + default_configs
244}
245
246set_defaults("source_set") {
247  configs = default_configs
248}
249
250set_defaults("static_library") {
251  configs = default_configs
252}
253
254set_defaults("shared_library") {
255  configs = default_configs
256}
257
258set_defaults("component") {
259  configs = default_configs
260  if (!is_component_build) {
261    complete_static_lib = true
262  }
263}
264
265if (is_win) {
266  # Windows tool chain
267  set_default_toolchain("//gn/toolchain:msvc")
268  default_toolchain_name = "msvc"
269  host_toolchain = "msvc"
270} else {
271  # GCC-like toolchains, including Clang.
272  set_default_toolchain("//gn/toolchain:gcc_like")
273  default_toolchain_name = "gcc_like"
274  host_toolchain = "gcc_like_host"
275}
276