2
0

OtherTests.cmake 4.7 KB

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