diff --git a/cmake/modules/ExternalLibraryHelper.cmake b/cmake/modules/ExternalLibraryHelper.cmake index 2851d62e7..48cae279d 100644 --- a/cmake/modules/ExternalLibraryHelper.cmake +++ b/cmake/modules/ExternalLibraryHelper.cmake @@ -1,52 +1,58 @@ include(FindPackageMessage) # Find a library component, set the variables and create an imported target. # Variable names are compliant with cmake standards. function(find_component LIB COMPONENT) cmake_parse_arguments(ARG "" "" - "HINTS;INCLUDE_DIRS;NAMES;PATHS;PATH_SUFFIXES" + "HINTS;INCLUDE_DIRS;INTERFACE_LINK_LIBRARIES;NAMES;PATHS;PATH_SUFFIXES" ${ARGN} ) # If the component is not requested, skip the search. if(${LIB}_FIND_COMPONENTS AND NOT ${COMPONENT} IN_LIST ${LIB}_FIND_COMPONENTS) return() endif() find_library(${LIB}_${COMPONENT}_LIBRARY NAMES ${ARG_NAMES} PATHS "" ${ARG_PATHS} HINTS "" ${ARG_HINTS} PATH_SUFFIXES "" ${ARG_PATH_SUFFIXES} ) mark_as_advanced(${LIB}_${COMPONENT}_LIBRARY) if(${LIB}_${COMPONENT}_LIBRARY) # On success, set the standard FOUND variable... set(${LIB}_${COMPONENT}_FOUND TRUE PARENT_SCOPE) # ... and append the library path to the LIBRARIES variable ... - list(APPEND ${LIB}_LIBRARIES "${${LIB}_${COMPONENT}_LIBRARY}") + list(APPEND ${LIB}_LIBRARIES + "${${LIB}_${COMPONENT}_LIBRARY}" + ${ARG_INTERFACE_LINK_LIBRARIES} + ) list(REMOVE_DUPLICATES ${LIB}_LIBRARIES) set(${LIB}_LIBRARIES ${${LIB}_LIBRARIES} PARENT_SCOPE) # ... and create an imported target for the component, if not already # done. if(NOT TARGET ${LIB}::${COMPONENT}) add_library(${LIB}::${COMPONENT} UNKNOWN IMPORTED) set_target_properties(${LIB}::${COMPONENT} PROPERTIES IMPORTED_LOCATION "${${LIB}_${COMPONENT}_LIBRARY}" ) set_property(TARGET ${LIB}::${COMPONENT} PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${ARG_INCLUDE_DIRS} ) + set_property(TARGET ${LIB}::${COMPONENT} PROPERTY + INTERFACE_LINK_LIBRARIES ${ARG_INTERFACE_LINK_LIBRARIES} + ) endif() find_package_message("${LIB}_${COMPONENT}" "Found ${LIB} component ${COMPONENT}: ${${LIB}_${COMPONENT}_LIBRARY}" "[${${LIB}_${COMPONENT}_LIBRARY}][${ARG_INCLUDE_DIRS}]" ) endif() endfunction() diff --git a/cmake/modules/FindEvent.cmake b/cmake/modules/FindEvent.cmake index f88e0cbba..3d5caa7d0 100644 --- a/cmake/modules/FindEvent.cmake +++ b/cmake/modules/FindEvent.cmake @@ -1,93 +1,88 @@ # Copyright (c) 2017-2020 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. #.rst # FindEvent # ------------- # # Find the Event library. The following components are available:: # # event # pthreads # # This will define the following variables:: # # Event_FOUND - system has Event lib # Event_INCLUDE_DIRS - the Event include directories # Event_LIBRARIES - Libraries needed to use Event # Event_VERSION - The library version MAJOR.MINOR.PATCH # # And the following imported target:: # # Event::event # Event::pthreads find_package(PkgConfig) pkg_check_modules(PC_Event QUIET libevent) include(BrewHelper) find_brew_prefix(BREW_HINT berkeley-db) find_path(Event_INCLUDE_DIR NAMES event.h PATHS ${PC_Event_INCLUDE_DIRS} HINTS ${BREW_HINT} ) set(Event_INCLUDE_DIRS ${Event_INCLUDE_DIR}) mark_as_advanced(Event_INCLUDE_DIR) if(Event_INCLUDE_DIR) include(ExternalLibraryHelper) find_component(Event event NAMES event HINTS "${BREW_HINT}" INCLUDE_DIRS ${Event_INCLUDE_DIRS} PATHS ${PC_Event_LIBRARY_DIRS} + INTERFACE_LINK_LIBRARIES "$<$:ws2_32;shell32;advapi32>" ) - set(_Event_WINDOWS_LIBRARIES "$<$:ws2_32;shell32;advapi32>") - set_property(TARGET Event::event - PROPERTY INTERFACE_LINK_LIBRARIES ${_Event_WINDOWS_LIBRARIES} - ) - list(APPEND Event_LIBRARIES ${_Event_WINDOWS_LIBRARIES}) - pkg_check_modules(PC_Event_pthreads QUIET event_pthreads libevent_pthreads) find_component(Event pthreads NAMES event_pthreads INCLUDE_DIRS ${Event_INCLUDE_DIRS} PATHS ${PC_Event_pthreads_LIBRARY_DIRS} ) endif() if(NOT Event_VERSION) # If pkgconfig found a version number, use it. if(PC_Event_VERSION) set(_Event_VERSION ${PC_Event_VERSION}) elseif(NOT CMAKE_CROSSCOMPILING) try_run(_Event_CheckVersion_RESULT _Event_CheckVersion_BUILD "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/utils/EventCheckVersion.cpp" CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${Event_INCLUDE_DIRS}" LINK_LIBRARIES "${Event_event_LIBRARY}" RUN_OUTPUT_VARIABLE _Event_VERSION ) else() # There is no way to determine the version. # Let's assume the user read the doc. set(_Event_VERSION 99.99.99) endif() set(Event_VERSION ${_Event_VERSION} CACHE INTERNAL "Event library full version" ) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Event REQUIRED_VARS Event_INCLUDE_DIR VERSION_VAR Event_VERSION HANDLE_COMPONENTS )