• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24include(CheckCSourceCompiles)
25# The begin of the sources (macros and includes)
26set(_source_epilogue "#undef inline")
27
28macro(add_header_include check header)
29  if(${check})
30    set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
31  endif()
32endmacro()
33
34set(signature_call_conv)
35if(HAVE_WINDOWS_H)
36  add_header_include(HAVE_WINSOCK2_H "winsock2.h")
37  add_header_include(HAVE_WINDOWS_H "windows.h")
38  set(_source_epilogue
39      "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif")
40  set(signature_call_conv "PASCAL")
41  if(HAVE_LIBWS2_32)
42    set(CMAKE_REQUIRED_LIBRARIES ws2_32)
43  endif()
44else()
45  add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
46  add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
47endif()
48
49set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
50
51check_c_source_compiles("${_source_epilogue}
52  int main(void) {
53    int flag = MSG_NOSIGNAL;
54    (void)flag;
55    return 0;
56  }" HAVE_MSG_NOSIGNAL)
57
58if(NOT HAVE_WINDOWS_H)
59  add_header_include(HAVE_SYS_TIME_H "sys/time.h")
60  add_header_include(TIME_WITH_SYS_TIME "time.h")
61  add_header_include(HAVE_TIME_H "time.h")
62endif()
63check_c_source_compiles("${_source_epilogue}
64int main(void) {
65  struct timeval ts;
66  ts.tv_sec  = 0;
67  ts.tv_usec = 0;
68  (void)ts;
69  return 0;
70}" HAVE_STRUCT_TIMEVAL)
71
72if(HAVE_WINDOWS_H)
73  set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
74else()
75  set(CMAKE_EXTRA_INCLUDE_FILES)
76  if(HAVE_SYS_SOCKET_H)
77    set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
78  endif()
79endif()
80
81check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
82if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
83  set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
84endif()
85
86unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
87
88if(NOT CMAKE_CROSSCOMPILING)
89  if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "iOS")
90    # only try this on non-apple platforms
91
92    # if not cross-compilation...
93    include(CheckCSourceRuns)
94    set(CMAKE_REQUIRED_FLAGS "")
95    if(HAVE_SYS_POLL_H)
96      set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
97    elseif(HAVE_POLL_H)
98      set(CMAKE_REQUIRED_FLAGS "-DHAVE_POLL_H")
99    endif()
100    check_c_source_runs("
101      #include <stdlib.h>
102      #include <sys/time.h>
103
104      #ifdef HAVE_SYS_POLL_H
105      #  include <sys/poll.h>
106      #elif  HAVE_POLL_H
107      #  include <poll.h>
108      #endif
109
110      int main(void)
111      {
112          if(0 != poll(0, 0, 10)) {
113            return 1; /* fail */
114          }
115          else {
116            /* detect the 10.12 poll() breakage */
117            struct timeval before, after;
118            int rc;
119            size_t us;
120
121            gettimeofday(&before, NULL);
122            rc = poll(NULL, 0, 500);
123            gettimeofday(&after, NULL);
124
125            us = (after.tv_sec - before.tv_sec) * 1000000 +
126              (after.tv_usec - before.tv_usec);
127
128            if(us < 400000) {
129              return 1;
130            }
131          }
132          return 0;
133    }" HAVE_POLL_FINE)
134  endif()
135endif()
136
137