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_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 config("curl_config_public") { 249 include_dirs = [ 250 "include", 251 "//third_party/curl/customized/include", 252 ] 253 } 254 255 if (ohos_kernel_type == "liteos_m") { 256 static_library("libcurl_static") { 257 sources = curl_source 258 deps = [ "//third_party/mbedtls" ] 259 deps += [ "//third_party/nghttp2/lib:nghttp2_lib_static" ] 260 configs += [ 261 ":curl_config", 262 ":curl_config_public", 263 ] 264 265 public_configs = [ ":curl_config_public" ] 266 } 267 } else { 268 shared_library("libcurl_shared") { 269 sources = curl_source 270 deps = [ "//third_party/mbedtls" ] 271 deps += [ "//third_party/nghttp2/lib:nghttp2_lib_shared" ] 272 configs += [ 273 ":curl_config", 274 ":curl_config_public", 275 ] 276 public_configs = [ ":curl_config_public" ] 277 } 278 } 279} else { 280 import("//build/config/config.gni") 281 282 config("curl_config") { 283 include_dirs = [ 284 "include", 285 "lib", 286 "//third_party/curl/customized/include", 287 ] 288 289 cflags = [ "-Wno-deprecated-declarations" ] 290 } 291 292 config("curl_config_public") { 293 include_dirs = [ 294 "include", 295 "//third_party/curl/customized/include", 296 ] 297 298 cflags = [ "-Wno-deprecated-declarations" ] 299 } 300 301 ohos_source_set("curl") { 302 configs = [ ":curl_config" ] 303 304 external_deps = [ "openssl:libssl_shared" ] 305 306 public_configs = [ ":curl_config_public" ] 307 308 sources = curl_source 309 310 if ("${current_os}_${current_cpu}" == "mingw_x86_64") { 311 curl_https_ca_file_path = "\"../../resources/cacert.pem\"" 312 313 cflags = [ 314 "-g", 315 "-O2", 316 "-Wall", 317 "-w", 318 "-fno-strict-aliasing", 319 "-m64", 320 "-D_AMD64_", 321 "-DBUILDING_LIBCURL", 322 "-c", 323 "-DUSE_OPENSSL", 324 "-DHAVE_OPENSSL_ENGINE_H", 325 "-DHAVE_OPENSSL_PKCS12_H", 326 "-DHAVE_ENGINE_LOAD_BUILTIN_ENGINES", 327 "-DOPENSSL_NO_KRB5", 328 "-DCURL_CA_BUNDLE=${curl_https_ca_file_path}", 329 "-Wno-deprecated-declarations", 330 "-Wimplicit-fallthrough", 331 ] 332 333 libs = [ 334 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libwsock32.a", 335 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libmincore.a", 336 ] 337 } else if (host_os == "mac" && current_os == "mac") { 338 cflags = [ 339 "-DHAVE_CONFIG_H", 340 "-Qunused-arguments", 341 "-Os", 342 "-mmacosx-version-min=10.8", 343 "-Werror=partial-availability", 344 "-fvisibility=hidden", 345 "-DBUILDING_LIBCURL", 346 "-DCURL_HIDDEN_SYMBOLS", 347 "-c", 348 "-Wno-deprecated-declarations", 349 "-Wimplicit-fallthrough", 350 ] 351 352 cflags_c = [ 353 "-Wno-unused-function", 354 "-Wno-unused-variable", 355 "-Wno-macro-redefined", 356 ] 357 358 frameworks = [ 359 # AppKit symbols NSFontWeightXXX may be dlsym'ed. 360 "AppKit.framework", 361 "ApplicationServices.framework", 362 "OpenGL.framework", 363 "CoreFoundation.framework", 364 "SystemConfiguration.framework", 365 ] 366 } else if ("${current_cpu}" == "arm64" || "${current_cpu}" == "arm" || 367 "${current_cpu}" == "x86_64") { 368 cflags = [ 369 "-fPIC", 370 "-g", 371 "-O2", 372 "-Wall", 373 "-w", 374 "-fno-strict-aliasing", 375 "-fvisibility=hidden", 376 "-DBUILDING_LIBCURL", 377 "-DCURL_HIDDEN_SYMBOLS", 378 "-c", 379 "-DHAVE_CONFIG_H", 380 "-Wno-deprecated-declarations", 381 "-Wimplicit-fallthrough", 382 ] 383 } else if (current_cpu == "x64" && current_os == "ios") { 384 cflags = [ 385 "-fPIC", 386 "-g", 387 "-O2", 388 "-Wall", 389 "-w", 390 "-fno-strict-aliasing", 391 "-fvisibility=hidden", 392 "-DBUILDING_LIBCURL", 393 "-DCURL_HIDDEN_SYMBOLS", 394 "-c", 395 "-DHAVE_CONFIG_H", 396 "-Wno-deprecated-declarations", 397 "-Wimplicit-fallthrough", 398 ] 399 } else if (current_cpu == "x64" && current_os == "linux") { 400 cflags = [ 401 "-fPIC", 402 "-g", 403 "-O2", 404 "-Wall", 405 "-w", 406 "-fno-strict-aliasing", 407 "-fvisibility=hidden", 408 "-DBUILDING_LIBCURL", 409 "-DCURL_HIDDEN_SYMBOLS", 410 "-c", 411 "-DHAVE_CONFIG_H", 412 "-Wno-deprecated-declarations", 413 "-Wimplicit-fallthrough", 414 ] 415 } 416 417 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_standard.h\"" ] 418 419 if (is_arkui_x) { 420 deps = [ 421 "//third_party/nghttp2/lib:libnghttp2_shared", 422 "//third_party/openssl:libcrypto_shared", 423 "//third_party/openssl:libssl_shared", 424 "//third_party/zlib:shared_libz", 425 ] 426 } else { 427 external_deps += [ 428 "nghttp2:libnghttp2_shared", 429 "openssl:libcrypto_shared", 430 "openssl:libssl_shared", 431 "zlib:shared_libz", 432 ] 433 } 434 435 if (current_os != "ios" && is_cares_on) { 436 if (is_arkui_x) { 437 deps += [ 438 "//third_party/brotli:brotli_shared", 439 "//third_party/cares:c_ares", 440 ] 441 } else { 442 external_deps += [ 443 "brotli:brotli_shared", 444 "cares:c_ares", 445 ] 446 } 447 defines = [ 448 "USE_ARES", 449 "HAVE_BROTLI", 450 "DISABLE_GETENV", 451 ] 452 } 453 subsystem_name = "thirdparty" 454 part_name = "curl" 455 } 456 457 ohos_source_set("curl_http3") { 458 configs = [ ":curl_config" ] 459 460 if (netstack_feature_http3) { 461 configs += [ "//vendor/open_source/quiche/quiche:quiche_config" ] 462 configs += [ "//vendor/open_source/boringssl:boringssl_config" ] 463 } else { 464 external_deps = [ "openssl:libssl_shared" ] 465 } 466 467 sources = curl_source 468 469 if ("${current_os}_${current_cpu}" == "mingw_x86_64") { 470 curl_https_ca_file_path = "\"../../resources/cacert.pem\"" 471 472 cflags = [ 473 "-g", 474 "-O2", 475 "-Wall", 476 "-w", 477 "-fno-strict-aliasing", 478 "-m64", 479 "-D_AMD64_", 480 "-DBUILDING_LIBCURL", 481 "-c", 482 "-DUSE_OPENSSL", 483 "-DHAVE_OPENSSL_ENGINE_H", 484 "-DHAVE_OPENSSL_PKCS12_H", 485 "-DHAVE_ENGINE_LOAD_BUILTIN_ENGINES", 486 "-DOPENSSL_NO_KRB5", 487 "-DCURL_CA_BUNDLE=${curl_https_ca_file_path}", 488 "-Wno-deprecated-declarations", 489 "-Wimplicit-fallthrough", 490 ] 491 492 libs = [ 493 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libwsock32.a", 494 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libmincore.a", 495 ] 496 } else if (host_os == "mac" && current_os == "mac") { 497 cflags = [ 498 "-DHAVE_CONFIG_H", 499 "-Qunused-arguments", 500 "-Os", 501 "-mmacosx-version-min=10.8", 502 "-Werror=partial-availability", 503 "-fvisibility=hidden", 504 "-DBUILDING_LIBCURL", 505 "-DCURL_HIDDEN_SYMBOLS", 506 "-c", 507 "-Wno-deprecated-declarations", 508 "-Wimplicit-fallthrough", 509 ] 510 511 cflags_c = [ 512 "-Wno-unused-function", 513 "-Wno-unused-variable", 514 "-Wno-macro-redefined", 515 ] 516 517 frameworks = [ 518 # AppKit symbols NSFontWeightXXX may be dlsym'ed. 519 "AppKit.framework", 520 "ApplicationServices.framework", 521 "OpenGL.framework", 522 "CoreFoundation.framework", 523 "SystemConfiguration.framework", 524 ] 525 } else if ("${current_cpu}" == "arm64" || "${current_cpu}" == "arm" || 526 "${current_cpu}" == "x86_64") { 527 cflags = [ 528 "-fPIC", 529 "-g", 530 "-O2", 531 "-Wall", 532 "-w", 533 "-fno-strict-aliasing", 534 "-fvisibility=hidden", 535 "-DBUILDING_LIBCURL", 536 "-DCURL_HIDDEN_SYMBOLS", 537 "-c", 538 "-DHAVE_CONFIG_H", 539 "-Wno-deprecated-declarations", 540 "-Wimplicit-fallthrough", 541 ] 542 } else if (current_cpu == "x64" && current_os == "ios") { 543 cflags = [ 544 "-fPIC", 545 "-g", 546 "-O2", 547 "-Wall", 548 "-w", 549 "-fno-strict-aliasing", 550 "-fvisibility=hidden", 551 "-DBUILDING_LIBCURL", 552 "-DCURL_HIDDEN_SYMBOLS", 553 "-c", 554 "-DHAVE_CONFIG_H", 555 "-Wno-deprecated-declarations", 556 "-Wimplicit-fallthrough", 557 ] 558 } else if (current_cpu == "x64" && current_os == "linux") { 559 cflags = [ 560 "-fPIC", 561 "-g", 562 "-O2", 563 "-Wall", 564 "-w", 565 "-fno-strict-aliasing", 566 "-fvisibility=hidden", 567 "-DBUILDING_LIBCURL", 568 "-DCURL_HIDDEN_SYMBOLS", 569 "-c", 570 "-DHAVE_CONFIG_H", 571 "-Wno-deprecated-declarations", 572 "-Wimplicit-fallthrough", 573 ] 574 } 575 576 if (netstack_feature_http3) { 577 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_standard_http3.h\"" ] 578 } else { 579 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_standard.h\"" ] 580 } 581 582 if (current_os == "ios") { 583 external_deps += [ 584 "nghttp2:libnghttp2_shared", 585 "openssl:libcrypto_shared", 586 "openssl:libssl_shared", 587 "zlib:shared_libz", 588 ] 589 } else { 590 external_deps += [ 591 "nghttp2:libnghttp2_shared", 592 "zlib:shared_libz", 593 ] 594 595 if (netstack_feature_http3) { 596 deps += [ "//vendor/open_source/quiche/quiche:lib" ] 597 } else { 598 external_deps += [ 599 "openssl:libcrypto_shared", 600 "openssl:libssl_shared", 601 ] 602 } 603 } 604 if (is_cares_on) { 605 if (is_arkui_x) { 606 deps += [ 607 "//third_party/brotli:brotli_shared", 608 "//third_party/cares:c_ares", 609 ] 610 } else { 611 external_deps += [ 612 "brotli:brotli_shared", 613 "cares:c_ares", 614 ] 615 } 616 defines = [ 617 "USE_ARES", 618 "HAVE_BROTLI", 619 "DISABLE_GETENV", 620 ] 621 } 622 subsystem_name = "thirdparty" 623 part_name = "curl" 624 } 625 626 ohos_shared_library("curl_shared") { 627 branch_protector_ret = "pac_ret" 628 if (current_os == "ios") { 629 ldflags = [ 630 "-Wl", 631 "-install_name", 632 "@rpath/libcurl_shared.framework/libcurl_shared", 633 ] 634 } 635 deps = [ ":curl" ] 636 configs = [ ":curl_config" ] 637 public_configs = [ ":curl_config_public" ] 638 639 if (product_name != "ohos-sdk") { 640 version_script = "curl_without_http3.map" 641 } 642 643 install_images = [ 644 "updater", 645 "system", 646 ] 647 innerapi_tags = [ 648 "chipsetsdk", 649 "platformsdk", 650 "sasdk", 651 ] 652 subsystem_name = "thirdparty" 653 part_name = "curl" 654 } 655 656 ohos_shared_library("curl_shared_http3") { 657 branch_protector_ret = "pac_ret" 658 if (current_os == "ios") { 659 ldflags = [ 660 "-Wl", 661 "-install_name", 662 "@rpath/libcurl_shared.framework/libcurl_shared", 663 ] 664 } 665 deps = [ ":curl_http3" ] 666 configs = [ ":curl_config" ] 667 public_configs = [ ":curl_config_public" ] 668 if (netstack_feature_http3) { 669 version_script = "curl.map" 670 } 671 672 install_images = [ 673 "updater", 674 "system", 675 ] 676 innerapi_tags = [ 677 "platformsdk", 678 "sasdk", 679 ] 680 subsystem_name = "thirdparty" 681 part_name = "curl" 682 } 683 684 if (current_os == "ios") { 685 ohos_combine_darwin_framework("libcurl_shared") { 686 deps = [ ":curl_shared" ] 687 subsystem_name = "thirdparty" 688 part_name = "curl" 689 } 690 } else { 691 group("libcurl_shared") { 692 } 693 } 694} 695 696group("curl_target") { 697 if (defined(ohos_lite)) { 698 if (ohos_kernel_type == "liteos_m") { 699 deps = [ ":libcurl_static" ] 700 } else { 701 deps = [ ":libcurl_shared" ] 702 } 703 } else { 704 deps = [ 705 ":curl", 706 ":curl_shared", 707 ] 708 } 709} 710