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