# This program is free software, licensed under the terms of the GNU GPL. # See the Bongo COPYING file for full details. # Copyright (c) 2026 Bongo Project contributors # Locate the validating Unbound resolver library. find_package(PkgConfig QUIET) if(PkgConfig_FOUND) pkg_check_modules(PC_UNBOUND QUIET libunbound) if(NOT PC_UNBOUND_FOUND) pkg_check_modules(PC_UNBOUND QUIET unbound) endif() endif() find_path(Unbound_INCLUDE_DIR NAMES unbound.h HINTS ${PC_UNBOUND_INCLUDEDIR} ${PC_UNBOUND_INCLUDE_DIRS}) find_library(Unbound_LIBRARY NAMES unbound HINTS ${PC_UNBOUND_LIBDIR} ${PC_UNBOUND_LIBRARY_DIRS}) set(Unbound_VERSION "${PC_UNBOUND_VERSION}") if(Unbound_INCLUDE_DIR AND NOT Unbound_VERSION AND EXISTS "${Unbound_INCLUDE_DIR}/unbound.h") file(STRINGS "${Unbound_INCLUDE_DIR}/unbound.h" _UNBOUND_VERSION_LINES REGEX "^#define UNBOUND_VERSION_(MAJOR|MINOR|MICRO) [0-9]+$") foreach(_component MAJOR MINOR MICRO) foreach(_line IN LISTS _UNBOUND_VERSION_LINES) if(_line MATCHES "^#define UNBOUND_VERSION_${_component} ([0-9]+)$") set(_UNBOUND_VERSION_${_component} "${CMAKE_MATCH_1}") endif() endforeach() endforeach() if(DEFINED _UNBOUND_VERSION_MAJOR AND DEFINED _UNBOUND_VERSION_MINOR AND DEFINED _UNBOUND_VERSION_MICRO) set(Unbound_VERSION "${_UNBOUND_VERSION_MAJOR}.${_UNBOUND_VERSION_MINOR}.${_UNBOUND_VERSION_MICRO}") endif() endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Unbound REQUIRED_VARS Unbound_LIBRARY Unbound_INCLUDE_DIR VERSION_VAR Unbound_VERSION) if(Unbound_FOUND AND NOT TARGET Unbound::Unbound) add_library(Unbound::Unbound UNKNOWN IMPORTED) set_target_properties(Unbound::Unbound PROPERTIES IMPORTED_LOCATION "${Unbound_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${Unbound_INCLUDE_DIR}") if(PC_UNBOUND_CFLAGS_OTHER) set_property(TARGET Unbound::Unbound PROPERTY INTERFACE_COMPILE_OPTIONS "${PC_UNBOUND_CFLAGS_OTHER}") endif() endif() mark_as_advanced(Unbound_INCLUDE_DIR Unbound_LIBRARY)