11cmake_minimum_required (VERSION 3.4)
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-
102project (libuv LANGUAGES C)
113
4+ cmake_policy (SET CMP0057 NEW) # Enable IN_LIST operator
5+ cmake_policy (SET CMP0064 NEW) # Support if (TEST) operator
6+
127list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
138
149include (CMakePackageConfigHelpers)
@@ -22,75 +17,38 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
2217set (CMAKE_C_EXTENSIONS ON )
2318set (CMAKE_C_STANDARD 90)
2419
25- set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
26-
27- option (LIBUV_BUILD_SHARED "Build shared lib" ON )
28-
2920cmake_dependent_option(LIBUV_BUILD_TESTS
3021 "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 )
22+ "BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF )
3223cmake_dependent_option(LIBUV_BUILD_BENCH
3324 "Build the benchmarks when building unit tests and we are the root project" ON
3425 "LIBUV_BUILD_TESTS" OFF )
3526
3627# Qemu Build
3728option (QEMU "build for qemu" OFF )
3829if (QEMU)
39- list ( APPEND uv_defines __QEMU__ =1)
30+ add_definitions (-D__QEMU__ =1)
4031endif ()
4132
42- # Note: these are mutually exclusive.
4333option (ASAN "Enable AddressSanitizer (ASan)" OFF )
44- option (MSAN "Enable MemorySanitizer (MSan)" OFF )
4534option (TSAN "Enable ThreadSanitizer (TSan)" OFF )
46- option (UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF )
4735
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 " )
36+ if ((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. " )
5038endif ()
5139
5240if (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" )
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" )
7045endif ()
7146
7247if (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- list (APPEND uv_defines __UBSAN__=1)
85- if (CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang" )
86- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=undefined" )
87- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=undefined" )
88- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=undefined" )
89- elseif (MSVC )
90- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=undefined" )
91- else ()
92- message (SEND_ERROR "UndefinedBehaviorSanitizer support requires clang, gcc, or msvc. Try again with -DCMAKE_C_COMPILER." )
93- endif ()
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" )
9452endif ()
9553
9654# Compiler check
@@ -168,7 +126,6 @@ set(uv_sources
168126 src/random.c
169127 src/strscpy.c
170128 src/strtok.c
171- src/thread-common.c
172129 src/threadpool.c
173130 src/timer.c
174131 src/uv-common.c
@@ -183,10 +140,7 @@ if(WIN32)
183140 advapi32
184141 iphlpapi
185142 userenv
186- ws2_32
187- dbghelp
188- ole32
189- uuid)
143+ ws2_32)
190144 list (APPEND uv_sources
191145 src/win/async.c
192146 src/win/core.c
@@ -262,11 +216,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Android")
262216 list (APPEND uv_defines _GNU_SOURCE)
263217 list (APPEND uv_libraries dl)
264218 list (APPEND uv_sources
265- src/unix /linux.c
219+ src/unix /linux-core.c
220+ src/unix /linux-inotify.c
221+ src/unix /linux-syscalls.c
266222 src/unix /procfs-exepath.c
223+ src/unix /pthread-fixes.c
267224 src/unix /random-getentropy.c
268225 src/unix /random-getrandom.c
269- src/unix /random-sysctl-linux.c)
226+ src/unix /random-sysctl-linux.c
227+ src/unix /epoll.c)
270228endif ()
271229
272230if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "Android|Linux" )
@@ -312,14 +270,22 @@ if(CMAKE_SYSTEM_NAME STREQUAL "GNU")
312270 src/unix /hurd.c)
313271endif ()
314272
273+ if (CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD" )
274+ list (APPEND uv_defines _GNU_SOURCE)
275+ list (APPEND uv_libraries dl freebsd-glue)
276+ endif ()
277+
315278if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
316279 list (APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112)
317280 list (APPEND uv_libraries dl rt)
318281 list (APPEND uv_sources
319- src/unix /linux.c
282+ src/unix /linux-core.c
283+ src/unix /linux-inotify.c
284+ src/unix /linux-syscalls.c
320285 src/unix /procfs-exepath.c
321286 src/unix /random-getrandom.c
322- src/unix /random-sysctl-linux.c)
287+ src/unix /random-sysctl-linux.c
288+ src/unix /epoll.c)
323289endif ()
324290
325291if (CMAKE_SYSTEM_NAME STREQUAL "NetBSD" )
@@ -350,6 +316,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
350316 list (APPEND uv_defines _XOPEN_SOURCE=600)
351317 list (APPEND uv_defines _XOPEN_SOURCE_EXTENDED)
352318 list (APPEND uv_sources
319+ src/unix /pthread-fixes.c
353320 src/unix /os390.c
354321 src/unix /os390-syscalls.c
355322 src/unix /os390-proctitle.c)
@@ -387,10 +354,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS400")
387354endif ()
388355
389356if (CMAKE_SYSTEM_NAME STREQUAL "SunOS" )
390- if (CMAKE_SYSTEM_VERSION STREQUAL "5.10" )
391- list (APPEND uv_defines SUNOS_NO_IFADDRS)
392- list (APPEND uv_libraries rt)
393- endif ()
394357 list (APPEND uv_defines __EXTENSIONS__ _XOPEN_SOURCE=500 _REENTRANT)
395358 list (APPEND uv_libraries kstat nsl sendfile socket)
396359 list (APPEND uv_sources
@@ -425,42 +388,25 @@ if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD")
425388 list (APPEND uv_test_libraries util)
426389endif ()
427390
428- if (CYGWIN OR MSYS)
429- list (APPEND uv_defines _GNU_SOURCE)
430- list (APPEND uv_sources
431- src/unix /cygwin .c
432- src/unix /bsd-ifaddrs.c
433- src/unix /no -fsevents.c
434- src/unix /no -proctitle.c
435- src/unix /posix-hrtime.c
436- src/unix /posix-poll.c
437- src/unix /procfs-exepath.c
438- src/unix /sysinfo-loadavg.c
439- src/unix /sysinfo-memory.c)
440- endif ()
441-
442- if (LIBUV_BUILD_SHARED)
443- add_library (uv SHARED ${uv_sources} )
444- target_compile_definitions (uv
445- INTERFACE
446- USING_UV_SHARED=1
447- PRIVATE
448- BUILDING_UV_SHARED=1
449- ${uv_defines} )
450- target_compile_options (uv PRIVATE ${uv_cflags} )
451- target_include_directories (uv
452- PUBLIC
453- $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
454- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
455- PRIVATE
456- $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /src>)
457- if (CMAKE_SYSTEM_NAME STREQUAL "OS390" )
458- target_include_directories (uv PUBLIC $<BUILD_INTERFACE:${ZOSLIB_DIR} /include >)
459- set_target_properties (uv PROPERTIES LINKER_LANGUAGE CXX)
460- endif ()
461- target_link_libraries (uv ${uv_libraries} )
462- set_target_properties (uv PROPERTIES OUTPUT_NAME "uv" )
391+ add_library (uv SHARED ${uv_sources} )
392+ target_compile_definitions (uv
393+ INTERFACE
394+ USING_UV_SHARED=1
395+ PRIVATE
396+ BUILDING_UV_SHARED=1
397+ ${uv_defines} )
398+ target_compile_options (uv PRIVATE ${uv_cflags} )
399+ target_include_directories (uv
400+ PUBLIC
401+ $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
402+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
403+ PRIVATE
404+ $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /src>)
405+ if (CMAKE_SYSTEM_NAME STREQUAL "OS390" )
406+ target_include_directories (uv PUBLIC $<BUILD_INTERFACE:${ZOSLIB_DIR} /include >)
407+ set_target_properties (uv PROPERTIES LINKER_LANGUAGE CXX)
463408endif ()
409+ target_link_libraries (uv ${uv_libraries} )
464410
465411add_library (uv_a STATIC ${uv_sources} )
466412target_compile_definitions (uv_a PRIVATE ${uv_defines} )
@@ -476,10 +422,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
476422 set_target_properties (uv_a PROPERTIES LINKER_LANGUAGE CXX)
477423endif ()
478424target_link_libraries (uv_a ${uv_libraries} )
479- set_target_properties (uv_a PROPERTIES OUTPUT_NAME "uv" )
480- if (MSVC )
481- set_target_properties (uv_a PROPERTIES PREFIX "lib" )
482- endif ()
483425
484426if (LIBUV_BUILD_TESTS)
485427 # Small hack: use ${uv_test_sources} now to get the runner skeleton,
@@ -642,7 +584,6 @@ if(LIBUV_BUILD_TESTS)
642584 test /test -tcp-rst.c
643585 test /test -tcp-shutdown-after-write.c
644586 test /test -tcp-try-write.c
645- test /test -tcp-write-in-a-row.c
646587 test /test -tcp-try-write-error.c
647588 test /test -tcp-unexpected-read.c
648589 test /test -tcp-write-after-connect.c
@@ -651,7 +592,6 @@ if(LIBUV_BUILD_TESTS)
651592 test /test -tcp-write-to-half-open-connection.c
652593 test /test -tcp-writealot.c
653594 test /test -test -macros .c
654- test /test -thread-affinity.c
655595 test /test -thread-equal .c
656596 test /test -thread.c
657597 test /test -threadpool-cancel.c
@@ -684,7 +624,6 @@ if(LIBUV_BUILD_TESTS)
684624 test /test -udp-sendmmsg-error.c
685625 test /test -udp-send-unreachable.c
686626 test /test -udp-try-send.c
687- test /test -udp-recv-in-a-row.c
688627 test /test -uname.c
689628 test /test -walk-handles.c
690629 test /test -watcher-cross-stop.c)
@@ -728,36 +667,27 @@ string(REPLACE ";" " " LIBS "${LIBS}")
728667file (STRINGS configure.ac configure_ac REGEX ^AC_INIT)
729668string (REGEX MATCH "([0-9]+)[.][0-9]+[.][0-9]+" PACKAGE_VERSION "${configure_ac} " )
730669set (UV_VERSION_MAJOR "${CMAKE_MATCH_1} " )
731-
670+ # The version in the filename is mirroring the behaviour of autotools.
671+ set_target_properties (uv PROPERTIES
672+ VERSION ${UV_VERSION_MAJOR} .0.0
673+ SOVERSION ${UV_VERSION_MAJOR} )
732674set (includedir ${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_INCLUDEDIR} )
733675set (libdir ${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_LIBDIR} )
734676set (prefix ${CMAKE_INSTALL_PREFIX} )
677+ configure_file (libuv.pc.in libuv.pc @ONLY)
735678configure_file (libuv-static .pc.in libuv-static .pc @ONLY)
736679
737680install (DIRECTORY include / DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
738681install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR} )
739- install (FILES LICENSE-extra DESTINATION ${CMAKE_INSTALL_DOCDIR} )
740- install (FILES ${PROJECT_BINARY_DIR} /libuv-static .pc
682+ install (FILES ${PROJECT_BINARY_DIR} /libuv.pc ${PROJECT_BINARY_DIR} /libuv-static .pc
741683 DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig)
684+ install (TARGETS uv EXPORT libuvConfig
685+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
686+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
687+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
742688install (TARGETS uv_a EXPORT libuvConfig
743689 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
744- install (EXPORT libuvConfig
745- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/libuv
746- NAMESPACE libuv::)
747-
748- if (LIBUV_BUILD_SHARED)
749- # The version in the filename is mirroring the behaviour of autotools.
750- set_target_properties (uv PROPERTIES
751- VERSION ${UV_VERSION_MAJOR} .0.0
752- SOVERSION ${UV_VERSION_MAJOR} )
753- configure_file (libuv.pc.in libuv.pc @ONLY)
754- install (FILES ${PROJECT_BINARY_DIR} /libuv.pc
755- DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig)
756- install (TARGETS uv EXPORT libuvConfig
757- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
758- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
759- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
760- endif ()
690+ install (EXPORT libuvConfig DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/libuv)
761691
762692if (MSVC )
763693 set (CMAKE_DEBUG_POSTFIX d)
0 commit comments