mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-20 02:42:09 +03:00
- cmake: fix compiler warnings in `CheckNonblockingSocketSupport`. detection functions. Without this, these detections fail when `ENABLE_WERROR=ON`. - cmake: disable ENABLE_WERROR for MSVC during symbol checks in `src`. CMake's built-in symbol check function `check_symbol_exists()` generate warnings with MSVC. With warnings considered errors, these detections fail permanently. Our workaround is to disable warnings-as-errors while running these checks. ``` CheckSymbolExists.c(8): warning C4054: 'type cast': from function pointer '__int64 (__cdecl *)(const char *,char **,int)' to data pointer 'int *' in `return ((int*)(&strtoll))[argc];` ``` Ref: https://ci.appveyor.com/project/libssh2org/libssh2/builds/46537222/job/4vg4yg333mu2lg9b - example: replace `strcasecmp()` with C89 `strcmp()`. To avoid using CMake symbol checks in `example`. Another option is to duplicate the `check_symbol_exists()` workaround from `src`, but I figure it's not worth the complexity. We use `strcasecmp()` solely to check optional command-line options for example programs, and those are fine as lower-case. Without this, these detections fail when `ENABLE_WERROR=ON`. - also delete `__function__` detection/use in `example`. To avoid the complexity for the sake of using it at a single place in of the example's error branch. Replace that use with a literal name of the function. - cmake: also use `CMakePushCheckState` functions instead of manual save/restore. Closes #857
120 lines
3.0 KiB
CMake
120 lines
3.0 KiB
CMake
include(CheckCSourceCompiles)
|
|
|
|
# - check_nonblocking_socket_support()
|
|
#
|
|
# Check for how to set a socket to non-blocking state. There seems to exist
|
|
# four known different ways, with the one used almost everywhere being POSIX
|
|
# and XPG3, while the other different ways for different systems (old BSD,
|
|
# Windows and Amiga).
|
|
#
|
|
# One of the following variables will be set indicating the supported
|
|
# method (if any):
|
|
# HAVE_O_NONBLOCK
|
|
# HAVE_FIONBIO
|
|
# HAVE_IOCTLSOCKET
|
|
# HAVE_IOCTLSOCKET_CASE
|
|
# HAVE_SO_NONBLOCK
|
|
# HAVE_DISABLED_NONBLOCKING
|
|
#
|
|
# The following variables may be set before calling this macro to
|
|
# modify the way the check is run:
|
|
#
|
|
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
|
|
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
|
|
# CMAKE_REQUIRED_INCLUDES = list of include directories
|
|
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
|
|
#
|
|
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("
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
|
|
#if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
|
# if defined(__SVR4) || defined(__srv4__)
|
|
# define PLATFORM_SOLARIS
|
|
# else
|
|
# define PLATFORM_SUNOS4
|
|
# endif
|
|
#endif
|
|
#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
|
|
# define PLATFORM_AIX_V3
|
|
#endif
|
|
|
|
#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
|
|
#error \"O_NONBLOCK does not work on this platform\"
|
|
#endif
|
|
|
|
int main(void)
|
|
{
|
|
int socket = 0;
|
|
(void)fcntl(socket, F_SETFL, O_NONBLOCK);
|
|
}"
|
|
HAVE_O_NONBLOCK)
|
|
|
|
if(NOT HAVE_O_NONBLOCK)
|
|
check_c_source_compiles("/* FIONBIO test (old-style unix) */
|
|
#include <unistd.h>
|
|
#include <stropts.h>
|
|
|
|
int main(void)
|
|
{
|
|
int socket = 0;
|
|
int flags = 0;
|
|
(void)ioctl(socket, FIONBIO, &flags);
|
|
}"
|
|
HAVE_FIONBIO)
|
|
|
|
if(NOT HAVE_FIONBIO)
|
|
check_c_source_compiles("/* ioctlsocket test (Windows) */
|
|
#undef inline
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
|
|
#include <windows.h>
|
|
#include <winsock2.h>
|
|
|
|
int main(void)
|
|
{
|
|
SOCKET sd = socket(0, 0, 0);
|
|
unsigned long flags = 0;
|
|
(void)ioctlsocket(sd, FIONBIO, &flags);
|
|
}"
|
|
HAVE_IOCTLSOCKET)
|
|
|
|
if(NOT HAVE_IOCTLSOCKET)
|
|
check_c_source_compiles("/* IoctlSocket test (Amiga?) */
|
|
#include <sys/ioctl.h>
|
|
|
|
int main(void)
|
|
{
|
|
int socket = 0;
|
|
(void)IoctlSocket(socket, FIONBIO, (long)1);
|
|
}"
|
|
HAVE_IOCTLSOCKET_CASE)
|
|
|
|
if(NOT HAVE_IOCTLSOCKET_CASE)
|
|
check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */
|
|
#include <socket.h>
|
|
|
|
int main(void)
|
|
{
|
|
long b = 1;
|
|
int socket = 0;
|
|
(void)setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
|
|
}"
|
|
HAVE_SO_NONBLOCK)
|
|
|
|
if(NOT HAVE_SO_NONBLOCK)
|
|
# No non-blocking socket method found
|
|
set(HAVE_DISABLED_NONBLOCKING 1)
|
|
endif()
|
|
endif()
|
|
endif()
|
|
endif()
|
|
endif()
|
|
endmacro()
|