Revert "Test reverting FindLibevent2"

This reverts commit c7b3f29f62.
This commit is contained in:
Sara Dickinson 2023-06-21 11:50:32 +01:00
parent c7b3f29f62
commit b15cecfb30
1 changed files with 52 additions and 36 deletions

View File

@ -1,15 +1,22 @@
#[=======================================================================[.rst: #[=======================================================================[.rst:
FindLibevent2 FindLibevent2
------------- -------------
Find the Libevent2 library. For now this finds the core library only. Find the Libevent2 library. For now this finds the core library only.
Imported targets Imported targets
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
This module defines the following :prop_tgt:`IMPORTED` targets: This module defines the following :prop_tgt:`IMPORTED` targets:
``Libevent2::Libevent_core`` ``Libevent2::Libevent_core``
The Libevent2 library, if found. The Libevent2 library, if found.
Result variables Result variables
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
This module will set the following variables in your project: This module will set the following variables in your project:
``Libevent2_FOUND`` ``Libevent2_FOUND``
If false, do not try to use Libevent2. If false, do not try to use Libevent2.
``LIBEVENT2_INCLUDE_DIR`` ``LIBEVENT2_INCLUDE_DIR``
@ -21,27 +28,37 @@ This module will set the following variables in your project:
#]=======================================================================] #]=======================================================================]
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(PkgLibevent IMPORTED_TARGET GLOBAL QUIET libevent>=2)
endif ()
if (PkgLibevent_FOUND)
set(LIBEVENT2_INCLUDE_DIR ${PkgLibevent_INCLUDE_DIRS} CACHE FILEPATH "libevent2 include path")
set(LIBEVENT2_LIBRARIES ${PkgLibevent_LIBRARIES} CACHE STRING "libevent2 libraries")
set(LIBEVENT2_VERSION ${PkgLibevent_VERSION})
add_library(Libevent2::Libevent_core ALIAS PkgConfig::PkgLibevent)
set(Libevent2_FOUND ON)
else ()
find_path(LIBEVENT2_INCLUDE_DIR event2/event.h find_path(LIBEVENT2_INCLUDE_DIR event2/event.h
HINTS HINTS
"${LIBEVENT2_DIR}" "${LIBEVENT2_DIR}"
"${LIBEVENT2_DIR}/include" "${LIBEVENT2_DIR}/include"
) )
find_library(LIBEVENT2_LIBRARY NAMES event_core libevent_core find_library(LIBEVENT2_LIBRARIES NAMES event_core libevent_core
HINTS HINTS
"${LIBEVENT2_DIR}" "${LIBEVENT2_DIR}"
"${LIBEVENT2_DIR}/lib" "${LIBEVENT2_DIR}/lib"
) )
set(LIBEVENT2_LIBRARIES "") if (LIBEVENT2_INCLUDE_DIR AND LIBEVENT2_LIBRARIES)
if (LIBEVENT2_INCLUDE_DIR AND LIBEVENT2_LIBRARY)
if (NOT TARGET Libevent2::Libevent_core) if (NOT TARGET Libevent2::Libevent_core)
add_library(Libevent2::Libevent_core UNKNOWN IMPORTED) add_library(Libevent2::Libevent_core UNKNOWN IMPORTED)
set_target_properties(Libevent2::Libevent_core PROPERTIES set_target_properties(Libevent2::Libevent_core PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBEVENT2_INCLUDE_DIR}" INTERFACE_INCLUDE_DIRECTORIES "${LIBEVENT2_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LIBEVENT2_LIBRARY}" IMPORTED_LOCATION "${LIBEVENT2_LIBRARIES}"
) )
endif () endif ()
@ -51,12 +68,11 @@ if (LIBEVENT2_INCLUDE_DIR AND LIBEVENT2_LIBRARY)
endif () endif ()
endif () endif ()
list(APPEND LIBEVENT2_LIBRARIES "${LIBEVENT2_LIBRARY}")
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libevent2 find_package_handle_standard_args(Libevent2
REQUIRED_VARS LIBEVENT2_LIBRARIES LIBEVENT2_INCLUDE_DIR REQUIRED_VARS LIBEVENT2_LIBRARIES LIBEVENT2_INCLUDE_DIR
VERSION_VAR LIBEVENT2_VERSION VERSION_VAR LIBEVENT2_VERSION
) )
endif ()
mark_as_advanced(LIBEVENT2_INCLUDE_DIR LIBEVENT2_LIBRARIES LIBEVENT2_LIBRARY) mark_as_advanced(LIBEVENT2_INCLUDE_DIR LIBEVENT2_LIBRARIES)