1# Copyright (c) 2020-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. 13import("//build/ohos.gni") 14 15declare_args() { 16 netstack_feature_http3 = false 17} 18 19curl_source = [ 20 "lib/altsvc.c", 21 "lib/amigaos.c", 22 "lib/asyn-ares.c", 23 "lib/asyn-thread.c", 24 "lib/base64.c", 25 "lib/bufq.c", 26 "lib/bufref.c", 27 "lib/c-hyper.c", 28 "lib/cf-h1-proxy.c", 29 "lib/cf-h2-proxy.c", 30 "lib/cf-haproxy.c", 31 "lib/cf-https-connect.c", 32 "lib/cf-socket.c", 33 "lib/cfilters.c", 34 "lib/conncache.c", 35 "lib/connect.c", 36 "lib/content_encoding.c", 37 "lib/cookie.c", 38 "lib/curl_addrinfo.c", 39 "lib/curl_des.c", 40 "lib/curl_endian.c", 41 "lib/curl_fnmatch.c", 42 "lib/curl_get_line.c", 43 "lib/curl_gethostname.c", 44 "lib/curl_gssapi.c", 45 "lib/curl_memrchr.c", 46 "lib/curl_multibyte.c", 47 "lib/curl_ntlm_core.c", 48 "lib/curl_ntlm_wb.c", 49 "lib/curl_path.c", 50 "lib/curl_range.c", 51 "lib/curl_rtmp.c", 52 "lib/curl_sasl.c", 53 "lib/curl_sspi.c", 54 "lib/curl_threads.c", 55 "lib/curl_trc.c", 56 "lib/dict.c", 57 "lib/doh.c", 58 "lib/dynbuf.c", 59 "lib/dynhds.c", 60 "lib/easy.c", 61 "lib/easygetopt.c", 62 "lib/easyoptions.c", 63 "lib/escape.c", 64 "lib/file.c", 65 "lib/fileinfo.c", 66 "lib/fopen.c", 67 "lib/formdata.c", 68 "lib/ftp.c", 69 "lib/ftplistparser.c", 70 "lib/getenv.c", 71 "lib/getinfo.c", 72 "lib/gopher.c", 73 "lib/hash.c", 74 "lib/headers.c", 75 "lib/hmac.c", 76 "lib/hostasyn.c", 77 "lib/hostip.c", 78 "lib/hostip4.c", 79 "lib/hostip6.c", 80 "lib/hostsyn.c", 81 "lib/hsts.c", 82 "lib/http.c", 83 "lib/http1.c", 84 "lib/http2.c", 85 "lib/http_aws_sigv4.c", 86 "lib/http_chunks.c", 87 "lib/http_digest.c", 88 "lib/http_negotiate.c", 89 "lib/http_ntlm.c", 90 "lib/http_proxy.c", 91 "lib/idn.c", 92 "lib/if2ip.c", 93 "lib/imap.c", 94 "lib/inet_ntop.c", 95 "lib/inet_pton.c", 96 "lib/krb5.c", 97 "lib/ldap.c", 98 "lib/llist.c", 99 "lib/macos.c", 100 "lib/md4.c", 101 "lib/md5.c", 102 "lib/memdebug.c", 103 "lib/mime.c", 104 "lib/mprintf.c", 105 "lib/mqtt.c", 106 "lib/multi.c", 107 "lib/netrc.c", 108 "lib/nonblock.c", 109 "lib/noproxy.c", 110 "lib/openldap.c", 111 "lib/parsedate.c", 112 "lib/pingpong.c", 113 "lib/pop3.c", 114 "lib/progress.c", 115 "lib/psl.c", 116 "lib/rand.c", 117 "lib/rename.c", 118 "lib/rtsp.c", 119 "lib/select.c", 120 "lib/sendf.c", 121 "lib/setopt.c", 122 "lib/sha256.c", 123 "lib/share.c", 124 "lib/slist.c", 125 "lib/smb.c", 126 "lib/smtp.c", 127 "lib/socketpair.c", 128 "lib/socks.c", 129 "lib/socks_gssapi.c", 130 "lib/socks_sspi.c", 131 "lib/speedcheck.c", 132 "lib/splay.c", 133 "lib/strcase.c", 134 "lib/strdup.c", 135 "lib/strerror.c", 136 "lib/strtok.c", 137 "lib/strtoofft.c", 138 "lib/system_win32.c", 139 "lib/telnet.c", 140 "lib/tftp.c", 141 "lib/timediff.c", 142 "lib/timeval.c", 143 "lib/transfer.c", 144 "lib/url.c", 145 "lib/urlapi.c", 146 "lib/vauth/cleartext.c", 147 "lib/vauth/cram.c", 148 "lib/vauth/digest.c", 149 "lib/vauth/digest_sspi.c", 150 "lib/vauth/gsasl.c", 151 "lib/vauth/krb5_gssapi.c", 152 "lib/vauth/krb5_sspi.c", 153 "lib/vauth/ntlm.c", 154 "lib/vauth/ntlm_sspi.c", 155 "lib/vauth/oauth2.c", 156 "lib/vauth/spnego_gssapi.c", 157 "lib/vauth/spnego_sspi.c", 158 "lib/vauth/vauth.c", 159 "lib/version.c", 160 "lib/version_win32.c", 161 "lib/vquic/curl_msh3.c", 162 "lib/vquic/curl_ngtcp2.c", 163 "lib/vquic/curl_quiche.c", 164 "lib/vquic/vquic.c", 165 "lib/vquic/vquic-tls.c", 166 "lib/vssh/libssh.c", 167 "lib/vssh/libssh2.c", 168 "lib/vssh/wolfssh.c", 169 "lib/vtls/bearssl.c", 170 "lib/vtls/gtls.c", 171 "lib/vtls/hostcheck.c", 172 "lib/vtls/keylog.c", 173 "lib/vtls/mbedtls.c", 174 "lib/vtls/mbedtls_threadlock.c", 175 "lib/vtls/openssl.c", 176 "lib/vtls/rustls.c", 177 "lib/vtls/schannel.c", 178 "lib/vtls/schannel_verify.c", 179 "lib/vtls/sectransp.c", 180 "lib/vtls/vtls.c", 181 "lib/vtls/wolfssl.c", 182 "lib/vtls/x509asn1.c", 183 "lib/warnless.c", 184 "lib/ws.c", 185] 186 187is_cares_on = !is_mingw && !is_mac && current_os != "ios" && host_os != "mac" && 188 current_os != "mac" && current_os != "android" 189print("Build curl is_cares_on: $is_cares_on") 190 191if (defined(ohos_lite)) { 192 import("//build/lite/config/component/lite_component.gni") 193 194 config("curl_config") { 195 include_dirs = [ "lib" ] 196 if (ohos_kernel_type == "liteos_m") { 197 include_dirs += [ "//kernel/liteos_m/kal/posix/include" ] 198 } 199 cflags = [ 200 "-DBUILDING_LIBCURL", 201 "-DHAVE_CONFIG_H", 202 "-D_GNU_SOURCE", 203 "-DOS=\"liteOS\"", 204 "-fPIC", 205 "-Wdeclaration-after-statement", 206 "-Wendif-labels", 207 "-Wfloat-equal", 208 "-Winline", 209 "-Wmissing-declarations", 210 "-Wmissing-prototypes", 211 "-Wnested-externs", 212 "-Wno-format-nonliteral", 213 "-Wno-implicit-function-declaration", 214 "-Wno-int-conversion", 215 "-Wno-long-long", 216 "-Wno-multichar", 217 "-Wno-nested-externs", 218 "-Wno-sign-compare", 219 "-Wno-system-headers", 220 "-Wno-varargs", 221 "-Wno-overflow", 222 "-Wpointer-arith", 223 "-Wstrict-prototypes", 224 "-Wunused", 225 "-Wwrite-strings", 226 "-Wno-unused-variable", 227 "-Wno-parentheses", 228 "-Wno-strict-prototypes", 229 "-Os", 230 "-ffunction-sections", 231 "-fdata-sections", 232 "-fno-unwind-tables", 233 "-fno-asynchronous-unwind-tables", 234 "-Wno-deprecated-declarations", 235 "-Wimplicit-fallthrough", 236 ] 237 if (ohos_kernel_type == "liteos_m") { 238 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_liteos_m.h\"" ] 239 } else { 240 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_liteos_a.h\"" ] 241 } 242 } 243 244 config("curl_config_public") { 245 include_dirs = [ 246 "include", 247 "//third_party/curl/customized/include", 248 ] 249 } 250 251 if (ohos_kernel_type == "liteos_m") { 252 static_library("libcurl_static") { 253 sources = curl_source 254 deps = [ "//third_party/mbedtls" ] 255 deps += [ "//third_party/nghttp2/lib:nghttp2_lib_static" ] 256 configs += [ 257 ":curl_config", 258 ":curl_config_public", 259 ] 260 261 public_configs = [ ":curl_config_public" ] 262 } 263 } else { 264 shared_library("libcurl_shared") { 265 sources = curl_source 266 deps = [ "//third_party/mbedtls" ] 267 deps += [ "//third_party/nghttp2/lib:nghttp2_lib_shared" ] 268 configs += [ 269 ":curl_config", 270 ":curl_config_public", 271 ] 272 public_configs = [ ":curl_config_public" ] 273 } 274 } 275} else { 276 import("//build/config/config.gni") 277 278 config("curl_config") { 279 include_dirs = [ 280 "include", 281 "lib", 282 "//third_party/curl/customized/include", 283 ] 284 285 cflags = [ "-Wno-deprecated-declarations" ] 286 } 287 288 config("curl_config_public") { 289 include_dirs = [ 290 "include", 291 "//third_party/curl/customized/include", 292 ] 293 294 cflags = [ "-Wno-deprecated-declarations" ] 295 } 296 297 ohos_source_set("curl") { 298 configs = [ ":curl_config" ] 299 300 external_deps = [ "openssl:libssl_shared" ] 301 302 public_configs = [ ":curl_config_public" ] 303 304 sources = curl_source 305 306 if ("${current_os}_${current_cpu}" == "mingw_x86_64") { 307 curl_https_ca_file_path = "\"../../resources/cacert.pem\"" 308 309 cflags = [ 310 "-g", 311 "-O2", 312 "-Wall", 313 "-w", 314 "-fno-strict-aliasing", 315 "-m64", 316 "-D_AMD64_", 317 "-DBUILDING_LIBCURL", 318 "-c", 319 "-DUSE_OPENSSL", 320 "-DHAVE_OPENSSL_ENGINE_H", 321 "-DHAVE_OPENSSL_PKCS12_H", 322 "-DHAVE_ENGINE_LOAD_BUILTIN_ENGINES", 323 "-DOPENSSL_NO_KRB5", 324 "-DCURL_CA_BUNDLE=${curl_https_ca_file_path}", 325 "-Wno-deprecated-declarations", 326 "-Wimplicit-fallthrough", 327 ] 328 329 libs = [ 330 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libwsock32.a", 331 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libmincore.a", 332 ] 333 } else if (host_os == "mac" && current_os == "mac") { 334 cflags = [ 335 "-DHAVE_CONFIG_H", 336 "-Qunused-arguments", 337 "-Os", 338 "-mmacosx-version-min=10.8", 339 "-Werror=partial-availability", 340 "-fvisibility=hidden", 341 "-DBUILDING_LIBCURL", 342 "-DCURL_HIDDEN_SYMBOLS", 343 "-c", 344 "-Wno-deprecated-declarations", 345 "-Wimplicit-fallthrough", 346 ] 347 348 cflags_c = [ 349 "-Wno-unused-function", 350 "-Wno-unused-variable", 351 "-Wno-macro-redefined", 352 ] 353 354 frameworks = [ 355 # AppKit symbols NSFontWeightXXX may be dlsym'ed. 356 "AppKit.framework", 357 "ApplicationServices.framework", 358 "OpenGL.framework", 359 "CoreFoundation.framework", 360 "SystemConfiguration.framework", 361 ] 362 } else if ("${current_cpu}" == "arm64" || "${current_cpu}" == "arm" || 363 "${current_cpu}" == "x86_64") { 364 cflags = [ 365 "-fPIC", 366 "-g", 367 "-O2", 368 "-Wall", 369 "-w", 370 "-fno-strict-aliasing", 371 "-fvisibility=hidden", 372 "-DBUILDING_LIBCURL", 373 "-DCURL_HIDDEN_SYMBOLS", 374 "-c", 375 "-DHAVE_CONFIG_H", 376 "-Wno-deprecated-declarations", 377 "-Wimplicit-fallthrough", 378 ] 379 } else if (current_cpu == "x64" && current_os == "ios") { 380 cflags = [ 381 "-fPIC", 382 "-g", 383 "-O2", 384 "-Wall", 385 "-w", 386 "-fno-strict-aliasing", 387 "-fvisibility=hidden", 388 "-DBUILDING_LIBCURL", 389 "-DCURL_HIDDEN_SYMBOLS", 390 "-c", 391 "-DHAVE_CONFIG_H", 392 "-Wno-deprecated-declarations", 393 "-Wimplicit-fallthrough", 394 ] 395 } else if (current_cpu == "x64" && current_os == "linux") { 396 cflags = [ 397 "-fPIC", 398 "-g", 399 "-O2", 400 "-Wall", 401 "-w", 402 "-fno-strict-aliasing", 403 "-fvisibility=hidden", 404 "-DBUILDING_LIBCURL", 405 "-DCURL_HIDDEN_SYMBOLS", 406 "-c", 407 "-DHAVE_CONFIG_H", 408 "-Wno-deprecated-declarations", 409 "-Wimplicit-fallthrough", 410 ] 411 } 412 413 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_standard.h\"" ] 414 415 if (is_arkui_x) { 416 deps = [ 417 "//third_party/nghttp2/lib:libnghttp2_shared", 418 "//third_party/openssl:libcrypto_shared", 419 "//third_party/openssl:libssl_shared", 420 "//third_party/zlib:shared_libz", 421 ] 422 } else { 423 external_deps += [ 424 "nghttp2:libnghttp2_shared", 425 "openssl:libcrypto_shared", 426 "openssl:libssl_shared", 427 "zlib:shared_libz", 428 ] 429 } 430 431 if (current_os != "ios" && is_cares_on) { 432 if (is_arkui_x) { 433 deps += [ 434 "//third_party/brotli:brotli_shared", 435 "//third_party/cares:c_ares", 436 ] 437 } else { 438 external_deps += [ 439 "brotli:brotli_shared", 440 "cares:c_ares", 441 ] 442 } 443 defines = [ 444 "USE_ARES", 445 "HAVE_BROTLI", 446 ] 447 } 448 subsystem_name = "thirdparty" 449 part_name = "curl" 450 } 451 452 ohos_source_set("curl_http3") { 453 configs = [ ":curl_config" ] 454 455 if (netstack_feature_http3) { 456 configs += [ "//vendor/open_source/quiche/quiche:quiche_config" ] 457 configs += [ "//vendor/open_source/boringssl:boringssl_config" ] 458 } else { 459 external_deps = [ "openssl:libssl_shared" ] 460 } 461 462 sources = curl_source 463 464 if ("${current_os}_${current_cpu}" == "mingw_x86_64") { 465 curl_https_ca_file_path = "\"../../resources/cacert.pem\"" 466 467 cflags = [ 468 "-g", 469 "-O2", 470 "-Wall", 471 "-w", 472 "-fno-strict-aliasing", 473 "-m64", 474 "-D_AMD64_", 475 "-DBUILDING_LIBCURL", 476 "-c", 477 "-DUSE_OPENSSL", 478 "-DHAVE_OPENSSL_ENGINE_H", 479 "-DHAVE_OPENSSL_PKCS12_H", 480 "-DHAVE_ENGINE_LOAD_BUILTIN_ENGINES", 481 "-DOPENSSL_NO_KRB5", 482 "-DCURL_CA_BUNDLE=${curl_https_ca_file_path}", 483 "-Wno-deprecated-declarations", 484 "-Wimplicit-fallthrough", 485 ] 486 487 libs = [ 488 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libwsock32.a", 489 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libmincore.a", 490 ] 491 } else if (host_os == "mac" && current_os == "mac") { 492 cflags = [ 493 "-DHAVE_CONFIG_H", 494 "-Qunused-arguments", 495 "-Os", 496 "-mmacosx-version-min=10.8", 497 "-Werror=partial-availability", 498 "-fvisibility=hidden", 499 "-DBUILDING_LIBCURL", 500 "-DCURL_HIDDEN_SYMBOLS", 501 "-c", 502 "-Wno-deprecated-declarations", 503 "-Wimplicit-fallthrough", 504 ] 505 506 cflags_c = [ 507 "-Wno-unused-function", 508 "-Wno-unused-variable", 509 "-Wno-macro-redefined", 510 ] 511 512 frameworks = [ 513 # AppKit symbols NSFontWeightXXX may be dlsym'ed. 514 "AppKit.framework", 515 "ApplicationServices.framework", 516 "OpenGL.framework", 517 "CoreFoundation.framework", 518 "SystemConfiguration.framework", 519 ] 520 } else if ("${current_cpu}" == "arm64" || "${current_cpu}" == "arm" || 521 "${current_cpu}" == "x86_64") { 522 cflags = [ 523 "-fPIC", 524 "-g", 525 "-O2", 526 "-Wall", 527 "-w", 528 "-fno-strict-aliasing", 529 "-fvisibility=hidden", 530 "-DBUILDING_LIBCURL", 531 "-DCURL_HIDDEN_SYMBOLS", 532 "-c", 533 "-DHAVE_CONFIG_H", 534 "-Wno-deprecated-declarations", 535 "-Wimplicit-fallthrough", 536 ] 537 } else if (current_cpu == "x64" && current_os == "ios") { 538 cflags = [ 539 "-fPIC", 540 "-g", 541 "-O2", 542 "-Wall", 543 "-w", 544 "-fno-strict-aliasing", 545 "-fvisibility=hidden", 546 "-DBUILDING_LIBCURL", 547 "-DCURL_HIDDEN_SYMBOLS", 548 "-c", 549 "-DHAVE_CONFIG_H", 550 "-Wno-deprecated-declarations", 551 "-Wimplicit-fallthrough", 552 ] 553 } else if (current_cpu == "x64" && current_os == "linux") { 554 cflags = [ 555 "-fPIC", 556 "-g", 557 "-O2", 558 "-Wall", 559 "-w", 560 "-fno-strict-aliasing", 561 "-fvisibility=hidden", 562 "-DBUILDING_LIBCURL", 563 "-DCURL_HIDDEN_SYMBOLS", 564 "-c", 565 "-DHAVE_CONFIG_H", 566 "-Wno-deprecated-declarations", 567 "-Wimplicit-fallthrough", 568 ] 569 } 570 571 if (netstack_feature_http3) { 572 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_standard_http3.h\"" ] 573 } else { 574 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_standard.h\"" ] 575 } 576 577 if (current_os == "ios") { 578 external_deps += [ 579 "nghttp2:libnghttp2_shared", 580 "openssl:libcrypto_shared", 581 "openssl:libssl_shared", 582 "zlib:shared_libz", 583 ] 584 } else { 585 external_deps += [ 586 "nghttp2:libnghttp2_shared", 587 "zlib:shared_libz", 588 ] 589 590 if (netstack_feature_http3) { 591 deps += [ "//vendor/open_source/quiche/quiche:lib" ] 592 } else { 593 external_deps += [ 594 "openssl:libcrypto_shared", 595 "openssl:libssl_shared", 596 ] 597 } 598 } 599 if (is_cares_on) { 600 if (is_arkui_x) { 601 deps += [ 602 "//third_party/brotli:brotli_shared", 603 "//third_party/cares:c_ares", 604 ] 605 } else { 606 external_deps += [ 607 "brotli:brotli_shared", 608 "cares:c_ares", 609 ] 610 } 611 defines = [ 612 "USE_ARES", 613 "HAVE_BROTLI", 614 ] 615 } 616 subsystem_name = "thirdparty" 617 part_name = "curl" 618 } 619 620 ohos_shared_library("curl_shared") { 621 branch_protector_ret = "pac_ret" 622 if (current_os == "ios") { 623 ldflags = [ 624 "-Wl", 625 "-install_name", 626 "@rpath/libcurl_shared.framework/libcurl_shared", 627 ] 628 } 629 deps = [ ":curl" ] 630 configs = [ ":curl_config" ] 631 public_configs = [ ":curl_config_public" ] 632 633 install_images = [ 634 "updater", 635 "system", 636 ] 637 innerapi_tags = [ 638 "chipsetsdk", 639 "platformsdk", 640 "sasdk", 641 ] 642 subsystem_name = "thirdparty" 643 part_name = "curl" 644 } 645 646 ohos_shared_library("curl_shared_http3") { 647 branch_protector_ret = "pac_ret" 648 if (current_os == "ios") { 649 ldflags = [ 650 "-Wl", 651 "-install_name", 652 "@rpath/libcurl_shared.framework/libcurl_shared", 653 ] 654 } 655 deps = [ ":curl_http3" ] 656 configs = [ ":curl_config" ] 657 public_configs = [ ":curl_config_public" ] 658 if (netstack_feature_http3) { 659 version_script = "curl.map" 660 } 661 662 install_images = [ 663 "updater", 664 "system", 665 ] 666 innerapi_tags = [ 667 "platformsdk", 668 "sasdk", 669 ] 670 subsystem_name = "thirdparty" 671 part_name = "curl" 672 } 673 674 if (current_os == "ios") { 675 ohos_combine_darwin_framework("libcurl_shared") { 676 deps = [ ":curl_shared" ] 677 subsystem_name = "thirdparty" 678 part_name = "curl" 679 } 680 } else { 681 group("libcurl_shared") { 682 } 683 } 684} 685 686group("curl_target") { 687 if (defined(ohos_lite)) { 688 if (ohos_kernel_type == "liteos_m") { 689 deps = [ ":libcurl_static" ] 690 } else { 691 deps = [ ":libcurl_shared" ] 692 } 693 } else { 694 deps = [ 695 ":curl", 696 ":curl_shared", 697 ] 698 } 699} 700