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