Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1 | include(CheckCSourceCompiles) |
| 2 | # The begin of the sources (macros and includes) |
| 3 | set(_source_epilogue "#undef inline") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 4 | |
| 5 | macro(add_header_include check header) |
| 6 | if(${check}) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 7 | set(_source_epilogue "${_source_epilogue}\n#include <${header}>") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 8 | endif(${check}) |
| 9 | endmacro(add_header_include) |
| 10 | |
| 11 | set(signature_call_conv) |
| 12 | if(HAVE_WINDOWS_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 13 | add_header_include(HAVE_WINSOCK2_H "winsock2.h") |
Alex Deymo | 8f1a214 | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 14 | add_header_include(HAVE_WINDOWS_H "windows.h") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 15 | add_header_include(HAVE_WINSOCK_H "winsock.h") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 16 | set(_source_epilogue |
| 17 | "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 18 | set(signature_call_conv "PASCAL") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 19 | if(HAVE_LIBWS2_32) |
| 20 | set(CMAKE_REQUIRED_LIBRARIES ws2_32) |
| 21 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 22 | else(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") |
| 25 | endif(HAVE_WINDOWS_H) |
| 26 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 27 | check_c_source_compiles("${_source_epilogue} |
| 28 | int main(void) { |
| 29 | recv(0, 0, 0, 0); |
| 30 | return 0; |
| 31 | }" curl_cv_recv) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 32 | if(curl_cv_recv) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 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) { |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 46 | ${recv_arg1} s=0; |
| 47 | ${recv_arg2} buf=0; |
| 48 | ${recv_arg3} len=0; |
| 49 | ${recv_arg4} flags=0; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 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})") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 74 | else() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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}") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 80 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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") |
| 85 | else(curl_cv_recv) |
| 86 | message(FATAL_ERROR "Unable to link function recv") |
| 87 | endif(curl_cv_recv) |
| 88 | set(curl_cv_func_recv_args "${curl_cv_func_recv_args}" CACHE INTERNAL "Arguments for recv") |
| 89 | set(HAVE_RECV 1) |
| 90 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 91 | check_c_source_compiles("${_source_epilogue} |
| 92 | int main(void) { |
| 93 | send(0, 0, 0, 0); |
| 94 | return 0; |
| 95 | }" curl_cv_send) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 96 | if(curl_cv_send) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 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) { |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 110 | ${send_arg1} s=0; |
| 111 | ${send_arg2} buf=0; |
| 112 | ${send_arg3} len=0; |
| 113 | ${send_arg4} flags=0; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 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})") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 121 | if(curl_cv_func_send_test) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 140 | else() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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}") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 147 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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") |
| 153 | else(curl_cv_send) |
| 154 | message(FATAL_ERROR "Unable to link function send") |
| 155 | endif(curl_cv_send) |
| 156 | set(curl_cv_func_send_args "${curl_cv_func_send_args}" CACHE INTERNAL "Arguments for send") |
| 157 | set(HAVE_SEND 1) |
| 158 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 159 | check_c_source_compiles("${_source_epilogue} |
| 160 | int main(void) { |
| 161 | int flag = MSG_NOSIGNAL; |
| 162 | (void)flag; |
| 163 | return 0; |
| 164 | }" HAVE_MSG_NOSIGNAL) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 165 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 166 | if(NOT HAVE_WINDOWS_H) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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") |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 170 | endif() |
| 171 | check_c_source_compiles("${_source_epilogue} |
| 172 | int 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) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 179 | |
| 180 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 181 | include(CheckCSourceRuns) |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 182 | # See HAVE_POLL in CMakeLists.txt for why poll is disabled on macOS |
| 183 | if(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) |
| 195 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 196 | |
| 197 | set(HAVE_SIG_ATOMIC_T 1) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 198 | set(CMAKE_REQUIRED_FLAGS) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 199 | if(HAVE_SIGNAL_H) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 200 | set(CMAKE_REQUIRED_FLAGS "-DHAVE_SIGNAL_H") |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 201 | set(CMAKE_EXTRA_INCLUDE_FILES "signal.h") |
| 202 | endif(HAVE_SIGNAL_H) |
| 203 | check_type_size("sig_atomic_t" SIZEOF_SIG_ATOMIC_T) |
| 204 | if(HAVE_SIZEOF_SIG_ATOMIC_T) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 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) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 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) |
| 218 | |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 219 | if(HAVE_WINDOWS_H) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 220 | set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h) |
| 221 | else() |
| 222 | set(CMAKE_EXTRA_INCLUDE_FILES) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 223 | if(HAVE_SYS_SOCKET_H) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 224 | set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h) |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 225 | endif(HAVE_SYS_SOCKET_H) |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 226 | endif() |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 227 | |
| 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) |
| 232 | |