1 include(CheckCSourceCompiles)
2 # The begin of the sources (macros and includes)
3 set(_source_epilogue "#undef inline")
5 macro(add_header_include check header)
7 set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
9 endmacro(add_header_include)
11 set(signature_call_conv)
13 add_header_include(HAVE_WINSOCK2_H "winsock2.h")
14 add_header_include(HAVE_WINDOWS_H "windows.h")
15 add_header_include(HAVE_WINSOCK_H "winsock.h")
17 "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif")
18 set(signature_call_conv "PASCAL")
20 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
23 add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
24 add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
27 check_c_source_compiles("${_source_epilogue}
33 if(NOT DEFINED curl_cv_func_recv_args OR "${curl_cv_func_recv_args}" STREQUAL "unknown")
34 foreach(recv_retv "int" "ssize_t" )
35 foreach(recv_arg1 "int" "ssize_t" "SOCKET")
36 foreach(recv_arg2 "void *" "char *")
37 foreach(recv_arg3 "size_t" "int" "socklen_t" "unsigned int")
38 foreach(recv_arg4 "int" "unsigned int")
39 if(NOT curl_cv_func_recv_done)
40 unset(curl_cv_func_recv_test CACHE)
41 check_c_source_compiles("
43 extern ${recv_retv} ${signature_call_conv}
44 recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4});
50 ${recv_retv} res = recv(s, buf, len, flags);
54 curl_cv_func_recv_test)
56 "Tested: ${recv_retv} recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4})")
57 if(curl_cv_func_recv_test)
58 set(curl_cv_func_recv_args
59 "${recv_arg1},${recv_arg2},${recv_arg3},${recv_arg4},${recv_retv}")
60 set(RECV_TYPE_ARG1 "${recv_arg1}")
61 set(RECV_TYPE_ARG2 "${recv_arg2}")
62 set(RECV_TYPE_ARG3 "${recv_arg3}")
63 set(RECV_TYPE_ARG4 "${recv_arg4}")
64 set(RECV_TYPE_RETV "${recv_retv}")
66 set(curl_cv_func_recv_done 1)
67 endif(curl_cv_func_recv_test)
68 endif(NOT curl_cv_func_recv_done)
75 string(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG1 "${curl_cv_func_recv_args}")
76 string(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG2 "${curl_cv_func_recv_args}")
77 string(REGEX REPLACE "^[^,]*,[^,]*,([^,]*),[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG3 "${curl_cv_func_recv_args}")
78 string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,([^,]*),[^,]*$" "\\1" RECV_TYPE_ARG4 "${curl_cv_func_recv_args}")
79 string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" RECV_TYPE_RETV "${curl_cv_func_recv_args}")
82 if("${curl_cv_func_recv_args}" STREQUAL "unknown")
83 message(FATAL_ERROR "Cannot find proper types to use for recv args")
84 endif("${curl_cv_func_recv_args}" STREQUAL "unknown")
86 message(FATAL_ERROR "Unable to link function recv")
88 set(curl_cv_func_recv_args "${curl_cv_func_recv_args}" CACHE INTERNAL "Arguments for recv")
91 check_c_source_compiles("${_source_epilogue}
97 if(NOT DEFINED curl_cv_func_send_args OR "${curl_cv_func_send_args}" STREQUAL "unknown")
98 foreach(send_retv "int" "ssize_t" )
99 foreach(send_arg1 "int" "ssize_t" "SOCKET")
100 foreach(send_arg2 "const void *" "void *" "char *" "const char *")
101 foreach(send_arg3 "size_t" "int" "socklen_t" "unsigned int")
102 foreach(send_arg4 "int" "unsigned int")
103 if(NOT curl_cv_func_send_done)
104 unset(curl_cv_func_send_test CACHE)
105 check_c_source_compiles("
107 extern ${send_retv} ${signature_call_conv}
108 send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4});
113 ${send_arg4} flags=0;
114 ${send_retv} res = send(s, buf, len, flags);
118 curl_cv_func_send_test)
120 "Tested: ${send_retv} send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4})")
121 if(curl_cv_func_send_test)
122 string(REGEX REPLACE "(const) .*" "\\1" send_qual_arg2 "${send_arg2}")
123 string(REGEX REPLACE "const (.*)" "\\1" send_arg2 "${send_arg2}")
124 set(curl_cv_func_send_args
125 "${send_arg1},${send_arg2},${send_arg3},${send_arg4},${send_retv},${send_qual_arg2}")
126 set(SEND_TYPE_ARG1 "${send_arg1}")
127 set(SEND_TYPE_ARG2 "${send_arg2}")
128 set(SEND_TYPE_ARG3 "${send_arg3}")
129 set(SEND_TYPE_ARG4 "${send_arg4}")
130 set(SEND_TYPE_RETV "${send_retv}")
132 set(curl_cv_func_send_done 1)
133 endif(curl_cv_func_send_test)
134 endif(NOT curl_cv_func_send_done)
135 endforeach(send_arg4)
136 endforeach(send_arg3)
137 endforeach(send_arg2)
138 endforeach(send_arg1)
139 endforeach(send_retv)
141 string(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG1 "${curl_cv_func_send_args}")
142 string(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG2 "${curl_cv_func_send_args}")
143 string(REGEX REPLACE "^[^,]*,[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG3 "${curl_cv_func_send_args}")
144 string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,([^,]*),[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG4 "${curl_cv_func_send_args}")
145 string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*),[^,]*$" "\\1" SEND_TYPE_RETV "${curl_cv_func_send_args}")
146 string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" SEND_QUAL_ARG2 "${curl_cv_func_send_args}")
149 if("${curl_cv_func_send_args}" STREQUAL "unknown")
150 message(FATAL_ERROR "Cannot find proper types to use for send args")
151 endif("${curl_cv_func_send_args}" STREQUAL "unknown")
152 set(SEND_QUAL_ARG2 "const")
154 message(FATAL_ERROR "Unable to link function send")
156 set(curl_cv_func_send_args "${curl_cv_func_send_args}" CACHE INTERNAL "Arguments for send")
159 check_c_source_compiles("${_source_epilogue}
161 int flag = MSG_NOSIGNAL;
164 }" HAVE_MSG_NOSIGNAL)
166 if(NOT HAVE_WINDOWS_H)
167 add_header_include(HAVE_SYS_TIME_H "sys/time.h")
168 add_header_include(TIME_WITH_SYS_TIME "time.h")
169 add_header_include(HAVE_TIME_H "time.h")
171 check_c_source_compiles("${_source_epilogue}
178 }" HAVE_STRUCT_TIMEVAL)
181 include(CheckCSourceRuns)
182 # See HAVE_POLL in CMakeLists.txt for why poll is disabled on macOS
184 set(CMAKE_REQUIRED_FLAGS)
186 set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
187 endif(HAVE_SYS_POLL_H)
188 check_c_source_runs("
189 #ifdef HAVE_SYS_POLL_H
190 # include <sys/poll.h>
193 return poll((void *)0, 0, 10 /*ms*/);
197 set(HAVE_SIG_ATOMIC_T 1)
198 set(CMAKE_REQUIRED_FLAGS)
200 set(CMAKE_REQUIRED_FLAGS "-DHAVE_SIGNAL_H")
201 set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
203 check_type_size("sig_atomic_t" SIZEOF_SIG_ATOMIC_T)
204 if(HAVE_SIZEOF_SIG_ATOMIC_T)
205 check_c_source_compiles("
210 static volatile sig_atomic_t dummy = 0;
213 }" HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
214 if(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
215 set(HAVE_SIG_ATOMIC_T_VOLATILE 1)
216 endif(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
217 endif(HAVE_SIZEOF_SIG_ATOMIC_T)
220 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
222 set(CMAKE_EXTRA_INCLUDE_FILES)
223 if(HAVE_SYS_SOCKET_H)
224 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
225 endif(HAVE_SYS_SOCKET_H)
228 check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
229 if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
230 set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
231 endif(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)