1# Copyright 2014 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("${skia_root_dir}/build/config/host_byteorder.gni") 6import("${skia_third_party_dir}/icu/config.gni") 7import("${skia_third_party_dir}/icu/sources.gni") 8 9if (is_android) { 10 import("${skia_root_dir}/build/config/android/rules.gni") 11} 12 13if (is_mac && !icu_is_in_fuchsia) { 14 import("${skia_root_dir}/build/config/sanitizers/sanitizers.gni") 15} 16 17assert(!icu_disable_thin_archive || !is_skia_component_build, 18 "icu_disable_thin_archive only works in static library builds") 19 20# Meta target that includes both icuuc and icui18n. Most targets want both. 21# You can depend on the individually if you need to. 22group("icu") { 23 public_deps = [ 24 ":icui18n", 25 ":icuuc", 26 ] 27} 28 29# Shared config used by ICU and all dependents. 30config("icu_config") { 31 defines = [ 32 # Tell ICU to not insert |using namespace icu;| into its headers, 33 # so that chrome's source explicitly has to use |icu::|. 34 "U_USING_ICU_NAMESPACE=0", 35 36 # We don't use ICU plugins and dyload is only necessary for them. 37 # NaCl-related builds also fail looking for dlfcn.h when it's enabled. 38 "U_ENABLE_DYLOAD=0", 39 40 # v8/Blink need to know whether Chromium's copy of ICU is used or not. 41 "USE_CHROMIUM_ICU=1", 42 43 # Enable tracing to connect to UMA but disable tracing of resource 44 # to avoid performance issues. 45 "U_ENABLE_TRACING=1", 46 "U_ENABLE_RESOURCE_TRACING=0", 47 ] 48 49 if (!is_skia_component_build) { 50 defines += [ "U_STATIC_IMPLEMENTATION" ] 51 } 52 53 include_dirs = [ 54 "source/common", 55 "source/i18n", 56 ] 57 58 if (icu_use_data_file) { 59 defines += [ "ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE" ] 60 } else { 61 defines += [ "ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC" ] 62 } 63} 64 65# Config used only by ICU code. 66config("icu_code") { 67 cflags = [] 68 defines = [ 69 "HAVE_DLOPEN=0", 70 71 # Only build encoding coverters and detectors necessary for HTML5. 72 "UCONFIG_ONLY_HTML_CONVERSION=1", 73 74 # TODO(jshin): do we still need this? 75 "UCONFIG_USE_WINDOWS_LCID_MAPPING_API=0", 76 77 # No dependency on the default platform encoding. 78 # Will cut down the code size. 79 "U_CHARSET_IS_UTF8=1", 80 ] 81 82 if (is_win) { 83 # Disable some compiler warnings. 84 cflags += [ 85 "/wd4005", # Macro redefinition. 86 "/wd4068", # Unknown pragmas. 87 "/wd4267", # Conversion from size_t on 64-bits. 88 "/utf-8", # ICU source files are in UTF-8. 89 ] 90 } else if (is_linux || is_chromeos || is_android || icu_is_in_fuchsia) { 91 cflags += [ "-Wno-unused-function" ] 92 } 93 if (is_clang) { 94 cflags += [ 95 # ICU has some code with the pattern: 96 # if (found = uprv_getWindowsTimeZoneInfo(...)) 97 "-Wno-parentheses", 98 99 # ucnv2022.cpp contains three functions that are only used when 100 # certain preprocessor defines are set. 101 # unistr.cpp also has an unused function for non-component builds. 102 "-Wno-unused-function", 103 104 # putil.cpp contains unused variables when building for iOS simulators. 105 "-Wno-unused-variable", 106 ] 107 } 108 if (is_clang || is_linux || is_chromeos || is_android || icu_is_in_fuchsia) { 109 cflags += [ 110 # ICU uses its own deprecated functions. 111 "-Wno-deprecated-declarations", 112 ] 113 } 114 if (icu_is_in_fuchsia) { 115 cflags += [ 116 # Disable spurious thread safety errors in umutex.cpp 117 "-Wno-thread-safety", 118 119 # Can probably remove the below after 120 # https://unicode-org.atlassian.net/projects/ICU/issues/ICU-20869 121 # is fixed. 122 "-Wno-implicit-int-float-conversion", 123 "-Wno-conversion", 124 125 # Used for conditional changes to the compilation process that 126 # are only needed for the Fuchsia toolchain. 127 "-DICU_IS_IN_FUCHSIA", 128 ] 129 } 130} 131 132# Config used to set default visibility to hidden. 133config("visibility_hidden") { 134 cflags = [] 135 if (is_mac || is_linux || is_chromeos || is_android || is_fuchsia) { 136 cflags += [ "-fvisibility=hidden" ] 137 } 138} 139 140template("generate_icu_component") { 141 if (icu_is_in_fuchsia) { 142 target(default_library_type, target_name) { 143 forward_variables_from(invoker, 144 "*", 145 [ 146 "testonly", 147 "visibility", 148 ]) 149 assert(fuchsia_output_name_postfix == "") 150 151 # ICU uses RTTI, replace the default "no rtti" config (if applied). 152 configs += [ 153 "${skia_root_dir}/build/config:no_rtti", 154 "${skia_root_dir}/build/config:symbol_visibility_hidden", 155 ] 156 configs -= [ 157 "${skia_root_dir}/build/config:no_rtti", 158 "${skia_root_dir}/build/config:symbol_visibility_hidden", 159 ] 160 161 configs += [ "${skia_root_dir}/build/config:rtti" ] 162 163 # These need to be applied after the main configs so the "-Wno-*" options 164 # take effect. 165 configs += [ ":icu_code" ] 166 configs += extra_configs 167 public_configs = [ ":icu_config" ] 168 } 169 } else { 170 component(target_name) { 171 forward_variables_from(invoker, 172 "*", 173 [ 174 "testonly", 175 "visibility", 176 ]) 177 if (is_fuchsia) { 178 # Fuchsia puts its own libicu*.so in /system/lib where we need to put our 179 # .so when doing component builds, so we need to give this a different name. 180 output_name = "${target_name}_cr${fuchsia_output_name_postfix}" 181 } else { 182 assert(fuchsia_output_name_postfix == "") 183 } 184 185 # ICU uses RTTI, replace the default "no rtti" config (if applied). 186 configs += [ 187 "${skia_root_dir}/build/config/compiler:no_rtti", 188 "${skia_root_dir}/build/config/compiler:chromium_code", 189 ] 190 configs -= [ 191 "${skia_root_dir}/build/config/compiler:no_rtti", 192 "${skia_root_dir}/build/config/compiler:chromium_code", 193 ] 194 configs += [ 195 "${skia_root_dir}/build/config/compiler:rtti", 196 "${skia_root_dir}/build/config/compiler:no_chromium_code", 197 ] 198 199 # These need to be applied after the main configs so the "-Wno-*" options 200 # take effect. 201 configs += [ ":icu_code" ] 202 configs += extra_configs 203 public_configs = [ ":icu_config" ] 204 205 # Make icu into a standalone static library. Currently This is only useful 206 # on Chrome OS. 207 if (invoker.check_thin_archive && icu_disable_thin_archive) { 208 configs -= [ "${skia_root_dir}/build/config/compiler:thin_archive" ] 209 complete_static_lib = true 210 } 211 } 212 } 213} 214 215template("generate_icui18n") { 216 if (!icu_is_in_fuchsia) { 217 check_thin_archive = true 218 } 219 220 generate_icu_component(target_name) { 221 assert(defined(invoker.icuuc_deps), "Need the 'icuuc_deps' parameter.") 222 icuuc_deps = invoker.icuuc_deps 223 224 fuchsia_output_name_postfix = "" 225 if (defined(invoker.fuchsia_output_name_postfix)) { 226 fuchsia_output_name_postfix = invoker.fuchsia_output_name_postfix 227 } 228 229 forward_variables_from(invoker, 230 "*", 231 [ 232 "testonly", 233 "visibility", 234 ]) 235 236 sources = icu18n_sources 237 public = icu18n_public 238 239 defines = [ "U_I18N_IMPLEMENTATION" ] 240 deps = icuuc_deps 241 } 242} 243 244generate_icui18n("icui18n") { 245 extra_configs = [] 246 icuuc_deps = [ ":icuuc" ] 247} 248 249generate_icui18n("icui18n_hidden_visibility") { 250 extra_configs = [ ":visibility_hidden" ] 251 icuuc_deps = [ ":icuuc_hidden_visibility" ] 252 if (is_fuchsia && !icu_is_in_fuchsia) { 253 fuchsia_output_name_postfix = "_hidden_visibility" 254 } 255} 256 257template("generate_icuuc") { 258 if (!icu_is_in_fuchsia) { 259 check_thin_archive = false 260 } 261 262 generate_icu_component(target_name) { 263 fuchsia_output_name_postfix = "" 264 if (defined(invoker.fuchsia_output_name_postfix)) { 265 fuchsia_output_name_postfix = invoker.fuchsia_output_name_postfix 266 } 267 268 forward_variables_from(invoker, 269 "*", 270 [ 271 "testonly", 272 "visibility", 273 ]) 274 275 sources = icuuc_sources 276 public = icuuc_public 277 278 defines = [ "U_COMMON_IMPLEMENTATION" ] 279 deps = [ ":icudata" ] 280 281 if (icu_use_data_file) { 282 sources += [ "source/stubdata/stubdata.cpp" ] 283 } 284 285 defines += [ "U_ICUDATAENTRY_IN_COMMON" ] 286 } 287} 288 289generate_icuuc("icuuc") { 290 extra_configs = [] 291} 292generate_icuuc("icuuc_hidden_visibility") { 293 extra_configs = [ ":visibility_hidden" ] 294 if (is_fuchsia && !icu_is_in_fuchsia) { 295 fuchsia_output_name_postfix = "_hidden_visibility" 296 } 297} 298 299if (is_android && enable_java_templates) { 300 android_assets("icu_assets") { 301 if (icu_use_data_file) { 302 sources = [ "$root_out_dir/icudtl.dat" ] 303 deps = [ ":icudata" ] 304 disable_compression = true 305 } 306 } 307 308 android_assets("icu_extra_assets") { 309 if (icu_use_data_file) { 310 sources = [ "$root_out_dir/icudtl_extra.dat" ] 311 deps = [ ":extra_icudata" ] 312 disable_compression = true 313 } 314 } 315} 316 317if (is_android) { 318 # Use android_small for now to keep the size till we decide to switch to the new one. 319 data_dir = "android_small" 320} else if (is_ios) { 321 data_dir = "ios" 322} else if (is_chromeos) { 323 data_dir = "chromeos" 324} else { 325 data_dir = "common" 326} 327 328if (current_cpu == "mips" || current_cpu == "mips64" || 329 host_byteorder == "big") { 330 data_bundle_prefix = "icudtb" 331} else { 332 data_bundle_prefix = "icudtl" 333} 334data_bundle = "${data_bundle_prefix}.dat" 335 336if (icu_use_data_file) { 337 if (is_ios) { 338 bundle_data("icudata") { 339 sources = [ "$data_dir/$data_bundle" ] 340 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] 341 } 342 } else { 343 copy("icudata") { 344 sources = [ "$data_dir/$data_bundle" ] 345 outputs = [ "$root_out_dir/$data_bundle" ] 346 data = [ "$root_out_dir/$data_bundle" ] 347 } 348 } 349 350 copy("extra_icudata") { 351 sources = [ "${skia_third_party_dir}/icu/android_small/icudtl_extra.dat" ] 352 outputs = [ "$root_out_dir/icudtl_extra.dat" ] 353 } 354} else { 355 data_assembly = "$target_gen_dir/${data_bundle_prefix}_dat.S" 356 inline_data_assembly = "$target_gen_dir/${data_bundle_prefix}_dat.cc" 357 action("make_data_assembly") { 358 script = "scripts/make_data_assembly.py" 359 inputs = [ "$data_dir/$data_bundle" ] 360 outputs = [ data_assembly ] 361 args = [ 362 rebase_path(inputs[0], root_build_dir), 363 rebase_path(data_assembly, root_build_dir), 364 ] 365 if (is_mac || is_ios) { 366 args += [ "--mac" ] 367 } else if (is_win) { 368 args += [ "--win" ] 369 } 370 } 371 372 if (is_win) { 373 action("make_inline_data_assembly") { 374 deps = [ ":make_data_assembly" ] 375 script = "scripts/asm_to_inline_asm.py" 376 inputs = [ data_assembly ] 377 outputs = [ inline_data_assembly ] 378 args = rebase_path([ 379 data_assembly, 380 inline_data_assembly, 381 ], 382 root_build_dir) 383 } 384 } else { 385 not_needed([ "inline_data_assembly" ]) 386 } 387 388 source_set("icudata") { 389 defines = [ "U_HIDE_DATA_SYMBOL" ] 390 if (is_win) { 391 sources = [ inline_data_assembly ] 392 deps = [ ":make_inline_data_assembly" ] 393 } else { 394 sources = [ data_assembly ] 395 deps = [ ":make_data_assembly" ] 396 } 397 } 398} 399