Merge bitcoin/bitcoin#31181: cmake: Revamp FindLibevent module

5a96767e3f depends, libevent: Do not install *.pc files and remove patches for them (Hennadii Stepanov)
ffda355b5a cmake, refactor: Move `HAVE_EVHTTP_...` to `libevent` interface (Hennadii Stepanov)
b619bdc330 cmake: Revamp `FindLibevent` module (Hennadii Stepanov)

Pull request description:

  This PR generalizes the use of `find_package` / `pkg_check_modules`, prioritizing the former.

  Addresses https://github.com/bitcoin/bitcoin/pull/30903#issuecomment-2444700876:
  > We should also follow up with refactoring the libevent module, to more generically use CMake/pkg-config, rather than restricting the CMake usage to `vcpkg`. At that point, we'd likely be able to dump pkg-config for the depends path entirely.

  Similar to https://github.com/bitcoin/bitcoin/pull/30903.

ACKs for top commit:
  fanquake:
    ACK 5a96767e3f

Tree-SHA512: 181020c16ccd2821e718c73f264badcdc5e62980c4a8d9691e759efe2ea00da2326e26308d1dcfdeac01e9e27930428ecace9f36941deee951b751b138d7266c
This commit is contained in:
merge-script 2024-11-11 15:31:58 +00:00
commit 8d340be924
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
10 changed files with 45 additions and 90 deletions

View File

@ -71,9 +71,6 @@
*/ */
#cmakedefine01 HAVE_DECL_SETSID #cmakedefine01 HAVE_DECL_SETSID
/* Define this symbol if evhttp_connection_get_peer expects const char** */
#cmakedefine HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR 1
/* Define to 1 if fdatasync is available. */ /* Define to 1 if fdatasync is available. */
#cmakedefine HAVE_FDATASYNC 1 #cmakedefine HAVE_FDATASYNC 1

View File

@ -35,46 +35,52 @@ function(check_evhttp_connection_get_peer target)
" HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR " HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR
) )
cmake_pop_check_state() cmake_pop_check_state()
set(HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR ${HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR} PARENT_SCOPE) target_compile_definitions(${target} INTERFACE
$<$<BOOL:${HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR}>:HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR>
)
endfunction() endfunction()
set(_libevent_components core extra)
if(NOT WIN32)
list(APPEND _libevent_components pthreads)
endif()
find_package(Libevent ${Libevent_FIND_VERSION} QUIET
NO_MODULE
)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
if(VCPKG_TARGET_TRIPLET) if(Libevent_FOUND)
find_package(Libevent ${Libevent_FIND_VERSION} NO_MODULE QUIET find_package(Libevent ${Libevent_FIND_VERSION} QUIET
COMPONENTS extra REQUIRED COMPONENTS ${_libevent_components}
NO_MODULE
) )
find_package_handle_standard_args(Libevent find_package_handle_standard_args(Libevent
REQUIRED_VARS Libevent_DIR REQUIRED_VARS Libevent_DIR
VERSION_VAR Libevent_VERSION VERSION_VAR Libevent_VERSION
) )
check_evhttp_connection_get_peer(libevent::extra) check_evhttp_connection_get_peer(libevent::extra)
add_library(libevent::libevent ALIAS libevent::extra)
mark_as_advanced(Libevent_DIR)
mark_as_advanced(_event_h)
mark_as_advanced(_event_lib)
else() else()
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(libevent QUIET foreach(component IN LISTS _libevent_components)
IMPORTED_TARGET pkg_check_modules(libevent_${component}
libevent>=${Libevent_FIND_VERSION} REQUIRED QUIET
) IMPORTED_TARGET GLOBAL
set(_libevent_required_vars libevent_LIBRARY_DIRS libevent_FOUND) libevent_${component}>=${Libevent_FIND_VERSION}
if(NOT WIN32)
pkg_check_modules(libevent_pthreads QUIET
IMPORTED_TARGET
libevent_pthreads>=${Libevent_FIND_VERSION}
) )
list(APPEND _libevent_required_vars libevent_pthreads_FOUND) if(TARGET PkgConfig::libevent_${component} AND NOT TARGET libevent::${component})
endif() add_library(libevent::${component} ALIAS PkgConfig::libevent_${component})
endif()
endforeach()
find_package_handle_standard_args(Libevent find_package_handle_standard_args(Libevent
REQUIRED_VARS ${_libevent_required_vars} REQUIRED_VARS libevent_core_LIBRARY_DIRS
VERSION_VAR libevent_VERSION VERSION_VAR libevent_core_VERSION
) )
unset(_libevent_required_vars) check_evhttp_connection_get_peer(PkgConfig::libevent_extra)
check_evhttp_connection_get_peer(PkgConfig::libevent)
add_library(libevent::libevent ALIAS PkgConfig::libevent)
if(NOT WIN32)
add_library(libevent::pthreads ALIAS PkgConfig::libevent_pthreads)
endif()
endif() endif()
unset(_libevent_components)
mark_as_advanced(Libevent_DIR)
mark_as_advanced(_event_h)
mark_as_advanced(_event_lib)

