11cb0ef41Sopenharmony_ci# Copyright (C) The c-ares project and its contributors
21cb0ef41Sopenharmony_ci# SPDX-License-Identifier: MIT
31cb0ef41Sopenharmony_ciCMAKE_MINIMUM_REQUIRED (VERSION 3.5.0)
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_cilist(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciINCLUDE (CheckIncludeFiles)
81cb0ef41Sopenharmony_ciINCLUDE (CheckTypeSize)
91cb0ef41Sopenharmony_ciINCLUDE (CheckFunctionExists)
101cb0ef41Sopenharmony_ciINCLUDE (CheckSymbolExists)
111cb0ef41Sopenharmony_ciINCLUDE (CheckCSourceCompiles)
121cb0ef41Sopenharmony_ciINCLUDE (CheckStructHasMember)
131cb0ef41Sopenharmony_ciINCLUDE (CheckLibraryExists)
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciPROJECT (c-ares LANGUAGES C VERSION "1.27.0" )
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci# Set this version before release
181cb0ef41Sopenharmony_ciSET (CARES_VERSION "1.27.0")
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciINCLUDE (GNUInstallDirs) # include this *AFTER* PROJECT(), otherwise paths are wrong.
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci# This is for libtool compatibility, and specified in a form that is easily
231cb0ef41Sopenharmony_ci# translatable from libtool (even if the actual form doesn't make sense).
241cb0ef41Sopenharmony_ci# For instance, in an autotools project, in Makefile.am there is a line that
251cb0ef41Sopenharmony_ci# contains something like:
261cb0ef41Sopenharmony_ci#     -version-info 4:0:2
271cb0ef41Sopenharmony_ci# This breaks down into sections of current:revision:age
281cb0ef41Sopenharmony_ci# This then generates a version of  "(current-age).age.revision"  with an
291cb0ef41Sopenharmony_ci# interface version of "(current-age)"
301cb0ef41Sopenharmony_ci# For example, a version of 4:0:2 would generate output such as:
311cb0ef41Sopenharmony_ci#    libname.so   -> libname.so.2
321cb0ef41Sopenharmony_ci#    libname.so.2 -> libname.so.2.2.0
331cb0ef41Sopenharmony_ciSET (CARES_LIB_VERSIONINFO "14:0:12")
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ciOPTION (CARES_STATIC        "Build as a static library"                                             OFF)
371cb0ef41Sopenharmony_ciOPTION (CARES_SHARED        "Build as a shared library"                                             ON)
381cb0ef41Sopenharmony_ciOPTION (CARES_INSTALL       "Create installation targets (chain builders may want to disable this)" ON)
391cb0ef41Sopenharmony_ciOPTION (CARES_STATIC_PIC    "Build the static library as PIC (position independent)"                OFF)
401cb0ef41Sopenharmony_ciOPTION (CARES_BUILD_TESTS   "Build and run tests"                                                   OFF)
411cb0ef41Sopenharmony_ciOPTION (CARES_BUILD_CONTAINER_TESTS "Build and run container tests (implies CARES_BUILD_TESTS, Linux only)" OFF)
421cb0ef41Sopenharmony_ciOPTION (CARES_BUILD_TOOLS   "Build tools"                                                           ON)
431cb0ef41Sopenharmony_ciOPTION (CARES_SYMBOL_HIDING "Hide private symbols in shared libraries"                              OFF)
441cb0ef41Sopenharmony_ciOPTION (CARES_THREADS       "Build with thread-safety support"                                      ON)
451cb0ef41Sopenharmony_ciSET    (CARES_RANDOM_FILE "/dev/urandom" CACHE STRING "Suitable File / Device Path for entropy, such as /dev/urandom")
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci# Tests require a C++14 compiler
491cb0ef41Sopenharmony_ciIF (CARES_BUILD_TESTS OR CARES_BUILD_CONTAINER_TESTS)
501cb0ef41Sopenharmony_ci	set(CMAKE_CXX_STANDARD 14)
511cb0ef41Sopenharmony_ci	set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
521cb0ef41Sopenharmony_ci	set(CMAKE_CXX_EXTENSIONS FALSE)
531cb0ef41Sopenharmony_ci	enable_language(CXX)
541cb0ef41Sopenharmony_ciENDIF ()
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci# Tests require static to be enabled on Windows to be able to access otherwise hidden symbols
571cb0ef41Sopenharmony_ciIF ((CARES_BUILD_TESTS OR CARES_BUILD_CONTAINER_TESTS) AND (NOT CARES_STATIC) AND WIN32)
581cb0ef41Sopenharmony_ci	SET (CARES_STATIC ON)
591cb0ef41Sopenharmony_ci	SET (CARES_STATIC_PIC ON)
601cb0ef41Sopenharmony_ci	MESSAGE (WARNING "Static building was requested be disabled, but re-enabled to support tests")
611cb0ef41Sopenharmony_ciENDIF ()
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ciINCLUDE (EnableWarnings)
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci# allow linking against the static runtime library in msvc
661cb0ef41Sopenharmony_ciIF (MSVC)
671cb0ef41Sopenharmony_ci	OPTION (CARES_MSVC_STATIC_RUNTIME "Link against the static runtime library" OFF)
681cb0ef41Sopenharmony_ci	IF (CARES_MSVC_STATIC_RUNTIME)
691cb0ef41Sopenharmony_ci		# CMAKE_CONFIGURATION_TYPES is empty on non-IDE generators (Ninja, NMake)
701cb0ef41Sopenharmony_ci		# and that's why we also use CMAKE_BUILD_TYPE to cover for those generators.
711cb0ef41Sopenharmony_ci		# For IDE generators, CMAKE_BUILD_TYPE is usually empty
721cb0ef41Sopenharmony_ci		FOREACH (config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
731cb0ef41Sopenharmony_ci			STRING (TOUPPER ${config_type} upper_config_type)
741cb0ef41Sopenharmony_ci			SET (flag_var "CMAKE_C_FLAGS_${upper_config_type}")
751cb0ef41Sopenharmony_ci			IF (${flag_var} MATCHES "/MD")
761cb0ef41Sopenharmony_ci				STRING (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
771cb0ef41Sopenharmony_ci			ENDIF ()
781cb0ef41Sopenharmony_ci		ENDFOREACH ()
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci		# clean up
811cb0ef41Sopenharmony_ci		SET (upper_config_type)
821cb0ef41Sopenharmony_ci		SET (config_type)
831cb0ef41Sopenharmony_ci		SET (flag_var)
841cb0ef41Sopenharmony_ci	ENDIF ()
851cb0ef41Sopenharmony_ciENDIF ()
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ciIF (CARES_SYMBOL_HIDING)
881cb0ef41Sopenharmony_ci	IF (CMAKE_VERSION VERSION_LESS 3.12)
891cb0ef41Sopenharmony_ci		MESSAGE (FATAL_ERROR "Hiding symbols requires CMake 3.12")
901cb0ef41Sopenharmony_ci	ENDIF ()
911cb0ef41Sopenharmony_ci	CMAKE_POLICY (SET CMP0063 NEW)
921cb0ef41Sopenharmony_ciENDIF ()
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci# Keep build organized, but only if it is the top-level project.
951cb0ef41Sopenharmony_ci# CMake 3.21 or later has PROJECT_IS_TOP_LEVEL, but we aren't yet depending on
961cb0ef41Sopenharmony_ci# that version.
971cb0ef41Sopenharmony_ciIF (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
981cb0ef41Sopenharmony_ci	SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
991cb0ef41Sopenharmony_ci	SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
1001cb0ef41Sopenharmony_ci	SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
1011cb0ef41Sopenharmony_ci	SET (PACKAGE_DIRECTORY ${PROJECT_BINARY_DIR}/package)
1021cb0ef41Sopenharmony_ciENDIF ()
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci# Destinations for installing different kinds of targets (pass to install command).
1051cb0ef41Sopenharmony_ciSET (TARGETS_INST_DEST
1061cb0ef41Sopenharmony_ci	RUNTIME DESTINATION  ${CMAKE_INSTALL_BINDIR}
1071cb0ef41Sopenharmony_ci	BUNDLE DESTINATION   ${CMAKE_INSTALL_BINDIR}
1081cb0ef41Sopenharmony_ci	LIBRARY DESTINATION  ${CMAKE_INSTALL_LIBDIR}
1091cb0ef41Sopenharmony_ci	ARCHIVE DESTINATION  ${CMAKE_INSTALL_LIBDIR}
1101cb0ef41Sopenharmony_ci)
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci# Function in Library
1131cb0ef41Sopenharmony_ci# CHECK_LIBRARY_EXISTS can't be used as it will return true if the function
1141cb0ef41Sopenharmony_ci# is found in a different required/dependent library.
1151cb0ef41Sopenharmony_ciMACRO (CARES_FUNCTION_IN_LIBRARY func lib var)
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci	SET (_ORIG_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
1181cb0ef41Sopenharmony_ci	SET (CMAKE_REQUIRED_LIBRARIES )
1191cb0ef41Sopenharmony_ci	CHECK_FUNCTION_EXISTS ("${func}" "_CARES_FUNC_IN_LIB_GLOBAL_${func}")
1201cb0ef41Sopenharmony_ci	SET (CMAKE_REQUIRED_LIBRARIES "${_ORIG_CMAKE_REQUIRED_LIBRARIES}")
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci	IF ("${_CARES_FUNC_IN_LIB_GLOBAL_${func}}")
1231cb0ef41Sopenharmony_ci		SET (${var} FALSE)
1241cb0ef41Sopenharmony_ci	ELSE ()
1251cb0ef41Sopenharmony_ci		CHECK_LIBRARY_EXISTS ("${lib}" "${func}" "" ${var})
1261cb0ef41Sopenharmony_ci	ENDIF ()
1271cb0ef41Sopenharmony_ciENDMACRO ()
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci# Look for dependent/required libraries
1301cb0ef41Sopenharmony_ciCARES_FUNCTION_IN_LIBRARY (res_servicename resolv HAVE_RES_SERVICENAME_IN_LIBRESOLV)
1311cb0ef41Sopenharmony_ciIF (HAVE_RES_SERVICENAME_IN_LIBRESOLV)
1321cb0ef41Sopenharmony_ci	SET (HAVE_LIBRESOLV 1)
1331cb0ef41Sopenharmony_ciENDIF ()
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ciIF (APPLE)
1361cb0ef41Sopenharmony_ci	CHECK_C_SOURCE_COMPILES ("
1371cb0ef41Sopenharmony_ci	#include <stdio.h>
1381cb0ef41Sopenharmony_ci	#include <TargetConditionals.h>
1391cb0ef41Sopenharmony_ci	int main() {
1401cb0ef41Sopenharmony_ci#if TARGET_OS_IPHONE == 0
1411cb0ef41Sopenharmony_ci#error Not an iPhone target
1421cb0ef41Sopenharmony_ci#endif
1431cb0ef41Sopenharmony_cireturn 0;
1441cb0ef41Sopenharmony_ci	}
1451cb0ef41Sopenharmony_ci	"
1461cb0ef41Sopenharmony_ci	IOS)
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_ci	CHECK_C_SOURCE_COMPILES ("
1491cb0ef41Sopenharmony_ci#include <stdio.h>
1501cb0ef41Sopenharmony_ci#include <TargetConditionals.h>
1511cb0ef41Sopenharmony_ci	int main() {
1521cb0ef41Sopenharmony_ci#if TARGET_OS_IPHONE == 0 || __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
1531cb0ef41Sopenharmony_ci#  error Not iOS v10
1541cb0ef41Sopenharmony_ci#endif
1551cb0ef41Sopenharmony_cireturn 0;
1561cb0ef41Sopenharmony_ci	}
1571cb0ef41Sopenharmony_ci	"
1581cb0ef41Sopenharmony_ci	IOS_V10)
1591cb0ef41Sopenharmony_ci
1601cb0ef41Sopenharmony_ci	CHECK_C_SOURCE_COMPILES ("
1611cb0ef41Sopenharmony_ci#include <stdio.h>
1621cb0ef41Sopenharmony_ci#include <AvailabilityMacros.h>
1631cb0ef41Sopenharmony_ci#ifndef MAC_OS_X_VERSION_10_12
1641cb0ef41Sopenharmony_ci#  define MAC_OS_X_VERSION_10_12 101200
1651cb0ef41Sopenharmony_ci#endif
1661cb0ef41Sopenharmony_ci	int main() {
1671cb0ef41Sopenharmony_ci#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
1681cb0ef41Sopenharmony_ci#  error Not MacOSX 10.12 or higher
1691cb0ef41Sopenharmony_ci#endif
1701cb0ef41Sopenharmony_cireturn 0;
1711cb0ef41Sopenharmony_ci	}
1721cb0ef41Sopenharmony_ci	"
1731cb0ef41Sopenharmony_ci	MACOS_V1012)
1741cb0ef41Sopenharmony_ciENDIF ()
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ciIF ((IOS OR APPLE OR ZOS) AND HAVE_LIBRESOLV)
1771cb0ef41Sopenharmony_ci	SET (CARES_USE_LIBRESOLV 1)
1781cb0ef41Sopenharmony_ciENDIF()
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_ciCARES_FUNCTION_IN_LIBRARY (gethostbyname nsl HAVE_LIBNSL)
1821cb0ef41Sopenharmony_ciCARES_FUNCTION_IN_LIBRARY (gethostbyname socket HAVE_GHBN_LIBSOCKET)
1831cb0ef41Sopenharmony_ciCARES_FUNCTION_IN_LIBRARY (gethostbyname network HAVE_LIBNETWORK)
1841cb0ef41Sopenharmony_ciCARES_FUNCTION_IN_LIBRARY (socket socket HAVE_SOCKET_LIBSOCKET)
1851cb0ef41Sopenharmony_ciIF (HAVE_GHBN_LIBSOCKET OR HAVE_SOCKET_LIBSOCKET)
1861cb0ef41Sopenharmony_ci	SET(HAVE_LIBSOCKET TRUE)
1871cb0ef41Sopenharmony_ciENDIF ()
1881cb0ef41Sopenharmony_ciCARES_FUNCTION_IN_LIBRARY (socket network HAVE_LIBNETWORK)
1891cb0ef41Sopenharmony_ciCARES_FUNCTION_IN_LIBRARY (clock_gettime rt HAVE_LIBRT)
1901cb0ef41Sopenharmony_ci
1911cb0ef41Sopenharmony_ci
1921cb0ef41Sopenharmony_ci# Look for necessary includes
1931cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (AvailabilityMacros.h  HAVE_AVAILABILITYMACROS_H)
1941cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/types.h           HAVE_SYS_TYPES_H)
1951cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/random.h          HAVE_SYS_RANDOM_H)
1961cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/socket.h          HAVE_SYS_SOCKET_H)
1971cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/sockio.h          HAVE_SYS_SOCKIO_H)
1981cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (arpa/inet.h           HAVE_ARPA_INET_H)
1991cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (arpa/nameser_compat.h HAVE_ARPA_NAMESER_COMPAT_H)
2001cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (arpa/nameser.h        HAVE_ARPA_NAMESER_H)
2011cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (assert.h              HAVE_ASSERT_H)
2021cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (errno.h               HAVE_ERRNO_H)
2031cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (fcntl.h               HAVE_FCNTL_H)
2041cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (inttypes.h            HAVE_INTTYPES_H)
2051cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (limits.h              HAVE_LIMITS_H)
2061cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (malloc.h              HAVE_MALLOC_H)
2071cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (memory.h              HAVE_MEMORY_H)
2081cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (netdb.h               HAVE_NETDB_H)
2091cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (netinet/in.h          HAVE_NETINET_IN_H)
2101cb0ef41Sopenharmony_ci# On old MacOS SDK versions, you must include sys/socket.h before net/if.h
2111cb0ef41Sopenharmony_ciIF (HAVE_SYS_SOCKET_H)
2121cb0ef41Sopenharmony_ci  CHECK_INCLUDE_FILES ("sys/socket.h;net/if.h"  HAVE_NET_IF_H)
2131cb0ef41Sopenharmony_ciELSE ()
2141cb0ef41Sopenharmony_ci  CHECK_INCLUDE_FILES (net/if.h                 HAVE_NET_IF_H)
2151cb0ef41Sopenharmony_ciENDIF ()
2161cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (signal.h              HAVE_SIGNAL_H)
2171cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (socket.h              HAVE_SOCKET_H)
2181cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (stdbool.h             HAVE_STDBOOL_H)
2191cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (stdint.h              HAVE_STDINT_H)
2201cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (stdlib.h              HAVE_STDLIB_H)
2211cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (strings.h             HAVE_STRINGS_H)
2221cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (string.h              HAVE_STRING_H)
2231cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (stropts.h             HAVE_STROPTS_H)
2241cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/ioctl.h           HAVE_SYS_IOCTL_H)
2251cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/param.h           HAVE_SYS_PARAM_H)
2261cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/select.h          HAVE_SYS_SELECT_H)
2271cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/stat.h            HAVE_SYS_STAT_H)
2281cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/time.h            HAVE_SYS_TIME_H)
2291cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/uio.h             HAVE_SYS_UIO_H)
2301cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/random.h          HAVE_SYS_RANDOM_H)
2311cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/event.h           HAVE_SYS_EVENT_H)
2321cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (sys/epoll.h           HAVE_SYS_EPOLL_H)
2331cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (ifaddrs.h             HAVE_IFADDRS_H)
2341cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (time.h                HAVE_TIME_H)
2351cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (poll.h                HAVE_POLL_H)
2361cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (dlfcn.h               HAVE_DLFCN_H)
2371cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (unistd.h              HAVE_UNISTD_H)
2381cb0ef41Sopenharmony_ci# On OpenBSD, you must include sys/types.h before netinet/tcp.h
2391cb0ef41Sopenharmony_ciIF (HAVE_SYS_TYPES_H)
2401cb0ef41Sopenharmony_ci  CHECK_INCLUDE_FILES ("sys/types.h;netinet/tcp.h"         HAVE_NETINET_TCP_H)
2411cb0ef41Sopenharmony_ciELSE ()
2421cb0ef41Sopenharmony_ci  CHECK_INCLUDE_FILES (netinet/tcp.h                       HAVE_NETINET_TCP_H)
2431cb0ef41Sopenharmony_ciENDIF ()
2441cb0ef41Sopenharmony_ci
2451cb0ef41Sopenharmony_ci# Include order matters for these windows files.
2461cb0ef41Sopenharmony_ci# As cygwin environment has both socket.h and winsock2.h
2471cb0ef41Sopenharmony_ci# headers check WIN32 not to include the later one here
2481cb0ef41Sopenharmony_ciIF (WIN32)
2491cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("winsock2.h;windows.h"            HAVE_WINSOCK2_H)
2501cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("winsock2.h;ws2tcpip.h;windows.h" HAVE_WS2TCPIP_H)
2511cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("winsock2.h;iphlpapi.h;windows.h" HAVE_IPHLPAPI_H)
2521cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("winsock2.h;netioapi.h;windows.h" HAVE_NETIOAPI_H)
2531cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("winsock2.h;mswsock.h;windows.h"  HAVE_MSWSOCK_H)
2541cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("winsock.h;windows.h"             HAVE_WINSOCK_H)
2551cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES (windows.h                         HAVE_WINDOWS_H)
2561cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("windows.h;winternl.h"            HAVE_WINTERNL_H)
2571cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("windows.h;ntdef.h"               HAVE_NTDEF_H)
2581cb0ef41Sopenharmony_ciCHECK_INCLUDE_FILES ("windows.h;ntdef.h;ntstatus.h"    HAVE_NTSTATUS_H)
2591cb0ef41Sopenharmony_ci
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_ciENDIF ()
2621cb0ef41Sopenharmony_ci
2631cb0ef41Sopenharmony_ci# Set system-specific compiler flags
2641cb0ef41Sopenharmony_ciIF (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
2651cb0ef41Sopenharmony_ci	LIST (APPEND SYSFLAGS -D_DARWIN_C_SOURCE)
2661cb0ef41Sopenharmony_ciELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
2671cb0ef41Sopenharmony_ci	LIST (APPEND SYSFLAGS -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700)
2681cb0ef41Sopenharmony_ciELSEIF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
2691cb0ef41Sopenharmony_ci	LIST (APPEND SYSFLAGS -D__EXTENSIONS__ -D_REENTRANT -D_XOPEN_SOURCE=700)
2701cb0ef41Sopenharmony_ciELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX")
2711cb0ef41Sopenharmony_ci	LIST (APPEND SYSFLAGS -D_ALL_SOURCE -D_XOPEN_SOURCE=700 -D_USE_IRS)
2721cb0ef41Sopenharmony_ciELSEIF (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
2731cb0ef41Sopenharmony_ci	# Don't define _XOPEN_SOURCE on FreeBSD, it actually reduces visibility instead of increasing it
2741cb0ef41Sopenharmony_ciELSEIF (WIN32)
2751cb0ef41Sopenharmony_ci	LIST (APPEND SYSFLAGS -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_WIN32_WINNT=0x0602)
2761cb0ef41Sopenharmony_ciENDIF ()
2771cb0ef41Sopenharmony_ciADD_DEFINITIONS(${SYSFLAGS})
2781cb0ef41Sopenharmony_ci
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ci# Tell C-Ares about libraries to depend on
2821cb0ef41Sopenharmony_ciIF (HAVE_LIBRESOLV)
2831cb0ef41Sopenharmony_ci	LIST (APPEND CARES_DEPENDENT_LIBS resolv)
2841cb0ef41Sopenharmony_ciENDIF ()
2851cb0ef41Sopenharmony_ciIF (HAVE_LIBNSL)
2861cb0ef41Sopenharmony_ci	LIST (APPEND CARES_DEPENDENT_LIBS nsl)
2871cb0ef41Sopenharmony_ciENDIF ()
2881cb0ef41Sopenharmony_ciIF (HAVE_LIBSOCKET)
2891cb0ef41Sopenharmony_ci	LIST (APPEND CARES_DEPENDENT_LIBS socket)
2901cb0ef41Sopenharmony_ciENDIF ()
2911cb0ef41Sopenharmony_ciIF (HAVE_LIBNETWORK)
2921cb0ef41Sopenharmony_ci	LIST (APPEND CARES_DEPENDENT_LIBS network)
2931cb0ef41Sopenharmony_ciENDIF ()
2941cb0ef41Sopenharmony_ciIF (HAVE_LIBRT)
2951cb0ef41Sopenharmony_ci	LIST (APPEND CARES_DEPENDENT_LIBS rt)
2961cb0ef41Sopenharmony_ciENDIF ()
2971cb0ef41Sopenharmony_ciIF (WIN32)
2981cb0ef41Sopenharmony_ci	LIST (APPEND CARES_DEPENDENT_LIBS ws2_32 advapi32 iphlpapi)
2991cb0ef41Sopenharmony_ciENDIF ()
3001cb0ef41Sopenharmony_ci
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci# When checking for symbols, we need to make sure we set the proper
3031cb0ef41Sopenharmony_ci# headers, libraries, and definitions for the detection to work properly
3041cb0ef41Sopenharmony_ci# CMAKE_REQUIRED_DEFINITIONS, CMAKE_REQUIRED_LIBRARIES, and
3051cb0ef41Sopenharmony_ci# CMAKE_EXTRA_INCLUDE_FILES.  When we're done with the detection, we'll
3061cb0ef41Sopenharmony_ci# unset them.
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ciSET (CMAKE_REQUIRED_DEFINITIONS ${SYSFLAGS})
3091cb0ef41Sopenharmony_ciLIST (APPEND CMAKE_REQUIRED_LIBRARIES ${CARES_DEPENDENT_LIBS})
3101cb0ef41Sopenharmony_ci
3111cb0ef41Sopenharmony_ciMACRO (CARES_EXTRAINCLUDE_IFSET var include)
3121cb0ef41Sopenharmony_ci	IF (${var})
3131cb0ef41Sopenharmony_ci		LIST (APPEND CMAKE_EXTRA_INCLUDE_FILES ${include})
3141cb0ef41Sopenharmony_ci	ENDIF ()
3151cb0ef41Sopenharmony_ciENDMACRO ()
3161cb0ef41Sopenharmony_ci
3171cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_AVAILABILITYMACROS_H AvailabilityMacros.h)
3181cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_STDBOOL_H      stdbool.h)
3191cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_TYPES_H    sys/types.h)
3201cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_ARPA_INET_H    arpa/inet.h)
3211cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_ARPA_NAMESER_H arpa/nameser.h)
3221cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_NETDB_H        netdb.h)
3231cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_NET_IF_H       net/if.h)
3241cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_IFADDRS_H      ifaddrs.h)
3251cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_NETINET_IN_H   netinet/in.h)
3261cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_NETINET_TCP_H  netinet/tcp.h)
3271cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SIGNAL_H       signal.h)
3281cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_STDLIB_H       stdlib.h)
3291cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_STRING_H       string.h)
3301cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_STRINGS_H      strings.h)
3311cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_IOCTL_H    sys/ioctl.h)
3321cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_RANDOM_H   sys/random.h)
3331cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SELECT_H   sys/select.h)
3341cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SOCKET_H   sys/socket.h)
3351cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_SOCKIO_H	sys/sockio.h)
3361cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_TIME_H     sys/time.h)
3371cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_STAT_H     sys/stat.h)
3381cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_UIO_H      sys/uio.h)
3391cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_RANDOM_H   sys/random.h)
3401cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_EVENT_H    sys/event.h)
3411cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_SYS_EPOLL_H    sys/epoll.h)
3421cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_TIME_H         time.h)
3431cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_POLL_H         poll.h)
3441cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_FCNTL_H        fcntl.h)
3451cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_UNISTD_H       unistd.h)
3461cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_WINSOCK2_H     winsock2.h)
3471cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_WS2TCPIP_H     ws2tcpip.h)
3481cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_IPHLPAPI_H     iphlpapi.h)
3491cb0ef41Sopenharmony_ciCARES_EXTRAINCLUDE_IFSET (HAVE_WINDOWS_H      windows.h)
3501cb0ef41Sopenharmony_ci
3511cb0ef41Sopenharmony_ci# Check Types
3521cb0ef41Sopenharmony_ci# CHECK_TYPE_SIZE can't be used to see if a type exists because on Apple when
3531cb0ef41Sopenharmony_ci# building multi-arch, it will throw an error.  So we need to wrap
3541cb0ef41Sopenharmony_ci# CHECK_C_SOURCE_COMPILES for our tests.
3551cb0ef41Sopenharmony_ciMACRO (CARES_TYPE_EXISTS type var)
3561cb0ef41Sopenharmony_ci	SET(_CARES_C_SOURCE "
3571cb0ef41Sopenharmony_ci		#include <stdio.h>
3581cb0ef41Sopenharmony_ci		#include <stdlib.h>
3591cb0ef41Sopenharmony_ci	")
3601cb0ef41Sopenharmony_ci	FOREACH(_C_HEADER ${CMAKE_EXTRA_INCLUDE_FILES})
3611cb0ef41Sopenharmony_ci		SET(_CARES_C_SOURCE "${_CARES_C_SOURCE}
3621cb0ef41Sopenharmony_ci		#include <${_C_HEADER}>")
3631cb0ef41Sopenharmony_ci	ENDFOREACH(_C_HEADER)
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_ci	SET(_CARES_C_SOURCE "${_CARES_C_SOURCE}
3661cb0ef41Sopenharmony_ci		int main() {
3671cb0ef41Sopenharmony_ci			${type} var_exists;
3681cb0ef41Sopenharmony_ci			(void)var_exists;
3691cb0ef41Sopenharmony_ci			return 0;
3701cb0ef41Sopenharmony_ci		}
3711cb0ef41Sopenharmony_ci	")
3721cb0ef41Sopenharmony_ci	CHECK_C_SOURCE_COMPILES ("${_CARES_C_SOURCE}" ${var})
3731cb0ef41Sopenharmony_ciENDMACRO ()
3741cb0ef41Sopenharmony_ci
3751cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS (socklen_t                 HAVE_SOCKLEN_T)
3761cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS (SOCKET                    HAVE_TYPE_SOCKET)
3771cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS (ssize_t                   HAVE_SSIZE_T)
3781cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS ("long long"               HAVE_LONGLONG)
3791cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS ("struct addrinfo"         HAVE_STRUCT_ADDRINFO)
3801cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS ("struct in6_addr"         HAVE_STRUCT_IN6_ADDR)
3811cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS ("struct sockaddr_in6"     HAVE_STRUCT_SOCKADDR_IN6)
3821cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS ("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
3831cb0ef41Sopenharmony_ciCARES_TYPE_EXISTS ("struct timeval"          HAVE_STRUCT_TIMEVAL)
3841cb0ef41Sopenharmony_ci
3851cb0ef41Sopenharmony_ci
3861cb0ef41Sopenharmony_ci# Check for preprocessor defines
3871cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (AF_INET6        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_AF_INET6)
3881cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (O_NONBLOCK      "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_O_NONBLOCK)
3891cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (FIONBIO         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_FIONBIO)
3901cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (SIOCGIFADDR     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IOCTL_SIOCGIFADDR)
3911cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (MSG_NOSIGNAL    "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_MSG_NOSIGNAL)
3921cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (PF_INET6        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_PF_INET6)
3931cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (SO_NONBLOCK     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SO_NONBLOCK)
3941cb0ef41Sopenharmony_ci
3951cb0ef41Sopenharmony_ci# XCode v8 bug: iOS when targeting less than v10, or MacOS when targeting less than v10.12 will
3961cb0ef41Sopenharmony_ci# say clock_gettime exists, it is a weak symbol that only exists in iOS10/MacOS10.12 and will
3971cb0ef41Sopenharmony_ci# cause a crash at runtime when running on older versions.  Skip finding CLOCK_MONOTONIC on older
3981cb0ef41Sopenharmony_ci# OS's.
3991cb0ef41Sopenharmony_ciIF ((NOT APPLE) OR IOS_V10 OR MACOS_V1012)
4001cb0ef41Sopenharmony_ci	CHECK_SYMBOL_EXISTS (CLOCK_MONOTONIC "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CLOCK_GETTIME_MONOTONIC)
4011cb0ef41Sopenharmony_ciENDIF ()
4021cb0ef41Sopenharmony_ci
4031cb0ef41Sopenharmony_ciCHECK_STRUCT_HAS_MEMBER("struct sockaddr_in6" sin6_scope_id "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID LANGUAGE C)
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci
4061cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (closesocket     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CLOSESOCKET)
4071cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (CloseSocket     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CLOSESOCKET_CAMEL)
4081cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (connect         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CONNECT)
4091cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (fcntl           "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_FCNTL)
4101cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (freeaddrinfo    "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_FREEADDRINFO)
4111cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (getaddrinfo     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETADDRINFO)
4121cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (getenv          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETENV)
4131cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (gethostname     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETHOSTNAME)
4141cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (getnameinfo     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETNAMEINFO)
4151cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (getrandom       "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETRANDOM)
4161cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (getservbyport_r "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETSERVBYPORT_R)
4171cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (getservbyname_r "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETSERVBYNAME_R)
4181cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (gettimeofday    "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETTIMEOFDAY)
4191cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (if_indextoname  "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IF_INDEXTONAME)
4201cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (if_nametoindex  "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IF_NAMETOINDEX)
4211cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (ConvertInterfaceIndexToLuid  "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CONVERTINTERFACEINDEXTOLUID)
4221cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (ConvertInterfaceLuidToNameA  "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_CONVERTINTERFACELUIDTONAMEA)
4231cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (inet_net_pton   "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_INET_NET_PTON)
4241cb0ef41Sopenharmony_ciIF (NOT WIN32)
4251cb0ef41Sopenharmony_ci	# Disabled on Windows, because these functions are only really supported on Windows
4261cb0ef41Sopenharmony_ci	# Vista or newer (_WIN32_WINNT >= 0x0600). Older versions of Windows may provide
4271cb0ef41Sopenharmony_ci	# them as experimental non-working features, so we have to disable them manually.
4281cb0ef41Sopenharmony_ci	CHECK_SYMBOL_EXISTS (inet_ntop       "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_INET_NTOP)
4291cb0ef41Sopenharmony_ci	CHECK_SYMBOL_EXISTS (inet_pton       "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_INET_PTON)
4301cb0ef41Sopenharmony_ciENDIF ()
4311cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (ioctl           "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IOCTL)
4321cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (ioctlsocket     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IOCTLSOCKET)
4331cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (IoctlSocket     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_IOCTLSOCKET_CAMEL)
4341cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (recv            "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_RECV)
4351cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (recvfrom        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_RECVFROM)
4361cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (send            "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SEND)
4371cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (setsockopt      "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SETSOCKOPT)
4381cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (socket          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SOCKET)
4391cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (strcasecmp      "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRCASECMP)
4401cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (strcmpi         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRCMPI)
4411cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (strdup          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRDUP)
4421cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (stricmp         "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRICMP)
4431cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (strncasecmp     "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRNCASECMP)
4441cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (strncmpi        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRNCMPI)
4451cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (strnicmp        "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRNICMP)
4461cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (writev          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_WRITEV)
4471cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (arc4random_buf  "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_ARC4RANDOM_BUF)
4481cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (stat            "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STAT)
4491cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (getifaddrs      "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_GETIFADDRS)
4501cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (poll            "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_POLL)
4511cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (pipe            "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_PIPE)
4521cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (pipe2           "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_PIPE2)
4531cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (kqueue          "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_KQUEUE)
4541cb0ef41Sopenharmony_ciCHECK_SYMBOL_EXISTS (epoll_create1   "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_EPOLL)
4551cb0ef41Sopenharmony_ci
4561cb0ef41Sopenharmony_ci
4571cb0ef41Sopenharmony_ci# On Android, the system headers may define __system_property_get(), but excluded
4581cb0ef41Sopenharmony_ci# from libc.  We need to perform a link test instead of a header/symbol test.
4591cb0ef41Sopenharmony_ciCHECK_FUNCTION_EXISTS (__system_property_get HAVE___SYSTEM_PROPERTY_GET)
4601cb0ef41Sopenharmony_ci
4611cb0ef41Sopenharmony_ci# Unset temporary data
4621cb0ef41Sopenharmony_ciSET (CMAKE_EXTRA_INCLUDE_FILES)
4631cb0ef41Sopenharmony_ciSET (CMAKE_REQUIRED_DEFINITIONS)
4641cb0ef41Sopenharmony_ciSET (CMAKE_REQUIRED_LIBRARIES)
4651cb0ef41Sopenharmony_ci
4661cb0ef41Sopenharmony_ci
4671cb0ef41Sopenharmony_ci################################################################################
4681cb0ef41Sopenharmony_ci# Threading Support
4691cb0ef41Sopenharmony_ci#
4701cb0ef41Sopenharmony_ciIF (CARES_THREADS)
4711cb0ef41Sopenharmony_ci	IF (WIN32)
4721cb0ef41Sopenharmony_ci		# Do nothing, always has threads
4731cb0ef41Sopenharmony_ci	ELSE ()
4741cb0ef41Sopenharmony_ci		# Need to prefer pthreads on platforms that may have more threading choices
4751cb0ef41Sopenharmony_ci		# (e.g. Solaris)
4761cb0ef41Sopenharmony_ci		SET (CMAKE_THREAD_PREFER_PTHREAD TRUE)
4771cb0ef41Sopenharmony_ci		FIND_PACKAGE (Threads)
4781cb0ef41Sopenharmony_ci
4791cb0ef41Sopenharmony_ci		IF (Threads_FOUND)
4801cb0ef41Sopenharmony_ci			# Fix solaris9 bug due to libc having pthread_create() stubs that always fail.  CMake
4811cb0ef41Sopenharmony_ci			# doesn't realize that the real pthread functions aren't in libc, so sets the pthread
4821cb0ef41Sopenharmony_ci			# library CAKE_THREAD_LIBS_INIT variable to blank instead of to the correct "-lpthread".
4831cb0ef41Sopenharmony_ci			IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS" AND NOT CMAKE_THREAD_LIBS_INIT)
4841cb0ef41Sopenharmony_ci				SET (CMAKE_THREAD_LIBS_INIT "-lpthread")
4851cb0ef41Sopenharmony_ci			ENDIF ()
4861cb0ef41Sopenharmony_ci
4871cb0ef41Sopenharmony_ci			# PThread functions.
4881cb0ef41Sopenharmony_ci			CHECK_INCLUDE_FILES (pthread.h                                 HAVE_PTHREAD_H)
4891cb0ef41Sopenharmony_ci			CHECK_INCLUDE_FILES (pthread_np.h                              HAVE_PTHREAD_NP_H)
4901cb0ef41Sopenharmony_ci			CARES_EXTRAINCLUDE_IFSET (HAVE_PTHREAD_H                       pthread.h)
4911cb0ef41Sopenharmony_ci			CARES_EXTRAINCLUDE_IFSET (HAVE_PTHREAD_NP_H                    pthread_np.h)
4921cb0ef41Sopenharmony_ci			CHECK_SYMBOL_EXISTS (pthread_init  "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_PTHREAD_INIT)
4931cb0ef41Sopenharmony_ci			# Make sure libcares.pc.cmake knows about thread libraries on static builds
4941cb0ef41Sopenharmony_ci			LIST (APPEND CARES_DEPENDENT_LIBS ${CMAKE_THREAD_LIBS_INIT})
4951cb0ef41Sopenharmony_ci		ELSE ()
4961cb0ef41Sopenharmony_ci			MESSAGE (WARNING "Threading support not found, disabling...")
4971cb0ef41Sopenharmony_ci			SET (CARES_THREADS OFF)
4981cb0ef41Sopenharmony_ci		ENDIF ()
4991cb0ef41Sopenharmony_ci	ENDIF ()
5001cb0ef41Sopenharmony_ciENDIF ()
5011cb0ef41Sopenharmony_ci
5021cb0ef41Sopenharmony_ci
5031cb0ef41Sopenharmony_ci
5041cb0ef41Sopenharmony_ci################################################################################
5051cb0ef41Sopenharmony_ci# recv, recvfrom, send, getnameinfo, gethostname
5061cb0ef41Sopenharmony_ci# ARGUMENTS AND RETURN VALUES
5071cb0ef41Sopenharmony_ci#
5081cb0ef41Sopenharmony_ci# The AutoTools build tries to be really thorough here.  So much so that it
5091cb0ef41Sopenharmony_ci# takes forever.  We really don't want to do that.  Lets make some educated
5101cb0ef41Sopenharmony_ci# guesses based on datatypes we have available, and for others, use some 'sane'
5111cb0ef41Sopenharmony_ci# defaults.  This should be much quicker and nearly as accurate ... and even
5121cb0ef41Sopenharmony_ci# if not, it probably won't matter in the least.
5131cb0ef41Sopenharmony_ci
5141cb0ef41Sopenharmony_ciIF (HAVE_SSIZE_T AND HAVE_SOCKLEN_T AND NOT WIN32)
5151cb0ef41Sopenharmony_ci	# If we have ssize_t and socklen_t, the API is usually sane and uses ssize_t and size_t for lengths
5161cb0ef41Sopenharmony_ci	SET (RECVFROM_TYPE_RETV ssize_t)
5171cb0ef41Sopenharmony_ci	SET (RECVFROM_TYPE_ARG3 size_t)
5181cb0ef41Sopenharmony_ciELSE ()
5191cb0ef41Sopenharmony_ci	SET (RECVFROM_TYPE_RETV int)
5201cb0ef41Sopenharmony_ci	SET (RECVFROM_TYPE_ARG3 int)
5211cb0ef41Sopenharmony_ciENDIF ()
5221cb0ef41Sopenharmony_ci
5231cb0ef41Sopenharmony_ciIF (HAVE_TYPE_SOCKET)
5241cb0ef41Sopenharmony_ci	# If the SOCKET type is defined, it uses socket ... should be windows only
5251cb0ef41Sopenharmony_ci	SET (RECVFROM_TYPE_ARG1 SOCKET)
5261cb0ef41Sopenharmony_ciELSE ()
5271cb0ef41Sopenharmony_ci	SET (RECVFROM_TYPE_ARG1 int)
5281cb0ef41Sopenharmony_ciENDIF()
5291cb0ef41Sopenharmony_ci
5301cb0ef41Sopenharmony_ciIF (HAVE_SOCKLEN_T)
5311cb0ef41Sopenharmony_ci	# If we have socklen_t the APIs pretty much always actually use it
5321cb0ef41Sopenharmony_ci	SET (RECVFROM_TYPE_ARG6 "socklen_t *")
5331cb0ef41Sopenharmony_ci	SET (GETNAMEINFO_TYPE_ARG2 socklen_t)
5341cb0ef41Sopenharmony_ci	SET (GETNAMEINFO_TYPE_ARG46 socklen_t)
5351cb0ef41Sopenharmony_ciELSE ()
5361cb0ef41Sopenharmony_ci	SET (RECVFROM_TYPE_ARG6 "int *")
5371cb0ef41Sopenharmony_ci	SET (GETNAMEINFO_TYPE_ARG2 int)
5381cb0ef41Sopenharmony_ci	SET (GETNAMEINFO_TYPE_ARG46 int)
5391cb0ef41Sopenharmony_ciENDIF ()
5401cb0ef41Sopenharmony_ci
5411cb0ef41Sopenharmony_ciIF (WIN32)
5421cb0ef41Sopenharmony_ci	SET (RECV_TYPE_ARG2 "char *")
5431cb0ef41Sopenharmony_ciELSE ()
5441cb0ef41Sopenharmony_ci	SET (RECV_TYPE_ARG2 "void *")
5451cb0ef41Sopenharmony_ciENDIF ()
5461cb0ef41Sopenharmony_ci
5471cb0ef41Sopenharmony_ci# Functions are typically consistent so the equivalent fields map ... equivalently
5481cb0ef41Sopenharmony_ciSET (RECV_TYPE_RETV ${RECVFROM_TYPE_RETV})
5491cb0ef41Sopenharmony_ciSET (SEND_TYPE_RETV ${RECVFROM_TYPE_RETV})
5501cb0ef41Sopenharmony_ciSET (RECV_TYPE_ARG1 ${RECVFROM_TYPE_ARG1})
5511cb0ef41Sopenharmony_ciSET (RECVFROM_TYPE_ARG2 ${RECV_TYPE_ARG2})
5521cb0ef41Sopenharmony_ciSET (SEND_TYPE_ARG1 ${RECVFROM_TYPE_ARG1})
5531cb0ef41Sopenharmony_ciSET (RECV_TYPE_ARG3 ${RECVFROM_TYPE_ARG3})
5541cb0ef41Sopenharmony_ciSET (SEND_TYPE_ARG3 ${RECVFROM_TYPE_ARG3})
5551cb0ef41Sopenharmony_ciSET (GETHOSTNAME_TYPE_ARG2 ${RECVFROM_TYPE_ARG3})
5561cb0ef41Sopenharmony_ci
5571cb0ef41Sopenharmony_ci# These should always be "sane" values to use always
5581cb0ef41Sopenharmony_ciSET (RECVFROM_QUAL_ARG5 )
5591cb0ef41Sopenharmony_ciSET (RECVFROM_TYPE_ARG4 int)
5601cb0ef41Sopenharmony_ciSET (RECVFROM_TYPE_ARG5 "struct sockaddr *")
5611cb0ef41Sopenharmony_ciSET (RECV_TYPE_ARG4 int)
5621cb0ef41Sopenharmony_ciSET (GETNAMEINFO_TYPE_ARG1 "struct sockaddr *")
5631cb0ef41Sopenharmony_ciSET (GETNAMEINFO_TYPE_ARG7 int)
5641cb0ef41Sopenharmony_ciSET (SEND_TYPE_ARG2 "void *")
5651cb0ef41Sopenharmony_ciSET (SEND_TYPE_ARG4 int)
5661cb0ef41Sopenharmony_ci################################################################################
5671cb0ef41Sopenharmony_ci
5681cb0ef41Sopenharmony_ci
5691cb0ef41Sopenharmony_ci# HAVE_CXX11  ??
5701cb0ef41Sopenharmony_ci# HAVE_SIG_ATOMIC_T_VOLATILE  ??
5711cb0ef41Sopenharmony_ci
5721cb0ef41Sopenharmony_ci
5731cb0ef41Sopenharmony_ci# Set a few variables by hand that C-Ares wants, logically, based on detection
5741cb0ef41Sopenharmony_ci# data.
5751cb0ef41Sopenharmony_ci
5761cb0ef41Sopenharmony_ciIF (HAVE_SOCKLEN_T)
5771cb0ef41Sopenharmony_ci	Set (CARES_TYPEOF_ARES_SOCKLEN_T "socklen_t")
5781cb0ef41Sopenharmony_ciELSE ()
5791cb0ef41Sopenharmony_ci	Set (CARES_TYPEOF_ARES_SOCKLEN_T "int")
5801cb0ef41Sopenharmony_ciENDIF ()
5811cb0ef41Sopenharmony_ci
5821cb0ef41Sopenharmony_ciIF (HAVE_SSIZE_T)
5831cb0ef41Sopenharmony_ci	Set (CARES_TYPEOF_ARES_SSIZE_T "ssize_t")
5841cb0ef41Sopenharmony_ciELSE ()
5851cb0ef41Sopenharmony_ci	IF (WIN32)
5861cb0ef41Sopenharmony_ci		IF ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
5871cb0ef41Sopenharmony_ci			Set (CARES_TYPEOF_ARES_SSIZE_T "__int64")
5881cb0ef41Sopenharmony_ci		ELSE ()
5891cb0ef41Sopenharmony_ci			Set (CARES_TYPEOF_ARES_SSIZE_T "int")
5901cb0ef41Sopenharmony_ci		ENDIF ()
5911cb0ef41Sopenharmony_ci	ELSE ()
5921cb0ef41Sopenharmony_ci		Set (CARES_TYPEOF_ARES_SSIZE_T "long")
5931cb0ef41Sopenharmony_ci	ENDIF ()
5941cb0ef41Sopenharmony_ciENDIF ()
5951cb0ef41Sopenharmony_ci
5961cb0ef41Sopenharmony_ciIF (HAVE_FCNTL AND HAVE_O_NONBLOCK)
5971cb0ef41Sopenharmony_ci	SET (HAVE_FCNTL_O_NONBLOCK 1)
5981cb0ef41Sopenharmony_ciENDIF ()
5991cb0ef41Sopenharmony_ci
6001cb0ef41Sopenharmony_ciIF (HAVE_IOCTL AND HAVE_FIONBIO)
6011cb0ef41Sopenharmony_ci	SET (HAVE_IOCTL_FIONBIO 1)
6021cb0ef41Sopenharmony_ciENDIF ()
6031cb0ef41Sopenharmony_ci
6041cb0ef41Sopenharmony_ciIF (HAVE_IOCTLSOCKET AND HAVE_FIONBIO)
6051cb0ef41Sopenharmony_ci	SET (HAVE_IOCTLSOCKET_FIONBIO 1)
6061cb0ef41Sopenharmony_ciENDIF ()
6071cb0ef41Sopenharmony_ci
6081cb0ef41Sopenharmony_ciIF (HAVE_IOCTLSOCKET_CAMEL AND HAVE_FIONBIO)
6091cb0ef41Sopenharmony_ci	SET (HAVE_IOCTLSOCKET_CAMEL_FIONBIO 1)
6101cb0ef41Sopenharmony_ciENDIF ()
6111cb0ef41Sopenharmony_ci
6121cb0ef41Sopenharmony_ciIF (HAVE_GETADDRINFO)
6131cb0ef41Sopenharmony_ci	IF (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
6141cb0ef41Sopenharmony_ci		CMAKE_SYSTEM_NAME STREQUAL "HPUX" OR
6151cb0ef41Sopenharmony_ci		CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
6161cb0ef41Sopenharmony_ci		CMAKE_SYSTEM_NAME STREQUAL "SunOS" OR
6171cb0ef41Sopenharmony_ci		CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
6181cb0ef41Sopenharmony_ci		CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
6191cb0ef41Sopenharmony_ci		WIN32)
6201cb0ef41Sopenharmony_ci			SET (HAVE_GETADDRINFO_THREADSAFE 1)
6211cb0ef41Sopenharmony_ci	ENDIF ()
6221cb0ef41Sopenharmony_ciENDIF ()
6231cb0ef41Sopenharmony_ci
6241cb0ef41Sopenharmony_ciIF (HAVE_TIME_H AND HAVE_SYS_TIME_H)
6251cb0ef41Sopenharmony_ci	SET (TIME_WITH_SYS_TIME 1)
6261cb0ef41Sopenharmony_ciENDIF ()
6271cb0ef41Sopenharmony_ci
6281cb0ef41Sopenharmony_ciIF (HAVE_GETSERVBYPORT_R)
6291cb0ef41Sopenharmony_ci	# TODO : Should probably autodetect
6301cb0ef41Sopenharmony_ci	IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
6311cb0ef41Sopenharmony_ci		SET (GETSERVBYPORT_R_ARGS 5)
6321cb0ef41Sopenharmony_ci	ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
6331cb0ef41Sopenharmony_ci		CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
6341cb0ef41Sopenharmony_ci		HAIKU)
6351cb0ef41Sopenharmony_ci		SET (GETSERVBYPORT_R_ARGS 4)
6361cb0ef41Sopenharmony_ci	ELSE ()
6371cb0ef41Sopenharmony_ci		# Probably linux
6381cb0ef41Sopenharmony_ci		SET (GETSERVBYPORT_R_ARGS 6)
6391cb0ef41Sopenharmony_ci	ENDIF ()
6401cb0ef41Sopenharmony_ciENDIF ()
6411cb0ef41Sopenharmony_ci
6421cb0ef41Sopenharmony_ciIF (HAVE_GETSERVBYNAME_R)
6431cb0ef41Sopenharmony_ci	# TODO : Should probably autodetect
6441cb0ef41Sopenharmony_ci	IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
6451cb0ef41Sopenharmony_ci		SET (GETSERVBYNAME_R_ARGS 5)
6461cb0ef41Sopenharmony_ci	ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
6471cb0ef41Sopenharmony_ci		CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
6481cb0ef41Sopenharmony_ci		HAIKU)
6491cb0ef41Sopenharmony_ci		SET (GETSERVBYNAME_R_ARGS 4)
6501cb0ef41Sopenharmony_ci	ELSE ()
6511cb0ef41Sopenharmony_ci		# Probably linux
6521cb0ef41Sopenharmony_ci		SET (GETSERVBYNAME_R_ARGS 6)
6531cb0ef41Sopenharmony_ci	ENDIF ()
6541cb0ef41Sopenharmony_ciENDIF ()
6551cb0ef41Sopenharmony_ci
6561cb0ef41Sopenharmony_ci# Set some aliases used for ares_build.h
6571cb0ef41Sopenharmony_ciIF (HAVE_SYS_TYPES_H)
6581cb0ef41Sopenharmony_ci	SET (CARES_HAVE_SYS_TYPES_H 1)
6591cb0ef41Sopenharmony_ciENDIF ()
6601cb0ef41Sopenharmony_ciIF (HAVE_SYS_SOCKET_H)
6611cb0ef41Sopenharmony_ci	SET (CARES_HAVE_SYS_SOCKET_H 1)
6621cb0ef41Sopenharmony_ciENDIF()
6631cb0ef41Sopenharmony_ciIF (HAVE_WS2TCPIP_H)
6641cb0ef41Sopenharmony_ci	SET (CARES_HAVE_WS2TCPIP_H 1)
6651cb0ef41Sopenharmony_ciENDIF()
6661cb0ef41Sopenharmony_ciIF (HAVE_WINSOCK2_H)
6671cb0ef41Sopenharmony_ci	SET (CARES_HAVE_WINSOCK2_H 1)
6681cb0ef41Sopenharmony_ciENDIF()
6691cb0ef41Sopenharmony_ciIF (HAVE_WINDOWS_H)
6701cb0ef41Sopenharmony_ci	SET (CARES_HAVE_WINDOWS_H 1)
6711cb0ef41Sopenharmony_ciENDIF()
6721cb0ef41Sopenharmony_ciIF (HAVE_ARPA_NAMESER_H)
6731cb0ef41Sopenharmony_ci	SET (CARES_HAVE_ARPA_NAMESER_H 1)
6741cb0ef41Sopenharmony_ciENDIF()
6751cb0ef41Sopenharmony_ciIF (HAVE_ARPA_NAMESER_COMPAT_H)
6761cb0ef41Sopenharmony_ci	SET (CARES_HAVE_ARPA_NAMESER_COMPAT_H 1)
6771cb0ef41Sopenharmony_ciENDIF()
6781cb0ef41Sopenharmony_ci
6791cb0ef41Sopenharmony_ci# TRANSFORM_MAKEFILE_INC
6801cb0ef41Sopenharmony_ci#
6811cb0ef41Sopenharmony_ci# This function consumes the "Makefile.inc" autotools file, and converts it into
6821cb0ef41Sopenharmony_ci#  "Makefile.inc.cmake", a cmake include file; transforming this:
6831cb0ef41Sopenharmony_ci#
6841cb0ef41Sopenharmony_ci# CSOURCES = ares__close_sockets.c	\
6851cb0ef41Sopenharmony_ci#   ares__get_hostent.c			\
6861cb0ef41Sopenharmony_ci#   ares__read_line.c			\
6871cb0ef41Sopenharmony_ci#   ...
6881cb0ef41Sopenharmony_ci#
6891cb0ef41Sopenharmony_ci#   into this:
6901cb0ef41Sopenharmony_ci#
6911cb0ef41Sopenharmony_ci# SET (CSOURCES
6921cb0ef41Sopenharmony_ci# 	ares__close_sockets.c
6931cb0ef41Sopenharmony_ci# 	ares__get_hostent.c
6941cb0ef41Sopenharmony_ci# 	ares__read_line.c
6951cb0ef41Sopenharmony_ci#	...
6961cb0ef41Sopenharmony_cifunction(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
6971cb0ef41Sopenharmony_ci	file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
6981cb0ef41Sopenharmony_ci	string(REPLACE "$(top_srcdir)"   "\${PROJECT_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
6991cb0ef41Sopenharmony_ci	string(REPLACE "$(top_builddir)" "\${PROJECT_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
7001cb0ef41Sopenharmony_ci
7011cb0ef41Sopenharmony_ci	string(REGEX REPLACE "\\\\\n" "ß!ß" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
7021cb0ef41Sopenharmony_ci	string(REGEX REPLACE "([a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*([^\n]*)" "SET(\\1 \\2)" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
7031cb0ef41Sopenharmony_ci	string(REPLACE "ß!ß" "\n" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
7041cb0ef41Sopenharmony_ci
7051cb0ef41Sopenharmony_ci	string(REGEX REPLACE "\\$\\(([a-zA-Z_][a-zA-Z0-9_]*)\\)" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace $() with ${}
7061cb0ef41Sopenharmony_ci	string(REGEX REPLACE "@([a-zA-Z_][a-zA-Z0-9_]*)@" "\${\\1}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})    # Replace @@ with ${}, even if that may not be read by CMake scripts.
7071cb0ef41Sopenharmony_ci	file(WRITE ${OUTPUT_FILE} ${MAKEFILE_INC_TEXT})
7081cb0ef41Sopenharmony_ciendfunction()
7091cb0ef41Sopenharmony_ci
7101cb0ef41Sopenharmony_ci# Directory for includes
7111cb0ef41Sopenharmony_ciADD_SUBDIRECTORY (include)
7121cb0ef41Sopenharmony_ci
7131cb0ef41Sopenharmony_ci# Directory for lib and tools
7141cb0ef41Sopenharmony_ciADD_SUBDIRECTORY (src)
7151cb0ef41Sopenharmony_ci
7161cb0ef41Sopenharmony_ci# Docs
7171cb0ef41Sopenharmony_ciADD_SUBDIRECTORY (docs)
7181cb0ef41Sopenharmony_ci
7191cb0ef41Sopenharmony_ci# Tests
7201cb0ef41Sopenharmony_ciIF (CARES_BUILD_TESTS OR CARES_BUILD_CONTAINER_TESTS)
7211cb0ef41Sopenharmony_ci	ENABLE_TESTING ()
7221cb0ef41Sopenharmony_ci	ADD_SUBDIRECTORY (test)
7231cb0ef41Sopenharmony_ciENDIF ()
7241cb0ef41Sopenharmony_ci
7251cb0ef41Sopenharmony_ci
7261cb0ef41Sopenharmony_ci# Export targets
7271cb0ef41Sopenharmony_ciIF (CARES_INSTALL)
7281cb0ef41Sopenharmony_ci	SET (CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
7291cb0ef41Sopenharmony_ci	INCLUDE (CMakePackageConfigHelpers)
7301cb0ef41Sopenharmony_ci	CONFIGURE_PACKAGE_CONFIG_FILE (${PROJECT_NAME}-config.cmake.in ${PROJECT_NAME}-config.cmake
7311cb0ef41Sopenharmony_ci		INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
7321cb0ef41Sopenharmony_ci		PATH_VARS CMAKE_INSTALL_INCLUDEDIR
7331cb0ef41Sopenharmony_ci		NO_CHECK_REQUIRED_COMPONENTS_MACRO
7341cb0ef41Sopenharmony_ci	)
7351cb0ef41Sopenharmony_ci
7361cb0ef41Sopenharmony_ci	WRITE_BASIC_PACKAGE_VERSION_FILE(${PROJECT_NAME}-config-version.cmake VERSION "${CARES_VERSION}" COMPATIBILITY SameMajorVersion)
7371cb0ef41Sopenharmony_ci	INSTALL (EXPORT ${PROJECT_NAME}-targets COMPONENT Devel DESTINATION ${CMAKECONFIG_INSTALL_DIR} NAMESPACE ${PROJECT_NAME}::)
7381cb0ef41Sopenharmony_ci	INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" COMPONENT Devel DESTINATION ${CMAKECONFIG_INSTALL_DIR})
7391cb0ef41Sopenharmony_ci
7401cb0ef41Sopenharmony_ci	# pkgconfig support
7411cb0ef41Sopenharmony_ci	IF (NOT CARES_SHARED)
7421cb0ef41Sopenharmony_ci		FOREACH (LIB ${CARES_DEPENDENT_LIBS})
7431cb0ef41Sopenharmony_ci			SET (CARES_PRIVATE_LIBS "${CARES_PRIVATE_LIBS} -l${LIB}")
7441cb0ef41Sopenharmony_ci		ENDFOREACH ()
7451cb0ef41Sopenharmony_ci	ENDIF ()
7461cb0ef41Sopenharmony_ci	CONFIGURE_FILE("libcares.pc.cmake" "libcares.pc" @ONLY)
7471cb0ef41Sopenharmony_ci	INSTALL (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcares.pc" COMPONENT Devel DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
7481cb0ef41Sopenharmony_ciENDIF ()
7491cb0ef41Sopenharmony_ci
7501cb0ef41Sopenharmony_ci
7511cb0ef41Sopenharmony_ci# Legacy chain-building variables (provided for compatibility with old code).
7521cb0ef41Sopenharmony_ci# Don't use these, external code should be updated to refer to the aliases directly (e.g., Cares::cares).
7531cb0ef41Sopenharmony_ciSET (CARES_FOUND 1 CACHE INTERNAL "CARES LIBRARY FOUND")
7541cb0ef41Sopenharmony_ciSET (CARES_LIBRARIES ${PROJECT_NAME}::cares CACHE INTERNAL "CARES LIBRARIES")
7551cb0ef41Sopenharmony_ci
7561cb0ef41Sopenharmony_ci
7571cb0ef41Sopenharmony_ciIF (CARES_INSTALL)
7581cb0ef41Sopenharmony_ci    # Package creation
7591cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_NAME ${PROJECT_NAME} )
7601cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_VENDOR "Daniel Stenberg" ) # Github project owner
7611cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "A C library for asynchronous DNS requests" )
7621cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_HOMEPAGE_URL "https://c-ares.org/" )
7631cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_CONTACT      "https://c-ares.org/" )
7641cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} )
7651cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR} )
7661cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH} )
7671cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} )
7681cb0ef41Sopenharmony_ci    set( CPACK_PACKAGE_INSTALL_DIRECTORY ${PROJECT_NAME} )
7691cb0ef41Sopenharmony_ci    set( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md" )
7701cb0ef41Sopenharmony_ci    set( CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md" )
7711cb0ef41Sopenharmony_ci
7721cb0ef41Sopenharmony_ci    set( CPACK_COMPONENT_Library_DISPLAY_NAME "c-ares Library" )
7731cb0ef41Sopenharmony_ci    set( CPACK_COMPONENT_Library_DESCRIPTION "The c-ares binary library." )
7741cb0ef41Sopenharmony_ci    set( CPACK_COMPONENT_Library_REQUIRED 1 )
7751cb0ef41Sopenharmony_ci    set( CPACK_COMPONENT_Devel_DISPLAY_NAME "c-ares Development Files" )
7761cb0ef41Sopenharmony_ci    set( CPACK_COMPONENT_Devel_DESCRIPTION "Development files for compiling against c-ares." )
7771cb0ef41Sopenharmony_ci    set( CPACK_COMPONENT_Devel_REQUIRED 0 )
7781cb0ef41Sopenharmony_ci    IF (CARES_BUILD_TOOLS)
7791cb0ef41Sopenharmony_ci        set( CPACK_COMPONENT_Tools_DISPLAY_NAME "c-ares Tools" )
7801cb0ef41Sopenharmony_ci        set( CPACK_COMPONENT_Tools_DESCRIPTION "Tools for using c-ares." )
7811cb0ef41Sopenharmony_ci        set( CPACK_COMPONENT_Tools_REQUIRED 0 )
7821cb0ef41Sopenharmony_ci    ENDIF ()
7831cb0ef41Sopenharmony_ci
7841cb0ef41Sopenharmony_ci    if( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
7851cb0ef41Sopenharmony_ci
7861cb0ef41Sopenharmony_ci        if ( "${CPACK_PACKAGE_ARCHITECTURE}" STREQUAL "" )
7871cb0ef41Sopenharmony_ci            set( CPACK_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}" )
7881cb0ef41Sopenharmony_ci        endif()
7891cb0ef41Sopenharmony_ci        if ( "${CPACK_PACKAGE_ARCHITECTURE}" STREQUAL "" )
7901cb0ef41Sopenharmony_ci            if ( "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows" )
7911cb0ef41Sopenharmony_ci                message( FATAL_ERROR "Failed to determine CPACK_PACKAGE_ARCHITECTURE. Is CMAKE_SYSTEM_PROCESSOR set?" )
7921cb0ef41Sopenharmony_ci            endif()
7931cb0ef41Sopenharmony_ci            # Note: the architecture should default to the local architecture, but it
7941cb0ef41Sopenharmony_ci            # in fact comes up empty.  We call `uname -m` to ask the kernel instead.
7951cb0ef41Sopenharmony_ci            EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE )
7961cb0ef41Sopenharmony_ci        endif()
7971cb0ef41Sopenharmony_ci
7981cb0ef41Sopenharmony_ci        set( CPACK_INCLUDE_TOPLEVEL_DIRECTORY 1 )
7991cb0ef41Sopenharmony_ci        set( CPACK_PACKAGE_RELEASE 1 )
8001cb0ef41Sopenharmony_ci
8011cb0ef41Sopenharmony_ci
8021cb0ef41Sopenharmony_ci        # RPM - https://cmake.org/cmake/help/latest/cpack_gen/rpm.html
8031cb0ef41Sopenharmony_ci        set( CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE} )
8041cb0ef41Sopenharmony_ci        set( CPACK_RPM_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE} )
8051cb0ef41Sopenharmony_ci        set( CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY} )
8061cb0ef41Sopenharmony_ci        set( CPACK_RPM_PACKAGE_URL ${CPACK_PACKAGE_HOMEPAGE_URL} )
8071cb0ef41Sopenharmony_ci        set( CPACK_RPM_PACKAGE_LICENSE "MIT" )
8081cb0ef41Sopenharmony_ci        set( CPACK_RPM_COMPONENT_INSTALL 1 )
8091cb0ef41Sopenharmony_ci        set( CPACK_RPM_COMPRESSION_TYPE "xz" )
8101cb0ef41Sopenharmony_ci        set( CPACK_RPM_PACKAGE_AUTOPROV 1 )
8111cb0ef41Sopenharmony_ci
8121cb0ef41Sopenharmony_ci        set( CPACK_RPM_Library_PACKAGE_SUMMARY ${CPACK_COMPONENT_Library_DESCRIPTION} )
8131cb0ef41Sopenharmony_ci        set( CPACK_RPM_Library_PACKAGE_ARCHITECTURE ${CPACK_RPM_PACKAGE_ARCHITECTURE} )
8141cb0ef41Sopenharmony_ci        set( CPACK_RPM_Library_PACKAGE_NAME "libcares${CARES_LIB_VERSION_MAJOR}" )
8151cb0ef41Sopenharmony_ci        set( CPACK_RPM_Library_FILE_NAME "RPM-DEFAULT" )
8161cb0ef41Sopenharmony_ci
8171cb0ef41Sopenharmony_ci        set( CPACK_RPM_Devel_PACKAGE_REQUIRES "cmake >= ${CMAKE_MINIMUM_REQUIRED_VERSION}, ${CPACK_RPM_Library_PACKAGE_NAME} >= ${CPACK_PACKAGE_VERSION}" )
8181cb0ef41Sopenharmony_ci        set( CPACK_RPM_Devel_PACKAGE_SUMMARY ${CPACK_COMPONENT_Devel_DESCRIPTION} )
8191cb0ef41Sopenharmony_ci        set( CPACK_RPM_Devel_PACKAGE_ARCHITECTURE ${CPACK_RPM_PACKAGE_ARCHITECTURE} )
8201cb0ef41Sopenharmony_ci        set( CPACK_RPM_Devel_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-devel" )
8211cb0ef41Sopenharmony_ci        set( CPACK_RPM_Devel_FILE_NAME "RPM-DEFAULT" )
8221cb0ef41Sopenharmony_ci
8231cb0ef41Sopenharmony_ci        IF (CARES_BUILD_TOOLS)
8241cb0ef41Sopenharmony_ci            set( CPACK_RPM_Tools_PACKAGE_REQUIRES "${CPACK_RPM_Library_PACKAGE_NAME} >= ${CPACK_PACKAGE_VERSION}" )
8251cb0ef41Sopenharmony_ci            set( CPACK_RPM_Tools_PACKAGE_SUMMARY ${CPACK_COMPONENT_Tools_DESCRIPTION} )
8261cb0ef41Sopenharmony_ci            set( CPACK_RPM_Tools_PACKAGE_ARCHITECTURE ${CPACK_RPM_PACKAGE_ARCHITECTURE} )
8271cb0ef41Sopenharmony_ci            set( CPACK_RPM_Tools_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-tools" )
8281cb0ef41Sopenharmony_ci            set( CPACK_RPM_Tools_FILE_NAME "RPM-DEFAULT" )
8291cb0ef41Sopenharmony_ci        ENDIF ()
8301cb0ef41Sopenharmony_ci
8311cb0ef41Sopenharmony_ci
8321cb0ef41Sopenharmony_ci        # DEB - https://cmake.org/cmake/help/latest/cpack_gen/deb.html
8331cb0ef41Sopenharmony_ci        set( CPACK_DEBIAN_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE} )
8341cb0ef41Sopenharmony_ci        set( CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PACKAGE_HOMEPAGE_URL} )
8351cb0ef41Sopenharmony_ci        set( CPACK_DEB_COMPONENT_INSTALL 1 )
8361cb0ef41Sopenharmony_ci        set( CPACK_DEBIAN_COMPRESSION_TYPE "xz")
8371cb0ef41Sopenharmony_ci        set( CPACK_DEBIAN_PACKAGE_SHLIBDEPS 1 )
8381cb0ef41Sopenharmony_ci
8391cb0ef41Sopenharmony_ci        if ( ${CPACK_PACKAGE_ARCHITECTURE} STREQUAL "x86_64" )
8401cb0ef41Sopenharmony_ci            set( CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64" )  # DEB doesn't always use the kernel's arch name
8411cb0ef41Sopenharmony_ci        else()
8421cb0ef41Sopenharmony_ci            set( CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CPACK_PACKAGE_ARCHITECTURE} )
8431cb0ef41Sopenharmony_ci        endif()
8441cb0ef41Sopenharmony_ci
8451cb0ef41Sopenharmony_ci        set( CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT" ) # Use default naming scheme
8461cb0ef41Sopenharmony_ci
8471cb0ef41Sopenharmony_ci        set( CPACK_DEBIAN_LIBRARY_PACKAGE_NAME ${CPACK_RPM_Library_PACKAGE_NAME} )
8481cb0ef41Sopenharmony_ci
8491cb0ef41Sopenharmony_ci        set( CPACK_DEBIAN_DEVEL_PACKAGE_DEPENDS "cmake (>= ${CMAKE_MINIMUM_REQUIRED_VERSION}), ${CPACK_DEBIAN_LIBRARY_PACKAGE_NAME} (>= ${CPACK_PACKAGE_VERSION})" )
8501cb0ef41Sopenharmony_ci        set( CPACK_DEBIAN_DEVEL_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-dev" )
8511cb0ef41Sopenharmony_ci
8521cb0ef41Sopenharmony_ci        IF (CARES_BUILD_TOOLS)
8531cb0ef41Sopenharmony_ci            set( CPACK_DEBIAN_TOOLS_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-tools" )
8541cb0ef41Sopenharmony_ci            set( CPACK_DEBIAN_TOOLS_PACKAGE_SHLIBDEPS OFF ) # dpkg-shlibdeps can't find the libs we built
8551cb0ef41Sopenharmony_ci            set( CPACK_DEBIAN_TOOLS_PACKAGE_DEPENDS "${CPACK_DEBIAN_LIBRARY_PACKAGE_NAME} (>= ${CPACK_PACKAGE_VERSION})" )
8561cb0ef41Sopenharmony_ci        ENDIF ()
8571cb0ef41Sopenharmony_ci
8581cb0ef41Sopenharmony_ci    elseif( ${CMAKE_HOST_WIN32} )
8591cb0ef41Sopenharmony_ci        set( CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON )
8601cb0ef41Sopenharmony_ci        set( CPACK_NSIS_DISPLAY_NAME ${PROJECT_NAME} )
8611cb0ef41Sopenharmony_ci        set( CPACK_NSIS_PACKAGE_NAME ${PROJECT_NAME} )
8621cb0ef41Sopenharmony_ci        set( CPACK_NSIS_URL_INFO_ABOUT ${CPACK_PACKAGE_HOMEPAGE_URL} )
8631cb0ef41Sopenharmony_ci    endif()
8641cb0ef41Sopenharmony_ci
8651cb0ef41Sopenharmony_ci    # This must always be last!
8661cb0ef41Sopenharmony_ci    include( CPack )
8671cb0ef41Sopenharmony_ciENDIF ()
868