1# Copyright (C) 2021-2023 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. 13 14import("//build/ohos.gni") 15import("//third_party/cares/cares.gni") 16 17cares_srcs = [ 18 "ares__addrinfo2hostent.c", 19 "ares__addrinfo_localhost.c", 20 "ares__close_sockets.c", 21 "ares__get_hostent.c", 22 "ares__parse_into_addrinfo.c", 23 "ares__read_line.c", 24 "ares__readaddrinfo.c", 25 "ares__sortaddrinfo.c", 26 "ares__timeval.c", 27 "ares_android.c", 28 "ares_cancel.c", 29 "ares_create_query.c", 30 "ares_data.c", 31 "ares_destroy.c", 32 "ares_expand_name.c", 33 "ares_expand_string.c", 34 "ares_fds.c", 35 "ares_free_hostent.c", 36 "ares_free_string.c", 37 "ares_freeaddrinfo.c", 38 "ares_getaddrinfo.c", 39 "ares_getenv.c", 40 "ares_gethostbyaddr.c", 41 "ares_gethostbyname.c", 42 "ares_getnameinfo.c", 43 "ares_getsock.c", 44 "ares_init.c", 45 "ares_library_init.c", 46 "ares_llist.c", 47 "ares_mkquery.c", 48 "ares_nowarn.c", 49 "ares_options.c", 50 "ares_parse_a_reply.c", 51 "ares_parse_aaaa_reply.c", 52 "ares_parse_caa_reply.c", 53 "ares_parse_mx_reply.c", 54 "ares_parse_naptr_reply.c", 55 "ares_parse_ns_reply.c", 56 "ares_parse_ptr_reply.c", 57 "ares_parse_soa_reply.c", 58 "ares_parse_srv_reply.c", 59 "ares_parse_txt_reply.c", 60 "ares_parse_uri_reply.c", 61 "ares_platform.c", 62 "ares_process.c", 63 "ares_query.c", 64 "ares_rand.c", 65 "ares_search.c", 66 "ares_send.c", 67 "ares_strcasecmp.c", 68 "ares_strdup.c", 69 "ares_strerror.c", 70 "ares_strsplit.c", 71 "ares_timeout.c", 72 "ares_version.c", 73 "ares_writev.c", 74 "bitncmp.c", 75 "inet_net_pton.c", 76 "inet_ntop.c", 77 "windows_port.c", 78] 79 80sources_test = [ 81 "test/ares-test-main.cc", 82 "test/ares-test.cc", 83 "test/ares-test-ns.cc", 84 "test/ares-test-parse.cc", 85 "test/ares-test-parse-a.cc", 86 "test/ares-test-parse-aaaa.cc", 87 "test/ares-test-parse-caa.cc", 88 "test/ares-test-parse-mx.cc", 89 "test/ares-test-parse-naptr.cc", 90 "test/ares-test-parse-ns.cc", 91 "test/ares-test-parse-ptr.cc", 92 "test/ares-test-parse-soa.cc", 93 "test/ares-test-parse-soa-any.cc", 94 "test/ares-test-parse-srv.cc", 95 "test/ares-test-parse-txt.cc", 96 "test/ares-test-parse-uri.cc", 97 "test/ares-test-misc.cc", 98 "test/ares-test-mock.cc", 99 "test/ares-test-internal.cc", 100 "test/dns-proto.cc", 101 "test/dns-proto-test.cc", 102 "test/gmock-1.11.0/gmock-gtest-all.cc", 103] 104 105src_path = "//third_party/cares" 106cares_path = root_out_dir + "/third_party_cares" 107code_dir = cares_path + "/c-ares-1.18.1" 108 109action("installOpenEulerCares") { 110 print("Cares install") 111 script = "install.sh" 112 args = [ 113 rebase_path(src_path, root_build_dir), 114 rebase_path(cares_path, root_build_dir), 115 ] 116 inputs = [ src_path ] 117 outputs = [] 118 foreach(src, cares_srcs) { 119 outputs += [ "$code_dir/src/lib/" + src ] 120 } 121 foreach(test, sources_test) { 122 outputs += [ "$code_dir/" + test ] 123 } 124} 125 126config("c_ares_config") { 127 include_dirs = [ "//third_party/cares/include" ] 128 cflags = [ 129 "-D_GNU_SOURCE", 130 "-D_HAS_EXCEPTIONS=0", 131 "-DHAVE_CONFIG_H", 132 "-Wno-macro-redefined", 133 ] 134} 135ohos_shared_library("c_ares") { 136 deps = [ ":installOpenEulerCares" ] 137 install_images = [ 138 "updater", 139 "system", 140 ] 141 sources = [] 142 foreach(src, cares_srcs) { 143 sources += [ "$code_dir/src/lib/" + src ] 144 } 145 146 public_configs = [ ":c_ares_config" ] 147 defines = [ "CARES_SHAREDLIB" ] 148 if (is_standard_system) { 149 defines += [ "OHOS_DNS_PROXY_BY_NETSYS=1" ] 150 } 151 152 include_dirs = [ 153 "//third_party/cares/include", 154 "$code_dir", 155 "$code_dir/include", 156 ] 157 158 install_enable = true 159 subsystem_name = "thirdparty" 160 part_name = "cares" 161} 162 163ohos_static_library("c_ares_static") { 164 deps = [ ":installOpenEulerCares" ] 165 sources = [] 166 foreach(src, cares_srcs) { 167 sources += [ "$code_dir/src/lib/" + src ] 168 } 169 170 public_configs = [ ":c_ares_config" ] 171 172 include_dirs = [ 173 "//third_party/cares/include", 174 "$code_dir", 175 "$code_dir/include", 176 ] 177 subsystem_name = "thirdparty" 178 part_name = "cares" 179} 180 181ohos_executable("cares_test") { 182 sources = [] 183 foreach(src, sources_test) { 184 sources += [ "$code_dir/" + src ] 185 } 186 deps = [ 187 ":c_ares", 188 ":installOpenEulerCares", 189 ] 190 include_dirs = [ 191 "//third_party/cares/include", 192 "$code_dir", 193 "$code_dir/src/lib", 194 "$code_dir/include", 195 "$code_dir/test", 196 "$code_dir/test/gmock-1.11.0", 197 ] 198 subsystem_name = "thirdparty" 199 part_name = "cares" 200} 201 202group("c_ares_target") { 203 deps = [ 204 ":c_ares", 205 ":c_ares_static", 206 ":cares_test", 207 ] 208} 209