View File

@ -4,7 +4,6 @@ $(package)_download_path=https://github.com/libevent/libevent/releases/download/
$(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=92e6de1be9ec176428fd2367677e61ceffc2ee1cb119035037a27d346b0403bb $(package)_sha256_hash=92e6de1be9ec176428fd2367677e61ceffc2ee1cb119035037a27d346b0403bb
$(package)_patches=cmake_fixups.patch $(package)_patches=cmake_fixups.patch
$(package)_patches+=fix_mingw_link.patch
$(package)_build_subdir=build $(package)_build_subdir=build
# When building for Windows, we set _WIN32_WINNT to target the same Windows # When building for Windows, we set _WIN32_WINNT to target the same Windows
@ -23,8 +22,7 @@ define $(package)_set_vars
endef endef
define $(package)_preprocess_cmds define $(package)_preprocess_cmds
patch -p1 < $($(package)_patch_dir)/cmake_fixups.patch && \ patch -p1 < $($(package)_patch_dir)/cmake_fixups.patch
patch -p1 < $($(package)_patch_dir)/fix_mingw_link.patch
endef endef
define $(package)_config_cmds define $(package)_config_cmds
@ -40,7 +38,8 @@ define $(package)_stage_cmds
endef endef
define $(package)_postprocess_cmds define $(package)_postprocess_cmds
rm -rf bin && \ rm -rf bin lib/pkgconfig && \
rm include/ev*.h && \ rm include/ev*.h && \
rm include/event2/*_compat.h rm include/event2/*_compat.h && \
rm lib/libevent.a
endef endef

View File

@ -1,8 +1,5 @@
cmake: set minimum version to 3.5 cmake: set minimum version to 3.5
Fix generated pkg-config files, see
https://github.com/libevent/libevent/pull/1165.
--- a/CMakeLists.txt --- a/CMakeLists.txt
+++ b/CMakeLists.txt +++ b/CMakeLists.txt
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
@ -14,22 +11,3 @@ https://github.com/libevent/libevent/pull/1165.
if (POLICY CMP0054) if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW) cmake_policy(SET CMP0054 NEW)
diff --git a/cmake/AddEventLibrary.cmake b/cmake/AddEventLibrary.cmake
index 04f5837e..d8ea42c4 100644
--- a/cmake/AddEventLibrary.cmake
+++ b/cmake/AddEventLibrary.cmake
@@ -20,12 +20,12 @@ macro(generate_pkgconfig LIB_NAME)
set(LIBS "")
foreach (LIB ${LIB_PLATFORM})
- set(LIBS "${LIBS} -L${LIB}")
+ set(LIBS "${LIBS} -l${LIB}")
endforeach()
set(OPENSSL_LIBS "")
foreach(LIB ${OPENSSL_LIBRARIES})
- set(OPENSSL_LIBS "${OPENSSL_LIBS} -L${LIB}")
+ set(OPENSSL_LIBS "${OPENSSL_LIBS} -l${LIB}")
endforeach()
configure_file("lib${LIB_NAME}.pc.in" "lib${LIB_NAME}.pc" @ONLY)

View File

@ -1,25 +0,0 @@
commit d108099913c5fdbe518f3f4d711f248f8522bd10
Author: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Date: Mon Apr 22 06:39:35 2024 +0100
build: Add `Iphlpapi` to `Libs.private` in `*.pc` files on Windows
It has been required since https://github.com/libevent/libevent/pull/923
at least for the `if_nametoindex` call.
See https://github.com/libevent/libevent/pull/1622.
diff --git a/configure.ac b/configure.ac
index d00e063a..cd1fce37 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -906,7 +906,7 @@ if(WIN32)
list(APPEND HDR_PRIVATE WIN32-Code/getopt.h)
set(EVENT__DNS_USE_FTIME_FOR_ID 1)
- set(LIB_PLATFORM ws2_32 shell32 advapi32)
+ set(LIB_PLATFORM ws2_32 shell32 advapi32 iphlpapi)
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
-D_CRT_NONSTDC_NO_DEPRECATE)

View File

@ -182,7 +182,7 @@ Setup and Build Example: Arch Linux
----------------------------------- -----------------------------------
This example lists the steps necessary to setup and build a command line only distribution of the latest changes on Arch Linux: This example lists the steps necessary to setup and build a command line only distribution of the latest changes on Arch Linux:
pacman --sync --needed cmake boost gcc git libevent make pkgconf python sqlite pacman --sync --needed cmake boost gcc git libevent make python sqlite
git clone https://github.com/bitcoin/bitcoin.git git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin/ cd bitcoin/
cmake -B build cmake -B build

View File

@ -290,13 +290,14 @@ target_link_libraries(bitcoin_node
core_interface core_interface
bitcoin_common bitcoin_common
bitcoin_util bitcoin_util
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
leveldb leveldb
minisketch minisketch
univalue univalue
Boost::headers Boost::headers
$<TARGET_NAME_IF_EXISTS:libevent::libevent> libevent::core
libevent::extra
$<TARGET_NAME_IF_EXISTS:libevent::pthreads> $<TARGET_NAME_IF_EXISTS:libevent::pthreads>
$<TARGET_NAME_IF_EXISTS:bitcoin_zmq>
$<TARGET_NAME_IF_EXISTS:USDT::headers> $<TARGET_NAME_IF_EXISTS:USDT::headers>
) )
@ -366,7 +367,8 @@ if(BUILD_CLI)
bitcoin_cli bitcoin_cli
bitcoin_common bitcoin_common
bitcoin_util bitcoin_util
$<TARGET_NAME_IF_EXISTS:libevent::libevent> libevent::core
libevent::extra
) )
list(APPEND installable_targets bitcoin-cli) list(APPEND installable_targets bitcoin-cli)
endif() endif()

View File

@ -2,8 +2,6 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <bitcoin-build-config.h> // IWYU pragma: keep
#include <httpserver.h> #include <httpserver.h>
#include <chainparamsbase.h> #include <chainparamsbase.h>

View File

@ -154,7 +154,7 @@ target_link_libraries(test_bitcoin
minisketch minisketch
secp256k1 secp256k1
Boost::headers Boost::headers
$<TARGET_NAME_IF_EXISTS:libevent::libevent> libevent::extra
) )
if(ENABLE_WALLET) if(ENABLE_WALLET)

View File

@ -140,7 +140,7 @@ target_link_libraries(fuzz
univalue univalue
secp256k1 secp256k1
Boost::headers Boost::headers
$<TARGET_NAME_IF_EXISTS:libevent::libevent> libevent::extra
) )
if(ENABLE_WALLET) if(ENABLE_WALLET)