xref: /netbsd-src/external/mit/libuv/dist/CMakeLists.txt (revision d536862b7d93d77932ef5de7eebdc48d76921b77)
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
33# Compiler check
34string(CONCAT is-msvc $<OR:
35  $<C_COMPILER_ID:MSVC>,
36  $<STREQUAL:${CMAKE_C_COMPILER_FRONTEND_VARIANT},MSVC>
37>)
38
39check_c_compiler_flag(/W4 UV_LINT_W4)
40check_c_compiler_flag(/wd4100 UV_LINT_NO_UNUSED_PARAMETER_MSVC)
41check_c_compiler_flag(/wd4127 UV_LINT_NO_CONDITIONAL_CONSTANT_MSVC)
42check_c_compiler_flag(/wd4201 UV_LINT_NO_NONSTANDARD_MSVC)
43check_c_compiler_flag(/wd4206 UV_LINT_NO_NONSTANDARD_EMPTY_TU_MSVC)
44check_c_compiler_flag(/wd4210 UV_LINT_NO_NONSTANDARD_FILE_SCOPE_MSVC)
45check_c_compiler_flag(/wd4232 UV_LINT_NO_NONSTANDARD_NONSTATIC_DLIMPORT_MSVC)
46check_c_compiler_flag(/wd4456 UV_LINT_NO_HIDES_LOCAL)
47check_c_compiler_flag(/wd4457 UV_LINT_NO_HIDES_PARAM)
48check_c_compiler_flag(/wd4459 UV_LINT_NO_HIDES_GLOBAL)
49check_c_compiler_flag(/wd4706 UV_LINT_NO_CONDITIONAL_ASSIGNMENT_MSVC)
50check_c_compiler_flag(/wd4996 UV_LINT_NO_UNSAFE_MSVC)
51
52check_c_compiler_flag(-Wall UV_LINT_WALL) # DO NOT use this under MSVC
53
54# TODO: Place these into its own function
55check_c_compiler_flag(-Wno-unused-parameter UV_LINT_NO_UNUSED_PARAMETER)
56check_c_compiler_flag(-Wstrict-prototypes UV_LINT_STRICT_PROTOTYPES)
57check_c_compiler_flag(-Wextra UV_LINT_EXTRA)
58
59set(lint-no-unused-parameter $<$<BOOL:${UV_LINT_NO_UNUSED_PARAMETER}>:-Wno-unused-parameter>)
60set(lint-strict-prototypes $<$<BOOL:${UV_LINT_STRICT_PROTOTYPES}>:-Wstrict-prototypes>)
61set(lint-extra $<$<BOOL:${UV_LINT_EXTRA}>:-Wextra>)
62set(lint-w4 $<$<BOOL:${UV_LINT_W4}>:/W4>)
63set(lint-no-unused-parameter-msvc $<$<BOOL:${UV_LINT_NO_UNUSED_PARAMETER_MSVC}>:/wd4100>)
64set(lint-no-conditional-constant-msvc $<$<BOOL:${UV_LINT_NO_CONDITIONAL_CONSTANT_MSVC}>:/wd4127>)
65set(lint-no-nonstandard-msvc $<$<BOOL:${UV_LINT_NO_NONSTANDARD_MSVC}>:/wd4201>)
66set(lint-no-nonstandard-empty-tu-msvc $<$<BOOL:${UV_LINT_NO_NONSTANDARD_EMPTY_TU_MSVC}>:/wd4206>)
67set(lint-no-nonstandard-file-scope-msvc $<$<BOOL:${UV_LINT_NO_NONSTANDARD_FILE_SCOPE_MSVC}>:/wd4210>)
68set(lint-no-nonstandard-nonstatic-dlimport-msvc $<$<BOOL:${UV_LINT_NO_NONSTANDARD_NONSTATIC_DLIMPORT_MSVC}>:/wd4232>)
69set(lint-no-hides-local-msvc $<$<BOOL:${UV_LINT_NO_HIDES_LOCAL}>:/wd4456>)
70set(lint-no-hides-param-msvc $<$<BOOL:${UV_LINT_NO_HIDES_PARAM}>:/wd4457>)
71set(lint-no-hides-global-msvc $<$<BOOL:${UV_LINT_NO_HIDES_GLOBAL}>:/wd4459>)
72set(lint-no-conditional-assignment-msvc $<$<BOOL:${UV_LINT_NO_CONDITIONAL_ASSIGNMENT_MSVC}>:/wd4706>)
73set(lint-no-unsafe-msvc $<$<BOOL:${UV_LINT_NO_UNSAFE_MSVC}>:/wd4996>)
74# Unfortunately, this one is complicated because MSVC and clang-cl support -Wall
75# but using it is like calling -Weverything
76string(CONCAT lint-default $<
77  $<AND:$<BOOL:${UV_LINT_WALL}>,$<NOT:${is-msvc}>>:-Wall
78>)
79
80list(APPEND uv_cflags ${lint-strict-prototypes} ${lint-extra} ${lint-default} ${lint-w4})
81list(APPEND uv_cflags ${lint-no-unused-parameter})
82list(APPEND uv_cflags ${lint-no-unused-parameter-msvc})
83list(APPEND uv_cflags ${lint-no-conditional-constant-msvc})
84list(APPEND uv_cflags ${lint-no-nonstandard-msvc})
85list(APPEND uv_cflags ${lint-no-nonstandard-empty-tu-msvc})
86list(APPEND uv_cflags ${lint-no-nonstandard-file-scope-msvc})
87list(APPEND uv_cflags ${lint-no-nonstandard-nonstatic-dlimport-msvc})
88list(APPEND uv_cflags ${lint-no-hides-local-msvc})
89list(APPEND uv_cflags ${lint-no-hides-param-msvc})
90list(APPEND uv_cflags ${lint-no-hides-global-msvc})
91list(APPEND uv_cflags ${lint-no-conditional-assignment-msvc})
92list(APPEND uv_cflags ${lint-no-unsafe-msvc})
93
94set(uv_sources
95    src/fs-poll.c
96    src/idna.c
97    src/inet.c
98    src/random.c
99    src/strscpy.c
100    src/threadpool.c
101    src/timer.c
102    src/uv-common.c
103    src/uv-data-getter-setters.c
104    src/version.c)
105
106if(WIN32)
107  list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0600)
108  list(APPEND uv_libraries
109       psapi
110       iphlpapi
111       userenv
112       ws2_32)
113  list(APPEND uv_sources
114       src/win/async.c
115       src/win/core.c
116       src/win/detect-wakeup.c
117       src/win/dl.c
118       src/win/error.c
119       src/win/fs.c
120       src/win/fs-event.c
121       src/win/getaddrinfo.c
122       src/win/getnameinfo.c
123       src/win/handle.c
124       src/win/loop-watcher.c
125       src/win/pipe.c
126       src/win/thread.c
127       src/win/poll.c
128       src/win/process.c
129       src/win/process-stdio.c
130       src/win/signal.c
131       src/win/snprintf.c
132       src/win/stream.c
133       src/win/tcp.c
134       src/win/tty.c
135       src/win/udp.c
136       src/win/util.c
137       src/win/winapi.c
138       src/win/winsock.c)
139  list(APPEND uv_test_libraries ws2_32)
140  list(APPEND uv_test_sources src/win/snprintf.c test/runner-win.c)
141else()
142  list(APPEND uv_defines _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE)
143  if(NOT CMAKE_SYSTEM_NAME MATCHES "Android|OS390")
144    # TODO: This should be replaced with find_package(Threads) if possible
145    # Android has pthread as part of its c library, not as a separate
146    # libpthread.so.
147    list(APPEND uv_libraries pthread)
148  endif()
149  list(APPEND uv_sources
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-watcher.c
157       src/unix/loop.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  list(APPEND uv_test_sources test/runner-unix.c)
169endif()
170
171if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
172  list(APPEND uv_defines
173       _ALL_SOURCE
174       _LINUX_SOURCE_COMPAT
175       _THREAD_SAFE
176       _XOPEN_SOURCE=500
177       HAVE_SYS_AHAFS_EVPRODS_H)
178  list(APPEND uv_libraries perfstat)
179  list(APPEND uv_sources
180       src/unix/aix.c
181       src/unix/aix-common.c)
182endif()
183
184if(CMAKE_SYSTEM_NAME STREQUAL "Android")
185  list(APPEND uv_libraries dl)
186  list(APPEND uv_sources
187       src/unix/android-ifaddrs.c
188       src/unix/linux-core.c
189       src/unix/linux-inotify.c
190       src/unix/linux-syscalls.c
191       src/unix/procfs-exepath.c
192       src/unix/pthread-fixes.c
193       src/unix/random-getentropy.c
194       src/unix/random-getrandom.c
195       src/unix/random-sysctl-linux.c
196       src/unix/sysinfo-loadavg.c)
197endif()
198
199if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Android|Linux|OS390")
200  list(APPEND uv_sources src/unix/proctitle.c)
201endif()
202
203if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD")
204  list(APPEND uv_sources src/unix/freebsd.c)
205endif()
206
207if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD")
208  list(APPEND uv_sources src/unix/posix-hrtime.c src/unix/bsd-proctitle.c)
209  list(APPEND uv_libraries kvm)
210endif()
211
212if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD")
213  list(APPEND uv_sources src/unix/bsd-ifaddrs.c src/unix/kqueue.c)
214endif()
215
216if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
217  list(APPEND uv_sources src/unix/random-getrandom.c)
218endif()
219
220if(APPLE OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
221  list(APPEND uv_sources src/unix/random-getentropy.c)
222endif()
223
224if(APPLE)
225  list(APPEND uv_defines _DARWIN_UNLIMITED_SELECT=1 _DARWIN_USE_64_BIT_INODE=1)
226  list(APPEND uv_sources
227       src/unix/darwin-proctitle.c
228       src/unix/darwin.c
229       src/unix/fsevents.c)
230endif()
231
232if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
233  list(APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112)
234  list(APPEND uv_libraries dl rt)
235  list(APPEND uv_sources
236       src/unix/linux-core.c
237       src/unix/linux-inotify.c
238       src/unix/linux-syscalls.c
239       src/unix/procfs-exepath.c
240       src/unix/random-getrandom.c
241       src/unix/random-sysctl-linux.c
242       src/unix/sysinfo-loadavg.c)
243endif()
244
245if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
246  list(APPEND uv_sources src/unix/netbsd.c)
247endif()
248
249if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
250  list(APPEND uv_sources src/unix/openbsd.c)
251endif()
252
253if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
254  list(APPEND uv_defines PATH_MAX=255)
255  list(APPEND uv_defines _AE_BIMODAL)
256  list(APPEND uv_defines _ALL_SOURCE)
257  list(APPEND uv_defines _ISOC99_SOURCE)
258  list(APPEND uv_defines _LARGE_TIME_API)
259  list(APPEND uv_defines _OPEN_MSGQ_EXT)
260  list(APPEND uv_defines _OPEN_SYS_FILE_EXT)
261  list(APPEND uv_defines _OPEN_SYS_IF_EXT)
262  list(APPEND uv_defines _OPEN_SYS_SOCK_EXT3)
263  list(APPEND uv_defines _OPEN_SYS_SOCK_IPV6)
264  list(APPEND uv_defines _UNIX03_SOURCE)
265  list(APPEND uv_defines _UNIX03_THREADS)
266  list(APPEND uv_defines _UNIX03_WITHDRAWN)
267  list(APPEND uv_defines _XOPEN_SOURCE_EXTENDED)
268  list(APPEND uv_sources
269       src/unix/pthread-fixes.c
270       src/unix/os390.c
271       src/unix/os390-syscalls.c)
272  list(APPEND uv_cflags -Wc,DLL -Wc,exportall -Wc,xplink)
273  list(APPEND uv_libraries -Wl,xplink)
274  list(APPEND uv_test_libraries -Wl,xplink)
275endif()
276
277if(CMAKE_SYSTEM_NAME STREQUAL "OS400")
278  list(APPEND uv_defines
279       _ALL_SOURCE
280       _LINUX_SOURCE_COMPAT
281       _THREAD_SAFE
282       _XOPEN_SOURCE=500)
283  list(APPEND uv_sources
284    src/unix/aix-common.c
285    src/unix/ibmi.c
286    src/unix/no-fsevents.c
287    src/unix/no-proctitle.c
288    src/unix/posix-poll.c)
289endif()
290
291if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
292  list(APPEND uv_defines __EXTENSIONS__ _XOPEN_SOURCE=500)
293  list(APPEND uv_libraries kstat nsl sendfile socket)
294  list(APPEND uv_sources src/unix/no-proctitle.c src/unix/sunos.c)
295endif()
296
297if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD")
298  list(APPEND uv_test_libraries util)
299endif()
300
301add_library(uv SHARED ${uv_sources})
302target_compile_definitions(uv
303  INTERFACE
304    USING_UV_SHARED=1
305  PRIVATE
306    BUILDING_UV_SHARED=1
307    ${uv_defines})
308target_compile_options(uv PRIVATE ${uv_cflags})
309target_include_directories(uv
310  PUBLIC
311    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
312    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
313  PRIVATE
314    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
315target_link_libraries(uv ${uv_libraries})
316
317add_library(uv_a STATIC ${uv_sources})
318target_compile_definitions(uv_a PRIVATE ${uv_defines})
319target_compile_options(uv_a PRIVATE ${uv_cflags})
320target_include_directories(uv_a
321  PUBLIC
322    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
323    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
324  PRIVATE
325    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
326target_link_libraries(uv_a ${uv_libraries})
327
328if(LIBUV_BUILD_TESTS)
329  # Small hack: use ${uv_test_sources} now to get the runner skeleton,
330  # before the actual tests are added.
331  add_executable(
332    uv_run_benchmarks_a
333    ${uv_test_sources}
334    test/benchmark-async-pummel.c
335    test/benchmark-async.c
336    test/benchmark-fs-stat.c
337    test/benchmark-getaddrinfo.c
338    test/benchmark-loop-count.c
339    test/benchmark-million-async.c
340    test/benchmark-million-timers.c
341    test/benchmark-multi-accept.c
342    test/benchmark-ping-pongs.c
343    test/benchmark-ping-udp.c
344    test/benchmark-pound.c
345    test/benchmark-pump.c
346    test/benchmark-sizes.c
347    test/benchmark-spawn.c
348    test/benchmark-tcp-write-batch.c
349    test/benchmark-thread.c
350    test/benchmark-udp-pummel.c
351    test/blackhole-server.c
352    test/dns-server.c
353    test/echo-server.c
354    test/run-benchmarks.c
355    test/runner.c)
356  target_compile_definitions(uv_run_benchmarks_a PRIVATE ${uv_defines})
357  target_compile_options(uv_run_benchmarks_a PRIVATE ${uv_cflags})
358  target_link_libraries(uv_run_benchmarks_a uv_a ${uv_test_libraries})
359
360  list(APPEND uv_test_sources
361       test/blackhole-server.c
362       test/echo-server.c
363       test/run-tests.c
364       test/runner.c
365       test/test-active.c
366       test/test-async-null-cb.c
367       test/test-async.c
368       test/test-barrier.c
369       test/test-callback-order.c
370       test/test-callback-stack.c
371       test/test-close-fd.c
372       test/test-close-order.c
373       test/test-condvar.c
374       test/test-connect-unspecified.c
375       test/test-connection-fail.c
376       test/test-cwd-and-chdir.c
377       test/test-default-loop-close.c
378       test/test-delayed-accept.c
379       test/test-dlerror.c
380       test/test-eintr-handling.c
381       test/test-embed.c
382       test/test-emfile.c
383       test/test-env-vars.c
384       test/test-error.c
385       test/test-fail-always.c
386       test/test-fork.c
387       test/test-fs-copyfile.c
388       test/test-fs-event.c
389       test/test-fs-poll.c
390       test/test-fs.c
391       test/test-fs-readdir.c
392       test/test-fs-fd-hash.c
393       test/test-fs-open-flags.c
394       test/test-get-currentexe.c
395       test/test-get-loadavg.c
396       test/test-get-memory.c
397       test/test-get-passwd.c
398       test/test-getaddrinfo.c
399       test/test-gethostname.c
400       test/test-getnameinfo.c
401       test/test-getsockname.c
402       test/test-getters-setters.c
403       test/test-gettimeofday.c
404       test/test-handle-fileno.c
405       test/test-homedir.c
406       test/test-hrtime.c
407       test/test-idle.c
408       test/test-idna.c
409       test/test-ip4-addr.c
410       test/test-ip6-addr.c
411       test/test-ipc-heavy-traffic-deadlock-bug.c
412       test/test-ipc-send-recv.c
413       test/test-ipc.c
414       test/test-loop-alive.c
415       test/test-loop-close.c
416       test/test-loop-configure.c
417       test/test-loop-handles.c
418       test/test-loop-stop.c
419       test/test-loop-time.c
420       test/test-multiple-listen.c
421       test/test-mutexes.c
422       test/test-osx-select.c
423       test/test-pass-always.c
424       test/test-ping-pong.c
425       test/test-pipe-bind-error.c
426       test/test-pipe-close-stdout-read-stdin.c
427       test/test-pipe-connect-error.c
428       test/test-pipe-connect-multiple.c
429       test/test-pipe-connect-prepare.c
430       test/test-pipe-getsockname.c
431       test/test-pipe-pending-instances.c
432       test/test-pipe-sendmsg.c
433       test/test-pipe-server-close.c
434       test/test-pipe-set-fchmod.c
435       test/test-pipe-set-non-blocking.c
436       test/test-platform-output.c
437       test/test-poll-close-doesnt-corrupt-stack.c
438       test/test-poll-close.c
439       test/test-poll-closesocket.c
440       test/test-poll-oob.c
441       test/test-poll.c
442       test/test-process-priority.c
443       test/test-process-title-threadsafe.c
444       test/test-process-title.c
445       test/test-queue-foreach-delete.c
446       test/test-random.c
447       test/test-ref.c
448       test/test-run-nowait.c
449       test/test-run-once.c
450       test/test-semaphore.c
451       test/test-shutdown-close.c
452       test/test-shutdown-eof.c
453       test/test-shutdown-twice.c
454       test/test-signal-multiple-loops.c
455       test/test-signal-pending-on-close.c
456       test/test-signal.c
457       test/test-socket-buffer-size.c
458       test/test-spawn.c
459       test/test-stdio-over-pipes.c
460       test/test-strscpy.c
461       test/test-tcp-alloc-cb-fail.c
462       test/test-tcp-bind-error.c
463       test/test-tcp-bind6-error.c
464       test/test-tcp-close-accept.c
465       test/test-tcp-close-while-connecting.c
466       test/test-tcp-close.c
467       test/test-tcp-close-reset.c
468       test/test-tcp-connect-error-after-write.c
469       test/test-tcp-connect-error.c
470       test/test-tcp-connect-timeout.c
471       test/test-tcp-connect6-error.c
472       test/test-tcp-create-socket-early.c
473       test/test-tcp-flags.c
474       test/test-tcp-oob.c
475       test/test-tcp-open.c
476       test/test-tcp-read-stop.c
477       test/test-tcp-shutdown-after-write.c
478       test/test-tcp-try-write.c
479       test/test-tcp-try-write-error.c
480       test/test-tcp-unexpected-read.c
481       test/test-tcp-write-after-connect.c
482       test/test-tcp-write-fail.c
483       test/test-tcp-write-queue-order.c
484       test/test-tcp-write-to-half-open-connection.c
485       test/test-tcp-writealot.c
486       test/test-thread-equal.c
487       test/test-thread.c
488       test/test-threadpool-cancel.c
489       test/test-threadpool.c
490       test/test-timer-again.c
491       test/test-timer-from-check.c
492       test/test-timer.c
493       test/test-tmpdir.c
494       test/test-tty-duplicate-key.c
495       test/test-tty-escape-sequence-processing.c
496       test/test-tty.c
497       test/test-udp-alloc-cb-fail.c
498       test/test-udp-bind.c
499       test/test-udp-connect.c
500       test/test-udp-create-socket-early.c
501       test/test-udp-dgram-too-big.c
502       test/test-udp-ipv6.c
503       test/test-udp-multicast-interface.c
504       test/test-udp-multicast-interface6.c
505       test/test-udp-multicast-join.c
506       test/test-udp-multicast-join6.c
507       test/test-udp-multicast-ttl.c
508       test/test-udp-open.c
509       test/test-udp-options.c
510       test/test-udp-send-and-recv.c
511       test/test-udp-send-hang-loop.c
512       test/test-udp-send-immediate.c
513       test/test-udp-send-unreachable.c
514       test/test-udp-try-send.c
515       test/test-uname.c
516       test/test-walk-handles.c
517       test/test-watcher-cross-stop.c)
518
519  add_executable(uv_run_tests ${uv_test_sources} uv_win_longpath.manifest)
520  target_compile_definitions(uv_run_tests
521                             PRIVATE ${uv_defines} USING_UV_SHARED=1)
522  target_compile_options(uv_run_tests PRIVATE ${uv_cflags})
523  target_link_libraries(uv_run_tests uv ${uv_test_libraries})
524  add_test(NAME uv_test
525           COMMAND uv_run_tests
526           WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
527  if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
528    set_tests_properties(uv_test PROPERTIES ENVIRONMENT
529                         "LIBPATH=${CMAKE_BINARY_DIR}:$ENV{LIBPATH}")
530  endif()
531  add_executable(uv_run_tests_a ${uv_test_sources} uv_win_longpath.manifest)
532  target_compile_definitions(uv_run_tests_a PRIVATE ${uv_defines})
533  target_compile_options(uv_run_tests_a PRIVATE ${uv_cflags})
534  if(QEMU)
535    target_link_libraries(uv_run_tests_a uv_a ${uv_test_libraries} -static)
536  else()
537    target_link_libraries(uv_run_tests_a uv_a ${uv_test_libraries})
538  endif()
539  add_test(NAME uv_test_a
540           COMMAND uv_run_tests_a
541           WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
542endif()
543
544if(UNIX)
545  # Now for some gibbering horrors from beyond the stars...
546  foreach(lib IN LISTS uv_libraries)
547    list(APPEND LIBS "-l${lib}")
548  endforeach()
549  string(REPLACE ";" " " LIBS "${LIBS}")
550  # Consider setting project version via project() call?
551  file(STRINGS configure.ac configure_ac REGEX ^AC_INIT)
552  string(REGEX MATCH "([0-9]+)[.][0-9]+[.][0-9]+" PACKAGE_VERSION "${configure_ac}")
553  set(UV_VERSION_MAJOR "${CMAKE_MATCH_1}")
554  # The version in the filename is mirroring the behaviour of autotools.
555  set_target_properties(uv PROPERTIES
556    VERSION ${UV_VERSION_MAJOR}.0.0
557    SOVERSION ${UV_VERSION_MAJOR})
558  set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
559  set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
560  set(prefix ${CMAKE_INSTALL_PREFIX})
561  configure_file(libuv.pc.in libuv.pc @ONLY)
562
563  install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
564  install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
565  install(FILES ${PROJECT_BINARY_DIR}/libuv.pc
566          DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
567  install(TARGETS uv LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
568  install(TARGETS uv_a ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
569endif()
570
571if(WIN32)
572  install(DIRECTORY include/ DESTINATION include)
573  install(FILES LICENSE DESTINATION .)
574  install(TARGETS uv uv_a
575          RUNTIME DESTINATION lib/$<CONFIG>
576          ARCHIVE DESTINATION lib/$<CONFIG>)
577endif()
578
579message(STATUS "summary of build options:
580    Install prefix:  ${CMAKE_INSTALL_PREFIX}
581    Target system:   ${CMAKE_SYSTEM_NAME}
582    Compiler:
583      C compiler:    ${CMAKE_C_COMPILER}
584      CFLAGS:        ${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS}
585")
586