• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include(CheckCSourceCompiles)
2# The begin of the sources (macros and includes)
3set(_source_epilogue "#undef inline")
4
5macro(add_header_include check header)
6  if(${check})
7    set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
8  endif(${check})
9endmacro(add_header_include)
10
11set(signature_call_conv)
12if(HAVE_WINDOWS_H)
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")
16  set(_source_epilogue
17      "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif")
18  set(signature_call_conv "PASCAL")
19  if(HAVE_LIBWS2_32)
20    set(CMAKE_REQUIRED_LIBRARIES ws2_32)
21  endif()
22else(HAVE_WINDOWS_H)
23  add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
24  add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
25endif(HAVE_WINDOWS_H)
26
27check_c_source_compiles("${_source_epilogue}
28int main(void) {
29    recv(0, 0, 0, 0);
30    return 0;
31}" curl_cv_recv)
32if(curl_cv_recv)
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("
42                  ${_source_epilogue}
43                  extern ${recv_retv} ${signature_call_conv}
44                  recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4});
45                  int main(void) {
46                    ${recv_arg1} s=0;
47                    ${recv_arg2} buf=0;
48                    ${recv_arg3} len=0;
49                    ${recv_arg4} flags=0;
50                    ${recv_retv} res = recv(s, buf, len, flags);
51                    (void) res;
52                    return 0;
53                  }"
54                  curl_cv_func_recv_test)
55                message(STATUS
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}")
65                  set(HAVE_RECV 1)
66                  set(curl_cv_func_recv_done 1)
67                endif(curl_cv_func_recv_test)
68              endif(NOT curl_cv_func_recv_done)
69            endforeach(recv_arg4)
70          endforeach(recv_arg3)
71        endforeach(recv_arg2)
72      endforeach(recv_arg1)
73    endforeach(recv_retv)
74  else()
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}")
80  endif()
81
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")
85else(curl_cv_recv)
86  message(FATAL_ERROR "Unable to link function recv")
87endif(curl_cv_recv)
88set(curl_cv_func_recv_args "${curl_cv_func_recv_args}" CACHE INTERNAL "Arguments for recv")
89set(HAVE_RECV 1)
90
91check_c_source_compiles("${_source_epilogue}
92int main(void) {
93    send(0, 0, 0, 0);
94    return 0;
95}" curl_cv_send)
96if(curl_cv_send)
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("
106                  ${_source_epilogue}
107                  extern ${send_retv} ${signature_call_conv}
108                  send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4});
109                  int main(void) {
110                    ${send_arg1} s=0;
111                    ${send_arg2} buf=0;
112                    ${send_arg3} len=0;
113                    ${send_arg4} flags=0;
114                    ${send_retv} res = send(s, buf, len, flags);
115                    (void) res;
116                    return 0;
117                  }"
118                  curl_cv_func_send_test)
119                message(STATUS
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}")
131                  set(HAVE_SEND 1)
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)
140  else()
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}")
147  endif()
148
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")
153else(curl_cv_send)
154  message(FATAL_ERROR "Unable to link function send")
155endif(curl_cv_send)
156set(curl_cv_func_send_args "${curl_cv_func_send_args}" CACHE INTERNAL "Arguments for send")
157set(HAVE_SEND 1)
158
159check_c_source_compiles("${_source_epilogue}
160  int main(void) {
161    int flag = MSG_NOSIGNAL;
162    (void)flag;
163    return 0;
164  }" HAVE_MSG_NOSIGNAL)
165
166if(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")
170endif()
171check_c_source_compiles("${_source_epilogue}
172int main(void) {
173  struct timeval ts;
174  ts.tv_sec  = 0;
175  ts.tv_usec = 0;
176  (void)ts;
177  return 0;
178}" HAVE_STRUCT_TIMEVAL)
179
180
181include(CheckCSourceRuns)
182# See HAVE_POLL in CMakeLists.txt for why poll is disabled on macOS
183if(NOT APPLE)
184  set(CMAKE_REQUIRED_FLAGS)
185  if(HAVE_SYS_POLL_H)
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>
191    #endif
192    int main(void) {
193      return poll((void *)0, 0, 10 /*ms*/);
194    }" HAVE_POLL_FINE)
195endif()
196
197set(HAVE_SIG_ATOMIC_T 1)
198set(CMAKE_REQUIRED_FLAGS)
199if(HAVE_SIGNAL_H)
200  set(CMAKE_REQUIRED_FLAGS "-DHAVE_SIGNAL_H")
201  set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
202endif(HAVE_SIGNAL_H)
203check_type_size("sig_atomic_t" SIZEOF_SIG_ATOMIC_T)
204if(HAVE_SIZEOF_SIG_ATOMIC_T)
205  check_c_source_compiles("
206    #ifdef HAVE_SIGNAL_H
207    #  include <signal.h>
208    #endif
209    int main(void) {
210      static volatile sig_atomic_t dummy = 0;
211      (void)dummy;
212      return 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)
217endif(HAVE_SIZEOF_SIG_ATOMIC_T)
218
219if(HAVE_WINDOWS_H)
220  set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
221else()
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)
226endif()
227
228check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
229if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
230  set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
231endif(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
232
233