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