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 25 # This is the configuration needed to use libuv. 26 config("libuv_config") { 27 include_dirs = [ 28 "include", 29 "src", 30 "src/unix", 31 ] 32 cflags = [ 33 "-Wno-unused-parameter", 34 "-Wno-incompatible-pointer-types", 35 "-D_GNU_SOURCE", 36 "-D_POSIX_C_SOURCE=200112", 37 ] 38 39 # Adding NDEBUG macro manually to avoid compilation 40 # error in debug version, FIX ME 41 # https://gitee.com/openharmony/build/pulls/1206/files 42 defines += [ "NDEBUG" ] 43 } 44 45 # This is the configuration used to build libuv itself. 46 # It should not be needed outside of this library. 47 config("libuv_private_config") { 48 visibility = [ ":*" ] 49 include_dirs = [ 50 "include", 51 "src", 52 "src/unix", 53 ] 54 55 # Adding NDEBUG macro manually to avoid compilation 56 # error in debug version, FIX ME 57 # https://gitee.com/openharmony/build/pulls/1206/files 58 defines += [ "NDEBUG" ] 59 } 60 61 source_set("libuv_source") { 62 include_dirs = [ 63 "include", 64 "src", 65 "src/unix", 66 ] 67 68 cflags = [ 69 "-Wno-unused-parameter", 70 "-Wno-incompatible-pointer-types", 71 "-D_GNU_SOURCE", 72 "-D_POSIX_C_SOURCE=200112", 73 "-U__linux__", 74 "-D__GNU__", 75 "-fPIC", 76 ] 77 78 sources = [ 79 # common_source 80 "src/fs-poll.c", 81 "src/idna.c", 82 "src/inet.c", 83 "src/random.c", 84 "src/strscpy.c", 85 "src/threadpool.c", 86 "src/timer.c", 87 "src/uv-common.c", 88 "src/uv-data-getter-setters.c", 89 "src/version.c", 90 91 # nonwin_srcs 92 "src/unix/async.c", 93 "src/unix/core.c", 94 "src/unix/dl.c", 95 "src/unix/epoll.c", 96 "src/unix/fs.c", 97 "src/unix/getaddrinfo.c", 98 "src/unix/getnameinfo.c", 99 "src/unix/loop-watcher.c", 100 "src/unix/loop.c", 101 "src/unix/no-fsevents.c", 102 "src/unix/pipe.c", 103 "src/unix/poll.c", 104 "src/unix/posix-hrtime.c", 105 "src/unix/posix-poll.c", 106 "src/unix/process.c", 107 "src/unix/random-devurandom.c", 108 "src/unix/signal.c", 109 "src/unix/stream.c", 110 "src/unix/tcp.c", 111 "src/unix/thread.c", 112 "src/unix/tty.c", 113 "src/unix/udp.c", 114 ] 115 } 116 117 static_library("uv_static") { 118 deps = [ ":libuv_source" ] 119 public_configs = [ ":libuv_config" ] 120 } 121 122 shared_library("uv") { 123 deps = [ ":libuv_source" ] 124 public_configs = [ ":libuv_config" ] 125 libs = [ 126 "pthread", 127 "dl", 128 ] 129 } 130} else { 131 import("//build/ohos.gni") 132 133 common_source = [ 134 "src/fs-poll.c", 135 "src/idna.c", 136 "src/inet.c", 137 "src/random.c", 138 "src/strscpy.c", 139 "src/threadpool.c", 140 "src/timer.c", 141 "src/uv-common.c", 142 "src/uv-data-getter-setters.c", 143 "src/version.c", 144 ] 145 if (!is_mingw && !is_win) { 146 nonwin_srcs = [ 147 "src/unix/epoll.c", 148 "src/unix/async.c", 149 "src/unix/core.c", 150 "src/unix/dl.c", 151 "src/unix/fs.c", 152 "src/unix/getaddrinfo.c", 153 "src/unix/getnameinfo.c", 154 "src/unix/loop.c", 155 "src/unix/loop-watcher.c", 156 "src/unix/pipe.c", 157 "src/unix/poll.c", 158 "src/unix/process.c", 159 "src/unix/random-devurandom.c", 160 "src/unix/signal.c", 161 "src/unix/stream.c", 162 "src/unix/tcp.c", 163 "src/unix/thread.c", 164 "src/unix/tty.c", 165 "src/unix/udp.c", 166 ] 167 } 168 169 # This is the configuration needed to use libuv. 170 config("libuv_config") { 171 include_dirs = [ 172 "include", 173 "src", 174 "src/unix", 175 ] 176 cflags = [ "-Wno-unused-parameter" ] 177 if (is_linux || is_ohos) { 178 cflags += [ 179 "-Wno-incompatible-pointer-types", 180 "-D_GNU_SOURCE", 181 "-D_POSIX_C_SOURCE=200112", 182 ] 183 184 # Adding NDEBUG macro manually to avoid compilation 185 # error in debug version, FIX ME 186 # https://gitee.com/openharmony/build/pulls/1206/files 187 defines = [ "NDEBUG" ] 188 } else if (is_mingw || is_win) { 189 cflags += [ 190 "-Wno-missing-braces", 191 "-Wno-implicit-function-declaration", 192 "-Wno-error=return-type", 193 "-Wno-error=sign-compare", 194 "-Wno-error=unused-variable", 195 "-Wno-error=unknown-pragmas", 196 "-Wno-unused-variable", 197 ] 198 defines = [ 199 "WIN32_LEAN_AND_MEAN", 200 "_WIN32_WINNT=0x0600", 201 ] 202 203 # Adding NDEBUG macro manually to avoid compilation 204 # error in debug version, FIX ME 205 # https://gitee.com/openharmony/build/pulls/1206/files 206 defines += [ "NDEBUG" ] 207 208 libs = [ 209 "psapi", 210 "user32", 211 "advapi32", 212 "iphlpapi", 213 "userenv", 214 "ws2_32", 215 ] 216 } 217 } 218 219 # This is the configuration used to build libuv itself. 220 # It should not be needed outside of this library. 221 config("libuv_private_config") { 222 visibility = [ ":*" ] 223 include_dirs = [ 224 "include", 225 "src", 226 "src/unix", 227 ] 228 229 # Adding NDEBUG macro manually to avoid compilation 230 # error in debug version, FIX ME 231 # https://gitee.com/openharmony/build/pulls/1206/files 232 defines = [ "NDEBUG" ] 233 } 234 235 ohos_source_set("libuv_source") { 236 configs = [ ":libuv_config" ] 237 sources = common_source 238 239 if (is_mac || (defined(is_ios) && is_ios)) { 240 sources += nonwin_srcs + [ 241 "src/unix/bsd-ifaddrs.c", 242 "src/unix/kqueue.c", 243 "src/unix/random-getentropy.c", 244 "src/unix/darwin-proctitle.c", 245 "src/unix/darwin.c", 246 "src/unix/fsevents.c", 247 "src/unix/os390-proctitle.c", 248 ] 249 sources -= [ "src/unix/epoll.c" ] 250 } else if (is_mingw || is_win) { 251 sources += [ 252 "src/win/async.c", 253 "src/win/core.c", 254 "src/win/detect-wakeup.c", 255 "src/win/dl.c", 256 "src/win/error.c", 257 "src/win/fs-event.c", 258 "src/win/fs.c", 259 "src/win/getaddrinfo.c", 260 "src/win/getnameinfo.c", 261 "src/win/handle.c", 262 "src/win/loop-watcher.c", 263 "src/win/pipe.c", 264 "src/win/poll.c", 265 "src/win/process-stdio.c", 266 "src/win/process.c", 267 "src/win/signal.c", 268 "src/win/snprintf.c", 269 "src/win/stream.c", 270 "src/win/tcp.c", 271 "src/win/thread.c", 272 "src/win/tty.c", 273 "src/win/udp.c", 274 "src/win/util.c", 275 "src/win/winapi.c", 276 "src/win/winsock.c", 277 ] 278 } else if (is_ohos || (defined(is_android) && is_android)) { 279 sources += nonwin_srcs + [ 280 "src/unix/linux-core.c", 281 "src/unix/linux-inotify.c", 282 "src/unix/linux-syscalls.c", 283 "src/unix/procfs-exepath.c", 284 "src/unix/pthread-fixes.c", 285 "src/unix/random-getentropy.c", 286 "src/unix/random-getrandom.c", 287 "src/unix/random-sysctl-linux.c", 288 "src/unix/proctitle.c", 289 ] 290 } else if (is_linux) { 291 sources += nonwin_srcs + [ 292 "src/unix/linux-core.c", 293 "src/unix/linux-inotify.c", 294 "src/unix/linux-syscalls.c", 295 "src/unix/procfs-exepath.c", 296 "src/unix/random-getrandom.c", 297 "src/unix/random-sysctl-linux.c", 298 "src/unix/proctitle.c", 299 ] 300 } else { 301 sources += nonwin_srcs + [ 302 "src/unix/linux-core.c", 303 "src/unix/linux-inotify.c", 304 "src/unix/linux-syscalls.c", 305 "src/unix/procfs-exepath.c", 306 "src/unix/random-getrandom.c", 307 "src/unix/random-sysctl-linux.c", 308 "src/unix/proctitle.c", 309 ] 310 } 311 subsystem_name = "thirdparty" 312 part_name = "libuv" 313 } 314 315 ohos_static_library("uv_static") { 316 deps = [ ":libuv_source" ] 317 public_configs = [ ":libuv_config" ] 318 subsystem_name = "thirdparty" 319 part_name = "libuv" 320 } 321 ohos_shared_library("uv") { 322 deps = [ ":libuv_source" ] 323 public_configs = [ ":libuv_config" ] 324 subsystem_name = "thirdparty" 325 part_name = "libuv" 326 if (is_ohos) { 327 output_extension = "so" 328 } 329 install_images = [ 330 "system", 331 "updater", 332 ] 333 } 334} 335 336ohos_ndk_library("libuv_ndk") { 337 ndk_description_file = "./libuv.ndk.json" 338 min_compact_version = "1" 339 output_name = "uv" 340 output_extension = "so" 341} 342 343ohos_ndk_headers("libuv_header") { 344 dest_dir = "$ndk_headers_out_dir" 345 sources = [ "include/uv_ndk/uv.h" ] 346} 347 348ohos_ndk_headers("libuv_uv_header") { 349 dest_dir = "$ndk_headers_out_dir/uv" 350 sources = [ 351 "include/uv/aix.h", 352 "include/uv/bsd.h", 353 "include/uv/darwin.h", 354 "include/uv/errno.h", 355 "include/uv/linux.h", 356 "include/uv/os390.h", 357 "include/uv/posix.h", 358 "include/uv/stdint-msvc2008.h", 359 "include/uv/sunos.h", 360 "include/uv/threadpool.h", 361 "include/uv/tree.h", 362 "include/uv/unix.h", 363 "include/uv/version.h", 364 "include/uv/win.h", 365 ] 366} 367