• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Huawei Device Co., Ltd.
2#
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to
5# deal in the Software without restriction, including without limitation the
6# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7# sell copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9#
10# The above copyright notice and this permission notice shall be included in
11# all copies or substantial portions of the Software.
12#
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19# IN THE SOFTWARE.
20
21if (defined(ohos_lite)) {
22  import("//build/lite/config/component/lite_component.gni")
23  import("//build/lite/ndk/ndk.gni")
24  import("//third_party/libuv/libuv.gni")
25
26  # This is the configuration needed to use libuv.
27  config("libuv_config") {
28    include_dirs = [
29      "include",
30      "src",
31      "src/unix",
32    ]
33    cflags = [
34      "-Wno-unused-parameter",
35      "-Wno-incompatible-pointer-types",
36      "-D_GNU_SOURCE",
37      "-D_POSIX_C_SOURCE=200112",
38    ]
39
40    # Adding NDEBUG macro manually to avoid compilation
41    # error in debug version, FIX ME
42    # https://gitee.com/openharmony/build/pulls/1206/files
43    defines += [ "NDEBUG" ]
44  }
45
46  # This is the configuration used to build libuv itself.
47  # It should not be needed outside of this library.
48  config("libuv_private_config") {
49    visibility = [ ":*" ]
50    include_dirs = [
51      "include",
52      "src",
53      "src/unix",
54    ]
55
56    # Adding NDEBUG macro manually to avoid compilation
57    # error in debug version, FIX ME
58    # https://gitee.com/openharmony/build/pulls/1206/files
59    defines += [ "NDEBUG" ]
60  }
61
62  source_set("libuv_source") {
63    include_dirs = [
64      "include",
65      "src",
66      "src/unix",
67    ]
68
69    cflags = [
70      "-Wno-unused-parameter",
71      "-Wno-incompatible-pointer-types",
72      "-D_GNU_SOURCE",
73      "-D_POSIX_C_SOURCE=200112",
74      "-U__linux__",
75      "-D__GNU__",
76      "-fPIC",
77    ]
78
79    sources = [
80      # common_source
81      "src/fs-poll.c",
82      "src/idna.c",
83      "src/inet.c",
84      "src/random.c",
85      "src/strscpy.c",
86      "src/threadpool.c",
87      "src/timer.c",
88      "src/uv-common.c",
89      "src/uv-data-getter-setters.c",
90      "src/version.c",
91
92      # nonwin_srcs
93      "src/unix/async.c",
94      "src/unix/core.c",
95      "src/unix/dl.c",
96      "src/unix/epoll.c",
97      "src/unix/fs.c",
98      "src/unix/getaddrinfo.c",
99      "src/unix/getnameinfo.c",
100      "src/unix/loop-watcher.c",
101      "src/unix/loop.c",
102      "src/unix/no-fsevents.c",
103      "src/unix/pipe.c",
104      "src/unix/poll.c",
105      "src/unix/posix-hrtime.c",
106      "src/unix/posix-poll.c",
107      "src/unix/process.c",
108      "src/unix/random-devurandom.c",
109      "src/unix/signal.c",
110      "src/unix/stream.c",
111      "src/unix/tcp.c",
112      "src/unix/thread.c",
113      "src/unix/tty.c",
114      "src/unix/udp.c",
115    ]
116  }
117
118  static_library("uv_static") {
119    deps = [ ":libuv_source" ]
120    public_configs = [ ":libuv_config" ]
121  }
122
123  shared_library("uv") {
124    deps = [ ":libuv_source" ]
125    public_configs = [ ":libuv_config" ]
126    libs = [
127      "pthread",
128      "dl",
129    ]
130  }
131} else {
132  import("//build/ohos.gni")
133  import("//third_party/libuv/libuv.gni")
134
135  common_source = [
136    "src/fs-poll.c",
137    "src/idna.c",
138    "src/inet.c",
139    "src/random.c",
140    "src/strscpy.c",
141    "src/threadpool.c",
142    "src/timer.c",
143    "src/uv-common.c",
144    "src/uv-data-getter-setters.c",
145    "src/version.c",
146  ]
147  if (!is_mingw && !is_win) {
148    nonwin_srcs = [
149      "src/unix/epoll.c",
150      "src/unix/async.c",
151      "src/unix/core.c",
152      "src/unix/dl.c",
153      "src/unix/fs.c",
154      "src/unix/getaddrinfo.c",
155      "src/unix/getnameinfo.c",
156      "src/unix/loop.c",
157      "src/unix/loop-watcher.c",
158      "src/unix/pipe.c",
159      "src/unix/poll.c",
160      "src/unix/process.c",
161      "src/unix/random-devurandom.c",
162      "src/unix/signal.c",
163      "src/unix/stream.c",
164      "src/unix/tcp.c",
165      "src/unix/thread.c",
166      "src/unix/tty.c",
167      "src/unix/udp.c",
168    ]
169  }
170
171  # This is the configuration needed to use libuv.
172  config("libuv_config") {
173    include_dirs = [
174      "include",
175      "src",
176      "src/unix",
177    ]
178    cflags = [ "-Wno-unused-parameter" ]
179    if (is_linux || is_ohos) {
180      cflags += [
181        "-Wno-incompatible-pointer-types",
182        "-D_GNU_SOURCE",
183        "-D_POSIX_C_SOURCE=200112",
184      ]
185
186      # Adding NDEBUG macro manually to avoid compilation
187      # error in debug version, FIX ME
188      # https://gitee.com/openharmony/build/pulls/1206/files
189      defines = [ "NDEBUG" ]
190      if (use_ffrt && is_ohos) {
191        defines += [ "USE_FFRT" ]
192      }
193    } else if (is_mingw || is_win) {
194      cflags += [
195        "-Wno-missing-braces",
196        "-Wno-implicit-function-declaration",
197        "-Wno-error=return-type",
198        "-Wno-error=sign-compare",
199        "-Wno-error=unused-variable",
200        "-Wno-error=unknown-pragmas",
201        "-Wno-unused-variable",
202      ]
203      defines = [
204        "WIN32_LEAN_AND_MEAN",
205        "_WIN32_WINNT=0x0600",
206      ]
207
208      # Adding NDEBUG macro manually to avoid compilation
209      # error in debug version, FIX ME
210      # https://gitee.com/openharmony/build/pulls/1206/files
211      defines += [ "NDEBUG" ]
212
213      libs = [
214        "psapi",
215        "user32",
216        "advapi32",
217        "iphlpapi",
218        "userenv",
219        "ws2_32",
220      ]
221    }
222  }
223
224  # This is the configuration used to build libuv itself.
225  # It should not be needed outside of this library.
226  config("libuv_private_config") {
227    visibility = [ ":*" ]
228    include_dirs = [
229      "include",
230      "src",
231      "src/unix",
232    ]
233
234    # Adding NDEBUG macro manually to avoid compilation
235    # error in debug version, FIX ME
236    # https://gitee.com/openharmony/build/pulls/1206/files
237    defines = [ "NDEBUG" ]
238  }
239
240  ohos_source_set("libuv_source") {
241    configs = [ ":libuv_config" ]
242    sources = common_source
243
244    if (is_mac || (defined(is_ios) && is_ios)) {
245      sources += nonwin_srcs + [
246                   "src/unix/bsd-ifaddrs.c",
247                   "src/unix/kqueue.c",
248                   "src/unix/random-getentropy.c",
249                   "src/unix/darwin-proctitle.c",
250                   "src/unix/darwin.c",
251                   "src/unix/fsevents.c",
252                   "src/unix/os390-proctitle.c",
253                 ]
254      sources -= [ "src/unix/epoll.c" ]
255    } else if (is_mingw || is_win) {
256      sources += [
257        "src/win/async.c",
258        "src/win/core.c",
259        "src/win/detect-wakeup.c",
260        "src/win/dl.c",
261        "src/win/error.c",
262        "src/win/fs-event.c",
263        "src/win/fs.c",
264        "src/win/getaddrinfo.c",
265        "src/win/getnameinfo.c",
266        "src/win/handle.c",
267        "src/win/loop-watcher.c",
268        "src/win/pipe.c",
269        "src/win/poll.c",
270        "src/win/process-stdio.c",
271        "src/win/process.c",
272        "src/win/signal.c",
273        "src/win/snprintf.c",
274        "src/win/stream.c",
275        "src/win/tcp.c",
276        "src/win/thread.c",
277        "src/win/tty.c",
278        "src/win/udp.c",
279        "src/win/util.c",
280        "src/win/winapi.c",
281        "src/win/winsock.c",
282      ]
283    } else if (is_ohos || (defined(is_android) && is_android)) {
284      sources += nonwin_srcs + [
285                   "src/unix/linux-core.c",
286                   "src/unix/linux-inotify.c",
287                   "src/unix/linux-syscalls.c",
288                   "src/unix/procfs-exepath.c",
289                   "src/unix/pthread-fixes.c",
290                   "src/unix/random-getentropy.c",
291                   "src/unix/random-getrandom.c",
292                   "src/unix/random-sysctl-linux.c",
293                   "src/unix/proctitle.c",
294                 ]
295      if (use_ffrt) {
296        external_deps = [ "ffrt:libffrt" ]
297      }
298    } else if (is_linux) {
299      sources += nonwin_srcs + [
300                   "src/unix/linux-core.c",
301                   "src/unix/linux-inotify.c",
302                   "src/unix/linux-syscalls.c",
303                   "src/unix/procfs-exepath.c",
304                   "src/unix/random-getrandom.c",
305                   "src/unix/random-sysctl-linux.c",
306                   "src/unix/proctitle.c",
307                 ]
308    } else {
309      sources += nonwin_srcs + [
310                   "src/unix/linux-core.c",
311                   "src/unix/linux-inotify.c",
312                   "src/unix/linux-syscalls.c",
313                   "src/unix/procfs-exepath.c",
314                   "src/unix/random-getrandom.c",
315                   "src/unix/random-sysctl-linux.c",
316                   "src/unix/proctitle.c",
317                 ]
318    }
319    subsystem_name = "thirdparty"
320    part_name = "libuv"
321  }
322
323  ohos_static_library("uv_static") {
324    deps = [ ":libuv_source" ]
325    public_configs = [ ":libuv_config" ]
326    subsystem_name = "thirdparty"
327    part_name = "libuv"
328  }
329  ohos_shared_library("uv") {
330    deps = [ ":libuv_source" ]
331    public_configs = [ ":libuv_config" ]
332    subsystem_name = "thirdparty"
333    innerapi_tags = [ "platformsdk" ]
334    part_name = "libuv"
335    if (is_ohos) {
336      output_extension = "so"
337    }
338    install_images = [
339      "system",
340      "updater",
341    ]
342  }
343}
344
345ohos_ndk_library("libuv_ndk") {
346  ndk_description_file = "./libuv.ndk.json"
347  min_compact_version = "1"
348  output_name = "uv"
349  output_extension = "so"
350}
351
352ohos_ndk_headers("libuv_header") {
353  dest_dir = "$ndk_headers_out_dir"
354  sources = [ "include/uv_ndk/uv.h" ]
355}
356
357ohos_ndk_headers("libuv_uv_header") {
358  dest_dir = "$ndk_headers_out_dir/uv"
359  sources = [
360    "include/uv/aix.h",
361    "include/uv/bsd.h",
362    "include/uv/darwin.h",
363    "include/uv/errno.h",
364    "include/uv/linux.h",
365    "include/uv/os390.h",
366    "include/uv/posix.h",
367    "include/uv/stdint-msvc2008.h",
368    "include/uv/sunos.h",
369    "include/uv/threadpool.h",
370    "include/uv/tree.h",
371    "include/uv/unix.h",
372    "include/uv/version.h",
373    "include/uv/win.h",
374  ]
375}
376