11# TODO: determine CMAKE_SYSTEM_NAME on OS/390. Currently assumes "OS/390".
2- cmake_minimum_required (VERSION 2.8.12)
3- project (libuv)
2+ cmake_minimum_required (VERSION 3.4)
3+ project (libuv LANGUAGES C)
4+
5+ include (CMakePackageConfigHelpers)
6+ include (CMakeDependentOption)
7+ include (GNUInstallDirs)
8+ include (CTest)
9+
10+ cmake_dependent_option(LIBUV_BUILD_TESTS
11+ "Build the unit tests when BUILD_TESTING is enabled and we are the root project" ON
12+ "BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF )
413
514if (MSVC )
615 list (APPEND uv_cflags /W4)
@@ -14,6 +23,7 @@ set(uv_sources
1423 src/fs-poll.c
1524 src/idna.c
1625 src/inet.c
26+ src/random.c
1727 src/strscpy.c
1828 src/threadpool.c
1929 src/timer.c
@@ -72,7 +82,6 @@ set(uv_test_sources
7282 test /test -idna.c
7383 test /test -ip4-addr.c
7484 test /test -ip6-addr.c
75- test /test -ip6-addr.c
7685 test /test -ipc-heavy-traffic-deadlock-bug.c
7786 test /test -ipc-send-recv.c
7887 test /test -ipc.c
@@ -108,6 +117,7 @@ set(uv_test_sources
108117 test /test -process-title-threadsafe.c
109118 test /test -process-title.c
110119 test /test -queue-foreach-delete.c
120+ test /test -random.c
111121 test /test -ref.c
112122 test /test -run-nowait.c
113123 test /test -run-once.c
@@ -236,6 +246,7 @@ else()
236246 src/unix /pipe.c
237247 src/unix /poll.c
238248 src/unix /process.c
249+ src/unix /random-devurandom.c
239250 src/unix /signal.c
240251 src/unix /stream.c
241252 src/unix /tcp.c
@@ -284,6 +295,14 @@ if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD")
284295 list (APPEND uv_sources src/unix /bsd-ifaddrs.c src/unix /kqueue.c)
285296endif ()
286297
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+
287306if (APPLE )
288307 list (APPEND uv_defines _DARWIN_UNLIMITED_SELECT=1 _DARWIN_USE_64_BIT_INODE=1)
289308 list (APPEND uv_sources
@@ -300,6 +319,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
300319 src/unix /linux-inotify.c
301320 src/unix /linux-syscalls.c
302321 src/unix /procfs-exepath.c
322+ src/unix /random-getrandom.c
323+ src/unix /random-sysctl.c
303324 src/unix /sysinfo-loadavg.c)
304325endif ()
305326
@@ -356,11 +377,7 @@ target_compile_options(uv_a PRIVATE ${uv_cflags})
356377target_include_directories (uv_a PUBLIC include PRIVATE src)
357378target_link_libraries (uv_a ${uv_libraries} )
358379
359- option (libuv_buildtests "Build the unit tests when BUILD_TESTING is enabled." ON )
360-
361- include (CTest)
362- if (BUILD_TESTING AND libuv_buildtests)
363- enable_testing ()
380+ if (LIBUV_BUILD_TESTS)
364381 add_executable (uv_run_tests ${uv_test_sources} )
365382 target_compile_definitions (uv_run_tests
366383 PRIVATE ${uv_defines} USING_UV_SHARED=1)
@@ -380,7 +397,6 @@ endif()
380397
381398if (UNIX )
382399 # Now for some gibbering horrors from beyond the stars...
383- include (GNUInstallDirs)
384400 foreach (x ${uv_libraries} )
385401 set (LIBS "${LIBS} -l${x} " )
386402 endforeach (x)
@@ -402,3 +418,11 @@ if(UNIX)
402418 install (TARGETS uv LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
403419 install (TARGETS uv_a ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
404420endif ()
421+
422+ if (WIN32 )
423+ install (DIRECTORY include / DESTINATION include )
424+ install (FILES LICENSE DESTINATION .)
425+ install (TARGETS uv uv_a
426+ RUNTIME DESTINATION lib/$<CONFIG>
427+ ARCHIVE DESTINATION lib/$<CONFIG>)
428+ endif ()
0 commit comments