summaryrefslogtreecommitdiffstats
path: root/third_party/cld_2/BUILD.gn
blob: 3edb31dae64f1aa62507195832bf80be55cb0f33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/features.gni")

gypi_values = exec_script("//build/gypi_to_gn.py",
                          [ rebase_path("cld_2.gyp") ],
                          "scope",
                          [ "cld_2.gyp" ])

# This variable controls which dependency is resolved by the pass-through
# target 'cld2_platform_impl', and allows the embedder to choose which
# kind of CLD2 support is required at build time:
#
# - If the value is 'static', then the cld2_platform_impl target will depend
#   upon the cld2_static target
# - If the value is 'dynamic', then the cld2_platform_impl target will
#   depend upon the cld2_dynamic target.
#
# High-level targets for Chromium unit tests hard-code a dependency upon
# cld2_static because doing so makes sense for use cases that aren't
# affected by the loading of language detection data; however, most other
# targets (e.g. the final executables and interactive UI tests) should be
# linked against whatever the embedder needs.
#
# Maintainers:
# This value may be reasonably tweaked on a per-platform basis.
# Don't forget to update this file as well to match:
#   components/translate/content/browser/browser_cld_utils.cc
#   components/translate/content/renderer/renderer_cld_utils.cc
cld2_platform_support = "static"

cld2_table_size = 2

config("cld2_data_warnings") {
  visibility = [ ":*" ]
  if (is_clang) {
    # The generated files don't have braces around subobject initializers.
    cflags = [ "-Wno-missing-braces" ]
  }
}

source_set("cld2_data") {
  sources = gypi_values.cld2_data_sources
  if (cld2_table_size == 0) {
    sources += gypi_values.cld2_data_smallest_sources
  } else if (cld2_table_size == 2) {
    sources += gypi_values.cld2_data_largest_sources
  }

  include_dirs = [
    "src/internal",
    "src/public",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    ":cld2_data_warnings",
    "//build/config/compiler:no_chromium_code",
  ]
}

# As in the corresponding gyp file, this just builds the core interfaces for
# CLD2. You must still declare a dependency on a specific data set, either
# cld2_dynamic or cld2_static.
source_set("cld_2") {
  sources = gypi_values.cld2_core_sources
  include_dirs = [
    "src/internal",
    "src/public",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
}

source_set("cld2_platform_impl") {
  deps = []
  if (cld2_platform_support == "static") {
    deps += [ ":cld2_static" ]
  } else if (cld2_platform_support == "dynamic") {
    deps += [ ":cld2_dynamic" ]
  }
}

config("cld2_warnings") {
  if (is_clang) {
    cflags = [
      # cld_2 contains unused private fields.
      # https://code.google.com/p/cld2/issues/detail?id=37
      "-Wno-unused-private-field",
    ]
  }
}

static_library("cld2_static") {
  sources = gypi_values.cld2_core_impl_sources
  include_dirs = [
    "src/internal",
    "src/public",
  ]

  deps = [
    ":cld_2",
    ":cld2_data",
  ]
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":cld2_warnings",
  ]
}

config("cld2_dynamic_mode_config") {
  defines = [ "CLD2_DYNAMIC_MODE" ]
}

static_library("cld2_dynamic") {
  sources = gypi_values.cld2_core_sources + gypi_values.cld2_core_impl_sources +
            gypi_values.cld2_dynamic_data_loader_sources
  include_dirs = [
    "src/internal",
    "src/public",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    ":cld2_dynamic_mode_config",
    "//build/config/compiler:no_chromium_code",
    ":cld2_warnings",
  ]
}

# Does not build on Windows.
if (!is_win) {
  executable("cld_2_dynamic_data_tool") {
    sources = [
      "src/internal/cld2_dynamic_data_extractor.cc",
      "src/internal/cld2_dynamic_data_extractor.h",
      "src/internal/cld2_dynamic_data_tool.cc",
    ]

    include_dirs = [
      "src/internal",
      "src/public",
    ]

    deps = [
      ":cld2_data",
      ":cld2_dynamic",
    ]

    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [
      ":cld2_dynamic_mode_config",
      "//build/config/compiler:no_chromium_code",
    ]
  }
}