xref: /aosp_15_r20/external/cronet/third_party/libxml/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2013 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# Define an "os_include" variable that points at the OS-specific generated
6# headers.  These were generated by running the configure script offline.
7if (is_linux || is_chromeos || is_android || is_nacl || is_fuchsia) {
8  os_include = "linux"
9} else if (is_apple) {
10  os_include = "mac"
11} else if (is_win) {
12  os_include = "win32"
13}
14
15import("//third_party/libxml/libxml_visibility.gni")
16
17config("libxml_config") {
18  # Define LIBXML_STATIC as nothing to match how libxml.h (an internal header)
19  # defines LIBXML_STATIC, otherwise we get the macro redefined warning from
20  # GCC. ("defines" does "-DFOO" which defines the macro FOO as 1.)
21  cflags = [ "-DLIBXML_STATIC=" ]
22
23  include_dirs = [
24    "src/include",
25    "$os_include/include",
26  ]
27}
28
29config("libxml_warnings") {
30  if (is_win) {
31    cflags_c = [
32      "/wd4018",  # Signed/unsigned mismatch in comparison.
33      "/wd4267",  # TODO(brucedawson): http://crbug.com/554200 fix C4267
34      "/wd4311",  # and C4311 warnings.
35    ]
36  }
37  if (is_clang) {
38    cflags = [
39      # libxml passes `const unsigned char*` through `const char*`.
40      "-Wno-pointer-sign",
41
42      # pattern.c and uri.c both have an intentional `for (...);` /
43      # `while(...);` loop. I submitted a patch to move the `'` to its own
44      # line, but until that's landed suppress the warning:
45      "-Wno-empty-body",
46
47      # debugXML.c compares array 'arg' to NULL.
48      "-Wno-tautological-pointer-compare",
49
50      # threads.c attempts to forward declare a pthread_equal which doesn't
51      # match the prototype in pthreads.h
52      "-Wno-ignored-attributes",
53
54      # libxml casts from int to long to void*.
55      "-Wno-int-to-void-pointer-cast",
56
57      # libxml passes a volatile LPCRITICAL_SECTION* to a function expecting
58      # a void* volatile*.
59      "-Wno-incompatible-pointer-types",
60
61      # trio_is_special_quantity and trio_is_negative are only
62      # used with certain preprocessor defines set.
63      "-Wno-unused-function",
64
65      # Comparison between xmlElementType and xmlXPathTypeVal.
66      # TODO(hans): See if we can fix upstream (http://crbug.com/763944).
67      "-Wno-enum-compare",
68    ]
69  } else if (is_linux || is_chromeos) {
70    cflags = [
71      # gcc spits out a bunch of warnings about passing too many arguments to
72      # __xmlSimpleError.
73      "-Wno-format-extra-args",
74    ]
75  }
76}
77
78# Please keep in sync with //build/linux/unbundle/libxml.gn.
79static_library("xml_reader") {
80  # Do not expand this visibility list without first consulting with the
81  # Security Team.
82  visibility = [
83    "//base/test:test_support",
84    "//components/policy/core/common:unit_tests",
85    "//services/data_decoder:*",
86  ]
87  if (is_win) {
88    visibility += [ "//components/wifi" ]
89  }
90  sources = [
91    "chromium/xml_reader.cc",
92    "chromium/xml_reader.h",
93  ]
94  deps = [
95    ":libxml",
96    ":libxml_utils",
97  ]
98  configs += [ ":libxml_config" ]
99}
100
101# Please keep in sync with //build/linux/unbundle/libxml.gn.
102static_library("xml_writer") {
103  # The XmlWriter is considered safe to use from any target.
104  visibility = [ "*" ]
105  sources = [
106    "chromium/xml_writer.cc",
107    "chromium/xml_writer.h",
108  ]
109  deps = [
110    ":libxml",
111    ":libxml_utils",
112  ]
113  configs += [ ":libxml_config" ]
114}
115
116# Please keep in sync with //build/linux/unbundle/libxml.gn.
117static_library("libxml_utils") {
118  # Do not expand this visibility list without first consulting with the
119  # Security Team.
120  visibility = [
121    ":xml_reader",
122    ":xml_writer",
123    "//base/test:test_support",
124    "//services/data_decoder:lib",
125    "//services/data_decoder:xml_parser_fuzzer_deps",
126  ]
127  sources = [
128    "chromium/libxml_utils.cc",
129    "chromium/libxml_utils.h",
130  ]
131  deps = [ ":libxml" ]
132  public_deps = [ "//third_party/icu:icuuc" ]
133  public_configs = [ ":libxml_config" ]
134}
135
136static_library("libxml") {
137  # Do not expand this visibility list without first consulting with the
138  # Security Team.
139  visibility = [
140    ":libxml_utils",
141    ":xml_reader",
142    ":xml_writer",
143    "//chromecast/internal",
144    "//testing/libfuzzer/*",
145    "//third_party/blink/renderer/*",
146    "//third_party/fontconfig",
147    "//third_party/libxslt",
148    "//third_party/maldoca/*",
149  ]
150  if (is_ios) {
151    foreach(tgt, ios_libxml_visibility_additions) {
152      visibility += [ "//ios_internal/$tgt" ]
153    }
154  }
155
156  output_name = "libxml2"
157
158  # Commented out sources are libxml2 files we do not want to include. They are
159  # here to make it easy to identify files which are new.
160  sources = [
161    "src/HTMLparser.c",
162    "src/HTMLtree.c",
163
164    #"src/SAX.c",
165    "src/SAX2.c",
166    "src/buf.c",
167
168    #"src/c14n.c",
169    #"src/catalog.c",
170    "src/chvalid.c",
171
172    #"src/debugXML.c",
173    "src/dict.c",
174    "src/encoding.c",
175    "src/entities.c",
176    "src/error.c",
177    "src/globals.c",
178    "src/hash.c",
179    "src/include/libxml/HTMLparser.h",
180    "src/include/libxml/HTMLtree.h",
181    "src/include/libxml/SAX.h",
182    "src/include/libxml/SAX2.h",
183    "src/include/libxml/c14n.h",
184    "src/include/libxml/catalog.h",
185    "src/include/libxml/chvalid.h",
186    "src/include/libxml/debugXML.h",
187    "src/include/libxml/dict.h",
188    "src/include/libxml/encoding.h",
189    "src/include/libxml/entities.h",
190    "src/include/libxml/globals.h",
191    "src/include/libxml/hash.h",
192    "src/include/libxml/list.h",
193    "src/include/libxml/nanoftp.h",
194    "src/include/libxml/nanohttp.h",
195    "src/include/libxml/parser.h",
196    "src/include/libxml/parserInternals.h",
197    "src/include/libxml/pattern.h",
198    "src/include/libxml/relaxng.h",
199    "src/include/libxml/schemasInternals.h",
200    "src/include/libxml/schematron.h",
201    "src/include/libxml/threads.h",
202    "src/include/libxml/tree.h",
203    "src/include/libxml/uri.h",
204    "src/include/libxml/valid.h",
205    "src/include/libxml/xinclude.h",
206    "src/include/libxml/xlink.h",
207    "src/include/libxml/xmlIO.h",
208    "src/include/libxml/xmlautomata.h",
209    "src/include/libxml/xmlerror.h",
210    "src/include/libxml/xmlexports.h",
211    "src/include/libxml/xmlmemory.h",
212    "src/include/libxml/xmlmodule.h",
213    "src/include/libxml/xmlreader.h",
214    "src/include/libxml/xmlregexp.h",
215    "src/include/libxml/xmlsave.h",
216    "src/include/libxml/xmlschemas.h",
217    "src/include/libxml/xmlschemastypes.h",
218    "src/include/libxml/xmlstring.h",
219    "src/include/libxml/xmlunicode.h",
220    "src/include/libxml/xmlwriter.h",
221    "src/include/libxml/xpath.h",
222    "src/include/libxml/xpathInternals.h",
223    "src/include/libxml/xpointer.h",
224
225    #"src/legacy.c",
226    "src/libxml.h",
227    "src/list.c",
228    "src/parser.c",
229    "src/parserInternals.c",
230    "src/pattern.c",
231
232    #"src/relaxng.c",
233
234    #"src/schematron.c",
235    "src/threads.c",
236    "src/timsort.h",
237    "src/tree.c",
238
239    "src/uri.c",
240    "src/valid.c",
241
242    #"src/xinclude.c",
243    #"src/xlink.c",
244    "src/xmlIO.c",
245    "src/xmlmemory.c",
246
247    #"src/xmlmodule.c",
248    "src/xmlreader.c",
249
250    #"src/xmlregexp.c",
251    "src/xmlsave.c",
252
253    #"src/xmlschemas.c",
254    #"src/xmlschemastypes.c",
255    "src/xmlstring.c",
256    "src/xmlunicode.c",
257    "src/xmlwriter.c",
258    "src/xpath.c",
259
260    #"src/xpointer.c",
261    #"src/xzlib.c",
262  ]
263
264  configs -= [ "//build/config/compiler:chromium_code" ]
265  configs += [
266    "//build/config/compiler:no_chromium_code",
267
268    # Must be after no_chromium_code for warning flags to be ordered correctly.
269    ":libxml_warnings",
270  ]
271
272  if (is_linux || is_chromeos) {
273    sources += [
274      "linux/config.h",
275      "linux/include/libxml/xmlversion.h",
276    ]
277  }
278
279  if (is_mac) {
280    sources += [
281      "mac/config.h",
282      "mac/include/libxml/xmlversion.h",
283    ]
284  }
285
286  if (is_win) {
287    sources += [
288      "src/include/win32config.h",
289      "src/include/wsockcompat.h",
290      "win32/config.h",
291      "win32/include/libxml/xmlversion.h",
292    ]
293
294    # libxml2 already defines WIN32_LEAN_AND_MEAN.
295    configs -= [ "//build/config/win:lean_and_mean" ]
296  }
297
298  sources += [ "chromium/disabled_libxml_features.cc" ]
299
300  public_configs = [ ":libxml_config" ]
301  public_deps = [ "//third_party/icu:icuuc" ]
302  deps = [ "//third_party/zlib" ]
303
304  if (is_apple || is_android || is_fuchsia) {
305    # http://www.xmlsoft.org/threads.html says that this is required when using
306    # libxml from several threads, which can possibly happen in chrome. On
307    # linux, this is picked up by transitivity from pkg-config output from
308    # build/linux/system.gyp.
309    defines = [ "_REENTRANT" ]
310  }
311
312  include_dirs = [ "$os_include" ]
313}
314