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 "DISABLE_GETENV", 447 ] 448 } 449 subsystem_name = "thirdparty" 450 part_name = "curl" 451 } 452 453 ohos_source_set("curl_http3") { 454 configs = [ ":curl_config" ] 455 456 if (netstack_feature_http3) { 457 configs += [ "//vendor/open_source/quiche/quiche:quiche_config" ] 458 configs += [ "//vendor/open_source/boringssl:boringssl_config" ] 459 } else { 460 external_deps = [ "openssl:libssl_shared" ] 461 } 462 463 sources = curl_source 464 465 if ("${current_os}_${current_cpu}" == "mingw_x86_64") { 466 curl_https_ca_file_path = "\"../../resources/cacert.pem\"" 467 468 cflags = [ 469 "-g", 470 "-O2", 471 "-Wall", 472 "-w", 473 "-fno-strict-aliasing", 474 "-m64", 475 "-D_AMD64_", 476 "-DBUILDING_LIBCURL", 477 "-c", 478 "-DUSE_OPENSSL", 479 "-DHAVE_OPENSSL_ENGINE_H", 480 "-DHAVE_OPENSSL_PKCS12_H", 481 "-DHAVE_ENGINE_LOAD_BUILTIN_ENGINES", 482 "-DOPENSSL_NO_KRB5", 483 "-DCURL_CA_BUNDLE=${curl_https_ca_file_path}", 484 "-Wno-deprecated-declarations", 485 "-Wimplicit-fallthrough", 486 ] 487 488 libs = [ 489 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libwsock32.a", 490 "//prebuilts/mingw-w64/ohos/linux-x86_64/clang-mingw/x86_64-w64-mingw32/lib/libmincore.a", 491 ] 492 } else if (host_os == "mac" && current_os == "mac") { 493 cflags = [ 494 "-DHAVE_CONFIG_H", 495 "-Qunused-arguments", 496 "-Os", 497 "-mmacosx-version-min=10.8", 498 "-Werror=partial-availability", 499 "-fvisibility=hidden", 500 "-DBUILDING_LIBCURL", 501 "-DCURL_HIDDEN_SYMBOLS", 502 "-c", 503 "-Wno-deprecated-declarations", 504 "-Wimplicit-fallthrough", 505 ] 506 507 cflags_c = [ 508 "-Wno-unused-function", 509 "-Wno-unused-variable", 510 "-Wno-macro-redefined", 511 ] 512 513 frameworks = [ 514 # AppKit symbols NSFontWeightXXX may be dlsym'ed. 515 "AppKit.framework", 516 "ApplicationServices.framework", 517 "OpenGL.framework", 518 "CoreFoundation.framework", 519 "SystemConfiguration.framework", 520 ] 521 } else if ("${current_cpu}" == "arm64" || "${current_cpu}" == "arm" || 522 "${current_cpu}" == "x86_64") { 523 cflags = [ 524 "-fPIC", 525 "-g", 526 "-O2", 527 "-Wall", 528 "-w", 529 "-fno-strict-aliasing", 530 "-fvisibility=hidden", 531 "-DBUILDING_LIBCURL", 532 "-DCURL_HIDDEN_SYMBOLS", 533 "-c", 534 "-DHAVE_CONFIG_H", 535 "-Wno-deprecated-declarations", 536 "-Wimplicit-fallthrough", 537 ] 538 } else if (current_cpu == "x64" && current_os == "ios") { 539 cflags = [ 540 "-fPIC", 541 "-g", 542 "-O2", 543 "-Wall", 544 "-w", 545 "-fno-strict-aliasing", 546 "-fvisibility=hidden", 547 "-DBUILDING_LIBCURL", 548 "-DCURL_HIDDEN_SYMBOLS", 549 "-c", 550 "-DHAVE_CONFIG_H", 551 "-Wno-deprecated-declarations", 552 "-Wimplicit-fallthrough", 553 ] 554 } else if (current_cpu == "x64" && current_os == "linux") { 555 cflags = [ 556 "-fPIC", 557 "-g", 558 "-O2", 559 "-Wall", 560 "-w", 561 "-fno-strict-aliasing", 562 "-fvisibility=hidden", 563 "-DBUILDING_LIBCURL", 564 "-DCURL_HIDDEN_SYMBOLS", 565 "-c", 566 "-DHAVE_CONFIG_H", 567 "-Wno-deprecated-declarations", 568 "-Wimplicit-fallthrough", 569 ] 570 } 571 572 if (netstack_feature_http3) { 573 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_standard_http3.h\"" ] 574 } else { 575 cflags += [ "-DOHOS_CURL_CONFIG_H=\"curl_config_standard.h\"" ] 576 } 577 578 if (current_os == "ios") { 579 external_deps += [ 580 "nghttp2:libnghttp2_shared", 581 "openssl:libcrypto_shared", 582 "openssl:libssl_shared", 583 "zlib:shared_libz", 584 ] 585 } else { 586 external_deps += [ 587 "nghttp2:libnghttp2_shared", 588 "zlib:shared_libz", 589 ] 590 591 if (netstack_feature_http3) { 592 deps += [ "//vendor/open_source/quiche/quiche:lib" ] 593 } else { 594 external_deps += [ 595 "openssl:libcrypto_shared", 596 "openssl:libssl_shared", 597 ] 598 } 599 } 600 if (is_cares_on) { 601 if (is_arkui_x) { 602 deps += [ 603 "//third_party/brotli:brotli_shared", 604 "//third_party/cares:c_ares", 605 ] 606 } else { 607 external_deps += [ 608 "brotli:brotli_shared", 609 "cares:c_ares", 610 ] 611 } 612 defines = [ 613 "USE_ARES", 614 "HAVE_BROTLI", 615 "DISABLE_GETENV", 616 ] 617 } 618 subsystem_name = "thirdparty" 619 part_name = "curl" 620 } 621 622 ohos_shared_library("curl_shared") { 623 if (current_os == "ios") { 624 ldflags = [ 625 "-Wl", 626 "-install_name", 627 "@rpath/libcurl_shared.framework/libcurl_shared", 628 ] 629 } 630 deps = [ ":curl" ] 631 configs = [ ":curl_config" ] 632 public_configs = [ ":curl_config_public" ] 633 634 install_images = [ 635 "updater", 636 "system", 637 ] 638 innerapi_tags = [ 639 "chipsetsdk", 640 "platformsdk", 641 "sasdk", 642 ] 643 subsystem_name = "thirdparty" 644 part_name = "curl" 645 } 646 647 ohos_shared_library("curl_shared_http3") { 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 } 681} 682 683group("curl_target") { 684 if (defined(ohos_lite)) { 685 if (ohos_kernel_type == "liteos_m") { 686 deps = [ ":libcurl_static" ] 687 } else { 688 deps = [ ":libcurl_shared" ] 689 } 690 } else { 691 deps = [ 692 ":curl", 693 ":curl_shared", 694 ] 695 } 696} 697