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