From f1e80d8d8ce9570d81836da96ba02f4d4552a7b3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 15 Apr 2023 16:15:04 +0000 Subject: [PATCH] cmake: optimize non-blocking tests on WIN32/non-WIN32 Skip testing unixy methods on Windows and vice versa. I continue to assume that CMake doesn't define `WIN32` with Cygwin (as Cygwin doesn't define `_WIN32`/`WIN32` for C), though I haven't tested this. Closes #970 --- cmake/CheckNonblockingSocketSupport.cmake | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cmake/CheckNonblockingSocketSupport.cmake b/cmake/CheckNonblockingSocketSupport.cmake index b34b8b98..12e2bd64 100644 --- a/cmake/CheckNonblockingSocketSupport.cmake +++ b/cmake/CheckNonblockingSocketSupport.cmake @@ -27,7 +27,8 @@ include(CheckCSourceCompiles) macro(check_nonblocking_socket_support) # There are two known platforms (AIX 3.x and SunOS 4.1.x) where the # O_NONBLOCK define is found but does not work. - check_c_source_compiles(" + if(NOT WIN32) + check_c_source_compiles(" #include #include #include @@ -52,10 +53,12 @@ int main(void) int socket = 0; (void)fcntl(socket, F_SETFL, O_NONBLOCK); }" - HAVE_O_NONBLOCK) + HAVE_O_NONBLOCK) + endif() if(NOT HAVE_O_NONBLOCK) - check_c_source_compiles("/* FIONBIO test (old-style unix) */ + if(NOT WIN32) + check_c_source_compiles("/* FIONBIO test (old-style unix) */ #include #include @@ -65,10 +68,12 @@ int main(void) int flags = 0; (void)ioctl(socket, FIONBIO, &flags); }" - HAVE_FIONBIO) + HAVE_FIONBIO) + endif() if(NOT HAVE_FIONBIO) - check_c_source_compiles("/* ioctlsocket test (Windows) */ + if(WIN32) + check_c_source_compiles("/* ioctlsocket test (Windows) */ #undef inline #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -82,7 +87,8 @@ int main(void) unsigned long flags = 0; (void)ioctlsocket(sd, FIONBIO, &flags); }" - HAVE_IOCTLSOCKET) + HAVE_IOCTLSOCKET) + endif() if(NOT HAVE_IOCTLSOCKET) check_c_source_compiles("/* IoctlSocket test (Amiga?) */ @@ -93,7 +99,7 @@ int main(void) int socket = 0; (void)IoctlSocket(socket, FIONBIO, (long)1); }" - HAVE_IOCTLSOCKET_CASE) + HAVE_IOCTLSOCKET_CASE) if(NOT HAVE_IOCTLSOCKET_CASE) check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */ @@ -105,7 +111,7 @@ int main(void) int socket = 0; (void)setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); }" - HAVE_SO_NONBLOCK) + HAVE_SO_NONBLOCK) if(NOT HAVE_SO_NONBLOCK) # No non-blocking socket method found