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
6import("../../gn/skia.gni")
7import("../third_party.gni")
8import("icu.gni")
9
10declare_args() {
11  skia_use_system_icu = is_official_build
12}
13
14if (skia_use_system_icu) {
15  system("icu") {
16    libs = [ "icuuc" ]
17    defines = [ "U_USING_ICU_NAMESPACE=0" ]
18  }
19} else {
20  if (target_cpu == "wasm") {
21    data_assembly = "$target_gen_dir/icudtl_dat.cpp"
22  } else {
23    data_assembly = "$target_gen_dir/icudtl_dat.S"
24  }
25  data_dir = "../externals/icu/"
26  if (target_cpu == "wasm") {
27    # Use a super super super stripped down version for wasm,
28    # which is the same thing flutter is using.
29    data_dir += "flutter"
30  } else if (is_android) {
31    data_dir += "android"
32  } else if (is_ios) {
33    data_dir += "ios"
34  } else {
35    data_dir += "common"
36  }
37  action("make_data_assembly") {
38    if (target_cpu == "wasm") {
39      _u_icu_version_major_num =
40          "65"  # defined in source/common/unicode/uvernum.h
41      script = "make_data_cpp.py"
42      inputs = [ "$data_dir/icudtl.dat" ]
43      outputs = [ data_assembly ]
44      args = [
45        "icudt${_u_icu_version_major_num}_dat",
46        rebase_path(inputs[0], root_build_dir),
47        rebase_path(data_assembly, root_build_dir),
48      ]
49    } else {
50      script = "../externals/icu/scripts/make_data_assembly.py"
51      inputs = [ "$data_dir/icudtl.dat" ]
52      outputs = [ "$data_assembly" ]
53      args = [
54        rebase_path(inputs[0], root_build_dir),
55        rebase_path(data_assembly, root_build_dir),
56      ]
57      if (is_mac || is_ios) {
58        args += [ "--mac" ]
59      }
60    }
61  }
62
63  third_party("icu") {
64    public_include_dirs = [
65      "../externals/icu/source/common",
66      "../externals/icu/source/i18n",
67      ".",
68    ]
69    public_defines = [
70      "U_USING_ICU_NAMESPACE=0",
71      "U_DISABLE_RENAMING",
72      "SK_USING_THIRD_PARTY_ICU",
73    ]
74    configs = [ "//gn/portable:add_rtti" ]
75    defines = [
76      # http://userguide.icu-project.org/howtouseicu
77      "U_COMMON_IMPLEMENTATION",
78      "U_STATIC_IMPLEMENTATION",
79      "U_ENABLE_DYLOAD=0",
80      "U_I18N_IMPLEMENTATION",
81
82      # If we don't set this to zero, ICU will set it to 600,
83      # which makes Macs set _POSIX_C_SOURCE=200112L,
84      # which makes Macs set __DARWIN_C_LEVEL=_POSIX_C_SOURCE instead of =__DARWIN_C_FULL,
85      # which makes <time.h> not expose timespec_get,
86      # which makes recent libc++ <ctime> not #include-able with -std=c++17.
87      "_XOPEN_SOURCE=0",
88    ]
89    if (target_cpu == "wasm") {
90      # Tell ICU that we are a 32 bit platform, otherwise,
91      # double-conversion-utils.h doesn't know how to operate.
92      defines += [ "__i386__" ]
93    }
94    sources = icu_sources
95    if (is_win) {
96      deps = [ ":icudata" ]
97      public_defines += [
98        "U_NOEXCEPT=",
99        "U_STATIC_IMPLEMENTATION",
100      ]
101      libs = [ "Advapi32.lib" ]
102      sources += [
103        "../externals/icu/source/stubdata/stubdata.cpp",
104        "SkLoadICU.cpp",
105      ]
106    } else {
107      sources += [ "$data_assembly" ]
108      deps = [ ":make_data_assembly" ]
109    }
110  }
111
112  copy("icudata") {
113    sources = [ "../externals/icu/common/icudtl.dat" ]
114    outputs = [ "$root_out_dir/icudtl.dat" ]
115    data = [ "$root_out_dir/icudtl.dat" ]
116  }
117}
118