1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-28 01:41:49 +03:00

cmake: fix ENABLE_WERROR=ON breaking auto-detections

- 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
This commit is contained in:
Viktor Szakats
2023-03-19 17:42:12 +00:00
parent de91e22081
commit 4997f921ee
12 changed files with 50 additions and 77 deletions

View File

@ -47,10 +47,10 @@ macro(check_nonblocking_socket_support)
#error \"O_NONBLOCK does not work on this platform\"
#endif
int main()
int main(void)
{
int socket;
int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
int socket = 0;
(void)fcntl(socket, F_SETFL, O_NONBLOCK);
}"
HAVE_O_NONBLOCK)
@ -59,10 +59,11 @@ int main()
#include <unistd.h>
#include <stropts.h>
int main()
int main(void)
{
int socket;
int flags = ioctl(socket, FIONBIO, &flags);
int socket = 0;
int flags = 0;
(void)ioctl(socket, FIONBIO, &flags);
}"
HAVE_FIONBIO)
@ -76,12 +77,11 @@ int main()
#include <windows.h>
#include <winsock2.h>
int main()
int main(void)
{
SOCKET sd;
SOCKET sd = socket(0, 0, 0);
unsigned long flags = 0;
sd = socket(0, 0, 0);
ioctlsocket(sd, FIONBIO, &flags);
(void)ioctlsocket(sd, FIONBIO, &flags);
}"
HAVE_IOCTLSOCKET)
@ -89,10 +89,10 @@ int main()
check_c_source_compiles("/* IoctlSocket test (Amiga?) */
#include <sys/ioctl.h>
int main()
int main(void)
{
int socket;
int flags = IoctlSocket(socket, FIONBIO, (long)1);
int socket = 0;
(void)IoctlSocket(socket, FIONBIO, (long)1);
}"
HAVE_IOCTLSOCKET_CASE)
@ -100,11 +100,11 @@ int main()
check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */
#include <socket.h>
int main()
int main(void)
{
long b = 1;
int socket;
int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
int socket = 0;
(void)setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
}"
HAVE_SO_NONBLOCK)