OtherTests.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. # The begin of the sources (macros and includes)
  26. set(_source_epilogue "#undef inline")
  27. macro(add_header_include check header)
  28. if(${check})
  29. set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
  30. endif()
  31. endmacro()
  32. set(signature_call_conv)
  33. if(HAVE_WINDOWS_H)
  34. add_header_include(HAVE_WINSOCK2_H "winsock2.h")
  35. add_header_include(HAVE_WINDOWS_H "windows.h")
  36. set(_source_epilogue
  37. "${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif")
  38. set(signature_call_conv "PASCAL")
  39. if(HAVE_LIBWS2_32)
  40. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  41. endif()
  42. else()
  43. add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
  44. add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
  45. endif()
  46. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  47. check_c_source_compiles("${_source_epilogue}
  48. int main(void) {
  49. int flag = MSG_NOSIGNAL;
  50. (void)flag;
  51. return 0;
  52. }" HAVE_MSG_NOSIGNAL)
  53. if(NOT HAVE_WINDOWS_H)
  54. add_header_include(HAVE_SYS_TIME_H "sys/time.h")
  55. add_header_include(TIME_WITH_SYS_TIME "time.h")
  56. add_header_include(HAVE_TIME_H "time.h")
  57. endif()
  58. check_c_source_compiles("${_source_epilogue}
  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. include(CheckCSourceRuns)
  84. set(CMAKE_REQUIRED_FLAGS "")
  85. if(HAVE_SYS_POLL_H)
  86. set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
  87. elseif(HAVE_POLL_H)
  88. set(CMAKE_REQUIRED_FLAGS "-DHAVE_POLL_H")
  89. endif()
  90. check_c_source_runs("
  91. #include <stdlib.h>
  92. #include <sys/time.h>
  93. #ifdef HAVE_SYS_POLL_H
  94. # include <sys/poll.h>
  95. #elif HAVE_POLL_H
  96. # include <poll.h>
  97. #endif
  98. int main(void)
  99. {
  100. if(0 != poll(0, 0, 10)) {
  101. return 1; /* fail */
  102. }
  103. else {
  104. /* detect the 10.12 poll() breakage */
  105. struct timeval before, after;
  106. int rc;
  107. size_t us;
  108. gettimeofday(&before, NULL);
  109. rc = poll(NULL, 0, 500);
  110. gettimeofday(&after, NULL);
  111. us = (after.tv_sec - before.tv_sec) * 1000000 +
  112. (after.tv_usec - before.tv_usec);
  113. if(us < 400000) {
  114. return 1;
  115. }
  116. }
  117. return 0;
  118. }" HAVE_POLL_FINE)
  119. endif()
  120. endif()