Author: brane
Date: Sat Aug  2 12:02:09 2025
New Revision: 1927582

Log:
In the CMake build, look for Unbound. The SCons build doesn't support this
yet, it only handles the new addition to the pkg-config file template.

* CMakeLists.txt:
   - Find Unbound.
   - Remove the temporary hack for using Unbound in the build.
   - Use the new variables from FindUnbound to generate the pkg-config file.
* SConstruct
  (PC_REQUIRES): New variable, substitute it into the pkg-config file.
* build/FindUnbound.cmake: New; Find Unbound, either through pkg-config
   or the old-fashioned way.
* build/SerfMacOS.cmake: Find "unbound" in Homebrew or MacPorts.
* build/serf.pc.in: Add the @PC_REQUIRES@ substitution for private
   dependencies that are available through pkg-config.

Added:
   serf/trunk/build/FindUnbound.cmake
Modified:
   serf/trunk/CMakeLists.txt
   serf/trunk/SConstruct
   serf/trunk/build/SerfMacOS.cmake
   serf/trunk/build/serf.pc.in

Modified: serf/trunk/CMakeLists.txt
==============================================================================
--- serf/trunk/CMakeLists.txt   Sat Aug  2 11:06:03 2025        (r1927581)
+++ serf/trunk/CMakeLists.txt   Sat Aug  2 12:02:09 2025        (r1927582)
@@ -262,21 +262,7 @@ else()
     message(WARNING "option GSSAPI_ROOT is not implemented on this platform")
   endif()
 endif()
-
-
-# FIXME: VERYTEMPORARY, figure out FindUnbound.cmake first.
-set(Unbound_FOUND FALSE)
-if (Unbound_FOUND)
-  set(UNBOUND_INCLUDE_DIR "/opt/homebrew/opt/unbound/include")
-  set(UNBOUND_LIBRARIES "/opt/homebrew/opt/unbound/lib/libunbound.dylib")
-  # set(UNBOUND_LIBRARIES "/usr/lib/aarch64-linux-gnu/libunbound.so")
-  # set(UNBOUND_LIBRARIES "/usr/lib64/libunbound.so")
-  add_library(Unbound::Unbound UNKNOWN IMPORTED)
-  set_target_properties(Unbound::Unbound PROPERTIES
-    INTERFACE_INCLUDE_DIRECTORIES "${UNBOUND_INCLUDE_DIR}")
-  set_target_properties(Unbound::Unbound PROPERTIES
-    IMPORTED_LOCATION "${UNBOUND_LIBRARIES}")
-endif(Unbound_FOUND)
+find_package(Unbound)
 
 # Calculate the set of private and public targets
 set(SERF_PRIVATE_TARGETS OpenSSL::Crypto OpenSSL::SSL ZLIB::ZLIB)
@@ -289,7 +275,7 @@ if(GSSAPI_FOUND)
 endif()
 if(Unbound_FOUND)
   list(APPEND SERF_C_DEFINES "SERF_HAVE_ASYNC_RESOLVER=1")
-  list(APPEND SERF_C_DEFINES "SERF_HAVE_UNBOUND")
+  list(APPEND SERF_C_DEFINES "SERF_HAVE_UNBOUND=1")
   list(APPEND SERF_PRIVATE_TARGETS Unbound::Unbound)
 endif()
 
@@ -510,6 +496,9 @@ if(NOT SERF_WINDOWS)
     set(LIBDIR \${prefix}/${SERF_INSTALL_LIBRARIES})
     set(VERSION ${SERF_VERSION})
     set(MAJOR ${SERF_MAJOR_VERSION})
+    set(PC_REQUIRES
+      ${UNBOUND_PC_REQUIRES}
+      )
     set(LIBS
       ${APR_LDFLAGS}
       ${APR_LIBRARIES}
@@ -520,6 +509,7 @@ if(NOT SERF_WINDOWS)
       ${BROTLI_COMMON_LIBRARY}
       ${BROTLI_DECODE_LIBRARY}
       ${GSSAPI_LIBRARIES}
+      ${UNBOUND_PC_LIBS}
       ${ZLIB_LIBRARIES}
       )
     list(REMOVE_DUPLICATES LIBS)
@@ -581,7 +571,7 @@ endif()
 if("SERF_HAVE_SSPI" IN_LIST SERF_C_DEFINES)
   set(_have_sspi ON)
 endif()
-if ("SERF_HAVE_UNBOUND" IN_LIST SERF_C_DEFINES)
+if ("SERF_HAVE_UNBOUND=1" IN_LIST SERF_C_DEFINES)
   set(_have_unbound "EXPERIMENTAL")
 endif()
 

Modified: serf/trunk/SConstruct
==============================================================================
--- serf/trunk/SConstruct       Sat Aug  2 11:06:03 2025        (r1927581)
+++ serf/trunk/SConstruct       Sat Aug  2 12:02:09 2025        (r1927582)
@@ -695,6 +695,7 @@ for d in env['LIBPATH']:
   env.Append(RPATH=[':'+d])
 
 # Set up the construction of serf-*.pc
