|
| 1 | +# TODO: determine CMAKE_SYSTEM_NAME on OS/390. Currently assumes "OS/390". |
| 2 | +cmake_minimum_required(VERSION 3.0) |
| 3 | +project(libuv) |
| 4 | +enable_testing() |
| 5 | + |
| 6 | +if(MSVC) |
| 7 | + list(APPEND uv_cflags /W4) |
| 8 | +elseif(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU") |
| 9 | + list(APPEND uv_cflags -fvisibility=hidden --std=gnu89) |
| 10 | + list(APPEND uv_cflags -Wall -Wextra -Wstrict-prototypes) |
| 11 | + list(APPEND uv_cflags -Wno-unused-parameter) |
| 12 | +endif() |
| 13 | + |
| 14 | +set(uv_sources |
| 15 | + src/fs-poll.c |
| 16 | + src/inet.c |
| 17 | + src/threadpool.c |
| 18 | + src/uv-common.c |
| 19 | + src/uv-data-getter-setters.c |
| 20 | + src/version.c) |
| 21 | + |
| 22 | +set(uv_test_sources |
| 23 | + test/blackhole-server.c |
| 24 | + test/echo-server.c |
| 25 | + test/run-tests.c |
| 26 | + test/runner.c |
| 27 | + test/test-active.c |
| 28 | + test/test-async-null-cb.c |
| 29 | + test/test-async.c |
| 30 | + test/test-barrier.c |
| 31 | + test/test-callback-order.c |
| 32 | + test/test-callback-stack.c |
| 33 | + test/test-close-fd.c |
| 34 | + test/test-close-order.c |
| 35 | + test/test-condvar.c |
| 36 | + test/test-connect-unspecified.c |
| 37 | + test/test-connection-fail.c |
| 38 | + test/test-cwd-and-chdir.c |
| 39 | + test/test-default-loop-close.c |
| 40 | + test/test-delayed-accept.c |
| 41 | + test/test-dlerror.c |
| 42 | + test/test-eintr-handling.c |
| 43 | + test/test-embed.c |
| 44 | + test/test-emfile.c |
| 45 | + test/test-env-vars.c |
| 46 | + test/test-error.c |
| 47 | + test/test-fail-always.c |
| 48 | + test/test-fork.c |
| 49 | + test/test-fs-copyfile.c |
| 50 | + test/test-fs-event.c |
| 51 | + test/test-fs-poll.c |
| 52 | + test/test-fs.c |
| 53 | + test/test-get-currentexe.c |
| 54 | + test/test-get-loadavg.c |
| 55 | + test/test-get-memory.c |
| 56 | + test/test-get-passwd.c |
| 57 | + test/test-getaddrinfo.c |
| 58 | + test/test-gethostname.c |
| 59 | + test/test-getnameinfo.c |
| 60 | + test/test-getsockname.c |
| 61 | + test/test-getters-setters.c |
| 62 | + test/test-handle-fileno.c |
| 63 | + test/test-homedir.c |
| 64 | + test/test-hrtime.c |
| 65 | + test/test-idle.c |
| 66 | + test/test-ip4-addr.c |
| 67 | + test/test-ip6-addr.c |
| 68 | + test/test-ip6-addr.c |
| 69 | + test/test-ipc-heavy-traffic-deadlock-bug.c |
| 70 | + test/test-ipc-send-recv.c |
| 71 | + test/test-ipc.c |
| 72 | + test/test-loop-alive.c |
| 73 | + test/test-loop-close.c |
| 74 | + test/test-loop-configure.c |
| 75 | + test/test-loop-handles.c |
| 76 | + test/test-loop-stop.c |
| 77 | + test/test-loop-time.c |
| 78 | + test/test-multiple-listen.c |
| 79 | + test/test-mutexes.c |
| 80 | + test/test-osx-select.c |
| 81 | + test/test-pass-always.c |
| 82 | + test/test-ping-pong.c |
| 83 | + test/test-pipe-bind-error.c |
| 84 | + test/test-pipe-close-stdout-read-stdin.c |
| 85 | + test/test-pipe-connect-error.c |
| 86 | + test/test-pipe-connect-multiple.c |
| 87 | + test/test-pipe-connect-prepare.c |
| 88 | + test/test-pipe-getsockname.c |
| 89 | + test/test-pipe-pending-instances.c |
| 90 | + test/test-pipe-sendmsg.c |
| 91 | + test/test-pipe-server-close.c |
| 92 | + test/test-pipe-set-fchmod.c |
| 93 | + test/test-pipe-set-non-blocking.c |
| 94 | + test/test-platform-output.c |
| 95 | + test/test-poll-close-doesnt-corrupt-stack.c |
| 96 | + test/test-poll-close.c |
| 97 | + test/test-poll-closesocket.c |
| 98 | + test/test-poll-oob.c |
| 99 | + test/test-poll.c |
| 100 | + test/test-process-title-threadsafe.c |
| 101 | + test/test-process-title.c |
| 102 | + test/test-queue-foreach-delete.c |
| 103 | + test/test-ref.c |
| 104 | + test/test-run-nowait.c |
| 105 | + test/test-run-once.c |
| 106 | + test/test-semaphore.c |
| 107 | + test/test-shutdown-close.c |
| 108 | + test/test-shutdown-eof.c |
| 109 | + test/test-shutdown-twice.c |
| 110 | + test/test-signal-multiple-loops.c |
| 111 | + test/test-signal.c |
| 112 | + test/test-socket-buffer-size.c |
| 113 | + test/test-spawn.c |
| 114 | + test/test-stdio-over-pipes.c |
| 115 | + test/test-tcp-alloc-cb-fail.c |
| 116 | + test/test-tcp-bind-error.c |
| 117 | + test/test-tcp-bind6-error.c |
| 118 | + test/test-tcp-close-accept.c |
| 119 | + test/test-tcp-close-while-connecting.c |
| 120 | + test/test-tcp-close.c |
| 121 | + test/test-tcp-connect-error-after-write.c |
| 122 | + test/test-tcp-connect-error.c |
| 123 | + test/test-tcp-connect-timeout.c |
| 124 | + test/test-tcp-connect6-error.c |
| 125 | + test/test-tcp-create-socket-early.c |
| 126 | + test/test-tcp-flags.c |
| 127 | + test/test-tcp-oob.c |
| 128 | + test/test-tcp-open.c |
| 129 | + test/test-tcp-read-stop.c |
| 130 | + test/test-tcp-shutdown-after-write.c |
| 131 | + test/test-tcp-try-write.c |
| 132 | + test/test-tcp-unexpected-read.c |
| 133 | + test/test-tcp-write-after-connect.c |
| 134 | + test/test-tcp-write-fail.c |
| 135 | + test/test-tcp-write-queue-order.c |
| 136 | + test/test-tcp-write-to-half-open-connection.c |
| 137 | + test/test-tcp-writealot.c |
| 138 | + test/test-thread-equal.c |
| 139 | + test/test-thread.c |
| 140 | + test/test-threadpool-cancel.c |
| 141 | + test/test-threadpool.c |
| 142 | + test/test-timer-again.c |
| 143 | + test/test-timer-from-check.c |
| 144 | + test/test-timer.c |
| 145 | + test/test-tmpdir.c |
| 146 | + test/test-tty.c |
| 147 | + test/test-udp-alloc-cb-fail.c |
| 148 | + test/test-udp-bind.c |
| 149 | + test/test-udp-create-socket-early.c |
| 150 | + test/test-udp-dgram-too-big.c |
| 151 | + test/test-udp-ipv6.c |
| 152 | + test/test-udp-multicast-interface.c |
| 153 | + test/test-udp-multicast-interface6.c |
| 154 | + test/test-udp-multicast-join.c |
| 155 | + test/test-udp-multicast-join6.c |
| 156 | + test/test-udp-multicast-ttl.c |
| 157 | + test/test-udp-open.c |
| 158 | + test/test-udp-options.c |
| 159 | + test/test-udp-send-and-recv.c |
| 160 | + test/test-udp-send-hang-loop.c |
| 161 | + test/test-udp-send-immediate.c |
| 162 | + test/test-udp-send-unreachable.c |
| 163 | + test/test-udp-try-send.c |
| 164 | + test/test-walk-handles.c |
| 165 | + test/test-watcher-cross-stop.c) |
| 166 | + |
| 167 | +if(WIN32) |
| 168 | + list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0600) |
| 169 | + list(APPEND uv_libraries |
| 170 | + advapi32 |
| 171 | + iphlpapi |
| 172 | + psapi |
| 173 | + shell32 |
| 174 | + user32 |
| 175 | + userenv |
| 176 | + ws2_32) |
| 177 | + list(APPEND uv_sources |
| 178 | + src/win/async.c |
| 179 | + src/win/core.c |
| 180 | + src/win/detect-wakeup.c |
| 181 | + src/win/dl.c |
| 182 | + src/win/error.c |
| 183 | + src/win/fs.c |
| 184 | + src/win/fs-event.c |
| 185 | + src/win/getaddrinfo.c |
| 186 | + src/win/getnameinfo.c |
| 187 | + src/win/handle.c |
| 188 | + src/win/loop-watcher.c |
| 189 | + src/win/pipe.c |
| 190 | + src/win/thread.c |
| 191 | + src/win/poll.c |
| 192 | + src/win/process.c |
| 193 | + src/win/process-stdio.c |
| 194 | + src/win/req.c |
| 195 | + src/win/signal.c |
| 196 | + src/win/snprintf.c |
| 197 | + src/win/stream.c |
| 198 | + src/win/tcp.c |
| 199 | + src/win/tty.c |
| 200 | + src/win/timer.c |
| 201 | + src/win/udp.c |
| 202 | + src/win/util.c |
| 203 | + src/win/winapi.c |
| 204 | + src/win/winsock.c) |
| 205 | + list(APPEND uv_test_libraries ws2_32) |
| 206 | + list(APPEND uv_test_sources src/win/snprintf.c test/runner-win.c) |
| 207 | +else() |
| 208 | + list(APPEND uv_defines _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE) |
| 209 | + list(APPEND uv_libraries pthread) |
| 210 | + list(APPEND uv_sources |
| 211 | + src/unix/async.c |
| 212 | + src/unix/core.c |
| 213 | + src/unix/dl.c |
| 214 | + src/unix/fs.c |
| 215 | + src/unix/getaddrinfo.c |
| 216 | + src/unix/getnameinfo.c |
| 217 | + src/unix/loop-watcher.c |
| 218 | + src/unix/loop.c |
| 219 | + src/unix/pipe.c |
| 220 | + src/unix/poll.c |
| 221 | + src/unix/process.c |
| 222 | + src/unix/signal.c |
| 223 | + src/unix/stream.c |
| 224 | + src/unix/tcp.c |
| 225 | + src/unix/thread.c |
| 226 | + src/unix/timer.c |
| 227 | + src/unix/tty.c |
| 228 | + src/unix/udp.c) |
| 229 | + list(APPEND uv_test_sources test/runner-unix.c) |
| 230 | +endif() |
| 231 | + |
| 232 | +if(CMAKE_SYSTEM_NAME STREQUAL "AIX") |
| 233 | + list(APPEND uv_defines |
| 234 | + _ALL_SOURCE |
| 235 | + _LINUX_SOURCE_COMPAT |
| 236 | + _THREAD_SAFE |
| 237 | + _XOPEN_SOURCE=500) |
| 238 | + list(APPEND uv_libraries perfstat) |
| 239 | + list(APPEND uv_sources src/unix/aix.c) |
| 240 | +endif() |
| 241 | + |
| 242 | +if(CMAKE_SYSTEM_NAME STREQUAL "Android") |
| 243 | + list(APPEND uv_libs dl) |
| 244 | + list(APPEND uv_sources |
| 245 | + src/unix/android-ifaddrs.c |
| 246 | + src/unix/linux-core.c |
| 247 | + src/unix/linux-inotify.c |
| 248 | + src/unix/linux-syscalls.c |
| 249 | + src/unix/procfs-exepath.c |
| 250 | + src/unix/pthread-fixes.c |
| 251 | + src/unix/sysinfo-loadavg.c |
| 252 | + src/unix/sysinfo-memory.c) |
| 253 | +endif() |
| 254 | + |
| 255 | +if(CMAKE_SYSTEM_NAME MATCHES "Android|Darwin|Linux|OS/390") |
| 256 | + list(APPEND uv_sources src/unix/proctitle.c) |
| 257 | +endif() |
| 258 | + |
| 259 | +if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD") |
| 260 | + list(APPEND uv_sources src/unix/freebsd.c) |
| 261 | +endif() |
| 262 | + |
| 263 | +if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD") |
| 264 | + list(APPEND uv_sources src/unix/posix-hrtime.c) |
| 265 | + list(APPEND uv_libraries kvm) |
| 266 | +endif() |
| 267 | + |
| 268 | +if(CMAKE_SYSTEM_NAME MATCHES "Darwin|DragonFly|FreeBSD|NetBSD|OpenBSD") |
| 269 | + list(APPEND uv_sources src/unix/bsd-ifaddrs.c src/unix/kqueue.c) |
| 270 | +endif() |
| 271 | + |
| 272 | +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 273 | + list(APPEND uv_defines _DARWIN_UNLIMITED_SELECT=1 _DARWIN_USE_64_BIT_INODE=1) |
| 274 | + list(APPEND uv_sources |
| 275 | + src/unix/darwin-proctitle.c |
| 276 | + src/unix/darwin.c |
| 277 | + src/unix/fsevents.c) |
| 278 | +endif() |
| 279 | + |
| 280 | +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 281 | + list(APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112) |
| 282 | + list(APPEND uv_libraries dl rt) |
| 283 | + list(APPEND uv_sources |
| 284 | + src/unix/linux-core.c |
| 285 | + src/unix/linux-inotify.c |
| 286 | + src/unix/linux-syscalls.c |
| 287 | + src/unix/procfs-exepath.c |
| 288 | + src/unix/sysinfo-loadavg.c |
| 289 | + src/unix/sysinfo-memory.c) |
| 290 | +endif() |
| 291 | + |
| 292 | +if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") |
| 293 | + list(APPEND uv_sources src/unix/netbsd.c) |
| 294 | +endif() |
| 295 | + |
| 296 | +if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") |
| 297 | + list(APPEND uv_sources src/unix/openbsd.c) |
| 298 | +endif() |
| 299 | + |
| 300 | +if(CMAKE_SYSTEM_NAME STREQUAL "OS/390") |
| 301 | + list(APPEND uv_defines PATH_MAX=255) |
| 302 | + list(APPEND uv_defines _AE_BIMODAL) |
| 303 | + list(APPEND uv_defines _ALL_SOURCE) |
| 304 | + list(APPEND uv_defines _LARGE_TIME_API) |
| 305 | + list(APPEND uv_defines _OPEN_MSGQ_EXT) |
| 306 | + list(APPEND uv_defines _OPEN_SYS_FILE_EXT) |
| 307 | + list(APPEND uv_defines _OPEN_SYS_IF_EXT) |
| 308 | + list(APPEND uv_defines _OPEN_SYS_SOCK_IPV6) |
| 309 | + list(APPEND uv_defines _UNIX03_SOURCE) |
| 310 | + list(APPEND uv_defines _UNIX03_THREADS) |
| 311 | + list(APPEND uv_defines _UNIX03_WITHDRAWN) |
| 312 | + list(APPEND uv_defines _XOPEN_SOURCE_EXTENDED) |
| 313 | + list(APPEND uv_sources |
| 314 | + src/unix/pthread-fixes.c |
| 315 | + src/unix/pthread-barrier.c |
| 316 | + src/unix/os390.c |
| 317 | + src/unix/os390-syscalls.c) |
| 318 | +endif() |
| 319 | + |
| 320 | +if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") |
| 321 | + list(APPEND uv_defines __EXTENSIONS__ _XOPEN_SOURCE=500) |
| 322 | + list(APPEND uv_libraries kstat nsl sendfile socket) |
| 323 | + list(APPEND uv_sources src/unix/no-proctitle.c src/unix/sunos.c) |
| 324 | +endif() |
| 325 | + |
| 326 | +if(CMAKE_SYSTEM_NAME MATCHES "Darwin|DragonFly|FreeBSD|Linux|NetBSD|OpenBSD") |
| 327 | + list(APPEND uv_test_libraries util) |
| 328 | +endif() |
| 329 | + |
| 330 | +add_library(uv SHARED ${uv_sources}) |
| 331 | +target_compile_definitions(uv PRIVATE ${uv_defines} BUILDING_UV_SHARED=1) |
| 332 | +target_compile_options(uv PRIVATE ${uv_cflags}) |
| 333 | +target_include_directories(uv PRIVATE include src) |
| 334 | +target_link_libraries(uv ${uv_libraries}) |
| 335 | + |
| 336 | +add_library(uv_a STATIC ${uv_sources}) |
| 337 | +target_compile_definitions(uv_a PRIVATE ${uv_defines}) |
| 338 | +target_compile_options(uv_a PRIVATE ${uv_cflags}) |
| 339 | +target_include_directories(uv_a PRIVATE include src) |
| 340 | +target_link_libraries(uv_a ${uv_libraries}) |
| 341 | + |
| 342 | +if(BUILD_TESTING) |
| 343 | + include(CTest) |
| 344 | + add_executable(uv_run_tests ${uv_test_sources}) |
| 345 | + target_compile_definitions(uv_run_tests PRIVATE ${uv_defines}) |
| 346 | + target_compile_options(uv_run_tests PRIVATE ${uv_cflags}) |
| 347 | + target_include_directories(uv_run_tests PRIVATE include) |
| 348 | + target_link_libraries(uv_run_tests uv ${uv_test_libraries}) |
| 349 | + add_test(NAME uv_test |
| 350 | + COMMAND uv_run_tests |
| 351 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 352 | + add_executable(uv_run_tests_a ${uv_test_sources}) |
| 353 | + target_compile_definitions(uv_run_tests_a PRIVATE ${uv_defines}) |
| 354 | + target_compile_options(uv_run_tests_a PRIVATE ${uv_cflags}) |
| 355 | + target_include_directories(uv_run_tests_a PRIVATE include) |
| 356 | + target_link_libraries(uv_run_tests_a uv_a ${uv_test_libraries}) |
| 357 | + add_test(NAME uv_test_a |
| 358 | + COMMAND uv_run_tests_a |
| 359 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 360 | +endif() |
| 361 | + |
| 362 | +if(UNIX) |
| 363 | + # Now for some gibbering horrors from beyond the stars... |
| 364 | + include(GNUInstallDirs) |
| 365 | + foreach(x ${uv_libraries}) |
| 366 | + set(LIBS "${LIBS} -l${x}") |
| 367 | + endforeach(x) |
| 368 | + file(STRINGS configure.ac configure_ac REGEX ^AC_INIT) |
| 369 | + string(REGEX MATCH [0-9]+[.][0-9]+[.][0-9]+ PACKAGE_VERSION "${configure_ac}") |
| 370 | + set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) |
| 371 | + set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) |
| 372 | + set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 373 | + configure_file(libuv.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libuv.pc @ONLY) |
| 374 | + |
| 375 | + install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 376 | + install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR}) |
| 377 | + install(FILES LICENSE ${CMAKE_CURRENT_BINARY_DIR}/libuv.pc |
| 378 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
| 379 | + install(TARGETS uv LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 380 | + install(TARGETS uv_a ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 381 | +endif() |
0 commit comments