cmake/Utilities/cmcurl/CMake/OtherTests.cmake

137 lines
3.9 KiB
CMake
Raw Normal View History

2020-08-30 11:54:41 +02:00
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
2023-07-02 19:51:09 +02:00
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
2020-08-30 11:54:41 +02:00
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
2021-09-14 00:13:48 +02:00
# are also available at https://curl.se/docs/copyright.html.
2020-08-30 11:54:41 +02:00
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
2022-11-16 20:14:03 +01:00
# SPDX-License-Identifier: curl
#
2020-08-30 11:54:41 +02:00
###########################################################################
2015-11-17 17:22:37 +01:00
include(CheckCSourceCompiles)
# The begin of the sources (macros and includes)
set(_source_epilogue "#undef inline")
2015-04-27 22:25:09 +02:00
macro(add_header_include check header)
if(${check})
2015-11-17 17:22:37 +01:00
set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
2018-10-28 12:09:07 +01:00
endif()
endmacro()
2015-04-27 22:25:09 +02:00
set(signature_call_conv)
if(HAVE_WINDOWS_H)
add_header_include(HAVE_WINSOCK2_H "winsock2.h")
2016-09-11 17:22:32 +02:00
add_header_include(HAVE_WINDOWS_H "windows.h")
2015-11-17 17:22:37 +01:00
set(_source_epilogue
"${_source_epilogue}\n#ifndef WIN32_LEAN_AND_MEAN\n#define WIN32_LEAN_AND_MEAN\n#endif")
2015-04-27 22:25:09 +02:00
set(signature_call_conv "PASCAL")
if(HAVE_LIBWS2_32)
set(CMAKE_REQUIRED_LIBRARIES ws2_32)
endif()
2018-10-28 12:09:07 +01:00
else()
add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
2018-10-28 12:09:07 +01:00
endif()
2019-11-11 23:01:05 +01:00
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
2015-11-17 17:22:37 +01:00
check_c_source_compiles("${_source_epilogue}
int main(void) {
int flag = MSG_NOSIGNAL;
(void)flag;
return 0;
}" HAVE_MSG_NOSIGNAL)
2015-04-27 22:25:09 +02:00
2015-11-17 17:22:37 +01:00
if(NOT HAVE_WINDOWS_H)
add_header_include(HAVE_SYS_TIME_H "sys/time.h")
add_header_include(TIME_WITH_SYS_TIME "time.h")
add_header_include(HAVE_TIME_H "time.h")
2015-11-17 17:22:37 +01:00
endif()
check_c_source_compiles("${_source_epilogue}
int main(void) {
struct timeval ts;
ts.tv_sec = 0;
ts.tv_usec = 0;
(void)ts;
return 0;
}" HAVE_STRUCT_TIMEVAL)
2015-04-27 22:25:09 +02:00
if(HAVE_WINDOWS_H)
2015-11-17 17:22:37 +01:00
set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
else()
set(CMAKE_EXTRA_INCLUDE_FILES)
2015-04-27 22:25:09 +02:00
if(HAVE_SYS_SOCKET_H)
2015-11-17 17:22:37 +01:00
set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
2018-10-28 12:09:07 +01:00
endif()
2015-11-17 17:22:37 +01:00
endif()
2015-04-27 22:25:09 +02:00
check_type_size("struct sockaddr_storage" SIZEOF_STRUCT_SOCKADDR_STORAGE)
if(HAVE_SIZEOF_STRUCT_SOCKADDR_STORAGE)
set(HAVE_STRUCT_SOCKADDR_STORAGE 1)
2018-10-28 12:09:07 +01:00
endif()
2019-11-11 23:01:05 +01:00
unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
2023-05-23 16:38:00 +02:00
if(NOT CMAKE_CROSSCOMPILING)
2022-08-04 22:12:04 +02:00
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "iOS")
2023-05-23 16:38:00 +02:00
# only try this on non-apple platforms
# if not cross-compilation...
include(CheckCSourceRuns)
set(CMAKE_REQUIRED_FLAGS "")
if(HAVE_SYS_POLL_H)
set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
elseif(HAVE_POLL_H)
set(CMAKE_REQUIRED_FLAGS "-DHAVE_POLL_H")
endif()
check_c_source_runs("
#include <stdlib.h>
#include <sys/time.h>
#ifdef HAVE_SYS_POLL_H
# include <sys/poll.h>
#elif HAVE_POLL_H
# include <poll.h>
#endif
int main(void)
{
if(0 != poll(0, 0, 10)) {
return 1; /* fail */
}
else {
/* detect the 10.12 poll() breakage */
struct timeval before, after;
int rc;
size_t us;
gettimeofday(&before, NULL);
rc = poll(NULL, 0, 500);
gettimeofday(&after, NULL);
us = (after.tv_sec - before.tv_sec) * 1000000 +
(after.tv_usec - before.tv_usec);
if(us < 400000) {
return 1;
}
2019-11-11 23:01:05 +01:00
}
2023-05-23 16:38:00 +02:00
return 0;
2019-11-11 23:01:05 +01:00
}" HAVE_POLL_FINE)
2021-11-20 13:41:27 +01:00
endif()
2019-11-11 23:01:05 +01:00
endif()