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