Home | History | Annotate | Download | only in CMake
      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(${check})
      9 endmacro(add_header_include)
     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(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 
     27 check_c_source_compiles("${_source_epilogue}
     28 int main(void) {
     29     recv(0, 0, 0, 0);
     30     return 0;
     31 }" curl_cv_recv)
     32 if(curl_cv_recv)
     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)
     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) {
     46                     ${recv_arg1} s=0;
     47                     ${recv_arg2} buf=0;
     48                     ${recv_arg3} len=0;
     49                     ${recv_arg4} flags=0;
     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})")
     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)
     74   else()
     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}")
     80   endif()
     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 
     91 check_c_source_compiles("${_source_epilogue}
     92 int main(void) {
     93     send(0, 0, 0, 0);
     94     return 0;
     95 }" curl_cv_send)
     96 if(curl_cv_send)
     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)
    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) {
    110                     ${send_arg1} s=0;
    111                     ${send_arg2} buf=0;
    112                     ${send_arg3} len=0;
    113                     ${send_arg4} flags=0;
    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})")
    121                 if(curl_cv_func_send_test)
    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)
    140   else()
    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}")
    147   endif()
    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 
    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)
    165 
    166 if(NOT HAVE_WINDOWS_H)
    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")
    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)
    179 
    180 
    181 include(CheckCSourceRuns)
    182 set(CMAKE_REQUIRED_FLAGS)
    183 if(HAVE_SYS_POLL_H)
    184   set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
    185 endif(HAVE_SYS_POLL_H)
    186 check_c_source_runs("
    187   #ifdef HAVE_SYS_POLL_H
    188   #  include <sys/poll.h>
    189   #endif
    190   int main(void) {
    191     return poll((void *)0, 0, 10 /*ms*/);
    192   }" HAVE_POLL_FINE)
    193 
    194 set(HAVE_SIG_ATOMIC_T 1)
    195 set(CMAKE_REQUIRED_FLAGS)
    196 if(HAVE_SIGNAL_H)
    197   set(CMAKE_REQUIRED_FLAGS "-DHAVE_SIGNAL_H")
    198   set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
    199 endif(HAVE_SIGNAL_H)
    200 check_type_size("sig_atomic_t" SIZEOF_SIG_ATOMIC_T)
    201 if(HAVE_SIZEOF_SIG_ATOMIC_T)
    202   check_c_source_compiles("
    203     #ifdef HAVE_SIGNAL_H
    204     #  include <signal.h>
    205     #endif
    206     int main(void) {
    207       static volatile sig_atomic_t dummy = 0;
    208       (void)dummy;
    209       return 0;
    210     }" HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
    211   if(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
    212     set(HAVE_SIG_ATOMIC_T_VOLATILE 1)
    213   endif(NOT HAVE_SIG_ATOMIC_T_NOT_VOLATILE)
    214 endif(HAVE_SIZEOF_SIG_ATOMIC_T)
    215 
    216 if(HAVE_WINDOWS_H)
    217   set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
    218 else()
    219   set(CMAKE_EXTRA_INCLUDE_FILES)
    220   if(HAVE_SYS_SOCKET_H)
    221     set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
    222   endif(HAVE_SYS_SOCKET_H)
    223 endif()
    224 
    225 check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
    226 if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
    227   set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
    228 endif(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
    229 
    230