From: Viktor Szakats Date: Sat, 8 Feb 2025 02:20:02 +0000 (+0100) Subject: cmake: fix/add missing feature detections for Windows/MS-DOS X-Git-Tag: curl-8_12_1~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ab1fa423bcc49a742b1cde2164ff981fdee38e8;p=thirdparty%2Fcurl.git cmake: fix/add missing feature detections for Windows/MS-DOS Almost all feature detection results are pre-filled on Windows for performance, so none of the issues fixed here affected builds. For good measure, this patch add missing detections and fixes others to make sure they work even when omitting the pre-fill. It also fixes detecting IPv6 for MS-DOS. - fix `HAVE_STRUCT_TIMEVAL` detection for MSVC. Follow-up to c1bc090d65b8d7d14e811dd36f5e8674be43dff3 #12495 - add `HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID` detection for Windows. - fix `HAVE_STRDUP` detection for MSVC. - fix `HAVE_SNPRINTF` detection for Windows. Regression from 8e345057761a8f796403923a96f2c8fd3edca647 #15164 - fix `HAVE_IOCTLSOCKET` detection for non-UWP MSVC. - exclude `if_nametoindex` detection for Windows. Although it exists on Windows, detection, usage and availability is complicated, and curl doesn't use it on this platform. Regression from 8e345057761a8f796403923a96f2c8fd3edca647 #15164 - move IPv6 detections so that pre-filling and MS-DOS Watt-32 configuration applies to them. This fixes `HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID` detection with MS-DOS. Ref: https://github.com/curl/curl/actions/runs/13260511764/job/37015877585#step:7:306 Follow-up to a3585c9576abccddbd27200058912cef900c3c0f #15543 Also: - add debug option to test without pre-filling. - replace `NOT LESS` with `GREATER_EQUAL` Closes #16278 --- diff --git a/CMake/CurlTests.c b/CMake/CurlTests.c index 8aa28a310a..c5a5257672 100644 --- a/CMake/CurlTests.c +++ b/CMake/CurlTests.c @@ -167,7 +167,7 @@ int main(void) { return 0; } int main(void) { /* ioctlsocket source code */ - int socket; + int socket = -1; unsigned long flags = ioctlsocket(socket, FIONBIO, &flags); ; return 0; diff --git a/CMake/OtherTests.cmake b/CMake/OtherTests.cmake index 01885381f3..8a7faaf657 100644 --- a/CMake/OtherTests.cmake +++ b/CMake/OtherTests.cmake @@ -65,6 +65,9 @@ endif() set(_source_epilogue "#undef inline") curl_add_header_include(HAVE_SYS_TIME_H "sys/time.h") check_c_source_compiles("${_source_epilogue} + #ifdef _MSC_VER + #include + #endif #include int main(void) { diff --git a/CMake/win32-cache.cmake b/CMake/win32-cache.cmake index 9d46736d57..272f5134d1 100644 --- a/CMake/win32-cache.cmake +++ b/CMake/win32-cache.cmake @@ -74,12 +74,12 @@ else() set(HAVE_UNISTD_H 0) set(HAVE_STDDEF_H 1) # detected by CMake internally in check_type_size() set(HAVE_STDATOMIC_H 0) - if(NOT MSVC_VERSION LESS 1600) + if(MSVC_VERSION GREATER_EQUAL 1600) set(HAVE_STDINT_H 1) # detected by CMake internally in check_type_size() else() set(HAVE_STDINT_H 0) # detected by CMake internally in check_type_size() endif() - if(NOT MSVC_VERSION LESS 1800) + if(MSVC_VERSION GREATER_EQUAL 1800) set(HAVE_STDBOOL_H 1) set(HAVE_STRTOLL 1) else() @@ -87,7 +87,7 @@ else() set(HAVE_STRTOLL 0) endif() set(HAVE_BOOL_T "${HAVE_STDBOOL_H}") - if(NOT MSVC_VERSION LESS 1900) + if(MSVC_VERSION GREATER_EQUAL 1900) set(HAVE_SNPRINTF 1) else() set(HAVE_SNPRINTF 0) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13a6e5d742..566863e3b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,7 +208,11 @@ if(WIN32) endif() endif() - list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN") # Apply to all feature checks + # Apply to all feature checks + list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN") + if(MSVC) + list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_CRT_NONSTDC_NO_DEPRECATE") # for strdup() detection + endif() set(CURL_TARGET_WINDOWS_VERSION "" CACHE STRING "Minimum target Windows version as hex string") if(CURL_TARGET_WINDOWS_VERSION) @@ -479,35 +483,6 @@ if(WINDOWS_STORE) set(CURL_DISABLE_TELNET ON) # telnet code needs fixing to compile for UWP. endif() -option(ENABLE_IPV6 "Enable IPv6 support" ON) -mark_as_advanced(ENABLE_IPV6) -if(ENABLE_IPV6 AND NOT WIN32) - include(CheckStructHasMember) - check_struct_has_member("struct sockaddr_in6" "sin6_addr" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_ADDR) - check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) - if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR) - if(NOT DOS AND NOT AMIGA) - message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support") - endif() - # Force the feature off as this name is used as guard macro... - set(ENABLE_IPV6 OFF CACHE BOOL "Enable IPv6 support" FORCE) - endif() - - if(APPLE AND NOT ENABLE_ARES) - set(_use_core_foundation_and_core_services ON) - - find_library(SYSTEMCONFIGURATION_FRAMEWORK NAMES "SystemConfiguration") - mark_as_advanced(SYSTEMCONFIGURATION_FRAMEWORK) - if(NOT SYSTEMCONFIGURATION_FRAMEWORK) - message(FATAL_ERROR "SystemConfiguration framework not found") - endif() - list(APPEND CURL_LIBS "-framework SystemConfiguration") - endif() -endif() -if(ENABLE_IPV6) - set(USE_IPV6 ON) -endif() - find_package(Perl) if(PERL_EXECUTABLE) @@ -564,15 +539,18 @@ include(CheckSymbolExists) include(CheckTypeSize) include(CheckCSourceCompiles) -if(WIN32) - # Preload settings on Windows - include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/win32-cache.cmake") -elseif(APPLE) - # Fast-track predictable feature detections - set(HAVE_EVENTFD 0) - set(HAVE_GETPASS_R 0) - set(HAVE_SENDMMSG 0) -elseif(AMIGA) +option(_CURL_QUICK_DETECT "Fast-track known feature detection results (Windows, some Apple)" ON) +if(_CURL_QUICK_DETECT) + if(WIN32) + include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/win32-cache.cmake") + elseif(APPLE) + set(HAVE_EVENTFD 0) + set(HAVE_GETPASS_R 0) + set(HAVE_SENDMMSG 0) + endif() +endif() + +if(AMIGA) set(HAVE_GETADDRINFO 0) # Breaks the build when detected and used. endif() if(DOS OR AMIGA) @@ -619,6 +597,38 @@ elseif(NOT WIN32 AND NOT APPLE) endif() endif() +option(ENABLE_IPV6 "Enable IPv6 support" ON) +mark_as_advanced(ENABLE_IPV6) +if(ENABLE_IPV6) + include(CheckStructHasMember) + if(WIN32) + check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "winsock2.h;ws2tcpip.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) + else() + check_struct_has_member("struct sockaddr_in6" "sin6_addr" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_ADDR) + check_struct_has_member("struct sockaddr_in6" "sin6_scope_id" "netinet/in.h" HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) + if(NOT HAVE_SOCKADDR_IN6_SIN6_ADDR) + if(NOT DOS AND NOT AMIGA) + message(WARNING "struct sockaddr_in6 not available, disabling IPv6 support") + endif() + set(ENABLE_IPV6 OFF CACHE BOOL "Enable IPv6 support" FORCE) # Force the feature off as we use this name as guard macro + endif() + + if(APPLE AND NOT ENABLE_ARES) + set(_use_core_foundation_and_core_services ON) + + find_library(SYSTEMCONFIGURATION_FRAMEWORK NAMES "SystemConfiguration") + mark_as_advanced(SYSTEMCONFIGURATION_FRAMEWORK) + if(NOT SYSTEMCONFIGURATION_FRAMEWORK) + message(FATAL_ERROR "SystemConfiguration framework not found") + endif() + list(APPEND CURL_LIBS "-framework SystemConfiguration") + endif() + endif() +endif() +if(ENABLE_IPV6) + set(USE_IPV6 ON) +endif() + # Check SSL libraries option(CURL_ENABLE_SSL "Enable SSL support" ON) @@ -1729,15 +1739,15 @@ check_function_exists("eventfd" HAVE_EVENTFD) check_symbol_exists("ftruncate" "unistd.h" HAVE_FTRUNCATE) check_symbol_exists("getpeername" "${CURL_INCLUDES}" HAVE_GETPEERNAME) # winsock2.h unistd.h proto/bsdsocket.h check_symbol_exists("getsockname" "${CURL_INCLUDES}" HAVE_GETSOCKNAME) # winsock2.h unistd.h proto/bsdsocket.h -check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # winsock2.h net/if.h check_function_exists("getrlimit" HAVE_GETRLIMIT) check_function_exists("setlocale" HAVE_SETLOCALE) check_function_exists("setmode" HAVE_SETMODE) check_function_exists("setrlimit" HAVE_SETRLIMIT) if(NOT WIN32) - check_function_exists("realpath" HAVE_REALPATH) - check_function_exists("sched_yield" HAVE_SCHED_YIELD) + check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # iphlpapi.h (Windows non-UWP), net/if.h + check_function_exists("realpath" HAVE_REALPATH) + check_function_exists("sched_yield" HAVE_SCHED_YIELD) check_symbol_exists("strcasecmp" "string.h" HAVE_STRCASECMP) check_symbol_exists("stricmp" "string.h" HAVE_STRICMP) check_symbol_exists("strcmpi" "string.h" HAVE_STRCMPI) @@ -1755,9 +1765,10 @@ if(NOT _ssl_enabled) check_symbol_exists("arc4random" "${CURL_INCLUDES};stdlib.h" HAVE_ARC4RANDOM) endif() -if(NOT MSVC OR (MSVC_VERSION GREATER_EQUAL 1900)) - # Earlier MSVC compilers had faulty snprintf implementations - check_function_exists("snprintf" HAVE_SNPRINTF) +if(NOT MSVC) + check_function_exists("snprintf" HAVE_SNPRINTF) # to match detection method in ./configure +elseif(MSVC_VERSION GREATER_EQUAL 1900) # Earlier MSVC compilers had faulty snprintf implementations + check_symbol_exists("snprintf" "stdio.h" HAVE_SNPRINTF) # snprintf may be a compatibility macro, not an exported function endif() if(APPLE) check_function_exists("mach_absolute_time" HAVE_MACH_ABSOLUTE_TIME) diff --git a/configure.ac b/configure.ac index a2879568ea..45dba219b9 100644 --- a/configure.ac +++ b/configure.ac @@ -4065,7 +4065,6 @@ AC_CHECK_FUNCS([\ getpwuid_r \ getrlimit \ gettimeofday \ - if_nametoindex \ mach_absolute_time \ pipe \ poll \ @@ -4081,8 +4080,9 @@ AC_CHECK_FUNCS([\ if test "$curl_cv_native_windows" != 'yes'; then AC_CHECK_FUNCS([\ - sched_yield \ - realpath \ + if_nametoindex \ + realpath \ + sched_yield \ ]) CURL_CHECK_FUNC_STRCASECMP CURL_CHECK_FUNC_STRCMPI