xref: /third_party/libxml2/BUILD.gn (revision 53aa9179)
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/config/config.gni")
14import("//build/ohos.gni")
15
16# Execute the script and extract libxml2
17action("libxml2_install_action") {
18  script = "//third_party/libxml2/install.py"
19  outputs = [
20    "${target_gen_dir}/libxml2-2.9.14/config.h.cmake.in",
21    "${target_gen_dir}/libxml2-2.9.14/include/libxml/xmlversion.h.in",
22    "${target_gen_dir}/libxml2-2.9.14/DOCBparser.c",
23    "${target_gen_dir}/libxml2-2.9.14/HTMLparser.c",
24    "${target_gen_dir}/libxml2-2.9.14/HTMLtree.c",
25    "${target_gen_dir}/libxml2-2.9.14/SAX.c",
26    "${target_gen_dir}/libxml2-2.9.14/SAX2.c",
27    "${target_gen_dir}/libxml2-2.9.14/buf.c",
28    "${target_gen_dir}/libxml2-2.9.14/c14n.c",
29    "${target_gen_dir}/libxml2-2.9.14/catalog.c",
30    "${target_gen_dir}/libxml2-2.9.14/chvalid.c",
31    "${target_gen_dir}/libxml2-2.9.14/debugXML.c",
32    "${target_gen_dir}/libxml2-2.9.14/dict.c",
33    "${target_gen_dir}/libxml2-2.9.14/encoding.c",
34    "${target_gen_dir}/libxml2-2.9.14/entities.c",
35    "${target_gen_dir}/libxml2-2.9.14/error.c",
36    "${target_gen_dir}/libxml2-2.9.14/globals.c",
37    "${target_gen_dir}/libxml2-2.9.14/hash.c",
38    "${target_gen_dir}/libxml2-2.9.14/legacy.c",
39    "${target_gen_dir}/libxml2-2.9.14/list.c",
40    "${target_gen_dir}/libxml2-2.9.14/nanoftp.c",
41    "${target_gen_dir}/libxml2-2.9.14/nanohttp.c",
42    "${target_gen_dir}/libxml2-2.9.14/parser.c",
43    "${target_gen_dir}/libxml2-2.9.14/parserInternals.c",
44    "${target_gen_dir}/libxml2-2.9.14/pattern.c",
45    "${target_gen_dir}/libxml2-2.9.14/relaxng.c",
46    "${target_gen_dir}/libxml2-2.9.14/schematron.c",
47    "${target_gen_dir}/libxml2-2.9.14/threads.c",
48    "${target_gen_dir}/libxml2-2.9.14/tree.c",
49    "${target_gen_dir}/libxml2-2.9.14/uri.c",
50    "${target_gen_dir}/libxml2-2.9.14/valid.c",
51    "${target_gen_dir}/libxml2-2.9.14/xinclude.c",
52    "${target_gen_dir}/libxml2-2.9.14/xlink.c",
53    "${target_gen_dir}/libxml2-2.9.14/xmlIO.c",
54    "${target_gen_dir}/libxml2-2.9.14/xmlmemory.c",
55    "${target_gen_dir}/libxml2-2.9.14/xmlmodule.c",
56    "${target_gen_dir}/libxml2-2.9.14/xmlreader.c",
57    "${target_gen_dir}/libxml2-2.9.14/xmlregexp.c",
58    "${target_gen_dir}/libxml2-2.9.14/xmlsave.c",
59    "${target_gen_dir}/libxml2-2.9.14/xmlschemas.c",
60    "${target_gen_dir}/libxml2-2.9.14/xmlschemastypes.c",
61    "${target_gen_dir}/libxml2-2.9.14/xmlstring.c",
62    "${target_gen_dir}/libxml2-2.9.14/xmlunicode.c",
63    "${target_gen_dir}/libxml2-2.9.14/xmlwriter.c",
64    "${target_gen_dir}/libxml2-2.9.14/xpath.c",
65    "${target_gen_dir}/libxml2-2.9.14/xpointer.c",
66    "${target_gen_dir}/libxml2-2.9.14/xzlib.c",
67  ]
68
69  inputs = [ "//third_party/libxml2/libxml2-2.9.14.tar.xz" ]
70
71  args = [
72    "--gen-dir",
73    rebase_path("${target_gen_dir}", root_build_dir),
74    "--source-file",
75    rebase_path("//third_party/libxml2"),
76  ]
77}
78
79# This is the configuration needed to use libxml2.
80config("libxml2_config") {
81  include_dirs = [
82    get_label_info(":libxml2_generate_header", "target_out_dir") + "/include",
83    get_label_info(":libxml2_install_action", "target_gen_dir") +
84        "/libxml2-2.9.14/include",
85  ]
86}
87
88# This is the configuration used to build libxml2 itself. It should not be needed outside of this
89# library.
90#
91# This has to be a config instead of flags directly specified on the libxml2 target so the -Wno-*
92# flags are ordered after the -Werror flags from the default configs.
93config("libxml2_private_config") {
94  visibility = [ ":*" ]
95  cflags = [
96    "-Wno-empty-body",
97    "-Wno-incompatible-pointer-types",
98    "-Wno-missing-field-initializers",
99    "-Wno-self-assign",
100    "-Wno-sign-compare",
101    "-Wno-tautological-pointer-compare",
102    "-Wno-unused-function",
103    "-Wno-enum-compare",
104    "-Wno-int-conversion",
105    "-Wno-uninitialized",
106  ]
107  defines = [
108    "HAVE_CONFIG_H",
109    "_REENTRANT",
110  ]
111  if (is_linux) {
112    defines += [ "_GNU_SOURCE" ]
113  }
114}
115
116# This is the configuration needed to use static libxml2.
117config("libxml2_static_config") {
118  include_dirs = [
119    get_label_info(":libxml2_generate_header", "target_out_dir") + "/include",
120    get_label_info(":libxml2_install_action", "target_gen_dir") +
121        "/libxml2-2.9.14/include",
122  ]
123  if (is_mingw) {
124    defines = [ "LIBXML_STATIC" ]
125  } else {
126    defines = [
127      "HAVE_CONFIG_H",
128      "_REENTRANT",
129    ]
130  }
131}
132
133config("libxml2_static_private_config") {
134  cflags = [
135    "-Wno-implicit-fallthrough",
136    "-Wno-implicit-function-declaration",
137    "-Wno-int-conversion",
138    "-Wno-uninitialized",
139    "-Wno-sometimes-uninitialized",
140  ]
141  cflags_cc = [ "-std=c++17" ]
142}
143
144group("xml2") {
145  public_deps = [ ":libxml2" ]
146}
147
148ohos_shared_library("libxml2") {
149  branch_protector_ret = "pac_ret"
150  output_values = get_target_outputs(":libxml2_install_action")
151  sources = filter_exclude(output_values,
152                           [
153                             "*.h.cmake.in",
154                             "*.h.in",
155                           ])
156  public_configs = [ ":libxml2_config" ]
157  configs = [ ":libxml2_private_config" ]
158
159  if (is_linux) {
160    libs = [ "dl" ]
161  }
162
163  if (current_os == "ios") {
164    ldflags = [
165      "-Wl",
166      "-install_name",
167      "@rpath/libxml2_shared.framework/libxml2_shared",
168    ]
169    output_name = "xml2_shared"
170  }
171  deps = [
172    ":libxml2_generate_header",
173    ":libxml2_install_action",
174  ]
175  innerapi_tags = [
176    "chipsetsdk",
177    "platformsdk",
178    "sasdk",
179  ]
180  install_images = [
181    "updater",
182    "system",
183  ]
184  part_name = "libxml2"
185  subsystem_name = "thirdparty"
186}
187
188if (current_os == "ios") {
189  ohos_combine_darwin_framework("libxml2_shared") {
190    deps = [ ":libxml2" ]
191    subsystem_name = "thirdparty"
192    part_name = "libxml2"
193  }
194}
195
196ohos_static_library("static_libxml2") {
197  output_values = get_target_outputs(":libxml2_install_action")
198  sources = filter_exclude(output_values,
199                           [
200                             "*.h.cmake.in",
201                             "*.h.in",
202                           ])
203  public_configs = [ ":libxml2_static_config" ]
204  configs = [ ":libxml2_static_private_config" ]
205
206  deps = [
207    ":libxml2_generate_header",
208    ":libxml2_install_action",
209  ]
210  part_name = "libxml2"
211  subsystem_name = "thirdparty"
212}
213
214action("libxml2_generate_header") {
215  script = "generate_header.py"
216
217  config_in_path = get_label_info(":libxml2_install_action", "target_gen_dir") +
218                   "/libxml2-2.9.14/config.h.cmake.in"
219  xmlversion_in_path =
220      get_label_info(":libxml2_install_action", "target_gen_dir") +
221      "/libxml2-2.9.14/include/libxml/xmlversion.h.in"
222  config_json_path = "config_linux.json"
223  xml_version_json_path = "xml_version.json"
224  if (is_mingw) {
225    config_json_path = "config_win.json"
226  }
227
228  inputs = [
229    config_in_path,
230    xmlversion_in_path,
231    config_json_path,
232    xml_version_json_path,
233  ]
234
235  config_path = get_label_info(":libxml2_generate_header", "target_out_dir") +
236                "/include/config.h"
237  xmlversion_path =
238      get_label_info(":libxml2_generate_header", "target_out_dir") +
239      "/include/libxml/xmlversion.h"
240
241  outputs = [
242    config_path,
243    xmlversion_path,
244  ]
245
246  args = [
247    "--config-input-path",
248    rebase_path(config_in_path, root_build_dir),
249    "--config-path",
250    rebase_path(config_path, root_build_dir),
251    "--xmlversion-input-path",
252    rebase_path(xmlversion_in_path, root_build_dir),
253    "--xmlversion-path",
254    rebase_path(xmlversion_path, root_build_dir),
255    "--config-json",
256    rebase_path(config_json_path, root_build_dir),
257    "--xmlversion-json",
258    rebase_path(xml_version_json_path, root_build_dir),
259  ]
260
261  deps = [ ":libxml2_install_action" ]
262}
263