• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/event-libs/glib",
141    "//third_party/libwebsockets/lib/cose",
142    "//third_party/libwebsockets/lib/core-net",
143    "//third_party/libwebsockets/lib/core-net/client",
144    "//third_party/libwebsockets/lib/tls",
145    "//third_party/libwebsockets/lib/tls/openssl",
146    "//third_party/libwebsockets/lib/abstract",
147    "//third_party/libwebsockets/lib/abstract/protocols",
148    "//third_party/libwebsockets/lib/abstract/protocols/smtp",
149    "//third_party/libwebsockets/lib/abstract/transports",
150    "//third_party/libwebsockets/lib/core",
151    "//third_party/libwebsockets/lib/misc",
152    "//third_party/libwebsockets/lib/misc/threadpool",
153    "//third_party/libwebsockets/lib/misc/fts",
154    "//third_party/libwebsockets/lib/misc/cache-ttl",
155    "//third_party/libwebsockets/lib/misc/lwsac",
156    "//third_party/libwebsockets/lib/secure-streams",
157    "//third_party/libwebsockets/lib/secure-streams/plugins",
158    "//third_party/libwebsockets/lib/secure-streams/plugins/ssp-h1url",
159    "//third_party/libwebsockets/lib/secure-streams/cpp",
160    "//third_party/libwebsockets/lib/secure-streams/protocols",
161    "//third_party/libwebsockets/lib/secure-streams/system",
162    "//third_party/libwebsockets/lib/secure-streams/system/auth-sigv4",
163    "//third_party/libwebsockets/lib/secure-streams/system/auth-api.amazon.com",
164    "//third_party/libwebsockets/lib/secure-streams/system/fetch-policy",
165    "//third_party/libwebsockets/lib/secure-streams/system/captive-portal-detect",
166    "//third_party/libwebsockets/lib/jose",
167    "//third_party/libwebsockets/lib/jose/jwk",
168    "//third_party/libwebsockets/lib/jose/jwe",
169    "//third_party/libwebsockets/lib/jose/jwe/enc",
170    "//third_party/libwebsockets/lib/jose/jws",
171    "//third_party/libwebsockets/lib/drivers",
172    "//third_party/libwebsockets/lib/drivers/spi",
173    "//third_party/libwebsockets/lib/drivers/spi/bitbang",
174    "//third_party/libwebsockets/lib/drivers/pwm",
175    "//third_party/libwebsockets/lib/drivers/netdev",
176    "//third_party/libwebsockets/lib/drivers/devices",
177    "//third_party/libwebsockets/lib/drivers/devices/display",
178    "//third_party/libwebsockets/lib/drivers/i2c",
179    "//third_party/libwebsockets/lib/drivers/i2c/bitbang",
180    "//third_party/libwebsockets/lib/drivers/display",
181    "//third_party/libwebsockets/lib/drivers/button",
182    "//third_party/libwebsockets/lib/drivers/settings",
183    "//third_party/libwebsockets/lib/drivers/led",
184    "//third_party/libwebsockets/lib/system",
185    "//third_party/libwebsockets/lib/system/fault-injection",
186    "//third_party/libwebsockets/lib/system/dhcpclient",
187    "//third_party/libwebsockets/lib/system/ntpclient",
188    "//third_party/libwebsockets/lib/system/metrics",
189    "//third_party/libwebsockets/lib/system/async-dns",
190    "//third_party/libwebsockets/lib/system/smd",
191    "//third_party/libwebsockets/lib/roles",
192    "//third_party/libwebsockets/lib/roles/raw-proxy",
193    "//third_party/libwebsockets/lib/roles/http",
194    "//third_party/libwebsockets/lib/roles/http/server",
195    "//third_party/libwebsockets/lib/roles/http/client",
196    "//third_party/libwebsockets/lib/roles/http/compression",
197    "//third_party/libwebsockets/lib/roles/http/compression/deflate",
198    "//third_party/libwebsockets/lib/roles/http/compression/brotli",
199    "//third_party/libwebsockets/lib/roles/h2",
200    "//third_party/libwebsockets/lib/roles/netlink",
201    "//third_party/libwebsockets/lib/roles/raw-skt",
202    "//third_party/libwebsockets/lib/roles/mqtt",
203    "//third_party/libwebsockets/lib/roles/mqtt/client",
204    "//third_party/libwebsockets/lib/roles/cgi",
205    "//third_party/libwebsockets/lib/roles/dbus",
206    "//third_party/libwebsockets/lib/roles/pipe",
207    "//third_party/libwebsockets/lib/roles/h1",
208    "//third_party/libwebsockets/lib/roles/listen",
209    "//third_party/libwebsockets/lib/roles/ws",
210    "//third_party/libwebsockets/lib/roles/ws/ext",
211    "//third_party/libwebsockets/lib/roles/raw-file",
212  ]
213
214  deps = []
215
216  if (is_arkui_x) {
217    if (target_os == "ios") {
218      deps += [
219        "//third_party/openssl:libcrypto_static",
220        "//third_party/openssl:libssl_static",
221      ]
222    } else {
223      deps += [
224        "//third_party/openssl:libcrypto_shared",
225        "//third_party/openssl:libssl_shared",
226      ]
227    }
228    include_dirs += [
229      "//third_party/openssl/include/openssl",
230      "//third_party/openssl/crypto/evp",
231      "//third_party/glib/glib",
232      "//third_party/glib",
233    ]
234  }
235
236  if (target_os == "ios") {
237    sources += [ "//third_party/libwebsockets/lib/core-net/vhost_ios.c" ]
238  } else {
239    sources += [ "//third_party/libwebsockets/lib/core-net/vhost.c" ]
240  }
241
242  defines = [
243    "OHOS_LIBWEBSOCKETS=1",
244    "OPENSSL_SUPPRESS_DEPRECATED",
245  ]
246  if (target_os == "ios") {
247    defines += [ "LWS_DETECTED_PLAT_IOS=1" ]
248    defines += [ "CROSS_PLATFORM_IOS_LIBWEBSOCKETS=1" ]
249  }
250
251  cflags = [
252    "-fPIC",
253    "-Os",
254    "-g",
255    "-Wall",
256    "-fno-strict-aliasing",
257    "-fvisibility=hidden",
258    "-Wmissing-declarations",
259    "-Waggregate-return",
260    "-pipe",
261  ]
262
263  external_deps = [
264    "glib:glib",
265    "openssl:libcrypto_shared",
266    "openssl:libssl_shared",
267    "zlib:libz",
268  ]
269  public_configs = [ ":websockets_public_config" ]
270}
271
272config("websocket_config") {
273  cflags = [
274    "-Wall",
275    "-Wsign-compare",
276    "-Wstrict-aliasing",
277    "-Wuninitialized",
278    "-fvisibility=hidden",
279    "-Wtype-limits",
280    "-Wignored-qualifiers",
281    "-Wno-deprecated-declarations",
282    "-pthread",
283    "-Wno-unused-command-line-argument",
284    "-Wno-unused-parameter",
285    "-Wno-implicit-function-declaration",
286  ]
287}
288
289config("websockets_public_config") {
290  include_dirs = [
291    "//third_party/libwebsockets/plugins",
292    "//third_party/libwebsockets/lib/core",
293    "//third_party/libwebsockets/lib/core-net",
294    "//third_party/libwebsockets/lib/event-libs",
295    "//third_party/libwebsockets/lib/abstract",
296    "//third_party/libwebsockets/lib/tls",
297    "//third_party/libwebsockets/lib/roles",
298    "//third_party/libwebsockets/lib/event-libs/libuv",
299    "//third_party/libwebsockets/lib/event-libs/poll",
300    "//third_party/libwebsockets/lib/event-libs/libevent",
301    "//third_party/libwebsockets/lib/event-libs/glib",
302    "//third_party/libwebsockets/lib/event-libs/libev",
303    "//third_party/libwebsockets/lib/jose/jwe",
304    "//third_party/libwebsockets/lib/jose/jws",
305    "//third_party/libwebsockets/lib/jose",
306    "//third_party/libwebsockets/lib/misc",
307    "//third_party/libwebsockets/lib/roles/http",
308    "//third_party/libwebsockets/lib/roles/http/compression",
309    "//third_party/libwebsockets/lib/roles/h1",
310    "//third_party/libwebsockets/lib/roles/h2",
311    "//third_party/libwebsockets/lib/roles/ws",
312    "//third_party/libwebsockets/lib/roles/cgi",
313    "//third_party/libwebsockets/lib/roles/dbus",
314    "//third_party/libwebsockets/lib/roles/raw-proxy",
315    "//third_party/libwebsockets/lib/abstract",
316    "//third_party/libwebsockets/lib/system/async-dns",
317    "//third_party/libwebsockets/lib/roles/mqtt",
318    "//third_party/libwebsockets/lib/system/metrics",
319    "//third_party/libwebsockets/lib",
320    "//third_party/libwebsockets/win32port/win32helpers",
321    "//third_party/libwebsockets/include",
322  ]
323  if (platform == "mingw_x86_64") {
324    include_dirs += [ "//third_party/libwebsockets/lib/plat/windows" ]
325  } else if (platform == "mac_arm64" || platform == "mac_x64" ||
326             platform == "linux_x64" || platform == "linux_arm64") {
327    include_dirs += [ "//third_party/libwebsockets/lib/plat/unix" ]
328  }
329  cflags = [ "-Wno-error=#warnings" ]
330}
331
332ohos_static_library("websockets_static") {
333  sources = [
334    "//third_party/libwebsockets/lib/core-net/adopt.c",
335    "//third_party/libwebsockets/lib/core-net/client/client.c",
336    "//third_party/libwebsockets/lib/core-net/client/connect.c",
337    "//third_party/libwebsockets/lib/core-net/client/connect2.c",
338    "//third_party/libwebsockets/lib/core-net/client/connect3.c",
339    "//third_party/libwebsockets/lib/core-net/client/connect4.c",
340    "//third_party/libwebsockets/lib/core-net/client/sort-dns.c",
341    "//third_party/libwebsockets/lib/core-net/close.c",
342    "//third_party/libwebsockets/lib/core-net/dummy-callback.c",
343    "//third_party/libwebsockets/lib/core-net/network.c",
344    "//third_party/libwebsockets/lib/core-net/output.c",
345    "//third_party/libwebsockets/lib/core-net/pollfd.c",
346    "//third_party/libwebsockets/lib/core-net/sequencer.c",
347    "//third_party/libwebsockets/lib/core-net/service.c",
348    "//third_party/libwebsockets/lib/core-net/sorted-usec-list.c",
349    "//third_party/libwebsockets/lib/core-net/state.c",
350    "//third_party/libwebsockets/lib/core-net/vhost.c",
351    "//third_party/libwebsockets/lib/core-net/wsi-timeout.c",
352    "//third_party/libwebsockets/lib/core-net/wsi.c",
353    "//third_party/libwebsockets/lib/core/alloc.c",
354    "//third_party/libwebsockets/lib/core/buflist.c",
355    "//third_party/libwebsockets/lib/core/context.c",
356    "//third_party/libwebsockets/lib/core/libwebsockets.c",
357    "//third_party/libwebsockets/lib/core/logs.c",
358    "//third_party/libwebsockets/lib/core/lws_dll2.c",
359    "//third_party/libwebsockets/lib/core/vfs.c",
360    "//third_party/libwebsockets/lib/event-libs/poll/poll.c",
361    "//third_party/libwebsockets/lib/misc/base64-decode.c",
362    "//third_party/libwebsockets/lib/misc/lejp.c",
363    "//third_party/libwebsockets/lib/misc/lws-ring.c",
364    "//third_party/libwebsockets/lib/misc/lwsac/cached-file.c",
365    "//third_party/libwebsockets/lib/misc/lwsac/lwsac.c",
366    "//third_party/libwebsockets/lib/misc/peer-limits.c",
367    "//third_party/libwebsockets/lib/misc/sha-1.c",
368    "//third_party/libwebsockets/lib/roles/h1/ops-h1.c",
369    "//third_party/libwebsockets/lib/roles/h2/hpack.c",
370    "//third_party/libwebsockets/lib/roles/h2/http2.c",
371    "//third_party/libwebsockets/lib/roles/h2/ops-h2.c",
372    "//third_party/libwebsockets/lib/roles/http/client/client-http.c",
373    "//third_party/libwebsockets/lib/roles/http/date.c",
374    "//third_party/libwebsockets/lib/roles/http/header.c",
375    "//third_party/libwebsockets/lib/roles/http/parsers.c",
376    "//third_party/libwebsockets/lib/roles/http/server/server.c",
377    "//third_party/libwebsockets/lib/roles/listen/ops-listen.c",
378    "//third_party/libwebsockets/lib/roles/pipe/ops-pipe.c",
379    "//third_party/libwebsockets/lib/roles/raw-file/ops-raw-file.c",
380    "//third_party/libwebsockets/lib/roles/raw-skt/ops-raw-skt.c",
381    "//third_party/libwebsockets/lib/roles/ws/client-parser-ws.c",
382    "//third_party/libwebsockets/lib/roles/ws/client-ws.c",
383    "//third_party/libwebsockets/lib/roles/ws/ops-ws.c",
384    "//third_party/libwebsockets/lib/roles/ws/server-ws.c",
385    "//third_party/libwebsockets/lib/system/system.c",
386  ]
387  if (platform == "mingw_x86_64") {
388    sources += [
389      "//third_party/libwebsockets/lib/plat/windows/windows-fds.c",
390      "//third_party/libwebsockets/lib/plat/windows/windows-file.c",
391      "//third_party/libwebsockets/lib/plat/windows/windows-init.c",
392      "//third_party/libwebsockets/lib/plat/windows/windows-misc.c",
393      "//third_party/libwebsockets/lib/plat/windows/windows-pipe.c",
394      "//third_party/libwebsockets/lib/plat/windows/windows-plugins.c",
395      "//third_party/libwebsockets/lib/plat/windows/windows-service.c",
396      "//third_party/libwebsockets/lib/plat/windows/windows-sockets.c",
397    ]
398  } else if (platform == "mac_arm64" || platform == "mac_x64" ||
399             platform == "linux_x64" || platform == "linux_arm64") {
400    defines = [ "LWS_HAVE_SYS_RESOURCE_H" ]
401    sources += [
402      "//third_party/libwebsockets/lib/plat/unix/unix-caps.c",
403      "//third_party/libwebsockets/lib/plat/unix/unix-fds.c",
404      "//third_party/libwebsockets/lib/plat/unix/unix-file.c",
405      "//third_party/libwebsockets/lib/plat/unix/unix-init.c",
406      "//third_party/libwebsockets/lib/plat/unix/unix-misc.c",
407      "//third_party/libwebsockets/lib/plat/unix/unix-pipe.c",
408      "//third_party/libwebsockets/lib/plat/unix/unix-service.c",
409      "//third_party/libwebsockets/lib/plat/unix/unix-sockets.c",
410    ]
411  }
412  configs = [ ":websocket_config" ]
413  public_configs = [ ":websockets_public_config" ]
414}
415