1 #***************************************************************************
3 # Project ___| | | | _ \| |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at https://curl.se/docs/copyright.html.
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
21 # SPDX-License-Identifier: curl
23 ###########################################################################
24 include(CheckCSourceCompiles)
25 # The begin of the sources (macros and includes)
26 set(_source_epilogue "#undef inline")
28 macro(add_header_include check header)
30 set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
34 set(signature_call_conv)
36 add_header_include(HAVE_WINSOCK2_H "winsock2.h")
37 add_header_include(HAVE_WINDOWS_H "windows.h")
39 "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif")
40 set(signature_call_conv "PASCAL")
42 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
45 add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
46 add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
49 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
51 check_c_source_compiles("${_source_epilogue}
53 int flag = MSG_NOSIGNAL;
58 if(NOT HAVE_WINDOWS_H)
59 add_header_include(HAVE_SYS_TIME_H "sys/time.h")
60 add_header_include(TIME_WITH_SYS_TIME "time.h")
61 add_header_include(HAVE_TIME_H "time.h")
63 check_c_source_compiles("${_source_epilogue}
70 }" HAVE_STRUCT_TIMEVAL)
73 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
75 set(CMAKE_EXTRA_INCLUDE_FILES)
77 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
81 check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
82 if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
83 set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
86 unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
88 if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
89 if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "iOS")
90 # only try this on non-apple platforms
92 # if not cross-compilation...
93 include(CheckCSourceRuns)
94 set(CMAKE_REQUIRED_FLAGS "")
96 set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
98 set(CMAKE_REQUIRED_FLAGS "-DHAVE_POLL_H")
100 check_c_source_runs("
102 #include <sys/time.h>
104 #ifdef HAVE_SYS_POLL_H
105 # include <sys/poll.h>
112 if(0 != poll(0, 0, 10)) {
116 /* detect the 10.12 poll() breakage */
117 struct timeval before, after;
121 gettimeofday(&before, NULL);
122 rc = poll(NULL, 0, 500);
123 gettimeofday(&after, NULL);
125 us = (after.tv_sec - before.tv_sec) * 1000000 +
126 (after.tv_usec - before.tv_usec);