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