2
0

OtherTests.cmake 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. ###########################################################################
  24. include(CheckCSourceCompiles)
  25. include(CheckCSourceRuns)
  26. # The begin of the sources (macros and includes)
  27. set(_source_epilogue "#undef inline")
  28. macro(add_header_include check header)
  29. if(${check})
  30. set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
  31. endif()
  32. endmacro()
  33. set(signature_call_conv)
  34. if(HAVE_WINDOWS_H)
  35. add_header_include(HAVE_WINSOCK2_H "winsock2.h")
  36. add_header_include(HAVE_WINDOWS_H "windows.h")
  37. set(_source_epilogue
  38. "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif")
  39. set(signature_call_conv "PASCAL")
  40. if(WIN32)
  41. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  42. endif()
  43. else()
  44. add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
  45. add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
  46. endif()
  47. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  48. check_c_source_compiles("${_source_epilogue}
  49. int main(void) {
  50. int flag = MSG_NOSIGNAL;
  51. (void)flag;
  52. return 0;
  53. }" HAVE_MSG_NOSIGNAL)
  54. if(NOT HAVE_WINDOWS_H)
  55. add_header_include(HAVE_SYS_TIME_H "sys/time.h")
  56. endif()
  57. check_c_source_compiles("${_source_epilogue}
  58. #include <time.h>
  59. int main(void) {
  60. struct timeval ts;
  61. ts.tv_sec = 0;
  62. ts.tv_usec = 0;
  63. (void)ts;
  64. return 0;
  65. }" HAVE_STRUCT_TIMEVAL)
  66. if(HAVE_WINDOWS_H)
  67. set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
  68. else()
  69. set(CMAKE_EXTRA_INCLUDE_FILES)
  70. if(HAVE_SYS_SOCKET_H)
  71. set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  72. endif()
  73. endif()
  74. check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
  75. if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
  76. set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
  77. endif()
  78. unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
  79. if(NOT CMAKE_CROSSCOMPILING)
  80. if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "iOS")
  81. # only try this on non-apple platforms
  82. # if not cross-compilation...
  83. set(CMAKE_REQUIRED_FLAGS "")
  84. if(HAVE_SYS_POLL_H)
  85. set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
  86. elseif(HAVE_POLL_H)
  87. set(CMAKE_REQUIRED_FLAGS "-DHAVE_POLL_H")
  88. endif()
  89. check_c_source_runs("
  90. #include <stdlib.h>
  91. #include <sys/time.h>
  92. #ifdef HAVE_SYS_POLL_H
  93. # include <sys/poll.h>
  94. #elif HAVE_POLL_H
  95. # include <poll.h>
  96. #endif
  97. int main(void)
  98. {
  99. if(0 != poll(0, 0, 10)) {
  100. return 1; /* fail */
  101. }
  102. else {
  103. /* detect the 10.12 poll() breakage */
  104. struct timeval before, after;
  105. int rc;
  106. size_t us;
  107. gettimeofday(&before, NULL);
  108. rc = poll(NULL, 0, 500);
  109. gettimeofday(&after, NULL);
  110. us = (after.tv_sec - before.tv_sec) * 1000000 +
  111. (after.tv_usec - before.tv_usec);
  112. if(us < 400000) {
  113. return 1;
  114. }
  115. }
  116. return 0;
  117. }" HAVE_POLL_FINE)
  118. endif()
  119. endif()
  120. # Detect HAVE_GETADDRINFO_THREADSAFE
  121. if(WIN32)
  122. set(HAVE_GETADDRINFO_THREADSAFE ${HAVE_GETADDRINFO})
  123. elseif(NOT HAVE_GETADDRINFO)
  124. set(HAVE_GETADDRINFO_THREADSAFE FALSE)
  125. elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
  126. CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
  127. CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
  128. CMAKE_SYSTEM_NAME STREQUAL "HP-UX" OR
  129. CMAKE_SYSTEM_NAME STREQUAL "MidnightBSD" OR
  130. CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
  131. CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  132. set(HAVE_GETADDRINFO_THREADSAFE TRUE)
  133. elseif(CMAKE_SYSTEM_NAME MATCHES "BSD")
  134. set(HAVE_GETADDRINFO_THREADSAFE FALSE)
  135. endif()
  136. if(NOT DEFINED HAVE_GETADDRINFO_THREADSAFE)
  137. set(_save_epilogue "${_source_epilogue}")
  138. set(_source_epilogue "#undef inline")
  139. add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
  140. add_header_include(HAVE_SYS_TIME_H "sys/time.h")
  141. add_header_include(HAVE_NETDB_H "netdb.h")
  142. check_c_source_compiles("${_source_epilogue}
  143. int main(void)
  144. {
  145. #ifdef h_errno
  146. return 0;
  147. #else
  148. force compilation error
  149. #endif
  150. }" HAVE_H_ERRNO)
  151. if(NOT HAVE_H_ERRNO)
  152. check_c_source_compiles("${_source_epilogue}
  153. int main(void)
  154. {
  155. h_errno = 2;
  156. return h_errno != 0 ? 1 : 0;
  157. }" HAVE_H_ERRNO_ASSIGNABLE)
  158. if(NOT HAVE_H_ERRNO_ASSIGNABLE)
  159. check_c_source_compiles("${_source_epilogue}
  160. int main(void)
  161. {
  162. #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
  163. return 0;
  164. #elif defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 700)
  165. return 0;
  166. #else
  167. force compilation error
  168. #endif
  169. }" HAVE_H_ERRNO_SBS_ISSUE_7)
  170. endif()
  171. endif()
  172. if(HAVE_H_ERRNO OR HAVE_H_ERRNO_ASSIGNABLE OR HAVE_H_ERRNO_SBS_ISSUE_7)
  173. set(HAVE_GETADDRINFO_THREADSAFE TRUE)
  174. endif()
  175. set(_source_epilogue "${_save_epilogue}")
  176. endif()
  177. if(NOT DEFINED HAVE_CLOCK_GETTIME_MONOTONIC_RAW)
  178. set(_save_epilogue "${_source_epilogue}")
  179. set(_source_epilogue "#undef inline")
  180. add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
  181. add_header_include(HAVE_SYS_TIME_H "sys/time.h")
  182. check_c_source_compiles("${_source_epilogue}
  183. #include <time.h>
  184. int main(void)
  185. {
  186. struct timespec ts;
  187. (void)clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
  188. return 0;
  189. }" HAVE_CLOCK_GETTIME_MONOTONIC_RAW)
  190. set(_source_epilogue "${_save_epilogue}")
  191. endif()