diff --git a/CMakeLists.txt b/CMakeLists.txt index d63d659e..e7248d49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,6 +111,7 @@ option(BUILD_GETDNS_QUERY "Compile and install the getdns_query tool." ON) option(BUILD_GETDNS_SERVER_MON "Compile and install the getdns_server_mon tool." ON) option(BUILD_STUBBY "Compile and install stubby, the (stub) resolver daemon." OFF) +option(USE_LIBEV "Use libev if available." ON) option(USE_LIBEVENT2 "Use libevent2 if available." ON) option(USE_LIBIDN "Use libidn if available." ON) option(USE_LIBIDN2 "Use libidn2 if available." ON) @@ -603,6 +604,45 @@ if (ENABLE_SHARED) endif () endif () +# libev extension. +if (USE_LIBEV) + find_package(Libev) + if (Libev_FOUND) + # Copy module header to getdns include dir. + file(COPY src/getdns/getdns_ext_libev.h DESTINATION getdns) + + add_library(ev_objects OBJECT src/extension/libev.c) + target_include_directories(ev_objects + PRIVATE + src + ${CMAKE_CURRENT_BINARY_DIR} + ) + set_property(TARGET ev_objects PROPERTY POSITION_INDEPENDENT_CODE 1) + set_property(TARGET ev_objects PROPERTY C_STANDARD 11) + if (ENABLE_STATIC) + add_library(getdns_ex_ev STATIC $) + target_include_directories(getdns_ex_ev PRIVATE Libev::Libev) + target_link_libraries(getdns_ex_ev PUBLIC getdns Libev::Libev) + set_target_properties(getdns_ex_ev PROPERTIES OUTPUT_NAME getdns_ex_ev${static_lib_suffix}) + endif () + if (ENABLE_SHARED) + add_library(getdns_ex_ev_shared SHARED $) + target_include_directories(getdns_ex_ev_shared PRIVATE Libev::Libev) + target_link_libraries(getdns_ex_ev_shared PUBLIC getdns_shared Libev::Libev) + set_target_properties(getdns_ex_ev_shared PROPERTIES OUTPUT_NAME getdns_ex_ev) + target_shared_library_version(getdns_ex_ev_shared ${GETDNS_VERSION_CURRENT} ${GETDNS_VERSION_REVISION} ${GETDNS_VERSION_AGE}) + file(STRINGS src/extension/libev.symbols symbols) + target_shared_library_exports(getdns_ex_ev_shared getdns_ex_ev "${symbols}") + if (NOT ENABLE_STATIC) + add_library(getdns_ex_ev ALIAS getdns_ex_ev_shared) + endif () + endif () + else () + message(WARNING "Libev not found, libev extension not built.") + set(USE_LIBEV OFF) + endif () +endif () + # libevent2 extension. if (USE_LIBEVENT2) find_package(Libevent2) @@ -766,12 +806,18 @@ configure_file(getdns.pc.in getdns.pc @ONLY) # Installing. if (ENABLE_STATIC) install(TARGETS getdns LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + if (USE_LIBEV) + install(TARGETS getdns_ex_ev LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + endif () if (USE_LIBEVENT2) install(TARGETS getdns_ex_event LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) endif () endif () if (ENABLE_SHARED) install(TARGETS getdns_shared LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + if (USE_LIBEV) + install(TARGETS getdns_ex_ev_shared LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + endif () if (USE_LIBEVENT2) install(TARGETS getdns_ex_event_shared LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) endif () diff --git a/cmake/modules/FindLibev.cmake b/cmake/modules/FindLibev.cmake new file mode 100644 index 00000000..7e21ecb8 --- /dev/null +++ b/cmake/modules/FindLibev.cmake @@ -0,0 +1,63 @@ +#[=======================================================================[.rst: +FindLibev +--------- + +Find the Libev library. + +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` targets: + +``Libev::Libev`` + The Libev library, if found. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``Libev_FOUND`` + If false, do not try to use Libev. +``LIBEV_INCLUDE_DIR`` + where to find check.h, etc. +``LIBEV_LIBRARIES`` + the libraries needed to use Libev. +``LIBEV_VERSION`` + the version of the Libev library found + +#]=======================================================================] + +find_path(LIBEV_INCLUDE_DIR ev.h + HINTS + "${LIBEV_DIR}" + "${LIBEV_DIR}/include" +) + +find_library(LIBEV_LIBRARY NAMES ev libev + HINTS + "${LIBEV_DIR}" + "${LIBEV_DIR}/lib" +) + +set(LIBEV_LIBRARIES "") + +if (LIBEV_INCLUDE_DIR AND LIBEV_LIBRARY) + if (NOT TARGET Libev::Libev) + add_library(Libev::Libev UNKNOWN IMPORTED) + set_target_properties(Libev::Libev PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBEV_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${LIBEV_LIBRARY}" + ) + endif () +endif() + +list(APPEND LIBEV_LIBRARIES "${LIBEV_LIBRARY}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libev + REQUIRED_VARS LIBEV_LIBRARIES LIBEV_INCLUDE_DIR + ) + +mark_as_advanced(LIBEV_INCLUDE_DIR LIBEV_LIBRARIES LIBEV_LIBRARY)