• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Huawei Device Co., Ltd.
2#   Licensed under the Apache License, Version 2.0 (the "License");
3#   you may not use this file except in compliance with the License.
4#   You may obtain a copy of the License at
5#
6#       http://www.apache.org/licenses/LICENSE-2.0
7#
8#   Unless required by applicable law or agreed to in writing, software
9#   distributed under the License is distributed on an "AS IS" BASIS,
10#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11#   See the License for the specific language governing permissions and
12#   limitations under the License.
13import("//build/ohos.gni")
14
15# This is the configuration needed to use libxml2.
16config("libxml2_config") {
17  include_dirs = [ "include" ]
18}
19
20# This is the configuration used to build libxml2 itself. It should not be needed outside of this
21# library.
22#
23# This has to be a config instead of flags directly specified on the libxml2 target so the -Wno-*
24# flags are ordered after the -Werror flags from the default configs.
25config("libxml2_private_config") {
26  visibility = [ ":*" ]
27  cflags = [
28    "-Wno-empty-body",
29    "-Wno-incompatible-pointer-types",
30    "-Wno-missing-field-initializers",
31    "-Wno-self-assign",
32    "-Wno-sign-compare",
33    "-Wno-tautological-pointer-compare",
34    "-Wno-unused-function",
35    "-Wno-enum-compare",
36  ]
37  defines = [
38    "HAVE_CONFIG_H",
39    "_REENTRANT",
40  ]
41  if (is_linux) {
42    defines += [ "_GNU_SOURCE" ]
43  }
44}
45
46group("libxml2") {
47  public_deps = [ ":xml2" ]
48}
49
50manager_sources = [
51  "DOCBparser.c",
52  "HTMLparser.c",
53  "HTMLtree.c",
54  "SAX.c",
55  "SAX2.c",
56  "buf.c",
57  "c14n.c",
58  "catalog.c",
59  "chvalid.c",
60  "debugXML.c",
61  "dict.c",
62  "encoding.c",
63  "entities.c",
64  "error.c",
65  "globals.c",
66  "hash.c",
67  "include/libxml/DOCBparser.h",
68  "include/libxml/HTMLparser.h",
69  "include/libxml/HTMLtree.h",
70  "include/libxml/SAX.h",
71  "include/libxml/SAX2.h",
72  "include/libxml/c14n.h",
73  "include/libxml/catalog.h",
74  "include/libxml/chvalid.h",
75  "include/libxml/debugXML.h",
76  "include/libxml/dict.h",
77  "include/libxml/encoding.h",
78  "include/libxml/entities.h",
79  "include/libxml/globals.h",
80  "include/libxml/hash.h",
81  "include/libxml/list.h",
82  "include/libxml/nanoftp.h",
83  "include/libxml/nanohttp.h",
84  "include/libxml/parser.h",
85  "include/libxml/parserInternals.h",
86  "include/libxml/pattern.h",
87  "include/libxml/relaxng.h",
88  "include/libxml/schemasInternals.h",
89  "include/libxml/schematron.h",
90  "include/libxml/threads.h",
91  "include/libxml/tree.h",
92  "include/libxml/uri.h",
93  "include/libxml/valid.h",
94  "include/libxml/xinclude.h",
95  "include/libxml/xlink.h",
96  "include/libxml/xmlIO.h",
97  "include/libxml/xmlautomata.h",
98  "include/libxml/xmlerror.h",
99  "include/libxml/xmlexports.h",
100  "include/libxml/xmlmemory.h",
101  "include/libxml/xmlmodule.h",
102  "include/libxml/xmlreader.h",
103  "include/libxml/xmlregexp.h",
104  "include/libxml/xmlsave.h",
105  "include/libxml/xmlschemas.h",
106  "include/libxml/xmlschemastypes.h",
107  "include/libxml/xmlstring.h",
108  "include/libxml/xmlunicode.h",
109  "include/libxml/xmlversion.h",
110  "include/libxml/xmlwriter.h",
111  "include/libxml/xpath.h",
112  "include/libxml/xpathInternals.h",
113  "include/libxml/xpointer.h",
114  "legacy.c",
115  "list.c",
116  "nanoftp.c",
117  "nanohttp.c",
118  "parser.c",
119  "parserInternals.c",
120  "pattern.c",
121  "relaxng.c",
122  "schematron.c",
123  "threads.c",
124  "tree.c",
125  "uri.c",
126  "valid.c",
127  "xinclude.c",
128  "xlink.c",
129  "xmlIO.c",
130  "xmlmemory.c",
131  "xmlmodule.c",
132  "xmlreader.c",
133  "xmlregexp.c",
134  "xmlsave.c",
135  "xmlschemas.c",
136  "xmlschemastypes.c",
137  "xmlstring.c",
138  "xmlunicode.c",
139  "xmlwriter.c",
140  "xpath.c",
141  "xpointer.c",
142  "xzlib.c",
143]
144
145ohos_shared_library("xml2") {
146  sources = manager_sources
147  public_configs = [ ":libxml2_config" ]
148
149  configs = [ ":libxml2_private_config" ]
150
151  if (is_linux) {
152    libs = [ "dl" ]
153  }
154
155  deps = [ "//third_party/zlib:libz" ]
156  part_name = "libxml2"
157  subsystem_name = "thirdparty"
158}
159
160config("libxml2_static_config") {
161  cflags = [
162    "-Wno-implicit-fallthrough",
163    "-Wno-implicit-function-declaration",
164    "-Wno-int-conversion",
165    "-Wno-uninitialized",
166    "-Wno-sometimes-uninitialized",
167  ]
168
169  include_dirs = []
170  if (is_mingw) {
171    defines = [ "LIBXML_STATIC" ]
172    include_dirs += [ get_label_info(":libxml2_generate_header",
173                                     "target_out_dir") + "/include" ]
174  } else if (is_mac) {
175    defines = [ "LIBXML_THREAD_ENABLED" ]
176  } else if (is_linux) {
177    include_dirs += [ get_label_info(":libxml2_generate_header",
178                                     "target_out_dir") + "/include" ]
179  }
180
181  include_dirs += [ "include" ]
182  cflags_cc = [ "-std=c++17" ]
183}
184
185ohos_static_library("static_libxml2") {
186  sources = manager_sources
187  public_configs = [ ":libxml2_static_config" ]
188  deps = [ ":libxml2_generate_header" ]
189  subsystem_name = "thirdparty"
190  part_name = "libxml2"
191}
192
193action("libxml2_generate_header") {
194  script = "generate_header.py"
195  inputs = [
196    "config.h.cmake.in",
197    "include/libxml/xmlversion.h.in",
198  ]
199
200  config_json_path = "config_linux.json"
201  xml_version_json_path = "xml_version.json"
202  if (is_mingw) {
203    config_json_path = "config_win.json"
204  }
205  inputs += [ config_json_path ]
206  inputs += [ xml_version_json_path ]
207
208  config_path = get_label_info(":libxml2_generate_header", "target_out_dir") +
209                "/include/config.h"
210  xmlversion_path =
211      get_label_info(":libxml2_generate_header", "target_out_dir") +
212      "/include/libxml/xmlversion.h"
213  outputs = [
214    config_path,
215    xmlversion_path,
216  ]
217
218  args = [
219    "--config-input-path",
220    rebase_path("config.h.cmake.in", root_build_dir),
221    "--config-path",
222    rebase_path(config_path, root_build_dir),
223    "--xmlversion-input-path",
224    rebase_path("include/libxml/xmlversion.h.in", root_build_dir),
225    "--xmlversion-path",
226    rebase_path(xmlversion_path, root_build_dir),
227    "--config-json",
228    rebase_path(config_json_path, root_build_dir),
229    "--xmlversion-json",
230    rebase_path(xml_version_json_path, root_build_dir),
231  ]
232}
233