+PC_REQUIRES = []                 # TODO: Add dependency pkg-config modules
 pkgprefix = os.path.relpath(env.subst('$PREFIX'), 
env.subst('$LIBDIR/pkgconfig'))
 pkglibdir = os.path.relpath(env.subst('$LIBDIR'), env.subst('$PREFIX'))
 pkgconfig = env.Textfile('serf-%d.pc' % (MAJOR,),
@@ -704,6 +705,7 @@ pkgconfig = env.Textfile('serf-%d.pc' %
                            '@PREFIX@': unsubstable('${pcfiledir}/' + 
pkgprefix),
                            '@LIBDIR@': unsubstable('${prefix}/' + pkglibdir),
                            '@INCLUDE_SUBDIR@': 'serf-%d' % (MAJOR,),
+                           '@PC_REQUIRES@': ' '.join(PC_REQUIRES),
                            '@VERSION@': '%d.%d.%d' % (MAJOR, MINOR, PATCH),
                            '@LIBS@': '%s %s %s %s -lz' % (apu_libs, apr_libs,
                                                           
env.get('GSSAPI_LIBS', ''),

Added: serf/trunk/build/FindUnbound.cmake
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ serf/trunk/build/FindUnbound.cmake  Sat Aug  2 12:02:09 2025        
(r1927582)
@@ -0,0 +1,158 @@
+# ===================================================================
+#   Licensed to the Apache Software Foundation (ASF) under one
+#   or more contributor license agreements.  See the NOTICE file
+#   distributed with this work for additional information
+#   regarding copyright ownership.  The ASF licenses this file
+#   to you under the Apache License, Version 2.0 (the
+#   "License"); you may not use this file except in compliance
+#   with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing,
+#   software distributed under the License is distributed on an
+#   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#   KIND, either express or implied.  See the License for the
+#   specific language governing permissions and limitations
+#   under the License.
+# ===================================================================
+
+cmake_minimum_required(VERSION 3.12)
+
+#.rst:
+# FindUnbound
+# -----------
+#
+# Find the Unbound library and headers.
+#
+# IMPORTED Targets
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines :prop_tgt:`IMPORTED` target ``Unbound::Unbound``, if
+# libunbound has been found.
+#
+# Result Variables
+# ^^^^^^^^^^^^^^^^
+#
+# This module defines the following variables:
+#
+# ::
+#
+#   Unbound_FOUND        - True if libunbound was found.
+#   UNBOUND_VERSION      - The version of libunbound found (x.y.z).
+#   UNBOUND_INCLUDE_DIR  - Where to find unbound.h.
+#   UNBOUND_LIBRARY      - Linker switches to use with ld to link the library.
+#
+# ::
+#
+#   UNBOUND_PC_REQUIRES  - The name of the pkg-config module for libunbound;
+#                          empty if pkg-config was not used to find the 
library.
+#   UNBOUND_PC_LIBS      - The link libraries for pkg-config, if
+#                          UNBOUND_PC_REQUUIRES is not set.
+#
+# Hints
+# ^^^^^
+#
+# A user may set ``Unbound_ROOT`` to tell this module where to look.
+
+include(FindPackageHandleStandardArgs)
+include(GNUInstallDirs)
+find_package(PkgConfig QUIET)
+
+# Save the PKG_CONFIG_PATH environment variable
+if(PKG_CONFIG_FOUND)
+  set(_pkg_config_path $ENV{PKG_CONFIG_PATH})
+endif()
+
+set(Unbound_FOUND FALSE)
+if(DEFINED Unbound_ROOT)
+  # Search in the provided root path
+  set(_root_search PATHS ${Unbound_ROOT} NO_DEFAULT_PATH)
+  list(APPEND _UNBOUND_SEARCHES _root_search)
+
+  # Set the PKG_CONFIG_PATH environment variable
+  if(PKG_CONFIG_FOUND)
+    find_path(_pcfile NAMES "libunbound.pc"
+              ${_root_search}
+              PATH_SUFFIXES
+              "lib/pkgconfig"
+              "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
+              "share/pkgconfig"
+              "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
+    if(_pcfile AND EXISTS "${_pcfile}/libunbound.pc")
+      set(ENV{PKG_CONFIG_PATH} ${_pcfile})
+    endif()
+  endif()
+endif()
+
+# Search in default paths
+set(_default_search)
+list(APPEND _UNBOUND_SEARCHES _default_search)
+
+# Try pkg-config first
+if(PKG_CONFIG_FOUND)
+  pkg_search_module(UNBOUND QUIET IMPORTED_TARGET libunbound)
+  if(UNBOUND_FOUND)
+    find_package_handle_standard_args(Unbound
+      REQUIRED_VARS UNBOUND_LINK_LIBRARIES UNBOUND_INCLUDEDIR
+      VERSION_VAR UNBOUND_VERSION)
+    if(Unbound_FOUND)
+      add_library(Unbound::Unbound ALIAS PkgConfig::UNBOUND)
+      set(UNBOUND_INCLUDE_DIR ${UNBOUND_INCLUDEDIR})
+      set(UNBOUND_LIBRARY ${UNBOUND_LINK_LIBRARIES})
+      set(UNBOUND_PC_REQUIRES libunbound)
+      set(UNBOUND_PC_LIBS)
+    endif()
+  endif()
+endif()
+
+if(NOT Unbound_FOUND)
+  # Try each search configuration
+  foreach(search ${_UNBOUND_SEARCHES})
+    find_path(UNBOUND_INCLUDE_DIR NAMES "unbound.h" ${${search}}
+              PATH_SUFFIXES "include" "${CMAKE_INSTALL_INCLUDEDIR}")
+    if(UNBOUND_INCLUDE_DIR AND EXISTS "${UNBOUND_INCLUDE_DIR}/unbound.h")
+      # Use the first successful search to find the libraries
+      if(NOT DEFINED libsearch)
+        set(libsearch ${search})
+      endif()
+    endif()
+  endforeach()
+
+  find_library(UNBOUND_LIBRARY NAMES "unbound" NAMES_PER_DIR ${${libsearch}}
+               PATH_SUFFIXES "lib" "${CMAKE_INSTALL_LIBDIR}")
+
+  # Extract the version number from the header
+  if(UNBOUND_INCLUDE_DIR AND EXISTS "${UNBOUND_INCLUDE_DIR}/unbound.h")
+    file(STRINGS "${UNBOUND_INCLUDE_DIR}/unbound.h" _major
+      REGEX "^ *# *define +UNBOUND_VERSION_MAJOR +[0-9]+.*$")
+    file(STRINGS "${UNBOUND_INCLUDE_DIR}/unbound.h" _minor
+      REGEX "^ *# *define +UNBOUND_VERSION_MINOR +[0-9]+.*$")
+    file(STRINGS "${UNBOUND_INCLUDE_DIR}/unbound.h" _micro
+      REGEX "^ *# *define +UNBOUND_VERSION_MICRO +[0-9]+.*$")
+    string(REGEX REPLACE "^[^0-9]+([0-9]+).*$" "\\1" _major ${_major})
+    string(REGEX REPLACE "^[^0-9]+([0-9]+).*$" "\\1" _minor ${_minor})
+    string(REGEX REPLACE "^[^0-9]+([0-9]+).*$" "\\1" _micro ${_micro})
+    set(UNBOUND_VERSION "${_major}.${_minor}.${_micro}")
+  endif()
+
+  find_package_handle_standard_args(Unbound
+    REQUIRED_VARS UNBOUND_LIBRARY UNBOUND_INCLUDE_DIR
+    VERSION_VAR UNBOUND_VERSION)
+  if(Unbound_FOUND)
+    add_library(Unbound::Unbound UNKNOWN IMPORTED)
+    set_target_properties(Unbound::Unbound PROPERTIES
+      INTERFACE_INCLUDE_DIRECTORIES "${UNBOUND_INCLUDE_DIR}"
+      IMPORTED_LOCATION "${UNBOUND_LIBRARY}")
+    set(UNBOUND_PC_REQUIRES)
+    set(UNBOUND_PC_LIBS "${UNBOUND_LIBRARY}")
+  endif()
+endif()
+
+mark_as_advanced(UNBOUND_INCLUDE_DIR)
+mark_as_advanced(UNBOUND_LIBRARY)
+
+# Restore the PKG_CONFIG_PATH environment variable
+if(PKG_CONFIG_FOUND)
+  set(ENV{PKG_CONFIG_PATH} ${_pkg_config_path})
+endif()

Modified: serf/trunk/build/SerfMacOS.cmake
==============================================================================
--- serf/trunk/build/SerfMacOS.cmake    Sat Aug  2 11:06:03 2025        
(r1927581)
+++ serf/trunk/build/SerfMacOS.cmake    Sat Aug  2 12:02:09 2025        
(r1927582)
@@ -52,6 +52,7 @@ function(serf_macos_find_packages)
   endif()
   _serf_macos__find_package("brotli" Brotli_ROOT "Path to Brotli's install 
area")
   _serf_macos__find_package("gssapi" GSSAPI_ROOT "Path to GSSAPI's install 
area")
+  _serf_macos__find_package("unbound" Unbound_ROOT "Path to Unbound's install 
area")
 endfunction()
 
 #

Modified: serf/trunk/build/serf.pc.in
==============================================================================
--- serf/trunk/build/serf.pc.in Sat Aug  2 11:06:03 2025        (r1927581)
+++ serf/trunk/build/serf.pc.in Sat Aug  2 12:02:09 2025        (r1927582)
@@ -7,7 +7,7 @@ includedir=${prefix}/include/@INCLUDE_SU
 Name: serf
 Description: HTTP client library
 Version: @VERSION@
-Requires.private: libssl libcrypto
+Requires.private: libssl libcrypto @PC_REQUIRES@
 Libs: -L${libdir} -lserf-${SERF_MAJOR_VERSION}
 Libs.private: @LIBS@
 Cflags: -I${includedir}

Reply via email to