xref: /aosp_15_r20/external/skia/modules/skunicode/BUILD.gn (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1# Copyright 2021 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/icu/icu.gni")
8import("skunicode.gni")
9
10declare_args() {
11  skia_use_runtime_icu = false
12  skunicode_tests_enabled = true
13}
14
15if (skia_use_icu || skia_use_client_icu || skia_use_libgrapheme ||
16    skia_use_icu4x) {
17  config("public_config") {
18    defines = [ "SK_UNICODE_AVAILABLE" ]
19    if (skia_use_icu) {
20      defines += [ "SK_UNICODE_ICU_IMPLEMENTATION" ]
21    }
22    if (skia_use_client_icu) {
23      defines += [ "SK_UNICODE_CLIENT_IMPLEMENTATION" ]
24    }
25    if (skia_use_libgrapheme) {
26      defines += [ "SK_UNICODE_LIBGRAPHEME_IMPLEMENTATION" ]
27    }
28    if (skia_use_icu4x) {
29      defines += [ "SK_UNICODE_ICU4X_IMPLEMENTATION" ]
30    }
31  }
32
33  config("cpp20") {
34    if (is_win) {
35      cflags_cc = [ "/std:c++20" ]
36    } else {
37      cflags_cc = [ "-std=c++20" ]
38    }
39  }
40
41  config("module") {
42    defines = [ "SKUNICODE_IMPLEMENTATION=1" ]
43    if (is_component_build) {
44      defines += [ "SKUNICODE_DLL" ]
45    }
46  }
47
48  component("skunicode_core") {
49    check_includes = false
50    deps = [ "../..:skia" ]
51    configs += [
52      ":module",
53      "../../:skia_private",
54      "../../third_party/icu/config:no_cxx",
55    ]
56    sources = skia_unicode_sources
57  }
58
59  if (skia_use_icu) {
60    component("skunicode_icu") {
61      check_includes = false
62      deps = [
63        ":skunicode_core",
64        "../..:skia",
65      ]
66      configs += [
67        ":module",
68        "../../:skia_private",
69        "../../third_party/icu/config:no_cxx",
70      ]
71
72      # These are explicitly *not* public defines because we don't want them
73      # to leak to dependents.
74      defines = [ "U_USING_ICU_NAMESPACE=0" ]
75      if (!skia_use_system_icu) {
76        defines += [ "U_DISABLE_RENAMING=1" ]
77      }
78
79      sources = skia_unicode_icu_bidi_sources
80      sources += skia_unicode_bidi_full_sources
81      sources += skia_unicode_icu_sources
82
83      # only available for Android at the moment
84      if (skia_use_runtime_icu && (is_android || is_linux)) {
85        sources += skia_unicode_runtime_icu_sources
86        defines += [ "SK_UNICODE_RUNTIME_ICU_AVAILABLE" ]
87        deps += [ "//third_party/icu:headers" ]
88      } else {
89        sources += skia_unicode_builtin_icu_sources
90        deps += [ "//third_party/icu" ]
91      }
92    }
93  }
94
95  if (skia_use_client_icu) {
96    component("skunicode_client_icu") {
97      check_includes = false
98      deps = [
99        ":skunicode_core",
100        "../..:skia",
101      ]
102      configs += [
103        ":module",
104        "../../:skia_private",
105        "../../third_party/icu/config:no_cxx",
106      ]
107      defines = [
108        # In order to use the bidi_subset at the same time as "full ICU", we must have
109        # compiled icu with the given defines also being set. This is to make sure the functions
110        # we call are given a suffix of "_skia" to prevent ODR violations if this "subset of ICU"
111        # is compiled alongside a full ICU build also.
112        # See https://chromium.googlesource.com/chromium/deps/icu.git/+/d94ab131bc8fef3bc17f356a628d8e4cd44d65d9/source/common/unicode/uversion.h
113        # for how these are used.
114        "U_DISABLE_RENAMING=0",
115        "U_USING_ICU_NAMESPACE=0",
116        "U_LIB_SUFFIX_C_NAME=_skia",
117        "U_HAVE_LIB_SUFFIX=1",
118        "U_DISABLE_VERSION_SUFFIX=1",
119      ]
120
121      sources = skia_unicode_icu_bidi_sources
122      sources += skia_unicode_bidi_subset_sources
123      sources += skia_unicode_client_icu_sources
124      deps += [ skia_icu_bidi_third_party_dir ]
125    }
126  }
127
128  if (skia_use_libgrapheme) {
129    component("skunicode_libgrapheme") {
130      check_includes = false
131      deps = [
132        ":skunicode_core",
133        "../..:skia",
134      ]
135      configs += [
136        ":module",
137        "../../:skia_private",
138        "../../third_party/icu/config:no_cxx",
139      ]
140      defines = [
141        "U_DISABLE_RENAMING=0",
142        "U_USING_ICU_NAMESPACE=0",
143        "U_LIB_SUFFIX_C_NAME=_skia",
144        "U_HAVE_LIB_SUFFIX=1",
145        "U_DISABLE_VERSION_SUFFIX=1",
146      ]
147
148      sources = skia_unicode_icu_bidi_sources
149      sources += skia_unicode_bidi_subset_sources
150
151      sources += skia_unicode_libgrapheme_sources
152      deps += [
153        skia_icu_bidi_third_party_dir,
154        skia_libgrapheme_third_party_dir,
155      ]
156    }
157  }
158
159  if (skia_use_icu4x) {
160    component("skunicode_icu4x") {
161      check_includes = false
162      deps = [
163        ":skunicode_core",
164        "../..:skia",
165      ]
166      configs += [
167        ":module",
168        "../../:skia_private",
169        "../../third_party/icu/config:no_cxx",
170      ]
171
172      sources = skia_unicode_icu4x_sources
173
174      deps += [ "//third_party/icu4x" ]
175    }
176  }
177
178  group("skunicode") {
179    public_configs = [ ":public_config" ]
180    public_deps = [ ":skunicode_core" ]
181
182    # We have these different flavors of skunicode as independent components because
183    # we have to set different defines for different builds of ICU.
184    if (skia_use_icu) {
185      public_deps += [ ":skunicode_icu" ]
186    }
187    if (skia_use_client_icu) {
188      public_deps += [ ":skunicode_client_icu" ]
189    }
190    if (skia_use_libgrapheme) {
191      public_deps += [ ":skunicode_libgrapheme" ]
192    }
193    if (skia_use_icu4x) {
194      public_deps += [ ":skunicode_icu4x" ]
195    }
196  }
197
198  if (defined(is_skia_standalone) && skia_enable_tools) {
199    skia_source_set("tests") {
200      if (skunicode_tests_enabled &&
201          (skia_use_icu || skia_use_libgrapheme || skia_use_icu4x)) {
202        testonly = true
203        deps = [
204          ":skunicode",
205          "../..:skia",
206          "../..:test",
207        ]
208        sources = skia_unicode_tests
209        deps += [ skia_icu_bidi_third_party_dir ]
210      } else {
211        sources = []
212      }
213    }
214  }
215} else {
216  group("skunicode") {
217  }
218  group("tests") {
219  }
220}
221