Mercurial
comparison third_party/libuv/CMakeLists.txt @ 160:948de3f54cea
[ThirdParty] Added libuv
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 14 Jan 2026 19:39:52 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 159:05cf9467a1c3 | 160:948de3f54cea |
|---|---|
| 1 cmake_minimum_required(VERSION 3.10) | |
| 2 | |
| 3 if(POLICY CMP0091) | |
| 4 cmake_policy(SET CMP0091 NEW) # Enable MSVC_RUNTIME_LIBRARY setting | |
| 5 endif() | |
| 6 if(POLICY CMP0092) | |
| 7 cmake_policy(SET CMP0092 NEW) # disable /W3 warning, if possible | |
| 8 endif() | |
| 9 | |
| 10 project(libuv LANGUAGES C) | |
| 11 | |
| 12 list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") | |
| 13 | |
| 14 include(CMakePackageConfigHelpers) | |
| 15 include(CMakeDependentOption) | |
| 16 include(CheckCCompilerFlag) | |
| 17 include(GNUInstallDirs) | |
| 18 include(CTest) | |
| 19 | |
| 20 set(CMAKE_C_VISIBILITY_PRESET hidden) | |
| 21 set(CMAKE_C_STANDARD_REQUIRED ON) | |
| 22 set(CMAKE_C_EXTENSIONS ON) | |
| 23 set(CMAKE_C_STANDARD 11) | |
| 24 | |
| 25 set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | |
| 26 | |
| 27 option(LIBUV_BUILD_SHARED "Build shared lib" ON) | |
| 28 | |
| 29 cmake_dependent_option(LIBUV_BUILD_TESTS | |
| 30 "Build the unit tests when BUILD_TESTING is enabled and we are the root project" ON | |
| 31 "BUILD_TESTING;LIBUV_BUILD_SHARED;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF) | |
| 32 cmake_dependent_option(LIBUV_BUILD_BENCH | |
| 33 "Build the benchmarks when building unit tests and we are the root project" ON | |
| 34 "LIBUV_BUILD_TESTS" OFF) | |
| 35 | |
| 36 # Qemu Build | |
| 37 option(QEMU "build for qemu" OFF) | |
| 38 if(QEMU) | |
| 39 list(APPEND uv_defines __QEMU__=1) | |
| 40 endif() | |
| 41 | |
| 42 # Note: these are mutually exclusive. | |
| 43 option(ASAN "Enable AddressSanitizer (ASan)" OFF) | |
| 44 option(MSAN "Enable MemorySanitizer (MSan)" OFF) | |
| 45 option(TSAN "Enable ThreadSanitizer (TSan)" OFF) | |
| 46 option(UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF) | |
| 47 | |
| 48 if(MSAN AND NOT CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang") | |
| 49 message(SEND_ERROR "MemorySanitizer requires clang. Try again with -DCMAKE_C_COMPILER=clang") | |
| 50 endif() | |
| 51 | |
| 52 if(ASAN) | |
| 53 list(APPEND uv_defines __ASAN__=1) | |
| 54 if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang") | |
| 55 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address") | |
| 56 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address") | |
| 57 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address") | |
| 58 elseif(MSVC) | |
| 59 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=address") | |
| 60 else() | |
| 61 message(SEND_ERROR "AddressSanitizer support requires clang, gcc, or msvc. Try again with -DCMAKE_C_COMPILER.") | |
| 62 endif() | |
| 63 endif() | |
| 64 | |
| 65 if(MSAN) | |
| 66 list(APPEND uv_defines __MSAN__=1) | |
| 67 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=memory") | |
| 68 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=memory") | |
| 69 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=memory") | |
| 70 endif() | |
| 71 | |
| 72 if(TSAN) | |
| 73 list(APPEND uv_defines __TSAN__=1) | |
| 74 if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang") | |
| 75 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=thread") | |
| 76 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread") | |
| 77 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread") | |
| 78 else() | |
| 79 message(SEND_ERROR "ThreadSanitizer support requires clang or gcc. Try again with -DCMAKE_C_COMPILER.") | |
| 80 endif() | |
| 81 endif() | |
| 82 | |
| 83 if(UBSAN) | |
| 84 cmake_minimum_required(VERSION 3.13) | |
| 85 list(APPEND uv_defines __UBSAN__=1) | |
| 86 if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang") | |
| 87 add_compile_options("-fsanitize=undefined" "-fno-sanitize-recover=undefined") | |
| 88 if (NOT WIN32) | |
| 89 add_link_options("-fsanitize=undefined") | |
| 90 endif() | |
| 91 if(MSVC) | |
| 92 add_compile_options("/Oy-") | |
| 93 else() | |
| 94 add_compile_options("-fno-omit-frame-pointer") | |
| 95 endif() | |
| 96 else() | |
| 97 message(SEND_ERROR "UndefinedBehaviorSanitizer support requires clang or gcc. Try again with -DCMAKE_C_COMPILER.") | |
| 98 endif() | |
| 99 endif() | |
| 100 | |
| 101 # Compiler check | |
| 102 string(CONCAT is-msvc $<OR: | |
| 103 $<C_COMPILER_ID:MSVC>, | |
| 104 $<STREQUAL:${CMAKE_C_COMPILER_FRONTEND_VARIANT},MSVC> | |
| 105 >) | |
| 106 | |
| 107 check_c_compiler_flag(/W4 UV_LINT_W4) | |
| 108 check_c_compiler_flag(/wd4100 UV_LINT_NO_UNUSED_PARAMETER_MSVC) | |
| 109 check_c_compiler_flag(/wd4127 UV_LINT_NO_CONDITIONAL_CONSTANT_MSVC) | |
| 110 check_c_compiler_flag(/wd4201 UV_LINT_NO_NONSTANDARD_MSVC) | |
| 111 check_c_compiler_flag(/wd4206 UV_LINT_NO_NONSTANDARD_EMPTY_TU_MSVC) | |
| 112 check_c_compiler_flag(/wd4210 UV_LINT_NO_NONSTANDARD_FILE_SCOPE_MSVC) | |
| 113 check_c_compiler_flag(/wd4232 UV_LINT_NO_NONSTANDARD_NONSTATIC_DLIMPORT_MSVC) | |
| 114 check_c_compiler_flag(/wd4456 UV_LINT_NO_HIDES_LOCAL) | |
| 115 check_c_compiler_flag(/wd4457 UV_LINT_NO_HIDES_PARAM) | |
| 116 check_c_compiler_flag(/wd4459 UV_LINT_NO_HIDES_GLOBAL) | |
| 117 check_c_compiler_flag(/wd4706 UV_LINT_NO_CONDITIONAL_ASSIGNMENT_MSVC) | |
| 118 check_c_compiler_flag(/wd4996 UV_LINT_NO_UNSAFE_MSVC) | |
| 119 | |
| 120 check_c_compiler_flag(-Wall UV_LINT_WALL) # DO NOT use this under MSVC | |
| 121 | |
| 122 # TODO: Place these into its own function | |
| 123 check_c_compiler_flag(-Wno-unused-parameter UV_LINT_NO_UNUSED_PARAMETER) | |
| 124 check_c_compiler_flag(-Wstrict-prototypes UV_LINT_STRICT_PROTOTYPES) | |
| 125 check_c_compiler_flag(-Wextra UV_LINT_EXTRA) | |
| 126 | |
| 127 check_c_compiler_flag(/utf-8 UV_LINT_UTF8_MSVC) | |
| 128 | |
| 129 set(lint-no-unused-parameter $<$<BOOL:${UV_LINT_NO_UNUSED_PARAMETER}>:-Wno-unused-parameter>) | |
| 130 set(lint-strict-prototypes $<$<BOOL:${UV_LINT_STRICT_PROTOTYPES}>:-Wstrict-prototypes>) | |
| 131 set(lint-extra $<$<BOOL:${UV_LINT_EXTRA}>:-Wextra>) | |
| 132 set(lint-w4 $<$<BOOL:${UV_LINT_W4}>:/W4>) | |
| 133 set(lint-no-unused-parameter-msvc $<$<BOOL:${UV_LINT_NO_UNUSED_PARAMETER_MSVC}>:/wd4100>) | |
| 134 set(lint-no-conditional-constant-msvc $<$<BOOL:${UV_LINT_NO_CONDITIONAL_CONSTANT_MSVC}>:/wd4127>) | |
| 135 set(lint-no-nonstandard-msvc $<$<BOOL:${UV_LINT_NO_NONSTANDARD_MSVC}>:/wd4201>) | |
| 136 set(lint-no-nonstandard-empty-tu-msvc $<$<BOOL:${UV_LINT_NO_NONSTANDARD_EMPTY_TU_MSVC}>:/wd4206>) | |
| 137 set(lint-no-nonstandard-file-scope-msvc $<$<BOOL:${UV_LINT_NO_NONSTANDARD_FILE_SCOPE_MSVC}>:/wd4210>) | |
| 138 set(lint-no-nonstandard-nonstatic-dlimport-msvc $<$<BOOL:${UV_LINT_NO_NONSTANDARD_NONSTATIC_DLIMPORT_MSVC}>:/wd4232>) | |
| 139 set(lint-no-hides-local-msvc $<$<BOOL:${UV_LINT_NO_HIDES_LOCAL}>:/wd4456>) | |
| 140 set(lint-no-hides-param-msvc $<$<BOOL:${UV_LINT_NO_HIDES_PARAM}>:/wd4457>) | |
| 141 set(lint-no-hides-global-msvc $<$<BOOL:${UV_LINT_NO_HIDES_GLOBAL}>:/wd4459>) | |
| 142 set(lint-no-conditional-assignment-msvc $<$<BOOL:${UV_LINT_NO_CONDITIONAL_ASSIGNMENT_MSVC}>:/wd4706>) | |
| 143 set(lint-no-unsafe-msvc $<$<BOOL:${UV_LINT_NO_UNSAFE_MSVC}>:/wd4996>) | |
| 144 # Unfortunately, this one is complicated because MSVC and clang-cl support -Wall | |
| 145 # but using it is like calling -Weverything | |
| 146 string(CONCAT lint-default $< | |
| 147 $<AND:$<BOOL:${UV_LINT_WALL}>,$<NOT:${is-msvc}>>:-Wall | |
| 148 >) | |
| 149 set(lint-utf8-msvc $<$<BOOL:${UV_LINT_UTF8_MSVC}>:/utf-8>) | |
| 150 | |
| 151 list(APPEND uv_cflags ${lint-strict-prototypes} ${lint-extra} ${lint-default} ${lint-w4}) | |
| 152 list(APPEND uv_cflags ${lint-no-unused-parameter}) | |
| 153 list(APPEND uv_cflags ${lint-no-unused-parameter-msvc}) | |
| 154 list(APPEND uv_cflags ${lint-no-conditional-constant-msvc}) | |
| 155 list(APPEND uv_cflags ${lint-no-nonstandard-msvc}) | |
| 156 list(APPEND uv_cflags ${lint-no-nonstandard-empty-tu-msvc}) | |
| 157 list(APPEND uv_cflags ${lint-no-nonstandard-file-scope-msvc}) | |
| 158 list(APPEND uv_cflags ${lint-no-nonstandard-nonstatic-dlimport-msvc}) | |
| 159 list(APPEND uv_cflags ${lint-no-hides-local-msvc}) | |
| 160 list(APPEND uv_cflags ${lint-no-hides-param-msvc}) | |
| 161 list(APPEND uv_cflags ${lint-no-hides-global-msvc}) | |
| 162 list(APPEND uv_cflags ${lint-no-conditional-assignment-msvc}) | |
| 163 list(APPEND uv_cflags ${lint-no-unsafe-msvc}) | |
| 164 list(APPEND uv_cflags ${lint-utf8-msvc} ) | |
| 165 | |
| 166 check_c_compiler_flag(-fno-strict-aliasing UV_F_STRICT_ALIASING) | |
| 167 list(APPEND uv_cflags $<$<BOOL:${UV_F_STRICT_ALIASING}>:-fno-strict-aliasing>) | |
| 168 | |
| 169 if (MSVC) | |
| 170 # Error on calling undeclared functions. | |
| 171 list(APPEND uv_cflags "/we4013") | |
| 172 endif() | |
| 173 | |
| 174 set(uv_sources | |
| 175 src/fs-poll.c | |
| 176 src/idna.c | |
| 177 src/inet.c | |
| 178 src/random.c | |
| 179 src/strscpy.c | |
| 180 src/strtok.c | |
| 181 src/thread-common.c | |
| 182 src/threadpool.c | |
| 183 src/timer.c | |
| 184 src/uv-common.c | |
| 185 src/uv-data-getter-setters.c | |
| 186 src/version.c) | |
| 187 | |
| 188 if(WIN32) | |
| 189 list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0A00 _CRT_DECLARE_NONSTDC_NAMES=0) | |
| 190 list(APPEND uv_libraries | |
| 191 psapi | |
| 192 user32 | |
| 193 advapi32 | |
| 194 iphlpapi | |
| 195 userenv | |
| 196 ws2_32 | |
| 197 dbghelp | |
| 198 ole32 | |
| 199 shell32) | |
| 200 list(APPEND uv_sources | |
| 201 src/win/async.c | |
| 202 src/win/core.c | |
| 203 src/win/detect-wakeup.c | |
| 204 src/win/dl.c | |
| 205 src/win/error.c | |
| 206 src/win/fs.c | |
| 207 src/win/fs-event.c | |
| 208 src/win/getaddrinfo.c | |
| 209 src/win/getnameinfo.c | |
| 210 src/win/handle.c | |
| 211 src/win/loop-watcher.c | |
| 212 src/win/pipe.c | |
| 213 src/win/thread.c | |
| 214 src/win/poll.c | |
| 215 src/win/process.c | |
| 216 src/win/process-stdio.c | |
| 217 src/win/signal.c | |
| 218 src/win/snprintf.c | |
| 219 src/win/stream.c | |
| 220 src/win/tcp.c | |
| 221 src/win/tty.c | |
| 222 src/win/udp.c | |
| 223 src/win/util.c | |
| 224 src/win/winapi.c | |
| 225 src/win/winsock.c) | |
| 226 list(APPEND uv_test_libraries ws2_32) | |
| 227 list(APPEND uv_test_sources src/win/snprintf.c test/runner-win.c) | |
| 228 else() | |
| 229 list(APPEND uv_defines _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE) | |
| 230 if(NOT CMAKE_SYSTEM_NAME MATCHES "Android|OS390|QNX") | |
| 231 # TODO: This should be replaced with find_package(Threads) if possible | |
| 232 # Android has pthread as part of its c library, not as a separate | |
| 233 # libpthread.so. | |
| 234 list(APPEND uv_libraries pthread) | |
| 235 endif() | |
| 236 list(APPEND uv_sources | |
| 237 src/unix/async.c | |
| 238 src/unix/core.c | |
| 239 src/unix/dl.c | |
| 240 src/unix/fs.c | |
| 241 src/unix/getaddrinfo.c | |
| 242 src/unix/getnameinfo.c | |
| 243 src/unix/loop-watcher.c | |
| 244 src/unix/loop.c | |
| 245 src/unix/pipe.c | |
| 246 src/unix/poll.c | |
| 247 src/unix/process.c | |
| 248 src/unix/random-devurandom.c | |
| 249 src/unix/signal.c | |
| 250 src/unix/stream.c | |
| 251 src/unix/tcp.c | |
| 252 src/unix/thread.c | |
| 253 src/unix/tty.c | |
| 254 src/unix/udp.c) | |
| 255 list(APPEND uv_test_sources test/runner-unix.c) | |
| 256 endif() | |
| 257 | |
| 258 if(CMAKE_SYSTEM_NAME STREQUAL "AIX") | |
| 259 list(APPEND uv_defines | |
| 260 _ALL_SOURCE | |
| 261 _LINUX_SOURCE_COMPAT | |
| 262 _THREAD_SAFE | |
| 263 _XOPEN_SOURCE=500 | |
| 264 HAVE_SYS_AHAFS_EVPRODS_H) | |
| 265 list(APPEND uv_libraries perfstat) | |
| 266 list(APPEND uv_sources | |
| 267 src/unix/aix.c | |
| 268 src/unix/aix-common.c) | |
| 269 endif() | |
| 270 | |
| 271 if(CMAKE_SYSTEM_NAME STREQUAL "Android") | |
| 272 list(APPEND uv_defines _GNU_SOURCE) | |
| 273 list(APPEND uv_libraries dl) | |
| 274 list(APPEND uv_sources | |
| 275 src/unix/linux.c | |
| 276 src/unix/procfs-exepath.c | |
| 277 src/unix/random-getentropy.c | |
| 278 src/unix/random-getrandom.c | |
| 279 src/unix/random-sysctl-linux.c) | |
| 280 endif() | |
| 281 | |
| 282 if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Android|Linux") | |
| 283 list(APPEND uv_sources src/unix/proctitle.c) | |
| 284 endif() | |
| 285 | |
| 286 if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD") | |
| 287 list(APPEND uv_sources src/unix/freebsd.c) | |
| 288 endif() | |
| 289 | |
| 290 if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD") | |
| 291 list(APPEND uv_sources src/unix/posix-hrtime.c src/unix/bsd-proctitle.c) | |
| 292 endif() | |
| 293 | |
| 294 if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD") | |
| 295 list(APPEND uv_sources src/unix/bsd-ifaddrs.c src/unix/kqueue.c) | |
| 296 endif() | |
| 297 | |
| 298 if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") | |
| 299 list(APPEND uv_sources src/unix/random-getrandom.c) | |
| 300 endif() | |
| 301 | |
| 302 if(APPLE OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") | |
| 303 list(APPEND uv_sources src/unix/random-getentropy.c) | |
| 304 endif() | |
| 305 | |
| 306 if(APPLE) | |
| 307 list(APPEND uv_defines _DARWIN_UNLIMITED_SELECT=1 _DARWIN_USE_64_BIT_INODE=1) | |
| 308 list(APPEND uv_sources | |
| 309 src/unix/darwin-proctitle.c | |
| 310 src/unix/darwin.c | |
| 311 src/unix/fsevents.c) | |
| 312 endif() | |
| 313 | |
| 314 if(CMAKE_SYSTEM_NAME STREQUAL "GNU") | |
| 315 list(APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112 _XOPEN_SOURCE=500) | |
| 316 list(APPEND uv_libraries dl) | |
| 317 list(APPEND uv_sources | |
| 318 src/unix/bsd-ifaddrs.c | |
| 319 src/unix/no-fsevents.c | |
| 320 src/unix/no-proctitle.c | |
| 321 src/unix/posix-hrtime.c | |
| 322 src/unix/posix-poll.c | |
| 323 src/unix/hurd.c) | |
| 324 endif() | |
| 325 | |
| 326 if(CMAKE_SYSTEM_NAME STREQUAL "Linux") | |
| 327 list(APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112) | |
| 328 list(APPEND uv_libraries dl rt) | |
| 329 list(APPEND uv_sources | |
| 330 src/unix/linux.c | |
| 331 src/unix/procfs-exepath.c | |
| 332 src/unix/random-getrandom.c | |
| 333 src/unix/random-sysctl-linux.c) | |
| 334 endif() | |
| 335 | |
| 336 if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") | |
| 337 list(APPEND uv_sources src/unix/netbsd.c) | |
| 338 list(APPEND uv_libraries kvm) | |
| 339 endif() | |
| 340 | |
| 341 if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") | |
| 342 list(APPEND uv_sources src/unix/openbsd.c) | |
| 343 endif() | |
| 344 | |
| 345 if(CMAKE_SYSTEM_NAME STREQUAL "OS390") | |
| 346 enable_language(CXX) | |
| 347 list(APPEND uv_defines PATH_MAX=1024) | |
| 348 list(APPEND uv_defines _AE_BIMODAL) | |
| 349 list(APPEND uv_defines _ALL_SOURCE) | |
| 350 list(APPEND uv_defines _ENHANCED_ASCII_EXT=0xFFFFFFFF) | |
| 351 list(APPEND uv_defines _ISOC99_SOURCE) | |
| 352 list(APPEND uv_defines _LARGE_TIME_API) | |
| 353 list(APPEND uv_defines _OPEN_MSGQ_EXT) | |
| 354 list(APPEND uv_defines _OPEN_SYS_FILE_EXT) | |
| 355 list(APPEND uv_defines _OPEN_SYS_IF_EXT) | |
| 356 list(APPEND uv_defines _OPEN_SYS_SOCK_EXT3) | |
| 357 list(APPEND uv_defines _OPEN_SYS_SOCK_IPV6) | |
| 358 list(APPEND uv_defines _UNIX03_SOURCE) | |
| 359 list(APPEND uv_defines _UNIX03_THREADS) | |
| 360 list(APPEND uv_defines _UNIX03_WITHDRAWN) | |
| 361 list(APPEND uv_defines _XOPEN_SOURCE=600) | |
| 362 list(APPEND uv_defines _XOPEN_SOURCE_EXTENDED) | |
| 363 list(APPEND uv_sources | |
| 364 src/unix/os390.c | |
| 365 src/unix/os390-syscalls.c | |
| 366 src/unix/os390-proctitle.c) | |
| 367 list(APPEND uv_cflags | |
| 368 -q64 | |
| 369 -qascii | |
| 370 -qexportall | |
| 371 -qgonumber | |
| 372 -qlongname | |
| 373 -qlibansi | |
| 374 -qfloat=IEEE | |
| 375 -qtune=10 | |
| 376 -qarch=10 | |
| 377 -qasm | |
| 378 -qasmlib=sys1.maclib:sys1.modgen) | |
| 379 find_library(ZOSLIB | |
| 380 NAMES zoslib | |
| 381 PATHS ${ZOSLIB_DIR} | |
| 382 PATH_SUFFIXES lib | |
| 383 ) | |
| 384 list(APPEND uv_libraries ${ZOSLIB}) | |
| 385 endif() | |
| 386 | |
| 387 if(CMAKE_SYSTEM_NAME STREQUAL "OS400") | |
| 388 list(APPEND uv_defines | |
| 389 _ALL_SOURCE | |
| 390 _LINUX_SOURCE_COMPAT | |
| 391 _THREAD_SAFE | |
| 392 _XOPEN_SOURCE=500) | |
| 393 list(APPEND uv_sources | |
| 394 src/unix/aix-common.c | |
| 395 src/unix/ibmi.c | |
| 396 src/unix/no-fsevents.c | |
| 397 src/unix/posix-poll.c) | |
| 398 endif() | |
| 399 | |
| 400 if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") | |
| 401 if(CMAKE_SYSTEM_VERSION STREQUAL "5.10") | |
| 402 list(APPEND uv_defines SUNOS_NO_IFADDRS) | |
| 403 list(APPEND uv_libraries rt) | |
| 404 endif() | |
| 405 list(APPEND uv_defines __EXTENSIONS__ _XOPEN_SOURCE=500 _REENTRANT) | |
| 406 list(APPEND uv_libraries kstat nsl sendfile socket) | |
| 407 list(APPEND uv_sources | |
| 408 src/unix/no-proctitle.c | |
| 409 src/unix/sunos.c) | |
| 410 endif() | |
| 411 | |
| 412 if(CMAKE_SYSTEM_NAME STREQUAL "Haiku") | |
| 413 list(APPEND uv_defines _BSD_SOURCE) | |
| 414 list(APPEND uv_libraries bsd network) | |
| 415 list(APPEND uv_sources | |
| 416 src/unix/haiku.c | |
| 417 src/unix/bsd-ifaddrs.c | |
| 418 src/unix/no-fsevents.c | |
| 419 src/unix/no-proctitle.c | |
| 420 src/unix/posix-hrtime.c | |
| 421 src/unix/posix-poll.c) | |
| 422 endif() | |
| 423 | |
| 424 if(CMAKE_SYSTEM_NAME STREQUAL "QNX") | |
| 425 list(APPEND uv_sources | |
| 426 src/unix/posix-hrtime.c | |
| 427 src/unix/posix-poll.c | |
| 428 src/unix/qnx.c | |
| 429 src/unix/bsd-ifaddrs.c | |
| 430 src/unix/no-proctitle.c | |
| 431 src/unix/no-fsevents.c) | |
| 432 list(APPEND uv_libraries socket) | |
| 433 endif() | |
| 434 | |
| 435 if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD") | |
| 436 list(APPEND uv_test_libraries util) | |
| 437 list(APPEND uv_libraries m) | |
| 438 endif() | |
| 439 | |
| 440 if(CYGWIN OR MSYS) | |
| 441 list(APPEND uv_defines _GNU_SOURCE) | |
| 442 list(APPEND uv_sources | |
| 443 src/unix/cygwin.c | |
| 444 src/unix/bsd-ifaddrs.c | |
| 445 src/unix/no-fsevents.c | |
| 446 src/unix/no-proctitle.c | |
| 447 src/unix/posix-hrtime.c | |
| 448 src/unix/posix-poll.c | |
| 449 src/unix/procfs-exepath.c | |
| 450 src/unix/sysinfo-loadavg.c | |
| 451 src/unix/sysinfo-memory.c) | |
| 452 endif() | |
| 453 | |
| 454 if(LIBUV_BUILD_SHARED) | |
| 455 add_library(uv SHARED ${uv_sources}) | |
| 456 target_compile_definitions(uv | |
| 457 INTERFACE | |
| 458 USING_UV_SHARED=1 | |
| 459 PRIVATE | |
| 460 BUILDING_UV_SHARED=1 | |
| 461 ${uv_defines}) | |
| 462 target_compile_options(uv PRIVATE ${uv_cflags}) | |
| 463 target_include_directories(uv | |
| 464 PUBLIC | |
| 465 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | |
| 466 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | |
| 467 PRIVATE | |
| 468 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>) | |
| 469 if(CMAKE_SYSTEM_NAME STREQUAL "OS390") | |
| 470 target_include_directories(uv PUBLIC $<BUILD_INTERFACE:${ZOSLIB_DIR}/include>) | |
| 471 set_target_properties(uv PROPERTIES LINKER_LANGUAGE CXX) | |
| 472 endif() | |
| 473 target_link_libraries(uv ${uv_libraries}) | |
| 474 set_target_properties(uv PROPERTIES OUTPUT_NAME "uv") | |
| 475 endif() | |
| 476 | |
| 477 add_library(uv_a STATIC ${uv_sources}) | |
| 478 target_compile_definitions(uv_a PRIVATE ${uv_defines}) | |
| 479 target_compile_options(uv_a PRIVATE ${uv_cflags}) | |
| 480 target_include_directories(uv_a | |
| 481 PUBLIC | |
| 482 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | |
| 483 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> | |
| 484 PRIVATE | |
| 485 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>) | |
| 486 if(CMAKE_SYSTEM_NAME STREQUAL "OS390") | |
| 487 target_include_directories(uv_a PUBLIC $<BUILD_INTERFACE:${ZOSLIB_DIR}/include>) | |
| 488 set_target_properties(uv_a PROPERTIES LINKER_LANGUAGE CXX) | |
| 489 endif() | |
| 490 target_link_libraries(uv_a ${uv_libraries}) | |
| 491 set_target_properties(uv_a PROPERTIES OUTPUT_NAME "uv") | |
| 492 if(WIN32) | |
| 493 set_target_properties(uv_a PROPERTIES PREFIX "lib") | |
| 494 endif() | |
| 495 | |
| 496 if(LIBUV_BUILD_TESTS) | |
| 497 # Small hack: use ${uv_test_sources} now to get the runner skeleton, | |
| 498 # before the actual tests are added. | |
| 499 add_executable( | |
| 500 uv_run_benchmarks_a | |
| 501 ${uv_test_sources} | |
| 502 test/benchmark-async-pummel.c | |
| 503 test/benchmark-async.c | |
| 504 test/benchmark-fs-stat.c | |
| 505 test/benchmark-getaddrinfo.c | |
| 506 test/benchmark-loop-count.c | |
| 507 test/benchmark-queue-work.c | |
| 508 test/benchmark-million-async.c | |
| 509 test/benchmark-million-timers.c | |
| 510 test/benchmark-multi-accept.c | |
| 511 test/benchmark-ping-pongs.c | |
| 512 test/benchmark-ping-udp.c | |
| 513 test/benchmark-pound.c | |
| 514 test/benchmark-pump.c | |
| 515 test/benchmark-sizes.c | |
| 516 test/benchmark-spawn.c | |
| 517 test/benchmark-tcp-write-batch.c | |
| 518 test/benchmark-thread.c | |
| 519 test/benchmark-udp-pummel.c | |
| 520 test/blackhole-server.c | |
| 521 test/echo-server.c | |
| 522 test/run-benchmarks.c | |
| 523 test/runner.c) | |
| 524 target_compile_definitions(uv_run_benchmarks_a PRIVATE ${uv_defines}) | |
| 525 target_compile_options(uv_run_benchmarks_a PRIVATE ${uv_cflags}) | |
| 526 target_link_libraries(uv_run_benchmarks_a uv_a ${uv_test_libraries}) | |
| 527 | |
| 528 list(APPEND uv_test_sources | |
| 529 test/blackhole-server.c | |
| 530 test/echo-server.c | |
| 531 test/run-tests.c | |
| 532 test/runner.c | |
| 533 test/test-active.c | |
| 534 test/test-async-null-cb.c | |
| 535 test/test-async.c | |
| 536 test/test-barrier.c | |
| 537 test/test-callback-stack.c | |
| 538 test/test-close-fd.c | |
| 539 test/test-close-order.c | |
| 540 test/test-condvar.c | |
| 541 test/test-connect-unspecified.c | |
| 542 test/test-connection-fail.c | |
| 543 test/test-cwd-and-chdir.c | |
| 544 test/test-default-loop-close.c | |
| 545 test/test-delayed-accept.c | |
| 546 test/test-dlerror.c | |
| 547 test/test-eintr-handling.c | |
| 548 test/test-embed.c | |
| 549 test/test-emfile.c | |
| 550 test/test-env-vars.c | |
| 551 test/test-error.c | |
| 552 test/test-fail-always.c | |
| 553 test/test-fork.c | |
| 554 test/test-fs-copyfile.c | |
| 555 test/test-fs-event.c | |
| 556 test/test-fs-poll.c | |
| 557 test/test-fs.c | |
| 558 test/test-fs-readdir.c | |
| 559 test/test-fs-fd-hash.c | |
| 560 test/test-fs-open-flags.c | |
| 561 test/test-get-currentexe.c | |
| 562 test/test-get-loadavg.c | |
| 563 test/test-get-memory.c | |
| 564 test/test-get-passwd.c | |
| 565 test/test-getaddrinfo.c | |
| 566 test/test-gethostname.c | |
| 567 test/test-getnameinfo.c | |
| 568 test/test-getsockname.c | |
| 569 test/test-getters-setters.c | |
| 570 test/test-gettimeofday.c | |
| 571 test/test-handle-fileno.c | |
| 572 test/test-homedir.c | |
| 573 test/test-hrtime.c | |
| 574 test/test-idle.c | |
| 575 test/test-idna.c | |
| 576 test/test-iouring-pollhup.c | |
| 577 test/test-ip4-addr.c | |
| 578 test/test-ip6-addr.c | |
| 579 test/test-ip-name.c | |
| 580 test/test-ipc-heavy-traffic-deadlock-bug.c | |
| 581 test/test-ipc-send-recv.c | |
| 582 test/test-ipc.c | |
| 583 test/test-loop-alive.c | |
| 584 test/test-loop-close.c | |
| 585 test/test-loop-configure.c | |
| 586 test/test-loop-handles.c | |
| 587 test/test-loop-oom.c | |
| 588 test/test-loop-stop.c | |
| 589 test/test-loop-time.c | |
| 590 test/test-metrics.c | |
| 591 test/test-multiple-listen.c | |
| 592 test/test-mutexes.c | |
| 593 test/test-not-readable-nor-writable-on-read-error.c | |
| 594 test/test-not-writable-after-shutdown.c | |
| 595 test/test-osx-select.c | |
| 596 test/test-pass-always.c | |
| 597 test/test-ping-pong.c | |
| 598 test/test-pipe-bind-error.c | |
| 599 test/test-pipe-close-stdout-read-stdin.c | |
| 600 test/test-pipe-connect-error.c | |
| 601 test/test-pipe-connect-multiple.c | |
| 602 test/test-pipe-connect-prepare.c | |
| 603 test/test-pipe-getsockname.c | |
| 604 test/test-pipe-pending-instances.c | |
| 605 test/test-pipe-sendmsg.c | |
| 606 test/test-pipe-server-close.c | |
| 607 test/test-pipe-set-fchmod.c | |
| 608 test/test-pipe-set-non-blocking.c | |
| 609 test/test-platform-output.c | |
| 610 test/test-poll-close-doesnt-corrupt-stack.c | |
| 611 test/test-poll-close.c | |
| 612 test/test-poll-closesocket.c | |
| 613 test/test-poll-multiple-handles.c | |
| 614 test/test-poll-oob.c | |
| 615 test/test-poll.c | |
| 616 test/test-process-priority.c | |
| 617 test/test-process-title-threadsafe.c | |
| 618 test/test-process-title.c | |
| 619 test/test-queue-foreach-delete.c | |
| 620 test/test-random.c | |
| 621 test/test-readable-on-eof.c | |
| 622 test/test-ref.c | |
| 623 test/test-run-nowait.c | |
| 624 test/test-run-once.c | |
| 625 test/test-semaphore.c | |
| 626 test/test-shutdown-close.c | |
| 627 test/test-shutdown-eof.c | |
| 628 test/test-shutdown-simultaneous.c | |
| 629 test/test-shutdown-twice.c | |
| 630 test/test-signal-multiple-loops.c | |
| 631 test/test-signal-pending-on-close.c | |
| 632 test/test-signal.c | |
| 633 test/test-socket-buffer-size.c | |
| 634 test/test-spawn.c | |
| 635 test/test-stdio-over-pipes.c | |
| 636 test/test-strscpy.c | |
| 637 test/test-strtok.c | |
| 638 test/test-tcp-alloc-cb-fail.c | |
| 639 test/test-tcp-bind-error.c | |
| 640 test/test-tcp-bind6-error.c | |
| 641 test/test-tcp-close-accept.c | |
| 642 test/test-tcp-close-after-read-timeout.c | |
| 643 test/test-tcp-close-while-connecting.c | |
| 644 test/test-tcp-close.c | |
| 645 test/test-tcp-close-reset.c | |
| 646 test/test-tcp-connect-error-after-write.c | |
| 647 test/test-tcp-connect-error.c | |
| 648 test/test-tcp-connect-timeout.c | |
| 649 test/test-tcp-connect6-error.c | |
| 650 test/test-tcp-create-socket-early.c | |
| 651 test/test-tcp-flags.c | |
| 652 test/test-tcp-oob.c | |
| 653 test/test-tcp-open.c | |
| 654 test/test-tcp-read-stop.c | |
| 655 test/test-tcp-reuseport.c | |
| 656 test/test-tcp-read-stop-start.c | |
| 657 test/test-tcp-rst.c | |
| 658 test/test-tcp-shutdown-after-write.c | |
| 659 test/test-tcp-try-write.c | |
| 660 test/test-tcp-write-in-a-row.c | |
| 661 test/test-tcp-try-write-error.c | |
| 662 test/test-tcp-unexpected-read.c | |
| 663 test/test-tcp-write-after-connect.c | |
| 664 test/test-tcp-write-fail.c | |
| 665 test/test-tcp-write-queue-order.c | |
| 666 test/test-tcp-write-to-half-open-connection.c | |
| 667 test/test-tcp-writealot.c | |
| 668 test/test-test-macros.c | |
| 669 test/test-thread-affinity.c | |
| 670 test/test-thread-equal.c | |
| 671 test/test-thread.c | |
| 672 test/test-thread-name.c | |
| 673 test/test-thread-priority.c | |
| 674 test/test-threadpool-cancel.c | |
| 675 test/test-threadpool.c | |
| 676 test/test-timer-again.c | |
| 677 test/test-timer-from-check.c | |
| 678 test/test-timer.c | |
| 679 test/test-tmpdir.c | |
| 680 test/test-tty-duplicate-key.c | |
| 681 test/test-tty-escape-sequence-processing.c | |
| 682 test/test-tty.c | |
| 683 test/test-udp-alloc-cb-fail.c | |
| 684 test/test-udp-bind.c | |
| 685 test/test-udp-connect.c | |
| 686 test/test-udp-connect6.c | |
| 687 test/test-udp-create-socket-early.c | |
| 688 test/test-udp-dgram-too-big.c | |
| 689 test/test-udp-ipv6.c | |
| 690 test/test-udp-mmsg.c | |
| 691 test/test-udp-multicast-interface.c | |
| 692 test/test-udp-multicast-interface6.c | |
| 693 test/test-udp-multicast-join.c | |
| 694 test/test-udp-multicast-join6.c | |
| 695 test/test-udp-multicast-ttl.c | |
| 696 test/test-udp-open.c | |
| 697 test/test-udp-options.c | |
| 698 test/test-udp-send-and-recv.c | |
| 699 test/test-udp-send-hang-loop.c | |
| 700 test/test-udp-send-immediate.c | |
| 701 test/test-udp-sendmmsg-error.c | |
| 702 test/test-udp-send-unreachable.c | |
| 703 test/test-udp-try-send.c | |
| 704 test/test-udp-recv-in-a-row.c | |
| 705 test/test-udp-reuseport.c | |
| 706 test/test-uname.c | |
| 707 test/test-walk-handles.c | |
| 708 test/test-watcher-cross-stop.c) | |
| 709 | |
| 710 add_executable(uv_run_tests ${uv_test_sources} uv_win_longpath.manifest) | |
| 711 target_compile_definitions(uv_run_tests | |
| 712 PRIVATE ${uv_defines} USING_UV_SHARED=1) | |
| 713 target_compile_options(uv_run_tests PRIVATE ${uv_cflags}) | |
| 714 target_link_libraries(uv_run_tests uv ${uv_test_libraries}) | |
| 715 add_test(NAME uv_test | |
| 716 COMMAND uv_run_tests | |
| 717 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | |
| 718 if(CMAKE_SYSTEM_NAME STREQUAL "OS390") | |
| 719 set_tests_properties(uv_test PROPERTIES ENVIRONMENT | |
| 720 "LIBPATH=${CMAKE_BINARY_DIR}:$ENV{LIBPATH}") | |
| 721 endif() | |
| 722 if(WIN32) | |
| 723 add_custom_command(TARGET uv_run_tests POST_BUILD | |
| 724 COMMAND "${CMAKE_COMMAND}" -E copy | |
| 725 "$<TARGET_FILE:uv_run_tests>" | |
| 726 "$<TARGET_FILE_DIR:uv_run_tests>/uv_run_tests_no_ext") | |
| 727 endif() | |
| 728 add_executable(uv_run_tests_a ${uv_test_sources} uv_win_longpath.manifest) | |
| 729 target_compile_definitions(uv_run_tests_a PRIVATE ${uv_defines}) | |
| 730 target_compile_options(uv_run_tests_a PRIVATE ${uv_cflags}) | |
| 731 if(QEMU) | |
| 732 target_link_libraries(uv_run_tests_a uv_a ${uv_test_libraries} -static) | |
| 733 else() | |
| 734 target_link_libraries(uv_run_tests_a uv_a ${uv_test_libraries}) | |
| 735 endif() | |
| 736 add_test(NAME uv_test_a | |
| 737 COMMAND uv_run_tests_a | |
| 738 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | |
| 739 if(CMAKE_SYSTEM_NAME STREQUAL "OS390") | |
| 740 set_target_properties(uv_run_benchmarks_a PROPERTIES LINKER_LANGUAGE CXX) | |
| 741 set_target_properties(uv_run_tests PROPERTIES LINKER_LANGUAGE CXX) | |
| 742 set_target_properties(uv_run_tests_a PROPERTIES LINKER_LANGUAGE CXX) | |
| 743 endif() | |
| 744 if(WIN32) | |
| 745 add_custom_command(TARGET uv_run_tests_a POST_BUILD | |
| 746 COMMAND "${CMAKE_COMMAND}" -E copy | |
| 747 "$<TARGET_FILE:uv_run_tests_a>" | |
| 748 "$<TARGET_FILE_DIR:uv_run_tests_a>/uv_run_tests_a_no_ext") | |
| 749 endif() | |
| 750 endif() | |
| 751 | |
| 752 # Now for some gibbering horrors from beyond the stars... | |
| 753 foreach(lib IN LISTS uv_libraries) | |
| 754 list(APPEND LIBS "-l${lib}") | |
| 755 endforeach() | |
| 756 string(REPLACE ";" " " LIBS "${LIBS}") | |
| 757 # Consider setting project version via project() call? | |
| 758 file(STRINGS configure.ac configure_ac REGEX ^AC_INIT) | |
| 759 string(REGEX MATCH "([0-9]+)[.][0-9]+[.][0-9]+" PACKAGE_VERSION "${configure_ac}") | |
| 760 set(UV_VERSION_MAJOR "${CMAKE_MATCH_1}") | |
| 761 | |
| 762 set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) | |
| 763 set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) | |
| 764 set(prefix ${CMAKE_INSTALL_PREFIX}) | |
| 765 configure_file(libuv-static.pc.in libuv-static.pc @ONLY) | |
| 766 | |
| 767 install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | |
| 768 install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR}) | |
| 769 install(FILES LICENSE-extra DESTINATION ${CMAKE_INSTALL_DOCDIR}) | |
| 770 install(FILES ${PROJECT_BINARY_DIR}/libuv-static.pc | |
| 771 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) | |
| 772 install(TARGETS uv_a EXPORT libuvConfig | |
| 773 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) | |
| 774 install(EXPORT libuvConfig | |
| 775 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libuv | |
| 776 NAMESPACE libuv::) | |
| 777 | |
| 778 if(LIBUV_BUILD_SHARED) | |
| 779 # The version in the filename is mirroring the behaviour of autotools. | |
| 780 set_target_properties(uv PROPERTIES | |
| 781 VERSION ${UV_VERSION_MAJOR}.0.0 | |
| 782 SOVERSION ${UV_VERSION_MAJOR}) | |
| 783 configure_file(libuv.pc.in libuv.pc @ONLY) | |
| 784 install(FILES ${PROJECT_BINARY_DIR}/libuv.pc | |
| 785 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) | |
| 786 install(TARGETS uv EXPORT libuvConfig | |
| 787 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | |
| 788 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | |
| 789 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) | |
| 790 endif() | |
| 791 | |
| 792 if(MSVC) | |
| 793 set(CMAKE_DEBUG_POSTFIX d) | |
| 794 get_filename_component(CMAKE_C_COMPILER_DIR ${CMAKE_C_COMPILER} DIRECTORY) | |
| 795 if(ASAN) | |
| 796 file(INSTALL "${CMAKE_C_COMPILER_DIR}/llvm-symbolizer.exe" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") | |
| 797 file(INSTALL "${CMAKE_C_COMPILER_DIR}/clang_rt.asan_dynamic-x86_64.dll" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") | |
| 798 file(INSTALL "${CMAKE_C_COMPILER_DIR}/clang_rt.asan_dbg_dynamic-x86_64.dll" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") | |
| 799 endif() | |
| 800 endif() | |
| 801 | |
| 802 if(BUILD_SHARED_LIBS) | |
| 803 set(LIB_SELECTED uv) | |
| 804 else() | |
| 805 set(LIB_SELECTED uv_a) | |
| 806 endif() | |
| 807 | |
| 808 add_library(libuv::libuv ALIAS ${LIB_SELECTED}) | |
| 809 | |
| 810 message(STATUS "summary of build options: | |
| 811 Install prefix: ${CMAKE_INSTALL_PREFIX} | |
| 812 Target system: ${CMAKE_SYSTEM_NAME} | |
| 813 Compiler: | |
| 814 C compiler: ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID}) | |
| 815 CFLAGS: ${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS} | |
| 816 ") |