OtherTests.cmake 11 KB

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