OtherTests.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. include(CheckTypeSize)
  27. macro(add_header_include _check _header)
  28. if(${_check})
  29. set(_source_epilogue "${_source_epilogue}
  30. #include <${_header}>")
  31. endif()
  32. endmacro()
  33. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  34. if(NOT DEFINED HAVE_STRUCT_SOCKADDR_STORAGE)
  35. unset(CMAKE_EXTRA_INCLUDE_FILES)
  36. if(WIN32)
  37. set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h")
  38. set(CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN")
  39. set(CMAKE_REQUIRED_LIBRARIES "ws2_32")
  40. elseif(HAVE_SYS_SOCKET_H)
  41. set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
  42. endif()
  43. check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
  44. set(HAVE_STRUCT_SOCKADDR_STORAGE ${HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE})
  45. set(CMAKE_EXTRA_INCLUDE_FILES "")
  46. endif()
  47. if(NOT WIN32)
  48. set(_source_epilogue "#undef inline")
  49. add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
  50. add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
  51. check_c_source_compiles("${_source_epilogue}
  52. int main(void)
  53. {
  54. int flag = MSG_NOSIGNAL;
  55. (void)flag;
  56. return 0;
  57. }" HAVE_MSG_NOSIGNAL)
  58. endif()
  59. set(_source_epilogue "#undef inline")
  60. add_header_include(HAVE_SYS_TIME_H "sys/time.h")
  61. check_c_source_compiles("${_source_epilogue}
  62. #include <time.h>
  63. int main(void)
  64. {
  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. unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
  72. # Detect HAVE_GETADDRINFO_THREADSAFE
  73. if(WIN32)
  74. set(HAVE_GETADDRINFO_THREADSAFE ${HAVE_GETADDRINFO})
  75. elseif(NOT HAVE_GETADDRINFO)
  76. set(HAVE_GETADDRINFO_THREADSAFE FALSE)
  77. elseif(APPLE OR
  78. CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
  79. CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
  80. CMAKE_SYSTEM_NAME STREQUAL "HP-UX" OR
  81. CMAKE_SYSTEM_NAME STREQUAL "MidnightBSD" OR
  82. CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
  83. CMAKE_SYSTEM_NAME STREQUAL "SunOS")
  84. set(HAVE_GETADDRINFO_THREADSAFE TRUE)
  85. elseif(CMAKE_SYSTEM_NAME MATCHES "BSD")
  86. set(HAVE_GETADDRINFO_THREADSAFE FALSE)
  87. endif()
  88. if(NOT DEFINED HAVE_GETADDRINFO_THREADSAFE)
  89. set(_source_epilogue "#undef inline")
  90. add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
  91. add_header_include(HAVE_SYS_TIME_H "sys/time.h")
  92. add_header_include(HAVE_NETDB_H "netdb.h")
  93. check_c_source_compiles("${_source_epilogue}
  94. int main(void)
  95. {
  96. #ifdef h_errno
  97. return 0;
  98. #else
  99. #error force compilation error
  100. #endif
  101. }" HAVE_H_ERRNO)
  102. if(NOT HAVE_H_ERRNO)
  103. check_c_source_compiles("${_source_epilogue}
  104. int main(void)
  105. {
  106. h_errno = 2;
  107. return h_errno != 0 ? 1 : 0;
  108. }" HAVE_H_ERRNO_ASSIGNABLE)
  109. if(NOT HAVE_H_ERRNO_ASSIGNABLE)
  110. check_c_source_compiles("${_source_epilogue}
  111. int main(void)
  112. {
  113. #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
  114. return 0;
  115. #elif defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 700)
  116. return 0;
  117. #else
  118. #error force compilation error
  119. #endif
  120. }" HAVE_H_ERRNO_SBS_ISSUE_7)
  121. endif()
  122. endif()
  123. if(HAVE_H_ERRNO OR HAVE_H_ERRNO_ASSIGNABLE OR HAVE_H_ERRNO_SBS_ISSUE_7)
  124. set(HAVE_GETADDRINFO_THREADSAFE TRUE)
  125. endif()
  126. endif()
  127. if(NOT WIN32 AND NOT DEFINED HAVE_CLOCK_GETTIME_MONOTONIC_RAW)
  128. set(_source_epilogue "#undef inline")
  129. add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
  130. add_header_include(HAVE_SYS_TIME_H "sys/time.h")
  131. check_c_source_compiles("${_source_epilogue}
  132. #include <time.h>
  133. int main(void)
  134. {
  135. struct timespec ts;
  136. (void)clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
  137. return 0;
  138. }" HAVE_CLOCK_GETTIME_MONOTONIC_RAW)
  139. endif()