| 1 |
include(CheckCSourceCompiles) |
| 2 |
# The begin of the sources (macros and includes) |
| 3 |
set(_source_epilogue "#undef inline") |
| 4 |
|
| 5 |
macro(add_header_include check header) |
| 6 |
if(${check}) |
| 7 |
set(_source_epilogue "${_source_epilogue}\n#include <${header}>") |
| 8 |
endif() |
| 9 |
endmacro() |
| 10 |
|
| 11 |
set(signature_call_conv) |
| 12 |
if(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() |
| 22 |
else() |
| 23 |
add_header_include(HAVE_SYS_TYPES_H "sys/types.h") |
| 24 |
add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h") |
| 25 |
endif() |
| 26 |
|
| 27 |
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 28 |
|
| 29 |
check_c_source_compiles("${_source_epilogue} |
| 30 |
int main(void) { |
| 31 |
recv(0, 0, 0, 0); |
| 32 |
return 0; |
| 33 |
}" curl_cv_recv) |
| 34 |
if(curl_cv_recv) |
| 35 |
if(NOT DEFINED curl_cv_func_recv_args OR curl_cv_func_recv_args STREQUAL "unknown") |
| 36 |
foreach(recv_retv "int" "ssize_t" ) |
| 37 |
foreach(recv_arg1 "SOCKET" "int" ) |
| 38 |
foreach(recv_arg2 "char *" "void *" ) |
| 39 |
foreach(recv_arg3 "int" "size_t" "socklen_t" "unsigned int") |
| 40 |
foreach(recv_arg4 "int" "unsigned int") |
| 41 |
if(NOT curl_cv_func_recv_done) |
| 42 |
unset(curl_cv_func_recv_test CACHE) |
| 43 |
check_c_source_compiles(" |
| 44 |
${_source_epilogue} |
| 45 |
extern ${recv_retv} ${signature_call_conv} |
| 46 |
recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4}); |
| 47 |
int main(void) { |
| 48 |
${recv_arg1} s=0; |
| 49 |
${recv_arg2} buf=0; |
| 50 |
${recv_arg3} len=0; |
| 51 |
${recv_arg4} flags=0; |
| 52 |
${recv_retv} res = recv(s, buf, len, flags); |
| 53 |
(void) res; |
| 54 |
return 0; |
| 55 |
}" |
| 56 |
curl_cv_func_recv_test) |
| 57 |
message(STATUS |
| 58 |
"Tested: ${recv_retv} recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4})") |
| 59 |
if(curl_cv_func_recv_test) |
| 60 |
set(curl_cv_func_recv_args |
| 61 |
"${recv_arg1},${recv_arg2},${recv_arg3},${recv_arg4},${recv_retv}") |
| 62 |
set(RECV_TYPE_ARG1 "${recv_arg1}") |
| 63 |
set(RECV_TYPE_ARG2 "${recv_arg2}") |
| 64 |
set(RECV_TYPE_ARG3 "${recv_arg3}") |
| 65 |
set(RECV_TYPE_ARG4 "${recv_arg4}") |
| 66 |
set(RECV_TYPE_RETV "${recv_retv}") |
| 67 |
set(HAVE_RECV 1) |
| 68 |
set(curl_cv_func_recv_done 1) |
| 69 |
endif() |
| 70 |
endif() |
| 71 |
endforeach() |
| 72 |
endforeach() |
| 73 |
endforeach() |
| 74 |
endforeach() |
| 75 |
endforeach() |
| 76 |
else() |
| 77 |
string(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG1 "${curl_cv_func_recv_args}") |
| 78 |
string(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG2 "${curl_cv_func_recv_args}") |
| 79 |
string(REGEX REPLACE "^[^,]*,[^,]*,([^,]*),[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG3 "${curl_cv_func_recv_args}") |
| 80 |
string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,([^,]*),[^,]*$" "\\1" RECV_TYPE_ARG4 "${curl_cv_func_recv_args}") |
| 81 |
string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" RECV_TYPE_RETV "${curl_cv_func_recv_args}") |
| 82 |
endif() |
| 83 |
|
| 84 |
if(curl_cv_func_recv_args STREQUAL "unknown") |
| 85 |
message(FATAL_ERROR "Cannot find proper types to use for recv args") |
| 86 |
endif() |
| 87 |
else() |
| 88 |
message(FATAL_ERROR "Unable to link function recv") |
| 89 |
endif() |
| 90 |
set(curl_cv_func_recv_args "${curl_cv_func_recv_args}" CACHE INTERNAL "Arguments for recv") |
| 91 |
set(HAVE_RECV 1) |
| 92 |
|
| 93 |
check_c_source_compiles("${_source_epilogue} |
| 94 |
int main(void) { |
| 95 |
send(0, 0, 0, 0); |
| 96 |
return 0; |
| 97 |
}" curl_cv_send) |
| 98 |
if(curl_cv_send) |
| 99 |
if(NOT DEFINED curl_cv_func_send_args OR "${curl_cv_func_send_args}" STREQUAL "unknown") |
| 100 |
foreach(send_retv "int" "ssize_t" ) |
| 101 |
foreach(send_arg1 "SOCKET" "int" "ssize_t" ) |
| 102 |
foreach(send_arg2 "const char *" "const void *" "void *" "char *") |
| 103 |
foreach(send_arg3 "int" "size_t" "socklen_t" "unsigned int") |
| 104 |
foreach(send_arg4 "int" "unsigned int") |
| 105 |
if(NOT curl_cv_func_send_done) |
| 106 |
unset(curl_cv_func_send_test CACHE) |
| 107 |
check_c_source_compiles(" |
| 108 |
${_source_epilogue} |
| 109 |
extern ${send_retv} ${signature_call_conv} |
| 110 |
send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4}); |
| 111 |
int main(void) { |
| 112 |
${send_arg1} s=0; |
| 113 |
${send_arg2} buf=0; |
| 114 |
${send_arg3} len=0; |
| 115 |
${send_arg4} flags=0; |
| 116 |
${send_retv} res = send(s, buf, len, flags); |
| 117 |
(void) res; |
| 118 |
return 0; |
| 119 |
}" |
| 120 |
curl_cv_func_send_test) |
| 121 |
message(STATUS |
| 122 |
"Tested: ${send_retv} send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4})") |
| 123 |
if(curl_cv_func_send_test) |
| 124 |
string(REGEX REPLACE "(const) .*" "\\1" send_qual_arg2 "${send_arg2}") |
| 125 |
string(REGEX REPLACE "const (.*)" "\\1" send_arg2 "${send_arg2}") |
| 126 |
set(curl_cv_func_send_args |
| 127 |
"${send_arg1},${send_arg2},${send_arg3},${send_arg4},${send_retv},${send_qual_arg2}") |
| 128 |
set(SEND_TYPE_ARG1 "${send_arg1}") |
| 129 |
set(SEND_TYPE_ARG2 "${send_arg2}") |
| 130 |
set(SEND_TYPE_ARG3 "${send_arg3}") |
| 131 |
set(SEND_TYPE_ARG4 "${send_arg4}") |
| 132 |
set(SEND_TYPE_RETV "${send_retv}") |
| 133 |
set(HAVE_SEND 1) |
| 134 |
set(curl_cv_func_send_done 1) |
| 135 |
endif() |
| 136 |
endif() |
| 137 |
endforeach() |
| 138 |
endforeach() |
| 139 |
endforeach() |
| 140 |
endforeach() |
| 141 |
endforeach() |
| 142 |
else() |
| 143 |
string(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG1 "${curl_cv_func_send_args}") |
| 144 |
string(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG2 "${curl_cv_func_send_args}") |
| 145 |
string(REGEX REPLACE "^[^,]*,[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG3 "${curl_cv_func_send_args}") |
| 146 |
string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,([^,]*),[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG4 "${curl_cv_func_send_args}") |
| 147 |
string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*),[^,]*$" "\\1" SEND_TYPE_RETV "${curl_cv_func_send_args}") |
| 148 |
string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" SEND_QUAL_ARG2 "${curl_cv_func_send_args}") |
| 149 |
endif() |
| 150 |
|
| 151 |
if("${curl_cv_func_send_args}" STREQUAL "unknown") |
| 152 |
message(FATAL_ERROR "Cannot find proper types to use for send args") |
| 153 |
endif() |
| 154 |
set(SEND_QUAL_ARG2 "const") |
| 155 |
else() |
| 156 |
message(FATAL_ERROR "Unable to link function send") |
| 157 |
endif() |
| 158 |
set(curl_cv_func_send_args "${curl_cv_func_send_args}" CACHE INTERNAL "Arguments for send") |
| 159 |
set(HAVE_SEND 1) |
| 160 |
|
| 161 |
check_c_source_compiles("${_source_epilogue} |
| 162 |
int main(void) { |
| 163 |
int flag = MSG_NOSIGNAL; |
| 164 |
(void)flag; |
| 165 |
return 0; |
| 166 |
}" HAVE_MSG_NOSIGNAL) |
| 167 |
|
| 168 |
if(NOT HAVE_WINDOWS_H) |
| 169 |
add_header_include(HAVE_SYS_TIME_H "sys/time.h") |
| 170 |
add_header_include(TIME_WITH_SYS_TIME "time.h") |
| 171 |
add_header_include(HAVE_TIME_H "time.h") |
| 172 |
endif() |
| 173 |
check_c_source_compiles("${_source_epilogue} |
| 174 |
int main(void) { |
| 175 |
struct timeval ts; |
| 176 |
ts.tv_sec = 0; |
| 177 |
ts.tv_usec = 0; |
| 178 |
(void)ts; |
| 179 |
return 0; |
| 180 |
}" HAVE_STRUCT_TIMEVAL) |
| 181 |
|
| 182 |
set(HAVE_SIG_ATOMIC_T 1) |
| 183 |
set(CMAKE_REQUIRED_FLAGS) |
| 184 |
if(HAVE_SIGNAL_H) |
| 185 |
set(CMAKE_REQUIRED_FLAGS "-DHAVE_SIGNAL_H") |
| 186 |
set(CMAKE_EXTRA_INCLUDE_FILES "signal.h") |
| 187 |
endif() |
| 188 |
check_type_size("sig_atomic_t" SIZEOF_SIG_ATOMIC_T) |
| 189 |
if(HAVE_SIZEOF_SIG_ATOMIC_T) |
| 190 |
check_c_source_compiles(" |
| 191 |
#ifdef HAVE_SIGNAL_H |
| 192 |
# include <signal.h> |
| 193 |
#endif |
| 194 |
int main(void) { |
| 195 |
static volatile sig_atomic_t dummy = 0; |
| 196 |
(void)dummy; |
| 197 |
return 0; |
| 198 |
}" HAVE_SIG_ATOMIC_T_NOT_VOLATILE) |
| 199 |
if(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE) |
| 200 |
set(HAVE_SIG_ATOMIC_T_VOLATILE 1) |
| 201 |
endif() |
| 202 |
endif() |
| 203 |
|
| 204 |
if(HAVE_WINDOWS_H) |
| 205 |
set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h) |
| 206 |
else() |
| 207 |
set(CMAKE_EXTRA_INCLUDE_FILES) |
| 208 |
if(HAVE_SYS_SOCKET_H) |
| 209 |
set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h) |
| 210 |
endif() |
| 211 |
endif() |
| 212 |
|
| 213 |
check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE) |
| 214 |
if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE) |
| 215 |
set(HAVE_STRUCT_SOCKADDR_STORAGE 1) |
| 216 |
endif() |
| 217 |
|
| 218 |
unset(CMAKE_TRY_COMPILE_TARGET_TYPE) |
| 219 |
|
| 220 |
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) |
| 221 |
# if not cross-compilation... |
| 222 |
include(CheckCSourceRuns) |
| 223 |
set(CMAKE_REQUIRED_FLAGS "") |
| 224 |
if(HAVE_SYS_POLL_H) |
| 225 |
set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H") |
| 226 |
elseif(HAVE_POLL_H) |
| 227 |
set(CMAKE_REQUIRED_FLAGS "-DHAVE_POLL_H") |
| 228 |
endif() |
| 229 |
check_c_source_runs(" |
| 230 |
#include <stdlib.h> |
| 231 |
#include <sys/time.h> |
| 232 |
|
| 233 |
#ifdef HAVE_SYS_POLL_H |
| 234 |
# include <sys/poll.h> |
| 235 |
#elif HAVE_POLL_H |
| 236 |
# include <poll.h> |
| 237 |
#endif |
| 238 |
|
| 239 |
int main(void) |
| 240 |
{ |
| 241 |
if(0 != poll(0, 0, 10)) { |
| 242 |
return 1; /* fail */ |
| 243 |
} |
| 244 |
else { |
| 245 |
/* detect the 10.12 poll() breakage */ |
| 246 |
struct timeval before, after; |
| 247 |
int rc; |
| 248 |
size_t us; |
| 249 |
|
| 250 |
gettimeofday(&before, NULL); |
| 251 |
rc = poll(NULL, 0, 500); |
| 252 |
gettimeofday(&after, NULL); |
| 253 |
|
| 254 |
us = (after.tv_sec - before.tv_sec) * 1000000 + |
| 255 |
(after.tv_usec - before.tv_usec); |
| 256 |
|
| 257 |
if(us < 400000) { |
| 258 |
return 1; |
| 259 |
} |
| 260 |
} |
| 261 |
return 0; |
| 262 |
}" HAVE_POLL_FINE) |
| 263 |
endif() |
| 264 |
|