1
1
cmake_minimum_required (VERSION 3.4 )
2
- project (libuv LANGUAGES C )
3
2
4
- cmake_policy (SET CMP0057 NEW ) # Enable IN_LIST operator
5
- cmake_policy (SET CMP0064 NEW ) # Support if (TEST) operator
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
+
10
+ project (libuv LANGUAGES C )
6
11
7
12
list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
8
13
@@ -17,38 +22,75 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
17
22
set (CMAKE_C_EXTENSIONS ON )
18
23
set (CMAKE_C_STANDARD 90 )
19
24
25
+ set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
26
+
27
+ option (LIBUV_BUILD_SHARED "Build shared lib" ON )
28
+
20
29
cmake_dependent_option (LIBUV_BUILD_TESTS
21
30
"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 )
31
+ "BUILD_TESTING;LIBUV_BUILD_SHARED; CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF )
23
32
cmake_dependent_option (LIBUV_BUILD_BENCH
24
33
"Build the benchmarks when building unit tests and we are the root project" ON
25
34
"LIBUV_BUILD_TESTS" OFF )
26
35
27
36
# Qemu Build
28
37
option (QEMU "build for qemu" OFF )
29
38
if (QEMU )
30
- add_definitions ( -D__QEMU__ =1 )
39
+ list ( APPEND uv_defines __QEMU__ =1 )
31
40
endif ()
32
41
42
+ # Note: these are mutually exclusive.
33
43
option (ASAN "Enable AddressSanitizer (ASan)" OFF )
44
+ option (MSAN "Enable MemorySanitizer (MSan)" OFF )
34
45
option (TSAN "Enable ThreadSanitizer (TSan)" OFF )
46
+ option (UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF )
35
47
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. " )
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 " )
38
50
endif ()
39
51
40
52
if (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" )
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" )
45
70
endif ()
46
71
47
72
if (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" )
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 ()
52
94
endif ()
53
95
54
96
# Compiler check
@@ -126,6 +168,7 @@ set(uv_sources
126
168
src/random.c
127
169
src/strscpy.c
128
170
src/strtok.c
171
+ src/thread-common.c
129
172
src/threadpool.c
130
173
src/timer.c
131
174
src/uv-common.c
@@ -140,7 +183,10 @@ if(WIN32)
140
183
advapi32
141
184
iphlpapi
142
185
userenv
143
- ws2_32 )
186
+ ws2_32
187
+ dbghelp
188
+ ole32
189
+ uuid )
144
190
list (APPEND uv_sources
145
191
src/win/async.c
146
192
src/win/core.c
@@ -216,15 +262,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Android")
216
262
list (APPEND uv_defines _GNU_SOURCE )
217
263
list (APPEND uv_libraries dl )
218
264
list (APPEND uv_sources
219
- src/unix/linux-core.c
220
- src/unix/linux-inotify.c
221
- src/unix/linux-syscalls.c
265
+ src/unix/linux.c
222
266
src/unix/procfs-exepath.c
223
- src/unix/pthread-fixes.c
224
267
src/unix/random-getentropy.c
225
268
src/unix/random-getrandom.c
226
- src/unix/random-sysctl-linux.c
227
- src/unix/epoll.c )
269
+ src/unix/random-sysctl-linux.c )
228
270
endif ()
229
271
230
272
if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "Android|Linux" )
@@ -270,22 +312,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "GNU")
270
312
src/unix/hurd.c )
271
313
endif ()
272
314
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
-
278
315
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
279
316
list (APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112 )
280
317
list (APPEND uv_libraries dl rt )
281
318
list (APPEND uv_sources
282
- src/unix/linux-core.c
283
- src/unix/linux-inotify.c
284
- src/unix/linux-syscalls.c
319
+ src/unix/linux.c
285
320
src/unix/procfs-exepath.c
286
321
src/unix/random-getrandom.c
287
- src/unix/random-sysctl-linux.c
288
- src/unix/epoll.c )
322
+ src/unix/random-sysctl-linux.c )
289
323
endif ()
290
324
291
325
if (CMAKE_SYSTEM_NAME STREQUAL "NetBSD" )
@@ -316,7 +350,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
316
350
list (APPEND uv_defines _XOPEN_SOURCE=600 )
317
351
list (APPEND uv_defines _XOPEN_SOURCE_EXTENDED )
318
352
list (APPEND uv_sources
319
- src/unix/pthread-fixes.c
320
353
src/unix/os390.c
321
354
src/unix/os390-syscalls.c
322
355
src/unix/os390-proctitle.c )
@@ -354,6 +387,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS400")
354
387
endif ()
355
388
356
389
if (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 ()
357
394
list (APPEND uv_defines __EXTENSIONS__ _XOPEN_SOURCE=500 _REENTRANT )
358
395
list (APPEND uv_libraries kstat nsl sendfile socket )
359
396
list (APPEND uv_sources
@@ -388,25 +425,42 @@ if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD")
388
425
list (APPEND uv_test_libraries util )
389
426
endif ()
390
427
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 )
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" )
408
463
endif ()
409
- target_link_libraries (uv ${uv_libraries} )
410
464
411
465
add_library (uv_a STATIC ${uv_sources} )
412
466
target_compile_definitions (uv_a PRIVATE ${uv_defines} )
@@ -422,6 +476,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
422
476
set_target_properties (uv_a PROPERTIES LINKER_LANGUAGE CXX )
423
477
endif ()
424
478
target_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 ()
425
483
426
484
if (LIBUV_BUILD_TESTS )
427
485
# Small hack: use ${uv_test_sources} now to get the runner skeleton,
@@ -584,6 +642,7 @@ if(LIBUV_BUILD_TESTS)
584
642
test /test-tcp-rst.c
585
643
test /test-tcp-shutdown-after-write.c
586
644
test /test-tcp-try-write.c
645
+ test /test-tcp-write-in-a-row.c
587
646
test /test-tcp-try-write-error.c
588
647
test /test-tcp-unexpected-read.c
589
648
test /test-tcp-write-after-connect.c
@@ -592,6 +651,7 @@ if(LIBUV_BUILD_TESTS)
592
651
test /test-tcp-write-to-half-open-connection.c
593
652
test /test-tcp-writealot.c
594
653
test /test-test-macros.c
654
+ test /test-thread-affinity.c
595
655
test /test-thread-equal.c
596
656
test /test-thread.c
597
657
test /test-threadpool-cancel.c
@@ -624,6 +684,7 @@ if(LIBUV_BUILD_TESTS)
624
684
test /test-udp-sendmmsg-error.c
625
685
test /test-udp-send-unreachable.c
626
686
test /test-udp-try-send.c
687
+ test /test-udp-recv-in-a-row.c
627
688
test /test-uname.c
628
689
test /test-walk-handles.c
629
690
test /test-watcher-cross-stop.c )
@@ -667,27 +728,36 @@ string(REPLACE ";" " " LIBS "${LIBS}")
667
728
file (STRINGS configure.ac configure_ac REGEX ^AC_INIT )
668
729
string (REGEX MATCH "([0-9]+)[.][0-9]+[.][0-9]+" PACKAGE_VERSION "${configure_ac} " )
669
730
set (UV_VERSION_MAJOR "${CMAKE_MATCH_1} " )
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} )
731
+
674
732
set (includedir ${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_INCLUDEDIR} )
675
733
set (libdir ${CMAKE_INSTALL_PREFIX} /${CMAKE_INSTALL_LIBDIR} )
676
734
set (prefix ${CMAKE_INSTALL_PREFIX} )
677
- configure_file (libuv.pc.in libuv.pc @ONLY )
678
735
configure_file (libuv-static.pc.in libuv-static.pc @ONLY )
679
736
680
737
install (DIRECTORY include / DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
681
738
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR} )
682
- install (FILES ${PROJECT_BINARY_DIR} /libuv.pc ${PROJECT_BINARY_DIR} /libuv-static.pc
739
+ install (FILES LICENSE-extra DESTINATION ${CMAKE_INSTALL_DOCDIR} )
740
+ install (FILES ${PROJECT_BINARY_DIR} /libuv-static.pc
683
741
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} )
688
742
install (TARGETS uv_a EXPORT libuvConfig
689
743
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} )
690
- install (EXPORT libuvConfig DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/libuv )
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 ()
691
761
692
762
if (MSVC )
693
763
set (CMAKE_DEBUG_POSTFIX d )
0 commit comments