2
0

OtherTests.cmake 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. include(CheckCSourceCompiles)
  2. # The begin of the sources (macros and includes)
  3. set(_source_epilogue "#undef inline")
  4. macro(add_header_include check header)
  5. if(${check})
  6. set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
  7. endif(${check})
  8. endmacro(add_header_include)
  9. set(signature_call_conv)
  10. if(HAVE_WINDOWS_H)
  11. add_header_include(HAVE_WINDOWS_H "windows.h")
  12. add_header_include(HAVE_WINSOCK2_H "winsock2.h")
  13. add_header_include(HAVE_WINSOCK_H "winsock.h")
  14. set(_source_epilogue
  15. "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif")
  16. set(signature_call_conv "PASCAL")
  17. if(HAVE_LIBWS2_32)
  18. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  19. endif()
  20. else(HAVE_WINDOWS_H)
  21. add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
  22. add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
  23. endif(HAVE_WINDOWS_H)
  24. check_c_source_compiles("${_source_epilogue}
  25. int main(void) {
  26. recv(0, 0, 0, 0);
  27. return 0;
  28. }" curl_cv_recv)
  29. if(curl_cv_recv)
  30. if(NOT DEFINED curl_cv_func_recv_args OR "${curl_cv_func_recv_args}" STREQUAL "unknown")
  31. foreach(recv_retv "int" "ssize_t" )
  32. foreach(recv_arg1 "int" "ssize_t" "SOCKET")
  33. foreach(recv_arg2 "void *" "char *")
  34. foreach(recv_arg3 "size_t" "int" "socklen_t" "unsigned int")
  35. foreach(recv_arg4 "int" "unsigned int")
  36. if(NOT curl_cv_func_recv_done)
  37. unset(curl_cv_func_recv_test CACHE)
  38. check_c_source_compiles("
  39. ${_source_epilogue}
  40. extern ${recv_retv} ${signature_call_conv}
  41. recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4});
  42. int main(void) {
  43. ${recv_arg1} s=0;
  44. ${recv_arg2} buf=0;
  45. ${recv_arg3} len=0;
  46. ${recv_arg4} flags=0;
  47. ${recv_retv} res = recv(s, buf, len, flags);
  48. (void) res;
  49. return 0;
  50. }"
  51. curl_cv_func_recv_test)
  52. message(STATUS
  53. "Tested: ${recv_retv} recv(${recv_arg1}, ${recv_arg2}, ${recv_arg3}, ${recv_arg4})")
  54. if(curl_cv_func_recv_test)
  55. set(curl_cv_func_recv_args
  56. "${recv_arg1},${recv_arg2},${recv_arg3},${recv_arg4},${recv_retv}")
  57. set(RECV_TYPE_ARG1 "${recv_arg1}")
  58. set(RECV_TYPE_ARG2 "${recv_arg2}")
  59. set(RECV_TYPE_ARG3 "${recv_arg3}")
  60. set(RECV_TYPE_ARG4 "${recv_arg4}")
  61. set(RECV_TYPE_RETV "${recv_retv}")
  62. set(HAVE_RECV 1)
  63. set(curl_cv_func_recv_done 1)
  64. endif(curl_cv_func_recv_test)
  65. endif(NOT curl_cv_func_recv_done)
  66. endforeach(recv_arg4)
  67. endforeach(recv_arg3)
  68. endforeach(recv_arg2)
  69. endforeach(recv_arg1)
  70. endforeach(recv_retv)
  71. else()
  72. string(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG1 "${curl_cv_func_recv_args}")
  73. string(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG2 "${curl_cv_func_recv_args}")
  74. string(REGEX REPLACE "^[^,]*,[^,]*,([^,]*),[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG3 "${curl_cv_func_recv_args}")
  75. string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,([^,]*),[^,]*$" "\\1" RECV_TYPE_ARG4 "${curl_cv_func_recv_args}")
  76. string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" RECV_TYPE_RETV "${curl_cv_func_recv_args}")
  77. endif()
  78. if("${curl_cv_func_recv_args}" STREQUAL "unknown")
  79. message(FATAL_ERROR "Cannot find proper types to use for recv args")
  80. endif("${curl_cv_func_recv_args}" STREQUAL "unknown")
  81. else(curl_cv_recv)
  82. message(FATAL_ERROR "Unable to link function recv")
  83. endif(curl_cv_recv)
  84. set(curl_cv_func_recv_args "${curl_cv_func_recv_args}" CACHE INTERNAL "Arguments for recv")
  85. set(HAVE_RECV 1)
  86. check_c_source_compiles("${_source_epilogue}
  87. int main(void) {
  88. send(0, 0, 0, 0);
  89. return 0;
  90. }" curl_cv_send)
  91. if(curl_cv_send)
  92. if(NOT DEFINED curl_cv_func_send_args OR "${curl_cv_func_send_args}" STREQUAL "unknown")
  93. foreach(send_retv "int" "ssize_t" )
  94. foreach(send_arg1 "int" "ssize_t" "SOCKET")
  95. foreach(send_arg2 "const void *" "void *" "char *" "const char *")
  96. foreach(send_arg3 "size_t" "int" "socklen_t" "unsigned int")
  97. foreach(send_arg4 "int" "unsigned int")
  98. if(NOT curl_cv_func_send_done)
  99. unset(curl_cv_func_send_test CACHE)
  100. check_c_source_compiles("
  101. ${_source_epilogue}
  102. extern ${send_retv} ${signature_call_conv}
  103. send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4});
  104. int main(void) {
  105. ${send_arg1} s=0;
  106. ${send_arg2} buf=0;
  107. ${send_arg3} len=0;
  108. ${send_arg4} flags=0;
  109. ${send_retv} res = send(s, buf, len, flags);
  110. (void) res;
  111. return 0;
  112. }"
  113. curl_cv_func_send_test)
  114. message(STATUS
  115. "Tested: ${send_retv} send(${send_arg1}, ${send_arg2}, ${send_arg3}, ${send_arg4})")
  116. if(curl_cv_func_send_test)
  117. string(REGEX REPLACE "(const) .*" "\\1" send_qual_arg2 "${send_arg2}")
  118. string(REGEX REPLACE "const (.*)" "\\1" send_arg2 "${send_arg2}")
  119. set(curl_cv_func_send_args
  120. "${send_arg1},${send_arg2},${send_arg3},${send_arg4},${send_retv},${send_qual_arg2}")
  121. set(SEND_TYPE_ARG1 "${send_arg1}")
  122. set(SEND_TYPE_ARG2 "${send_arg2}")
  123. set(SEND_TYPE_ARG3 "${send_arg3}")
  124. set(SEND_TYPE_ARG4 "${send_arg4}")
  125. set(SEND_TYPE_RETV "${send_retv}")
  126. set(HAVE_SEND 1)
  127. set(curl_cv_func_send_done 1)
  128. endif(curl_cv_func_send_test)
  129. endif(NOT curl_cv_func_send_done)
  130. endforeach(send_arg4)
  131. endforeach(send_arg3)
  132. endforeach(send_arg2)
  133. endforeach(send_arg1)
  134. endforeach(send_retv)
  135. else()
  136. string(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG1 "${curl_cv_func_send_args}")
  137. string(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG2 "${curl_cv_func_send_args}")
  138. string(REGEX REPLACE "^[^,]*,[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG3 "${curl_cv_func_send_args}")
  139. string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,([^,]*),[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG4 "${curl_cv_func_send_args}")
  140. string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,([^,]*),[^,]*$" "\\1" SEND_TYPE_RETV "${curl_cv_func_send_args}")
  141. string(REGEX REPLACE "^[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,([^,]*)$" "\\1" SEND_QUAL_ARG2 "${curl_cv_func_send_args}")
  142. endif()
  143. if("${curl_cv_func_send_args}" STREQUAL "unknown")
  144. message(FATAL_ERROR "Cannot find proper types to use for send args")
  145. endif("${curl_cv_func_send_args}" STREQUAL "unknown")
  146. set(SEND_QUAL_ARG2 "const")
  147. else(curl_cv_send)
  148. message(FATAL_ERROR "Unable to link function send")
  149. endif(curl_cv_send)
  150. set(curl_cv_func_send_args "${curl_cv_func_send_args}" CACHE INTERNAL "Arguments for send")
  151. set(HAVE_SEND 1)
  152. check_c_source_compiles("${_source_epilogue}
  153. int main(void) {
  154. int flag = MSG_NOSIGNAL;
  155. (void)flag;
  156. return 0;
  157. }" HAVE_MSG_NOSIGNAL)
  158. if(NOT HAVE_WINDOWS_H)
  159. add_header_include(HAVE_SYS_TIME_H "sys/time.h")
  160. add_header_include(TIME_WITH_SYS_TIME "time.h")
  161. add_header_include(HAVE_TIME_H "time.h")
  162. endif()
  163. check_c_source_compiles("${_source_epilogue}
  164. int main(void) {
  165. struct timeval ts;
  166. ts.tv_sec = 0;
  167. ts.tv_usec = 0;
  168. (void)ts;
  169. return 0;
  170. }" HAVE_STRUCT_TIMEVAL)
  171. include(CheckCSourceRuns)
  172. set(CMAKE_REQUIRED_FLAGS)
  173. if(HAVE_SYS_POLL_H)
  174. set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
  175. endif(HAVE_SYS_POLL_H)
  176. check_c_source_runs("
  177. #ifdef HAVE_SYS_POLL_H
  178. # include <sys/poll.h>
  179. #endif
  180. int main(void) {
  181. return poll((void *)0, 0, 10 /*ms*/);
  182. }" HAVE_POLL_FINE)
  183. set(HAVE_SIG_ATOMIC_T 1)
  184. set(CMAKE_REQUIRED_FLAGS)
  185. if(HAVE_SIGNAL_H)
  186. set(CMAKE_REQUIRED_FLAGS "-DHAVE_SIGNAL_H")
  187. set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
  188. endif(HAVE_SIGNAL_H)
  189. check_type_size("sig_atomic_t" SIZEOF_SIG_ATOMIC_T)
  190. if(HAVE_SIZEOF_SIG_ATOMIC_T)
  191. check_c_source_compiles("
  192. #ifdef HAVE_SIGNAL_H
  193. # include <signal.h>
  194. #endif
  195. int main(void) {
  196. static volatile sig_atomic_t dummy = 0;
  197. (void)dummy;
  198. return 0;
  199. }" HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
  200. if(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
  201. set(HAVE_SIG_ATOMIC_T_VOLATILE 1)
  202. endif(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
  203. endif(HAVE_SIZEOF_SIG_ATOMIC_T)
  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(HAVE_SYS_SOCKET_H)
  211. endif()
  212. check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
  213. if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
  214. set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
  215. endif(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)