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