1- cmake_minimum_required (VERSION 3.4 )
1+ cmake_minimum_required (VERSION 3.10 )
22
33if (POLICY CMP0091)
44 cmake_policy (SET CMP0091 NEW) # Enable MSVC_RUNTIME_LIBRARY setting
@@ -20,7 +20,7 @@ include(CTest)
2020set (CMAKE_C_VISIBILITY_PRESET hidden)
2121set (CMAKE_C_STANDARD_REQUIRED ON )
2222set (CMAKE_C_EXTENSIONS ON )
23- set (CMAKE_C_STANDARD 90 )
23+ set (CMAKE_C_STANDARD 11 )
2424
2525set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
2626
@@ -81,15 +81,20 @@ if(TSAN)
8181endif ()
8282
8383if (UBSAN)
84+ cmake_minimum_required (VERSION 3.13)
8485 list (APPEND uv_defines __UBSAN__=1)
8586 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" )
87+ add_compile_options ("-fsanitize=undefined" "-fno-sanitize-recover=undefined" )
88+ if (NOT WIN32 )
89+ add_link_options ("-fsanitize=undefined" )
90+ endif ()
91+ if (MSVC )
92+ add_compile_options ("/Oy-" )
93+ else ()
94+ add_compile_options ("-fno-omit-frame-pointer" )
95+ endif ()
9196 else ()
92- message (SEND_ERROR "UndefinedBehaviorSanitizer support requires clang, gcc, or msvc . Try again with -DCMAKE_C_COMPILER." )
97+ message (SEND_ERROR "UndefinedBehaviorSanitizer support requires clang or gcc . Try again with -DCMAKE_C_COMPILER." )
9398 endif ()
9499endif ()
95100
@@ -161,6 +166,11 @@ list(APPEND uv_cflags ${lint-utf8-msvc} )
161166check_c_compiler_flag(-fno-strict-aliasing UV_F_STRICT_ALIASING)
162167list (APPEND uv_cflags $<$<BOOL :${UV_F_STRICT_ALIASING} >:-fno-strict-aliasing>)
163168
169+ if (MSVC )
170+ # Error on calling undeclared functions.
171+ list (APPEND uv_cflags "/we4013" )
172+ endif ()
173+
164174set (uv_sources
165175 src/fs-poll.c
166176 src/idna.c
@@ -176,7 +186,7 @@ set(uv_sources
176186 src/version .c)
177187
178188if (WIN32 )
179- list (APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0602 )
189+ list (APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0A00 _CRT_DECLARE_NONSTDC_NAMES=0 )
180190 list (APPEND uv_libraries
181191 psapi
182192 user32
@@ -186,7 +196,7 @@ if(WIN32)
186196 ws2_32
187197 dbghelp
188198 ole32
189- uuid )
199+ shell32 )
190200 list (APPEND uv_sources
191201 src/win/async.c
192202 src/win/core.c
@@ -302,6 +312,7 @@ if(APPLE)
302312endif ()
303313
304314if (CMAKE_SYSTEM_NAME STREQUAL "GNU" )
315+ list (APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112 _XOPEN_SOURCE=500)
305316 list (APPEND uv_libraries dl)
306317 list (APPEND uv_sources
307318 src/unix /bsd-ifaddrs.c
@@ -423,6 +434,7 @@ endif()
423434
424435if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD" )
425436 list (APPEND uv_test_libraries util)
437+ list (APPEND uv_libraries m)
426438endif ()
427439
428440if (CYGWIN OR MSYS)
@@ -477,7 +489,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
477489endif ()
478490target_link_libraries (uv_a ${uv_libraries} )
479491set_target_properties (uv_a PROPERTIES OUTPUT_NAME "uv" )
480- if (MSVC )
492+ if (WIN32 )
481493 set_target_properties (uv_a PROPERTIES PREFIX "lib" )
482494endif ()
483495
@@ -561,6 +573,7 @@ if(LIBUV_BUILD_TESTS)
561573 test /test -hrtime.c
562574 test /test -idle.c
563575 test /test -idna.c
576+ test /test -iouring-pollhup.c
564577 test /test -ip4-addr.c
565578 test /test -ip6-addr.c
566579 test /test -ip-name .c
@@ -571,6 +584,7 @@ if(LIBUV_BUILD_TESTS)
571584 test /test -loop-close.c
572585 test /test -loop-configure.c
573586 test /test -loop-handles.c
587+ test /test -loop-oom.c
574588 test /test -loop-stop.c
575589 test /test -loop-time.c
576590 test /test -metrics.c
@@ -638,6 +652,7 @@ if(LIBUV_BUILD_TESTS)
638652 test /test -tcp-oob.c
639653 test /test -tcp-open.c
640654 test /test -tcp-read-stop.c
655+ test /test -tcp-reuseport.c
641656 test /test -tcp-read-stop-start .c
642657 test /test -tcp-rst.c
643658 test /test -tcp-shutdown-after-write.c
@@ -654,6 +669,8 @@ if(LIBUV_BUILD_TESTS)
654669 test /test -thread-affinity.c
655670 test /test -thread-equal .c
656671 test /test -thread.c
672+ test /test -thread-name .c
673+ test /test -thread-priority.c
657674 test /test -threadpool-cancel.c
658675 test /test -threadpool.c
659676 test /test -timer-again.c
@@ -685,6 +702,7 @@ if(LIBUV_BUILD_TESTS)
685702 test /test -udp-send-unreachable.c
686703 test /test -udp-try-send.c
687704 test /test -udp-recv-in-a-row.c
705+ test /test -udp-reuseport.c
688706 test /test -uname.c
689707 test /test -walk-handles.c
690708 test /test -watcher-cross-stop.c)
@@ -701,6 +719,12 @@ if(LIBUV_BUILD_TESTS)
701719 set_tests_properties (uv_test PROPERTIES ENVIRONMENT
702720 "LIBPATH=${CMAKE_BINARY_DIR} :$ENV{LIBPATH} " )
703721 endif ()
722+ if (WIN32 )
723+ add_custom_command (TARGET uv_run_tests POST_BUILD
724+ COMMAND "${CMAKE_COMMAND} " -E copy
725+ "$<TARGET_FILE:uv_run_tests>"
726+ "$<TARGET_FILE_DIR:uv_run_tests>/uv_run_tests_no_ext" )
727+ endif ()
704728 add_executable (uv_run_tests_a ${uv_test_sources} uv_win_longpath.manifest)
705729 target_compile_definitions (uv_run_tests_a PRIVATE ${uv_defines} )
706730 target_compile_options (uv_run_tests_a PRIVATE ${uv_cflags} )
@@ -717,6 +741,12 @@ if(LIBUV_BUILD_TESTS)
717741 set_target_properties (uv_run_tests PROPERTIES LINKER_LANGUAGE CXX)
718742 set_target_properties (uv_run_tests_a PROPERTIES LINKER_LANGUAGE CXX)
719743 endif ()
744+ if (WIN32 )
745+ add_custom_command (TARGET uv_run_tests_a POST_BUILD
746+ COMMAND "${CMAKE_COMMAND} " -E copy
747+ "$<TARGET_FILE:uv_run_tests_a>"
748+ "$<TARGET_FILE_DIR:uv_run_tests_a>/uv_run_tests_a_no_ext" )
749+ endif ()
720750endif ()
721751
722752# Now for some gibbering horrors from beyond the stars...
@@ -761,8 +791,22 @@ endif()
761791
762792if (MSVC )
763793 set (CMAKE_DEBUG_POSTFIX d)
794+ get_filename_component (CMAKE_C_COMPILER_DIR ${CMAKE_C_COMPILER} DIRECTORY )
795+ if (ASAN)
796+ file (INSTALL "${CMAKE_C_COMPILER_DIR} /llvm-symbolizer.exe" DESTINATION "${CMAKE_CURRENT_BINARY_DIR} " )
797+ file (INSTALL "${CMAKE_C_COMPILER_DIR} /clang_rt.asan_dynamic-x86_64.dll" DESTINATION "${CMAKE_CURRENT_BINARY_DIR} " )
798+ file (INSTALL "${CMAKE_C_COMPILER_DIR} /clang_rt.asan_dbg_dynamic-x86_64.dll" DESTINATION "${CMAKE_CURRENT_BINARY_DIR} " )
799+ endif ()
800+ endif ()
801+
802+ if (BUILD_SHARED_LIBS )
803+ set (LIB_SELECTED uv)
804+ else ()
805+ set (LIB_SELECTED uv_a)
764806endif ()
765807
808+ add_library (libuv::libuv ALIAS ${LIB_SELECTED} )
809+
766810message (STATUS "summary of build options:
767811 Install prefix: ${CMAKE_INSTALL_PREFIX}
768812 Target system: ${CMAKE_SYSTEM_NAME}
0 commit comments