diff --git a/cmake/module/AddLibeventIfNeeded.cmake b/cmake/module/AddLibeventIfNeeded.cmake index ddd159fb3b4f5..302d068fe916c 100644 --- a/cmake/module/AddLibeventIfNeeded.cmake +++ b/cmake/module/AddLibeventIfNeeded.cmake @@ -2,9 +2,11 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. +# Check whether evhttp_connection_get_peer expects const char**. +# See https://github.com/libevent/libevent/commit/a18301a2bb160ff7c3ffaf5b7653c39ffe27b385 macro(check_evhttp_connection_get_peer target) - # Check whether evhttp_connection_get_peer expects const char**. - # Fail if neither are available. + cmake_push_check_state(RESET) + set(CMAKE_REQUIRED_LIBRARIES ${target}) check_cxx_source_compiles(" #include #include @@ -18,6 +20,7 @@ macro(check_evhttp_connection_get_peer target) } " HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR ) + cmake_pop_check_state() target_compile_definitions(${target} INTERFACE $<$:HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR=1> ) @@ -38,7 +41,10 @@ function(add_libevent_if_needed) endif() include(CrossPkgConfig) - cross_pkg_check_modules(libevent REQUIRED libevent>=${libevent_minimum_version} IMPORTED_TARGET GLOBAL) + cross_pkg_check_modules(libevent + REQUIRED IMPORTED_TARGET GLOBAL + libevent>=${libevent_minimum_version} + ) check_evhttp_connection_get_peer(PkgConfig::libevent) target_link_libraries(PkgConfig::libevent INTERFACE $<$:iphlpapi;ssp;ws2_32> @@ -46,6 +52,9 @@ function(add_libevent_if_needed) add_library(libevent::libevent ALIAS PkgConfig::libevent) if(NOT WIN32) - cross_pkg_check_modules(libevent_pthreads REQUIRED libevent_pthreads>=${libevent_minimum_version} IMPORTED_TARGET) + cross_pkg_check_modules(libevent_pthreads + REQUIRED IMPORTED_TARGET GLOBAL + libevent_pthreads>=${libevent_minimum_version} + ) endif() endfunction()