mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
cmake: Revamp FindLibevent
module
This change generalizes the use of `find_package` / `pkg_check_modules`, prioritizing the former.
This commit is contained in:
parent
45e2f8f87d
commit
b619bdc330
5 changed files with 38 additions and 32 deletions
|
@ -38,43 +38,47 @@ function(check_evhttp_connection_get_peer target)
|
||||||
set(HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR ${HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR} PARENT_SCOPE)
|
set(HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR ${HAVE_EVHTTP_CONNECTION_GET_PEER_CONST_CHAR} PARENT_SCOPE)
|
||||||
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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -153,7 +153,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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue