From 6d54be2cc078351b4ce1e469bedc4a976f4e3636 Mon Sep 17 00:00:00 2001 From: yuangongji Date: Sat, 14 Mar 2020 11:13:38 +0800 Subject: [PATCH 1/4] autoconf: fix getaddrinfo checking errors on mingw `AC_CHECK_FUNCS` can not properly check `getaddrinfo` because this function requires some special headers on mingw. Using `AC_CHECK_DECL` can effectively solve this issue. Same for - getnameinfo - getprotobynumber - getservbyname - inet_ntop - inet_pton --- configure.ac | 40 ++++++++++++++++++++++++++++++---------- m4/ax_check_funcs_ex.m4 | 22 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 m4/ax_check_funcs_ex.m4 diff --git a/configure.ac b/configure.ac index 31a6614d..3504d182 100644 --- a/configure.ac +++ b/configure.ac @@ -251,6 +251,7 @@ AC_CHECK_HEADERS([ \ sys/wait.h \ sys/random.h \ errno.h \ + afunix.h \ ]) case "${host_os}" in @@ -347,7 +348,7 @@ AM_CONDITIONAL(BUILD_MIDIPIX, test x$midipix = xtrue) AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue || test x$midipix = xtrue) if test x$bwin32 = xtrue; then - AC_SEARCH_LIBS([getservbyname],[ws2_32]) + AC_HAVE_LIBRARY([ws2_32]) fi dnl Checks for typedefs, structures, and compiler characteristics. @@ -367,11 +368,7 @@ AC_CHECK_FUNCS([ \ getegid \ geteuid \ getifaddrs \ - getnameinfo \ - getprotobynumber \ gettimeofday \ - inet_ntop \ - inet_pton \ issetugid \ mach_absolute_time \ mmap \ @@ -396,17 +393,36 @@ AC_CHECK_FUNCS([ \ unsetenv \ usleep \ vasprintf \ - getservbyname \ getrandom \ ]) -AC_CHECK_FUNCS(_gmtime64_s, [have__gmtime64_s=yes], ) -if test "x$have__gmtime64_s" != "xyes"; then - AC_CHECK_FUNCS(_gmtime64) -fi +AS_IF([test x$bwin32 = xtrue], + AC_CHECK_FUNCS(_gmtime64_s, , [AC_CHECK_FUNCS(_gmtime64)]) +) AM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno]) +m4_define([funcstochk], + [getnameinfo + getprotobynumber + getservbyname + inet_ntop + inet_pton] +) + +AS_IF([test x$bwin32 = xtrue], + [AX_CHECK_DECLS_EX([funcstochk getaddrinfo], + [#ifdef _WIN32 + #include + #include + #endif])], + [AC_CHECK_FUNCS(m4_normalize(funcstochk))] +) + +m4_undefine([funcstochk]) + +dnl check getaddrinfo and gethostbyname_r for non-windows +AS_IF([test x$bwin32 = xfalse], [ AC_CACHE_CHECK( [for getaddrinfo], [libevent_cv_getaddrinfo], @@ -486,6 +502,7 @@ AC_CHECK_FUNC(gethostbyname_r, [ ]) fi +]) dnl end of checking getaddrinfo and gethostbyname_r AC_MSG_CHECKING(for F_SETFD in fcntl.h) AC_EGREP_CPP(yes, @@ -739,6 +756,9 @@ AC_CHECK_TYPES([struct linger],,, #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef _WIN32 +#include +#endif ]) AC_MSG_CHECKING([for socklen_t]) diff --git a/m4/ax_check_funcs_ex.m4 b/m4/ax_check_funcs_ex.m4 new file mode 100644 index 00000000..7aaa58b0 --- /dev/null +++ b/m4/ax_check_funcs_ex.m4 @@ -0,0 +1,22 @@ +# Check if the function is available. +# HAVE_XXX will be defined if yes. + +# $1: the name of function +# $2: the headers in where the function declared +AC_DEFUN([AX_CHECK_DECL_EX], [dnl + AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])]) + AS_VAR_PUSHDEF([have_func_var], [HAVE_[]m4_toupper($1)]) + AC_CHECK_DECL([$1],dnl + [AC_DEFINE([have_func_var], [1], [Define to 1 if you have the `$1' function.])],,dnl + [$2]dnl + ) + AS_VAR_POPDEF([have_func_var])dnl +]) + +AC_DEFUN([AX_CHECK_DECLS_EX], [dnl + AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])]) + m4_foreach([decl],dnl + m4_split(m4_normalize($1)),dnl + [AX_CHECK_DECL_EX([decl], [$2])]dnl + ) +]) From 61c5c19bfdabd2f16407a3ed615060c9d0502e82 Mon Sep 17 00:00:00 2001 From: yuangongji Date: Mon, 16 Mar 2020 18:57:54 +0800 Subject: [PATCH 2/4] cmake: remove CheckFunctionExistsEx `CheckFunctionExistsEx` is copied from the cmake modules before 3.1.2, which is the minimum required version of libevent. The internal module `CheckFunctionExists`of cmake can completely replace it. --- CMakeLists.txt | 113 +++++++++++++++--------------- cmake/CheckFunctionExistsEx.c | 28 -------- cmake/CheckFunctionExistsEx.cmake | 69 ------------------ 3 files changed, 56 insertions(+), 154 deletions(-) delete mode 100644 cmake/CheckFunctionExistsEx.c delete mode 100644 cmake/CheckFunctionExistsEx.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e33d132c..36094d20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,6 @@ string(REGEX MATCH "SunOS" SOLARIS "${CMAKE_SYSTEM_NAME}") include(CheckTypeSize) -include(CheckFunctionExistsEx) include(CheckFileOffsetBits) include(CheckFunctionExists) include(CheckIncludeFile) @@ -452,62 +451,62 @@ CHECK_INCLUDE_FILE(sys/timerfd.h EVENT__HAVE_SYS_TIMERFD_H) CHECK_INCLUDE_FILE(errno.h EVENT__HAVE_ERRNO_H) -CHECK_FUNCTION_EXISTS_EX(epoll_create EVENT__HAVE_EPOLL) -CHECK_FUNCTION_EXISTS_EX(epoll_ctl EVENT__HAVE_EPOLL_CTL) -CHECK_FUNCTION_EXISTS_EX(eventfd EVENT__HAVE_EVENTFD) +CHECK_FUNCTION_EXISTS(epoll_create EVENT__HAVE_EPOLL) +CHECK_FUNCTION_EXISTS(epoll_ctl EVENT__HAVE_EPOLL_CTL) +CHECK_FUNCTION_EXISTS(eventfd EVENT__HAVE_EVENTFD) if(NOT EVENT__DISABLE_CLOCK_GETTIME) - CHECK_FUNCTION_EXISTS_EX(clock_gettime EVENT__HAVE_CLOCK_GETTIME) + CHECK_FUNCTION_EXISTS(clock_gettime EVENT__HAVE_CLOCK_GETTIME) endif() -CHECK_FUNCTION_EXISTS_EX(fcntl EVENT__HAVE_FCNTL) -CHECK_FUNCTION_EXISTS_EX(getaddrinfo EVENT__HAVE_GETADDRINFO) -CHECK_FUNCTION_EXISTS_EX(getnameinfo EVENT__HAVE_GETNAMEINFO) -CHECK_FUNCTION_EXISTS_EX(gettimeofday EVENT__HAVE_GETTIMEOFDAY) -CHECK_FUNCTION_EXISTS_EX(getprotobynumber EVENT__HAVE_GETPROTOBYNUMBER) -CHECK_FUNCTION_EXISTS_EX(getservbyname EVENT__HAVE_GETSERVBYNAME) -CHECK_FUNCTION_EXISTS_EX(inet_ntop EVENT__HAVE_INET_NTOP) -CHECK_FUNCTION_EXISTS_EX(inet_pton EVENT__HAVE_INET_PTON) -CHECK_FUNCTION_EXISTS_EX(kqueue EVENT__HAVE_KQUEUE) -CHECK_FUNCTION_EXISTS_EX(mmap EVENT__HAVE_MMAP) -CHECK_FUNCTION_EXISTS_EX(pipe EVENT__HAVE_PIPE) -CHECK_FUNCTION_EXISTS_EX(pipe2 EVENT__HAVE_PIPE2) -CHECK_FUNCTION_EXISTS_EX(poll EVENT__HAVE_POLL) -CHECK_FUNCTION_EXISTS_EX(port_create EVENT__HAVE_PORT_CREATE) -CHECK_FUNCTION_EXISTS_EX(sendfile EVENT__HAVE_SENDFILE) -CHECK_FUNCTION_EXISTS_EX(sigaction EVENT__HAVE_SIGACTION) -CHECK_FUNCTION_EXISTS_EX(signal EVENT__HAVE_SIGNAL) -CHECK_FUNCTION_EXISTS_EX(strsignal EVENT__HAVE_STRSIGNAL) -CHECK_FUNCTION_EXISTS_EX(splice EVENT__HAVE_SPLICE) -CHECK_FUNCTION_EXISTS_EX(strlcpy EVENT__HAVE_STRLCPY) -CHECK_FUNCTION_EXISTS_EX(strsep EVENT__HAVE_STRSEP) -CHECK_FUNCTION_EXISTS_EX(strtok_r EVENT__HAVE_STRTOK_R) -CHECK_FUNCTION_EXISTS_EX(strtoll EVENT__HAVE_STRTOLL) -CHECK_FUNCTION_EXISTS_EX(vasprintf EVENT__HAVE_VASPRINTF) -CHECK_FUNCTION_EXISTS_EX(sysctl EVENT__HAVE_SYSCTL) -CHECK_FUNCTION_EXISTS_EX(accept4 EVENT__HAVE_ACCEPT4) -CHECK_FUNCTION_EXISTS_EX(arc4random EVENT__HAVE_ARC4RANDOM) -CHECK_FUNCTION_EXISTS_EX(arc4random_buf EVENT__HAVE_ARC4RANDOM_BUF) -CHECK_FUNCTION_EXISTS_EX(arc4random_addrandom EVENT__HAVE_ARC4RANDOM_ADDRANDOM) -CHECK_FUNCTION_EXISTS_EX(epoll_create1 EVENT__HAVE_EPOLL_CREATE1) -CHECK_FUNCTION_EXISTS_EX(getegid EVENT__HAVE_GETEGID) -CHECK_FUNCTION_EXISTS_EX(geteuid EVENT__HAVE_GETEUID) -CHECK_FUNCTION_EXISTS_EX(getifaddrs EVENT__HAVE_GETIFADDRS) -CHECK_FUNCTION_EXISTS_EX(issetugid EVENT__HAVE_ISSETUGID) -CHECK_FUNCTION_EXISTS_EX(mach_absolute_time EVENT__HAVE_MACH_ABSOLUTE_TIME) -CHECK_FUNCTION_EXISTS_EX(nanosleep EVENT__HAVE_NANOSLEEP) -CHECK_FUNCTION_EXISTS_EX(usleep EVENT__HAVE_USLEEP) -CHECK_FUNCTION_EXISTS_EX(timeradd EVENT__HAVE_TIMERADD) -CHECK_FUNCTION_EXISTS_EX(timerclear EVENT__HAVE_TIMERCLEAR) -CHECK_FUNCTION_EXISTS_EX(timercmp EVENT__HAVE_TIMERCMP) -CHECK_FUNCTION_EXISTS_EX(timerfd_create EVENT__HAVE_TIMERFD_CREATE) -CHECK_FUNCTION_EXISTS_EX(timerisset EVENT__HAVE_TIMERISSET) -CHECK_FUNCTION_EXISTS_EX(putenv EVENT__HAVE_PUTENV) -CHECK_FUNCTION_EXISTS_EX(setenv EVENT__HAVE_SETENV) -CHECK_FUNCTION_EXISTS_EX(setrlimit EVENT__HAVE_SETRLIMIT) -CHECK_FUNCTION_EXISTS_EX(umask EVENT__HAVE_UMASK) -CHECK_FUNCTION_EXISTS_EX(unsetenv EVENT__HAVE_UNSETENV) +CHECK_FUNCTION_EXISTS(fcntl EVENT__HAVE_FCNTL) +CHECK_FUNCTION_EXISTS(getaddrinfo EVENT__HAVE_GETADDRINFO) +CHECK_FUNCTION_EXISTS(getnameinfo EVENT__HAVE_GETNAMEINFO) +CHECK_FUNCTION_EXISTS(gettimeofday EVENT__HAVE_GETTIMEOFDAY) +CHECK_FUNCTION_EXISTS(getprotobynumber EVENT__HAVE_GETPROTOBYNUMBER) +CHECK_FUNCTION_EXISTS(getservbyname EVENT__HAVE_GETSERVBYNAME) +CHECK_FUNCTION_EXISTS(inet_ntop EVENT__HAVE_INET_NTOP) +CHECK_FUNCTION_EXISTS(inet_pton EVENT__HAVE_INET_PTON) +CHECK_FUNCTION_EXISTS(kqueue EVENT__HAVE_KQUEUE) +CHECK_FUNCTION_EXISTS(mmap EVENT__HAVE_MMAP) +CHECK_FUNCTION_EXISTS(pipe EVENT__HAVE_PIPE) +CHECK_FUNCTION_EXISTS(pipe2 EVENT__HAVE_PIPE2) +CHECK_FUNCTION_EXISTS(poll EVENT__HAVE_POLL) +CHECK_FUNCTION_EXISTS(port_create EVENT__HAVE_PORT_CREATE) +CHECK_FUNCTION_EXISTS(sendfile EVENT__HAVE_SENDFILE) +CHECK_FUNCTION_EXISTS(sigaction EVENT__HAVE_SIGACTION) +CHECK_FUNCTION_EXISTS(signal EVENT__HAVE_SIGNAL) +CHECK_FUNCTION_EXISTS(strsignal EVENT__HAVE_STRSIGNAL) +CHECK_FUNCTION_EXISTS(splice EVENT__HAVE_SPLICE) +CHECK_FUNCTION_EXISTS(strlcpy EVENT__HAVE_STRLCPY) +CHECK_FUNCTION_EXISTS(strsep EVENT__HAVE_STRSEP) +CHECK_FUNCTION_EXISTS(strtok_r EVENT__HAVE_STRTOK_R) +CHECK_FUNCTION_EXISTS(strtoll EVENT__HAVE_STRTOLL) +CHECK_FUNCTION_EXISTS(vasprintf EVENT__HAVE_VASPRINTF) +CHECK_FUNCTION_EXISTS(sysctl EVENT__HAVE_SYSCTL) +CHECK_FUNCTION_EXISTS(accept4 EVENT__HAVE_ACCEPT4) +CHECK_FUNCTION_EXISTS(arc4random EVENT__HAVE_ARC4RANDOM) +CHECK_FUNCTION_EXISTS(arc4random_buf EVENT__HAVE_ARC4RANDOM_BUF) +CHECK_FUNCTION_EXISTS(arc4random_addrandom EVENT__HAVE_ARC4RANDOM_ADDRANDOM) +CHECK_FUNCTION_EXISTS(epoll_create1 EVENT__HAVE_EPOLL_CREATE1) +CHECK_FUNCTION_EXISTS(getegid EVENT__HAVE_GETEGID) +CHECK_FUNCTION_EXISTS(geteuid EVENT__HAVE_GETEUID) +CHECK_FUNCTION_EXISTS(getifaddrs EVENT__HAVE_GETIFADDRS) +CHECK_FUNCTION_EXISTS(issetugid EVENT__HAVE_ISSETUGID) +CHECK_FUNCTION_EXISTS(mach_absolute_time EVENT__HAVE_MACH_ABSOLUTE_TIME) +CHECK_FUNCTION_EXISTS(nanosleep EVENT__HAVE_NANOSLEEP) +CHECK_FUNCTION_EXISTS(usleep EVENT__HAVE_USLEEP) +CHECK_FUNCTION_EXISTS(timeradd EVENT__HAVE_TIMERADD) +CHECK_FUNCTION_EXISTS(timerclear EVENT__HAVE_TIMERCLEAR) +CHECK_FUNCTION_EXISTS(timercmp EVENT__HAVE_TIMERCMP) +CHECK_FUNCTION_EXISTS(timerfd_create EVENT__HAVE_TIMERFD_CREATE) +CHECK_FUNCTION_EXISTS(timerisset EVENT__HAVE_TIMERISSET) +CHECK_FUNCTION_EXISTS(putenv EVENT__HAVE_PUTENV) +CHECK_FUNCTION_EXISTS(setenv EVENT__HAVE_SETENV) +CHECK_FUNCTION_EXISTS(setrlimit EVENT__HAVE_SETRLIMIT) +CHECK_FUNCTION_EXISTS(umask EVENT__HAVE_UMASK) +CHECK_FUNCTION_EXISTS(unsetenv EVENT__HAVE_UNSETENV) # Get the gethostbyname_r prototype. -CHECK_FUNCTION_EXISTS_EX(gethostbyname_r EVENT__HAVE_GETHOSTBYNAME_R) +CHECK_FUNCTION_EXISTS(gethostbyname_r EVENT__HAVE_GETHOSTBYNAME_R) if(EVENT__HAVE_GETHOSTBYNAME_R) CHECK_PROTOTYPE_DEFINITION(gethostbyname_r @@ -534,13 +533,13 @@ if(HAVE_PORT_H AND HAVE_PORT_CREATE) endif() if(NOT WIN32) - CHECK_FUNCTION_EXISTS_EX(select EVENT__HAVE_SELECT) + CHECK_FUNCTION_EXISTS(select EVENT__HAVE_SELECT) endif() if(WIN32) - CHECK_FUNCTION_EXISTS_EX(_gmtime64_s EVENT__HAVE__GMTIME64_S) + CHECK_FUNCTION_EXISTS(_gmtime64_s EVENT__HAVE__GMTIME64_S) if (NOT EVENT__HAVE__GMTIME64_S) - CHECK_FUNCTION_EXISTS_EX(_gmtime64 EVENT__HAVE__GMTIME64) + CHECK_FUNCTION_EXISTS(_gmtime64 EVENT__HAVE__GMTIME64) endif() endif() @@ -583,7 +582,7 @@ CHECK_SYMBOL_EXISTS(TAILQ_FOREACH sys/queue.h EVENT__HAVE_TAILQFOREACH) CHECK_CONST_EXISTS(CTL_KERN sys/sysctl.h EVENT__HAVE_DECL_CTL_KERN) CHECK_CONST_EXISTS(KERN_ARND sys/sysctl.h EVENT__HAVE_DECL_KERN_ARND) CHECK_SYMBOL_EXISTS(F_SETFD fcntl.h EVENT__HAVE_SETFD) -CHECK_FUNCTION_EXISTS_EX(getrandom EVENT__HAVE_GETRANDOM) +CHECK_FUNCTION_EXISTS(getrandom EVENT__HAVE_GETRANDOM) CHECK_TYPE_SIZE(fd_mask EVENT__HAVE_FD_MASK) diff --git a/cmake/CheckFunctionExistsEx.c b/cmake/CheckFunctionExistsEx.c deleted file mode 100644 index 224e3404..00000000 --- a/cmake/CheckFunctionExistsEx.c +++ /dev/null @@ -1,28 +0,0 @@ -#ifdef CHECK_FUNCTION_EXISTS - -#ifdef __cplusplus -extern "C" -#endif - char - CHECK_FUNCTION_EXISTS(void); -#ifdef __CLASSIC_C__ -int main() -{ - int ac; - char* av[]; -#else -int main(int ac, char* av[]) -{ -#endif - CHECK_FUNCTION_EXISTS(); - if (ac > 1000) { - return *av[0]; - } - return 0; -} - -#else /* CHECK_FUNCTION_EXISTS */ - -#error "CHECK_FUNCTION_EXISTS has to specify the function" - -#endif /* CHECK_FUNCTION_EXISTS */ diff --git a/cmake/CheckFunctionExistsEx.cmake b/cmake/CheckFunctionExistsEx.cmake deleted file mode 100644 index 78bc2ecc..00000000 --- a/cmake/CheckFunctionExistsEx.cmake +++ /dev/null @@ -1,69 +0,0 @@ -# - Check if a C function can be linked -# CHECK_FUNCTION_EXISTS( ) -# -# Check that the is provided by libraries on the system and -# store the result in a . This does not verify that any -# system header file declares the function, only that it can be found -# at link time (considure using CheckSymbolExists). -# -# The following variables may be set before calling this macro to -# modify the way the check is run: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_INCLUDES = list of include directories -# CMAKE_REQUIRED_LIBRARIES = list of libraries to link - -#============================================================================= -# Copyright 2002-2011 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -MACRO(CHECK_FUNCTION_EXISTS_EX FUNCTION VARIABLE) - IF(${VARIABLE} MATCHES "^${VARIABLE}$") - SET(MACRO_CHECK_FUNCTION_DEFINITIONS - "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}") - MESSAGE(STATUS "Looking for ${FUNCTION}") - IF(CMAKE_REQUIRED_LIBRARIES) - SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") - ELSE(CMAKE_REQUIRED_LIBRARIES) - SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES) - ENDIF(CMAKE_REQUIRED_LIBRARIES) - IF(CMAKE_REQUIRED_INCLUDES) - SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") - ELSE(CMAKE_REQUIRED_INCLUDES) - SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES) - ENDIF(CMAKE_REQUIRED_INCLUDES) - TRY_COMPILE(${VARIABLE} - ${CMAKE_BINARY_DIR} - ${PROJECT_SOURCE_DIR}/cmake/CheckFunctionExistsEx.c - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} - "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}" - "${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}" - OUTPUT_VARIABLE OUTPUT) - IF(${VARIABLE}) - SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}") - MESSAGE(STATUS "Looking for ${FUNCTION} - found") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the function ${FUNCTION} exists passed with the following output:\n" - "${OUTPUT}\n\n") - ELSE(${VARIABLE}) - MESSAGE(STATUS "Looking for ${FUNCTION} - not found") - SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the function ${FUNCTION} exists failed with the following output:\n" - "${OUTPUT}\n\n") - ENDIF(${VARIABLE}) - ENDIF() -ENDMACRO(CHECK_FUNCTION_EXISTS_EX) From 503ba1d36571e3cb01826d15dc462b7d8b5094de Mon Sep 17 00:00:00 2001 From: yuangongji Date: Mon, 16 Mar 2020 20:11:06 +0800 Subject: [PATCH 3/4] cmake: fix getaddrinfo checking error Using `CheckFunctionExists` on Windows to check `getaddrinfo` will get `not found`, but it actually exists. Using `CheckSymbolExists` with headers will get correct results. Other functions such as `getnameinfo`,`inet_ntop`,etc. have the same issue. --- CMakeLists.txt | 32 ++++++++++++++++++++------------ cmake/CheckSymbolsExist.cmake | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 cmake/CheckSymbolsExist.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 36094d20..7dc45fd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ include(CheckIncludeFile) include(CheckIncludeFiles) include(CheckVariableExists) include(CheckSymbolExists) +include(CheckSymbolsExist) include(CheckStructHasMember) include(CheckCSourceCompiles) include(CheckPrototypeDefinition) @@ -338,7 +339,7 @@ endif() if(WIN32) set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h) set(CMAKE_REQUIRED_LIBRARIES ws2_32.lib shell32.lib advapi32.lib) - set(CMAKE_REQUIRED_DEFINITIONS -FIwinsock2.h -FIws2tcpip.h) + set(CMAKE_REQUIRED_DEFINITIONS -FIwinsock2.h -FIws2tcpip.h -D_WIN32_WINNT=0x0600) endif() if (SOLARIS) set(CMAKE_REQUIRED_LIBRARIES socket nsl) @@ -450,6 +451,24 @@ endif() CHECK_INCLUDE_FILE(sys/timerfd.h EVENT__HAVE_SYS_TIMERFD_H) CHECK_INCLUDE_FILE(errno.h EVENT__HAVE_ERRNO_H) +if (WIN32) + list(APPEND CHECK_SYMBOL_HEADERS winsock2.h ws2tcpip.h) +endif() +list(APPEND SYMBOLS_TO_CHECK + getaddrinfo + getnameinfo + getprotobynumber + inet_ntop + inet_pton + strtoll + timerclear + timercmp + timerisset + putenv +) +CHECK_SYMBOLS_EXIST("${SYMBOLS_TO_CHECK}" "${CHECK_SYMBOL_HEADERS}" "EVENT") +unset(CHECK_SYMBOL_HEADERS) +unset(SYMBOLS_TO_CHECK) CHECK_FUNCTION_EXISTS(epoll_create EVENT__HAVE_EPOLL) CHECK_FUNCTION_EXISTS(epoll_ctl EVENT__HAVE_EPOLL_CTL) @@ -458,13 +477,7 @@ if(NOT EVENT__DISABLE_CLOCK_GETTIME) CHECK_FUNCTION_EXISTS(clock_gettime EVENT__HAVE_CLOCK_GETTIME) endif() CHECK_FUNCTION_EXISTS(fcntl EVENT__HAVE_FCNTL) -CHECK_FUNCTION_EXISTS(getaddrinfo EVENT__HAVE_GETADDRINFO) -CHECK_FUNCTION_EXISTS(getnameinfo EVENT__HAVE_GETNAMEINFO) CHECK_FUNCTION_EXISTS(gettimeofday EVENT__HAVE_GETTIMEOFDAY) -CHECK_FUNCTION_EXISTS(getprotobynumber EVENT__HAVE_GETPROTOBYNUMBER) -CHECK_FUNCTION_EXISTS(getservbyname EVENT__HAVE_GETSERVBYNAME) -CHECK_FUNCTION_EXISTS(inet_ntop EVENT__HAVE_INET_NTOP) -CHECK_FUNCTION_EXISTS(inet_pton EVENT__HAVE_INET_PTON) CHECK_FUNCTION_EXISTS(kqueue EVENT__HAVE_KQUEUE) CHECK_FUNCTION_EXISTS(mmap EVENT__HAVE_MMAP) CHECK_FUNCTION_EXISTS(pipe EVENT__HAVE_PIPE) @@ -479,7 +492,6 @@ CHECK_FUNCTION_EXISTS(splice EVENT__HAVE_SPLICE) CHECK_FUNCTION_EXISTS(strlcpy EVENT__HAVE_STRLCPY) CHECK_FUNCTION_EXISTS(strsep EVENT__HAVE_STRSEP) CHECK_FUNCTION_EXISTS(strtok_r EVENT__HAVE_STRTOK_R) -CHECK_FUNCTION_EXISTS(strtoll EVENT__HAVE_STRTOLL) CHECK_FUNCTION_EXISTS(vasprintf EVENT__HAVE_VASPRINTF) CHECK_FUNCTION_EXISTS(sysctl EVENT__HAVE_SYSCTL) CHECK_FUNCTION_EXISTS(accept4 EVENT__HAVE_ACCEPT4) @@ -495,11 +507,7 @@ CHECK_FUNCTION_EXISTS(mach_absolute_time EVENT__HAVE_MACH_ABSOLUTE_TIME) CHECK_FUNCTION_EXISTS(nanosleep EVENT__HAVE_NANOSLEEP) CHECK_FUNCTION_EXISTS(usleep EVENT__HAVE_USLEEP) CHECK_FUNCTION_EXISTS(timeradd EVENT__HAVE_TIMERADD) -CHECK_FUNCTION_EXISTS(timerclear EVENT__HAVE_TIMERCLEAR) -CHECK_FUNCTION_EXISTS(timercmp EVENT__HAVE_TIMERCMP) CHECK_FUNCTION_EXISTS(timerfd_create EVENT__HAVE_TIMERFD_CREATE) -CHECK_FUNCTION_EXISTS(timerisset EVENT__HAVE_TIMERISSET) -CHECK_FUNCTION_EXISTS(putenv EVENT__HAVE_PUTENV) CHECK_FUNCTION_EXISTS(setenv EVENT__HAVE_SETENV) CHECK_FUNCTION_EXISTS(setrlimit EVENT__HAVE_SETRLIMIT) CHECK_FUNCTION_EXISTS(umask EVENT__HAVE_UMASK) diff --git a/cmake/CheckSymbolsExist.cmake b/cmake/CheckSymbolsExist.cmake new file mode 100644 index 00000000..2c3c5dc3 --- /dev/null +++ b/cmake/CheckSymbolsExist.cmake @@ -0,0 +1,20 @@ +# Check if each symbol in the symbol list exists, +# and define PREFIX__HAVE_SYMNAME to 1 if yes. +# + +include(CheckSymbolExists) + +# SYMLIST: list of symbols to check +# HEADERS: header files to be included in check code +# PREFIX: the prefix of definition +macro(CHECK_SYMBOLS_EXIST SYMLIST HEADERS PREFIX) + foreach(SYMNAME ${SYMLIST}) + string(TOUPPER "${SYMNAME}" SYMNAME_UPPER) + if("${PREFIX}" STREQUAL "") + set(HAVE_SYM_DEF "HAVE_${SYMNAME_UPPER}") + else() + set(HAVE_SYM_DEF "${PREFIX}__HAVE_${SYMNAME_UPPER}") + endif() + CHECK_SYMBOL_EXISTS(${SYMNAME} "${HEADERS}" ${HAVE_SYM_DEF}) + endforeach() +endmacro() From a3cb3119c7254a7ad7e4b14cdc77977e140f5f22 Mon Sep 17 00:00:00 2001 From: yuangongji Date: Tue, 17 Mar 2020 19:57:10 +0800 Subject: [PATCH 4/4] github workflow: fix configure error on mingw-w64 --- .github/workflows/mingw.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/mingw.yml b/.github/workflows/mingw.yml index 4624f054..98241a9e 100644 --- a/.github/workflows/mingw.yml +++ b/.github/workflows/mingw.yml @@ -34,7 +34,7 @@ jobs: steps: - uses: actions/checkout@v2.0.0 - - name: Cache MingW + - name: Cache MinGW id: cache-mingw uses: actions/cache@v1.0.3 with: @@ -55,7 +55,7 @@ jobs: - name: Install Dependes if: steps.cache-mingw.outputs.cache-hit != 'true' run: | - msys2do pacman -S --noconfirm mingw-w64-x86_64-gcc make autoconf automake libtool openssl-devel + msys2do pacman -S --noconfirm mingw-w64-x86_64-gcc make autoconf automake libtool mingw-w64-x86_64-openssl - name: Build And Test shell: powershell @@ -74,7 +74,7 @@ jobs: mkdir -p build cd build [[ $? -ne 0 ]] && exit 1 - LDFLAGS="-L/usr/lib" CFLAGS="-I/usr/include" ../configure $EVENT_CONFIGURE_OPTIONS 2>&1 + LDFLAGS="-L/mingw64/lib" CFLAGS="-I/mingw64/include" ../configure $EVENT_CONFIGURE_OPTIONS 2>&1 [[ $? -ne 0 ]] && exit 1 make -j $EVENT_BUILD_PARALLEL 2>&1 [[ $? -ne 0 ]] && exit 1