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