1# Copyright (c) 2021-2022 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") 15 16platform = "${current_os}_${current_cpu}" 17 18if (target_os == "ios") { 19 libwebsockets_path = rebase_path("//third_party/libwebsockets") 20 exec_script("for_ios.sh", [ "$libwebsockets_path" ]) 21} 22 23ohos_static_library("websockets") { 24 sources = [ 25 "//third_party/libwebsockets/lib/core-net/adopt.c", 26 "//third_party/libwebsockets/lib/core-net/client/client.c", 27 "//third_party/libwebsockets/lib/core-net/client/conmon.c", 28 "//third_party/libwebsockets/lib/core-net/client/connect.c", 29 "//third_party/libwebsockets/lib/core-net/client/connect2.c", 30 "//third_party/libwebsockets/lib/core-net/client/connect3.c", 31 "//third_party/libwebsockets/lib/core-net/client/connect4.c", 32 "//third_party/libwebsockets/lib/core-net/client/sort-dns.c", 33 "//third_party/libwebsockets/lib/core-net/close.c", 34 "//third_party/libwebsockets/lib/core-net/dummy-callback.c", 35 "//third_party/libwebsockets/lib/core-net/network.c", 36 "//third_party/libwebsockets/lib/core-net/output.c", 37 "//third_party/libwebsockets/lib/core-net/pollfd.c", 38 "//third_party/libwebsockets/lib/core-net/service.c", 39 "//third_party/libwebsockets/lib/core-net/sorted-usec-list.c", 40 "//third_party/libwebsockets/lib/core-net/state.c", 41 "//third_party/libwebsockets/lib/core-net/wsi-timeout.c", 42 "//third_party/libwebsockets/lib/core-net/wsi.c", 43 "//third_party/libwebsockets/lib/core/alloc.c", 44 "//third_party/libwebsockets/lib/core/buflist.c", 45 "//third_party/libwebsockets/lib/core/context.c", 46 "//third_party/libwebsockets/lib/core/libwebsockets.c", 47 "//third_party/libwebsockets/lib/core/logs.c", 48 "//third_party/libwebsockets/lib/core/lws_dll2.c", 49 "//third_party/libwebsockets/lib/core/lws_map.c", 50 "//third_party/libwebsockets/lib/core/vfs.c", 51 "//third_party/libwebsockets/lib/event-libs/poll/poll.c", 52 "//third_party/libwebsockets/lib/misc/base64-decode.c", 53 "//third_party/libwebsockets/lib/misc/cache-ttl/file.c", 54 "//third_party/libwebsockets/lib/misc/cache-ttl/heap.c", 55 "//third_party/libwebsockets/lib/misc/cache-ttl/lws-cache-ttl.c", 56 "//third_party/libwebsockets/lib/misc/dir.c", 57 "//third_party/libwebsockets/lib/misc/lejp.c", 58 "//third_party/libwebsockets/lib/misc/lws-ring.c", 59 "//third_party/libwebsockets/lib/misc/lwsac/cached-file.c", 60 "//third_party/libwebsockets/lib/misc/lwsac/lwsac.c", 61 "//third_party/libwebsockets/lib/misc/prng.c", 62 "//third_party/libwebsockets/lib/misc/sha-1.c", 63 "//third_party/libwebsockets/lib/plat/unix/unix-caps.c", 64 "//third_party/libwebsockets/lib/plat/unix/unix-fds.c", 65 "//third_party/libwebsockets/lib/plat/unix/unix-file.c", 66 "//third_party/libwebsockets/lib/plat/unix/unix-init.c", 67 "//third_party/libwebsockets/lib/plat/unix/unix-misc.c", 68 "//third_party/libwebsockets/lib/plat/unix/unix-pipe.c", 69 "//third_party/libwebsockets/lib/plat/unix/unix-service.c", 70 "//third_party/libwebsockets/lib/plat/unix/unix-sockets.c", 71 "//third_party/libwebsockets/lib/roles/h1/ops-h1.c", 72 "//third_party/libwebsockets/lib/roles/h2/hpack.c", 73 "//third_party/libwebsockets/lib/roles/h2/http2.c", 74 "//third_party/libwebsockets/lib/roles/h2/ops-h2.c", 75 "//third_party/libwebsockets/lib/roles/http/client/client-http.c", 76 "//third_party/libwebsockets/lib/roles/http/cookie.c", 77 "//third_party/libwebsockets/lib/roles/http/date.c", 78 "//third_party/libwebsockets/lib/roles/http/header.c", 79 "//third_party/libwebsockets/lib/roles/http/parsers.c", 80 "//third_party/libwebsockets/lib/roles/http/server/lejp-conf.c", 81 "//third_party/libwebsockets/lib/roles/http/server/lws-spa.c", 82 "//third_party/libwebsockets/lib/roles/http/server/server.c", 83 "//third_party/libwebsockets/lib/roles/listen/ops-listen.c", 84 "//third_party/libwebsockets/lib/roles/pipe/ops-pipe.c", 85 "//third_party/libwebsockets/lib/roles/raw-file/ops-raw-file.c", 86 "//third_party/libwebsockets/lib/roles/raw-skt/ops-raw-skt.c", 87 "//third_party/libwebsockets/lib/roles/ws/client-parser-ws.c", 88 "//third_party/libwebsockets/lib/roles/ws/client-ws.c", 89 "//third_party/libwebsockets/lib/roles/ws/ops-ws.c", 90 "//third_party/libwebsockets/lib/roles/ws/server-ws.c", 91 "//third_party/libwebsockets/lib/system/smd/smd.c", 92 "//third_party/libwebsockets/lib/system/system.c", 93 "//third_party/libwebsockets/lib/tls/openssl/openssl-client.c", 94 "//third_party/libwebsockets/lib/tls/openssl/openssl-server.c", 95 "//third_party/libwebsockets/lib/tls/openssl/openssl-session.c", 96 "//third_party/libwebsockets/lib/tls/openssl/openssl-ssl.c", 97 "//third_party/libwebsockets/lib/tls/openssl/openssl-tls.c", 98 "//third_party/libwebsockets/lib/tls/openssl/openssl-x509.c", 99 "//third_party/libwebsockets/lib/tls/tls-client.c", 100 "//third_party/libwebsockets/lib/tls/tls-network.c", 101 "//third_party/libwebsockets/lib/tls/tls-server.c", 102 "//third_party/libwebsockets/lib/tls/tls-sessions.c", 103 "//third_party/libwebsockets/lib/tls/tls.c", 104 ] 105 106 part_name = "libwebsockets" 107 subsystem_name = "thirdparty" 108 109 if (target_os != "ios") { 110 sources += [ 111 "//third_party/libwebsockets/lib/core-net/route.c", 112 "//third_party/libwebsockets/lib/roles/netlink/ops-netlink.c", 113 ] 114 } 115 116 include_dirs = [ 117 "//third_party/libwebsockets/include", 118 "//third_party/libwebsockets/include/libwebsockets", 119 "//third_party/libwebsockets/include/libwebsockets/abstract", 120 "//third_party/libwebsockets/include/libwebsockets/abstract/protocols", 121 122 ################################################# 123 "//third_party/libwebsockets/lib", 124 "//third_party/libwebsockets/lib/plat", 125 "//third_party/libwebsockets/lib/plat/windows", 126 "//third_party/libwebsockets/lib/plat/unix", 127 "//third_party/libwebsockets/lib/plat/unix/android", 128 "//third_party/libwebsockets/lib/plat/optee", 129 "//third_party/libwebsockets/lib/plat/freertos", 130 "//third_party/libwebsockets/lib/plat/freertos/esp32", 131 "//third_party/libwebsockets/lib/plat/freertos/esp32/drivers", 132 "//third_party/libwebsockets/lib/plat/freertos/esp32/drivers/netdev", 133 "//third_party/libwebsockets/lib/event-libs", 134 "//third_party/libwebsockets/lib/event-libs/libevent", 135 "//third_party/libwebsockets/lib/event-libs/libuv", 136 "//third_party/libwebsockets/lib/event-libs/uloop", 137 "//third_party/libwebsockets/lib/event-libs/libev", 138 "//third_party/libwebsockets/lib/event-libs/sdevent", 139 "//third_party/libwebsockets/lib/event-libs/poll", 140 "//third_party/libwebsockets/lib/cose", 141 "//third_party/libwebsockets/lib/core-net", 142 "//third_party/libwebsockets/lib/core-net/client", 143 "//third_party/libwebsockets/lib/tls", 144 "//third_party/libwebsockets/lib/tls/openssl", 145 "//third_party/libwebsockets/lib/abstract", 146 "//third_party/libwebsockets/lib/abstract/protocols", 147 "//third_party/libwebsockets/lib/abstract/protocols/smtp", 148 "//third_party/libwebsockets/lib/abstract/transports", 149 "//third_party/libwebsockets/lib/core", 150 "//third_party/libwebsockets/lib/misc", 151 "//third_party/libwebsockets/lib/misc/threadpool", 152 "//third_party/libwebsockets/lib/misc/fts", 153 "//third_party/libwebsockets/lib/misc/cache-ttl", 154 "//third_party/libwebsockets/lib/misc/lwsac", 155 "//third_party/libwebsockets/lib/secure-streams", 156 "//third_party/libwebsockets/lib/secure-streams/plugins", 157 "//third_party/libwebsockets/lib/secure-streams/plugins/ssp-h1url", 158 "//third_party/libwebsockets/lib/secure-streams/cpp", 159 "//third_party/libwebsockets/lib/secure-streams/protocols", 160 "//third_party/libwebsockets/lib/secure-streams/system", 161 "//third_party/libwebsockets/lib/secure-streams/system/auth-sigv4", 162 "//third_party/libwebsockets/lib/secure-streams/system/auth-api.amazon.com", 163 "//third_party/libwebsockets/lib/secure-streams/system/fetch-policy", 164 "//third_party/libwebsockets/lib/secure-streams/system/captive-portal-detect", 165 "//third_party/libwebsockets/lib/jose", 166 "//third_party/libwebsockets/lib/jose/jwk", 167 "//third_party/libwebsockets/lib/jose/jwe", 168 "//third_party/libwebsockets/lib/jose/jwe/enc", 169 "//third_party/libwebsockets/lib/jose/jws", 170 "//third_party/libwebsockets/lib/drivers", 171 "//third_party/libwebsockets/lib/drivers/spi", 172 "//third_party/libwebsockets/lib/drivers/spi/bitbang", 173 "//third_party/libwebsockets/lib/drivers/pwm", 174 "//third_party/libwebsockets/lib/drivers/netdev", 175 "//third_party/libwebsockets/lib/drivers/devices", 176 "//third_party/libwebsockets/lib/drivers/devices/display", 177 "//third_party/libwebsockets/lib/drivers/i2c", 178 "//third_party/libwebsockets/lib/drivers/i2c/bitbang", 179 "//third_party/libwebsockets/lib/drivers/display", 180 "//third_party/libwebsockets/lib/drivers/button", 181 "//third_party/libwebsockets/lib/drivers/settings", 182 "//third_party/libwebsockets/lib/drivers/led", 183 "//third_party/libwebsockets/lib/system", 184 "//third_party/libwebsockets/lib/system/fault-injection", 185 "//third_party/libwebsockets/lib/system/dhcpclient", 186 "//third_party/libwebsockets/lib/system/ntpclient", 187 "//third_party/libwebsockets/lib/system/metrics", 188 "//third_party/libwebsockets/lib/system/async-dns", 189 "//third_party/libwebsockets/lib/system/smd", 190 "//third_party/libwebsockets/lib/roles", 191 "//third_party/libwebsockets/lib/roles/raw-proxy", 192 "//third_party/libwebsockets/lib/roles/http", 193 "//third_party/libwebsockets/lib/roles/http/server", 194 "//third_party/libwebsockets/lib/roles/http/client", 195 "//third_party/libwebsockets/lib/roles/http/compression", 196 "//third_party/libwebsockets/lib/roles/http/compression/deflate", 197 "//third_party/libwebsockets/lib/roles/http/compression/brotli", 198 "//third_party/libwebsockets/lib/roles/h2", 199 "//third_party/libwebsockets/lib/roles/netlink", 200 "//third_party/libwebsockets/lib/roles/raw-skt", 201 "//third_party/libwebsockets/lib/roles/mqtt", 202 "//third_party/libwebsockets/lib/roles/mqtt/client", 203 "//third_party/libwebsockets/lib/roles/cgi", 204 "//third_party/libwebsockets/lib/roles/dbus", 205 "//third_party/libwebsockets/lib/roles/pipe", 206 "//third_party/libwebsockets/lib/roles/h1", 207 "//third_party/libwebsockets/lib/roles/listen", 208 "//third_party/libwebsockets/lib/roles/ws", 209 "//third_party/libwebsockets/lib/roles/ws/ext", 210 "//third_party/libwebsockets/lib/roles/raw-file", 211 ] 212 213 deps = [] 214 215 if (is_arkui_x) { 216 if (target_os == "ios") { 217 deps += [ 218 "//third_party/openssl:libcrypto_static", 219 "//third_party/openssl:libssl_static", 220 ] 221 } else { 222 deps += [ 223 "//third_party/openssl:libcrypto_shared", 224 "//third_party/openssl:libssl_shared", 225 ] 226 } 227 include_dirs += [ 228 "//third_party/openssl/include/openssl", 229 "//third_party/openssl/crypto/evp", 230 ] 231 } 232 233 if (target_os == "ios") { 234 sources += [ "//third_party/libwebsockets/lib/core-net/vhost_ios.c" ] 235 } else { 236 sources += [ "//third_party/libwebsockets/lib/core-net/vhost.c" ] 237 } 238 239 defines = [ 240 "OHOS_LIBWEBSOCKETS=1", 241 "OPENSSL_SUPPRESS_DEPRECATED", 242 ] 243 if (target_os == "ios") { 244 defines += [ "LWS_DETECTED_PLAT_IOS=1" ] 245 defines += [ "CROSS_PLATFORM_IOS_LIBWEBSOCKETS=1" ] 246 } 247 248 cflags = [ 249 "-fPIC", 250 "-Os", 251 "-g", 252 "-Wall", 253 "-fno-strict-aliasing", 254 "-fvisibility=hidden", 255 "-Wmissing-declarations", 256 "-Waggregate-return", 257 "-pipe", 258 ] 259 260 external_deps = [ 261 "openssl:libcrypto_shared", 262 "openssl:libssl_shared", 263 "zlib:libz", 264 ] 265 public_configs = [ ":websockets_public_config" ] 266} 267 268config("websocket_config") { 269 cflags = [ 270 "-Wall", 271 "-Wsign-compare", 272 "-Wstrict-aliasing", 273 "-Wuninitialized", 274 "-fvisibility=hidden", 275 "-Wtype-limits", 276 "-Wignored-qualifiers", 277 "-Wno-deprecated-declarations", 278 "-pthread", 279 "-Wno-unused-command-line-argument", 280 "-Wno-unused-parameter", 281 "-Wno-implicit-function-declaration", 282 ] 283} 284 285config("websockets_public_config") { 286 include_dirs = [ 287 "//third_party/libwebsockets/plugins", 288 "//third_party/libwebsockets/lib/core", 289 "//third_party/libwebsockets/lib/core-net", 290 "//third_party/libwebsockets/lib/event-libs", 291 "//third_party/libwebsockets/lib/abstract", 292 "//third_party/libwebsockets/lib/tls", 293 "//third_party/libwebsockets/lib/roles", 294 "//third_party/libwebsockets/lib/event-libs/libuv", 295 "//third_party/libwebsockets/lib/event-libs/poll", 296 "//third_party/libwebsockets/lib/event-libs/libevent", 297 "//third_party/libwebsockets/lib/event-libs/libev", 298 "//third_party/libwebsockets/lib/jose/jwe", 299 "//third_party/libwebsockets/lib/jose/jws", 300 "//third_party/libwebsockets/lib/jose", 301 "//third_party/libwebsockets/lib/misc", 302 "//third_party/libwebsockets/lib/roles/http", 303 "//third_party/libwebsockets/lib/roles/http/compression", 304 "//third_party/libwebsockets/lib/roles/h1", 305 "//third_party/libwebsockets/lib/roles/h2", 306 "//third_party/libwebsockets/lib/roles/ws", 307 "//third_party/libwebsockets/lib/roles/cgi", 308 "//third_party/libwebsockets/lib/roles/dbus", 309 "//third_party/libwebsockets/lib/roles/raw-proxy", 310 "//third_party/libwebsockets/lib/abstract", 311 "//third_party/libwebsockets/lib/system/async-dns", 312 "//third_party/libwebsockets/lib/roles/mqtt", 313 "//third_party/libwebsockets/lib/system/metrics", 314 "//third_party/libwebsockets/lib", 315 "//third_party/libwebsockets/win32port/win32helpers", 316 "//third_party/libwebsockets/include", 317 ] 318 if (platform == "mingw_x86_64") { 319 include_dirs += [ "//third_party/libwebsockets/lib/plat/windows" ] 320 } else if (platform == "mac_arm64" || platform == "mac_x64" || 321 platform == "linux_x64" || platform == "linux_arm64") { 322 include_dirs += [ "//third_party/libwebsockets/lib/plat/unix" ] 323 } 324 cflags = [ "-Wno-error=#warnings" ] 325} 326 327ohos_static_library("websockets_static") { 328 sources = [ 329 "//third_party/libwebsockets/lib/core-net/adopt.c", 330 "//third_party/libwebsockets/lib/core-net/client/client.c", 331 "//third_party/libwebsockets/lib/core-net/client/connect.c", 332 "//third_party/libwebsockets/lib/core-net/client/connect2.c", 333 "//third_party/libwebsockets/lib/core-net/client/connect3.c", 334 "//third_party/libwebsockets/lib/core-net/client/connect4.c", 335 "//third_party/libwebsockets/lib/core-net/client/sort-dns.c", 336 "//third_party/libwebsockets/lib/core-net/close.c", 337 "//third_party/libwebsockets/lib/core-net/dummy-callback.c", 338 "//third_party/libwebsockets/lib/core-net/network.c", 339 "//third_party/libwebsockets/lib/core-net/output.c", 340 "//third_party/libwebsockets/lib/core-net/pollfd.c", 341 "//third_party/libwebsockets/lib/core-net/sequencer.c", 342 "//third_party/libwebsockets/lib/core-net/service.c", 343 "//third_party/libwebsockets/lib/core-net/sorted-usec-list.c", 344 "//third_party/libwebsockets/lib/core-net/state.c", 345 "//third_party/libwebsockets/lib/core-net/vhost.c", 346 "//third_party/libwebsockets/lib/core-net/wsi-timeout.c", 347 "//third_party/libwebsockets/lib/core-net/wsi.c", 348 "//third_party/libwebsockets/lib/core/alloc.c", 349 "//third_party/libwebsockets/lib/core/buflist.c", 350 "//third_party/libwebsockets/lib/core/context.c", 351 "//third_party/libwebsockets/lib/core/libwebsockets.c", 352 "//third_party/libwebsockets/lib/core/logs.c", 353 "//third_party/libwebsockets/lib/core/lws_dll2.c", 354 "//third_party/libwebsockets/lib/core/vfs.c", 355 "//third_party/libwebsockets/lib/event-libs/poll/poll.c", 356 "//third_party/libwebsockets/lib/misc/base64-decode.c", 357 "//third_party/libwebsockets/lib/misc/lejp.c", 358 "//third_party/libwebsockets/lib/misc/lws-ring.c", 359 "//third_party/libwebsockets/lib/misc/lwsac/cached-file.c", 360 "//third_party/libwebsockets/lib/misc/lwsac/lwsac.c", 361 "//third_party/libwebsockets/lib/misc/peer-limits.c", 362 "//third_party/libwebsockets/lib/misc/sha-1.c", 363 "//third_party/libwebsockets/lib/roles/h1/ops-h1.c", 364 "//third_party/libwebsockets/lib/roles/h2/hpack.c", 365 "//third_party/libwebsockets/lib/roles/h2/http2.c", 366 "//third_party/libwebsockets/lib/roles/h2/ops-h2.c", 367 "//third_party/libwebsockets/lib/roles/http/client/client-http.c", 368 "//third_party/libwebsockets/lib/roles/http/date.c", 369 "//third_party/libwebsockets/lib/roles/http/header.c", 370 "//third_party/libwebsockets/lib/roles/http/parsers.c", 371 "//third_party/libwebsockets/lib/roles/http/server/server.c", 372 "//third_party/libwebsockets/lib/roles/listen/ops-listen.c", 373 "//third_party/libwebsockets/lib/roles/pipe/ops-pipe.c", 374 "//third_party/libwebsockets/lib/roles/raw-file/ops-raw-file.c", 375 "//third_party/libwebsockets/lib/roles/raw-skt/ops-raw-skt.c", 376 "//third_party/libwebsockets/lib/roles/ws/client-parser-ws.c", 377 "//third_party/libwebsockets/lib/roles/ws/client-ws.c", 378 "//third_party/libwebsockets/lib/roles/ws/ops-ws.c", 379 "//third_party/libwebsockets/lib/roles/ws/server-ws.c", 380 "//third_party/libwebsockets/lib/system/system.c", 381 ] 382 if (platform == "mingw_x86_64") { 383 sources += [ 384 "//third_party/libwebsockets/lib/plat/windows/windows-fds.c", 385 "//third_party/libwebsockets/lib/plat/windows/windows-file.c", 386 "//third_party/libwebsockets/lib/plat/windows/windows-init.c", 387 "//third_party/libwebsockets/lib/plat/windows/windows-misc.c", 388 "//third_party/libwebsockets/lib/plat/windows/windows-pipe.c", 389 "//third_party/libwebsockets/lib/plat/windows/windows-plugins.c", 390 "//third_party/libwebsockets/lib/plat/windows/windows-service.c", 391 "//third_party/libwebsockets/lib/plat/windows/windows-sockets.c", 392 ] 393 } else if (platform == "mac_arm64" || platform == "mac_x64" || 394 platform == "linux_x64" || platform == "linux_arm64") { 395 defines = [ "LWS_HAVE_SYS_RESOURCE_H" ] 396 sources += [ 397 "//third_party/libwebsockets/lib/plat/unix/unix-caps.c", 398 "//third_party/libwebsockets/lib/plat/unix/unix-fds.c", 399 "//third_party/libwebsockets/lib/plat/unix/unix-file.c", 400 "//third_party/libwebsockets/lib/plat/unix/unix-init.c", 401 "//third_party/libwebsockets/lib/plat/unix/unix-misc.c", 402 "//third_party/libwebsockets/lib/plat/unix/unix-pipe.c", 403 "//third_party/libwebsockets/lib/plat/unix/unix-service.c", 404 "//third_party/libwebsockets/lib/plat/unix/unix-sockets.c", 405 ] 406 } 407 configs = [ ":websocket_config" ] 408 public_configs = [ ":websockets_public_config" ] 409} 410