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