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    "//third_party/openssl/include/openssl",
215    "//third_party/openssl/crypto/evp",
216    "//third_party/glib/glib",
217    "//third_party/glib",
218  ]
219
220  if (target_os == "ios") {
221    sources += [ "//third_party/libwebsockets/lib/core-net/vhost_ios.c" ]
222  } else {
223    sources += [ "//third_party/libwebsockets/lib/core-net/vhost.c" ]
224  }
225
226  defines = [
227    "OHOS_LIBWEBSOCKETS=1",
228    "OPENSSL_SUPPRESS_DEPRECATED",
229  ]
230  if (target_os == "ios") {
231    defines += [ "LWS_DETECTED_PLAT_IOS=1" ]
232    defines += [ "CROSS_PLATFORM_IOS_LIBWEBSOCKETS=1" ]
233  }
234
235  cflags = [
236    "-fPIC",
237    "-Os",
238    "-g",
239    "-Wall",
240    "-fno-strict-aliasing",
241    "-fvisibility=hidden",
242    "-Wmissing-declarations",
243    "-Waggregate-return",
244    "-pipe",
245  ]
246
247  deps = [
248    "//third_party/openssl:libcrypto_shared",
249    "//third_party/openssl:libssl_shared",
250  ]
251  external_deps = [ "zlib:libz" ]
252}
253
254config("websocket_config") {
255  cflags = [
256    "-Wall",
257    "-Wsign-compare",
258    "-Wstrict-aliasing",
259    "-Wuninitialized",
260    "-fvisibility=hidden",
261    "-Wtype-limits",
262    "-Wignored-qualifiers",
263    "-Wno-deprecated-declarations",
264    "-pthread",
265    "-Wno-unused-command-line-argument",
266    "-Wno-unused-parameter",
267    "-Wno-implicit-function-declaration",
268  ]
269}
270
271config("websockets_public_config") {
272  include_dirs = [
273    "//third_party/libwebsockets/plugins",
274    "//third_party/libwebsockets/lib/core",
275    "//third_party/libwebsockets/lib/core-net",
276    "//third_party/libwebsockets/lib/event-libs",
277    "//third_party/libwebsockets/lib/abstract",
278    "//third_party/libwebsockets/lib/tls",
279    "//third_party/libwebsockets/lib/roles",
280    "//third_party/libwebsockets/lib/event-libs/libuv",
281    "//third_party/libwebsockets/lib/event-libs/poll",
282    "//third_party/libwebsockets/lib/event-libs/libevent",
283    "//third_party/libwebsockets/lib/event-libs/glib",
284    "//third_party/libwebsockets/lib/event-libs/libev",
285    "//third_party/libwebsockets/lib/jose/jwe",
286    "//third_party/libwebsockets/lib/jose/jws",
287    "//third_party/libwebsockets/lib/jose",
288    "//third_party/libwebsockets/lib/misc",
289    "//third_party/libwebsockets/lib/roles/http",
290    "//third_party/libwebsockets/lib/roles/http/compression",
291    "//third_party/libwebsockets/lib/roles/h1",
292    "//third_party/libwebsockets/lib/roles/h2",
293    "//third_party/libwebsockets/lib/roles/ws",
294    "//third_party/libwebsockets/lib/roles/cgi",
295    "//third_party/libwebsockets/lib/roles/dbus",
296    "//third_party/libwebsockets/lib/roles/raw-proxy",
297    "//third_party/libwebsockets/lib/abstract",
298    "//third_party/libwebsockets/lib/system/async-dns",
299    "//third_party/libwebsockets/lib/roles/mqtt",
300    "//third_party/libwebsockets/lib/system/metrics",
301    "//third_party/libwebsockets/lib",
302    "//third_party/libwebsockets/win32port/win32helpers",
303    "//third_party/libwebsockets/include",
304  ]
305  if (platform == "mingw_x86_64") {
306    include_dirs += [ "//third_party/libwebsockets/lib/plat/windows" ]
307  } else if (platform == "mac_arm64" || platform == "mac_x64" ||
308             platform == "linux_x64" || platform == "linux_arm64") {
309    include_dirs += [ "//third_party/libwebsockets/lib/plat/unix" ]
310  }
311  cflags = [ "-Wno-error=#warnings" ]
312}
313
314ohos_static_library("websockets_static") {
315  sources = [
316    "//third_party/libwebsockets/lib/core-net/adopt.c",
317    "//third_party/libwebsockets/lib/core-net/client/client.c",
318    "//third_party/libwebsockets/lib/core-net/client/connect.c",
319    "//third_party/libwebsockets/lib/core-net/client/connect2.c",
320    "//third_party/libwebsockets/lib/core-net/client/connect3.c",
321    "//third_party/libwebsockets/lib/core-net/client/connect4.c",
322    "//third_party/libwebsockets/lib/core-net/client/sort-dns.c",
323    "//third_party/libwebsockets/lib/core-net/close.c",
324    "//third_party/libwebsockets/lib/core-net/dummy-callback.c",
325    "//third_party/libwebsockets/lib/core-net/network.c",
326    "//third_party/libwebsockets/lib/core-net/output.c",
327    "//third_party/libwebsockets/lib/core-net/pollfd.c",
328    "//third_party/libwebsockets/lib/core-net/sequencer.c",
329    "//third_party/libwebsockets/lib/core-net/service.c",
330    "//third_party/libwebsockets/lib/core-net/sorted-usec-list.c",
331    "//third_party/libwebsockets/lib/core-net/state.c",
332    "//third_party/libwebsockets/lib/core-net/vhost.c",
333    "//third_party/libwebsockets/lib/core-net/wsi-timeout.c",
334    "//third_party/libwebsockets/lib/core-net/wsi.c",
335    "//third_party/libwebsockets/lib/core/alloc.c",
336    "//third_party/libwebsockets/lib/core/buflist.c",
337    "//third_party/libwebsockets/lib/core/context.c",
338    "//third_party/libwebsockets/lib/core/libwebsockets.c",
339    "//third_party/libwebsockets/lib/core/logs.c",
340    "//third_party/libwebsockets/lib/core/lws_dll2.c",
341    "//third_party/libwebsockets/lib/core/vfs.c",
342    "//third_party/libwebsockets/lib/event-libs/poll/poll.c",
343    "//third_party/libwebsockets/lib/misc/base64-decode.c",
344    "//third_party/libwebsockets/lib/misc/lejp.c",
345    "//third_party/libwebsockets/lib/misc/lws-ring.c",
346    "//third_party/libwebsockets/lib/misc/lwsac/cached-file.c",
347    "//third_party/libwebsockets/lib/misc/lwsac/lwsac.c",
348    "//third_party/libwebsockets/lib/misc/peer-limits.c",
349    "//third_party/libwebsockets/lib/misc/sha-1.c",
350    "//third_party/libwebsockets/lib/roles/h1/ops-h1.c",
351    "//third_party/libwebsockets/lib/roles/h2/hpack.c",
352    "//third_party/libwebsockets/lib/roles/h2/http2.c",
353    "//third_party/libwebsockets/lib/roles/h2/ops-h2.c",
354    "//third_party/libwebsockets/lib/roles/http/client/client-http.c",
355    "//third_party/libwebsockets/lib/roles/http/date.c",
356    "//third_party/libwebsockets/lib/roles/http/header.c",
357    "//third_party/libwebsockets/lib/roles/http/parsers.c",
358    "//third_party/libwebsockets/lib/roles/http/server/server.c",
359    "//third_party/libwebsockets/lib/roles/listen/ops-listen.c",
360    "//third_party/libwebsockets/lib/roles/pipe/ops-pipe.c",
361    "//third_party/libwebsockets/lib/roles/raw-file/ops-raw-file.c",
362    "//third_party/libwebsockets/lib/roles/raw-skt/ops-raw-skt.c",
363    "//third_party/libwebsockets/lib/roles/ws/client-parser-ws.c",
364    "//third_party/libwebsockets/lib/roles/ws/client-ws.c",
365    "//third_party/libwebsockets/lib/roles/ws/ops-ws.c",
366    "//third_party/libwebsockets/lib/roles/ws/server-ws.c",
367    "//third_party/libwebsockets/lib/system/system.c",
368  ]
369  if (platform == "mingw_x86_64") {
370    sources += [
371      "//third_party/libwebsockets/lib/plat/windows/windows-fds.c",
372      "//third_party/libwebsockets/lib/plat/windows/windows-file.c",
373      "//third_party/libwebsockets/lib/plat/windows/windows-init.c",
374      "//third_party/libwebsockets/lib/plat/windows/windows-misc.c",
375      "//third_party/libwebsockets/lib/plat/windows/windows-pipe.c",
376      "//third_party/libwebsockets/lib/plat/windows/windows-plugins.c",
377      "//third_party/libwebsockets/lib/plat/windows/windows-service.c",
378      "//third_party/libwebsockets/lib/plat/windows/windows-sockets.c",
379    ]
380  } else if (platform == "mac_arm64" || platform == "mac_x64" ||
381             platform == "linux_x64" || platform == "linux_arm64") {
382    defines = [ "LWS_HAVE_SYS_RESOURCE_H" ]
383    sources += [
384      "//third_party/libwebsockets/lib/plat/unix/unix-caps.c",
385      "//third_party/libwebsockets/lib/plat/unix/unix-fds.c",
386      "//third_party/libwebsockets/lib/plat/unix/unix-file.c",
387      "//third_party/libwebsockets/lib/plat/unix/unix-init.c",
388      "//third_party/libwebsockets/lib/plat/unix/unix-misc.c",
389      "//third_party/libwebsockets/lib/plat/unix/unix-pipe.c",
390      "//third_party/libwebsockets/lib/plat/unix/unix-service.c",
391      "//third_party/libwebsockets/lib/plat/unix/unix-sockets.c",
392    ]
393  }
394  configs = [ ":websocket_config" ]
395  public_configs = [ ":websockets_public_config" ]
396}
397