Skip to content

Commit ce4cc3a

Browse files
committed
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. git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1927582 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8c36696 commit ce4cc3a

File tree

5 files changed

+169
-18
lines changed

5 files changed

+169
-18
lines changed

CMakeLists.txt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,7 @@ else()
262262
message(WARNING "option GSSAPI_ROOT is not implemented on this platform")
263263
endif()
264264
endif()
265-
266-
267-
# FIXME: VERYTEMPORARY, figure out FindUnbound.cmake first.
268-
set(Unbound_FOUND FALSE)
269-
if (Unbound_FOUND)
270-
set(UNBOUND_INCLUDE_DIR "/opt/homebrew/opt/unbound/include")
271-
set(UNBOUND_LIBRARIES "/opt/homebrew/opt/unbound/lib/libunbound.dylib")
272-
# set(UNBOUND_LIBRARIES "/usr/lib/aarch64-linux-gnu/libunbound.so")
273-
# set(UNBOUND_LIBRARIES "/usr/lib64/libunbound.so")
274-
add_library(Unbound::Unbound UNKNOWN IMPORTED)
275-
set_target_properties(Unbound::Unbound PROPERTIES
276-
INTERFACE_INCLUDE_DIRECTORIES "${UNBOUND_INCLUDE_DIR}")
277-
set_target_properties(Unbound::Unbound PROPERTIES
278-
IMPORTED_LOCATION "${UNBOUND_LIBRARIES}")
279-
endif(Unbound_FOUND)
265+
find_package(Unbound)
280266

281267
# Calculate the set of private and public targets
282268
set(SERF_PRIVATE_TARGETS OpenSSL::Crypto OpenSSL::SSL ZLIB::ZLIB)
@@ -289,7 +275,7 @@ if(GSSAPI_FOUND)
289275
endif()
290276
if(Unbound_FOUND)
291277
list(APPEND SERF_C_DEFINES "SERF_HAVE_ASYNC_RESOLVER=1")
292-
list(APPEND SERF_C_DEFINES "SERF_HAVE_UNBOUND")
278+
list(APPEND SERF_C_DEFINES "SERF_HAVE_UNBOUND=1")
293279
list(APPEND SERF_PRIVATE_TARGETS Unbound::Unbound)
294280
endif()
295281

@@ -510,6 +496,9 @@ if(NOT SERF_WINDOWS)
510496
set(LIBDIR \${prefix}/${SERF_INSTALL_LIBRARIES})
511497
set(VERSION ${SERF_VERSION})
512498
set(MAJOR ${SERF_MAJOR_VERSION})
499+
set(PC_REQUIRES
500+
${UNBOUND_PC_REQUIRES}
501+
)
513502
set(LIBS
514503
${APR_LDFLAGS}
515504
${APR_LIBRARIES}
@@ -520,6 +509,7 @@ if(NOT SERF_WINDOWS)
520509
${BROTLI_COMMON_LIBRARY}
521510
${BROTLI_DECODE_LIBRARY}
522511
${GSSAPI_LIBRARIES}
512+
${UNBOUND_PC_LIBS}
523513
${ZLIB_LIBRARIES}
524514
)
525515
list(REMOVE_DUPLICATES LIBS)
@@ -581,7 +571,7 @@ endif()
581571
if("SERF_HAVE_SSPI" IN_LIST SERF_C_DEFINES)
582572
set(_have_sspi ON)
583573
endif()
584-
if ("SERF_HAVE_UNBOUND" IN_LIST SERF_C_DEFINES)
574+
if ("SERF_HAVE_UNBOUND=1" IN_LIST SERF_C_DEFINES)
585575
set(_have_unbound "EXPERIMENTAL")
586576
endif()
587577

SConstruct

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ for d in env['LIBPATH']:
695695
env.Append(RPATH=[':'+d])
696696

697697
# Set up the construction of serf-*.pc
698+
PC_REQUIRES = [] # TODO: Add dependency pkg-config modules
698699
pkgprefix = os.path.relpath(env.subst('$PREFIX'), env.subst('$LIBDIR/pkgconfig'))
699700
pkglibdir = os.path.relpath(env.subst('$LIBDIR'), env.subst('$PREFIX'))
700701
pkgconfig = env.Textfile('serf-%d.pc' % (MAJOR,),
@@ -704,6 +705,7 @@ pkgconfig = env.Textfile('serf-%d.pc' % (MAJOR,),
704705
'@PREFIX@': unsubstable('${pcfiledir}/' + pkgprefix),
705706
'@LIBDIR@': unsubstable('${prefix}/' + pkglibdir),
706707
'@INCLUDE_SUBDIR@': 'serf-%d' % (MAJOR,),
708+
'@PC_REQUIRES@': ' '.join(PC_REQUIRES),
707709
'@VERSION@': '%d.%d.%d' % (MAJOR, MINOR, PATCH),
708710
'@LIBS@': '%s %s %s %s -lz' % (apu_libs, apr_libs,
709711
env.get('GSSAPI_LIBS', ''),

build/FindUnbound.cmake

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# ===================================================================
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
# ===================================================================
19+
20+
cmake_minimum_required(VERSION 3.12)
21+
22+
#.rst:
23+
# FindUnbound
24+
# -----------
25+
#
26+
# Find the Unbound library and headers.
27+
#
28+
# IMPORTED Targets
29+
# ^^^^^^^^^^^^^^^^
30+
#
31+
# This module defines :prop_tgt:`IMPORTED` target ``Unbound::Unbound``, if
32+
# libunbound has been found.
33+
#
34+
# Result Variables
35+
# ^^^^^^^^^^^^^^^^
36+
#
37+
# This module defines the following variables:
38+
#
39+
# ::
40+
#
41+
# Unbound_FOUND - True if libunbound was found.
42+
# UNBOUND_VERSION - The version of libunbound found (x.y.z).
43+
# UNBOUND_INCLUDE_DIR - Where to find unbound.h.
44+
# UNBOUND_LIBRARY - Linker switches to use with ld to link the library.
45+
#
46+
# ::
47+
#
48+
# UNBOUND_PC_REQUIRES - The name of the pkg-config module for libunbound;
49+
# empty if pkg-config was not used to find the library.
50+
# UNBOUND_PC_LIBS - The link libraries for pkg-config, if
51+
# UNBOUND_PC_REQUUIRES is not set.
52+
#
53+
# Hints
54+
# ^^^^^
55+
#
56+
# A user may set ``Unbound_ROOT`` to tell this module where to look.
57+
58+
include(FindPackageHandleStandardArgs)
59+
include(GNUInstallDirs)
60+
find_package(PkgConfig QUIET)
61+
62+
# Save the PKG_CONFIG_PATH environment variable
63+
if(PKG_CONFIG_FOUND)
64+
set(_pkg_config_path $ENV{PKG_CONFIG_PATH})
65+
endif()
66+
67+
set(Unbound_FOUND FALSE)
68+
if(DEFINED Unbound_ROOT)
69+
# Search in the provided root path
70+
set(_root_search PATHS ${Unbound_ROOT} NO_DEFAULT_PATH)
71+
list(APPEND _UNBOUND_SEARCHES _root_search)
72+
73+
# Set the PKG_CONFIG_PATH environment variable
74+
if(PKG_CONFIG_FOUND)
75+
find_path(_pcfile NAMES "libunbound.pc"
76+
${_root_search}
77+
PATH_SUFFIXES
78+
"lib/pkgconfig"
79+
"${CMAKE_INSTALL_LIBDIR}/pkgconfig"
80+
"share/pkgconfig"
81+
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
82+
if(_pcfile AND EXISTS "${_pcfile}/libunbound.pc")
83+
set(ENV{PKG_CONFIG_PATH} ${_pcfile})
84+
endif()
85+
endif()
86+
endif()
87+
88+
# Search in default paths
89+
set(_default_search)
90+
list(APPEND _UNBOUND_SEARCHES _default_search)
91+
92+
# Try pkg-config first
93+
if(PKG_CONFIG_FOUND)
94+
pkg_search_module(UNBOUND QUIET IMPORTED_TARGET libunbound)
95+
if(UNBOUND_FOUND)
96+
find_package_handle_standard_args(Unbound
97+
REQUIRED_VARS UNBOUND_LINK_LIBRARIES UNBOUND_INCLUDEDIR
98+
VERSION_VAR UNBOUND_VERSION)
99+
if(Unbound_FOUND)
100+
add_library(Unbound::Unbound ALIAS PkgConfig::UNBOUND)
101+
set(UNBOUND_INCLUDE_DIR ${UNBOUND_INCLUDEDIR})
102+
set(UNBOUND_LIBRARY ${UNBOUND_LINK_LIBRARIES})
103+
set(UNBOUND_PC_REQUIRES libunbound)
104+
set(UNBOUND_PC_LIBS)
105+
endif()
106+
endif()
107+
endif()
108+
109+
if(NOT Unbound_FOUND)
110+
# Try each search configuration
111+
foreach(search ${_UNBOUND_SEARCHES})
112+
find_path(UNBOUND_INCLUDE_DIR NAMES "unbound.h" ${${search}}
113+
PATH_SUFFIXES "include" "${CMAKE_INSTALL_INCLUDEDIR}")
114+
if(UNBOUND_INCLUDE_DIR AND EXISTS "${UNBOUND_INCLUDE_DIR}/unbound.h")
115+
# Use the first successful search to find the libraries
116+
if(NOT DEFINED libsearch)
117+
set(libsearch ${search})
118+
endif()
119+
endif()
120+
endforeach()
121+
122+
find_library(UNBOUND_LIBRARY NAMES "unbound" NAMES_PER_DIR ${${libsearch}}
123+
PATH_SUFFIXES "lib" "${CMAKE_INSTALL_LIBDIR}")
124+
125+
# Extract the version number from the header
126+
if(UNBOUND_INCLUDE_DIR AND EXISTS "${UNBOUND_INCLUDE_DIR}/unbound.h")
127+
file(STRINGS "${UNBOUND_INCLUDE_DIR}/unbound.h" _major
128+
REGEX "^ *# *define +UNBOUND_VERSION_MAJOR +[0-9]+.*$")
129+
file(STRINGS "${UNBOUND_INCLUDE_DIR}/unbound.h" _minor
130+
REGEX "^ *# *define +UNBOUND_VERSION_MINOR +[0-9]+.*$")
131+
file(STRINGS "${UNBOUND_INCLUDE_DIR}/unbound.h" _micro
132+
REGEX "^ *# *define +UNBOUND_VERSION_MICRO +[0-9]+.*$")
133+
string(REGEX REPLACE "^[^0-9]+([0-9]+).*$" "\\1" _major ${_major})
134+
string(REGEX REPLACE "^[^0-9]+([0-9]+).*$" "\\1" _minor ${_minor})
135+
string(REGEX REPLACE "^[^0-9]+([0-9]+).*$" "\\1" _micro ${_micro})
136+
set(UNBOUND_VERSION "${_major}.${_minor}.${_micro}")
137+
endif()
138+
139+
find_package_handle_standard_args(Unbound
140+
REQUIRED_VARS UNBOUND_LIBRARY UNBOUND_INCLUDE_DIR
141+
VERSION_VAR UNBOUND_VERSION)
142+
if(Unbound_FOUND)
143+
add_library(Unbound::Unbound UNKNOWN IMPORTED)
144+
set_target_properties(Unbound::Unbound PROPERTIES
145+
INTERFACE_INCLUDE_DIRECTORIES "${UNBOUND_INCLUDE_DIR}"
146+
IMPORTED_LOCATION "${UNBOUND_LIBRARY}")
147+
set(UNBOUND_PC_REQUIRES)
148+
set(UNBOUND_PC_LIBS "${UNBOUND_LIBRARY}")
149+
endif()
150+
endif()
151+
152+
mark_as_advanced(UNBOUND_INCLUDE_DIR)
153+
mark_as_advanced(UNBOUND_LIBRARY)
154+
155+
# Restore the PKG_CONFIG_PATH environment variable
156+
if(PKG_CONFIG_FOUND)
157+
set(ENV{PKG_CONFIG_PATH} ${_pkg_config_path})
158+
endif()

build/SerfMacOS.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function(serf_macos_find_packages)
5252
endif()
5353
_serf_macos__find_package("brotli" Brotli_ROOT "Path to Brotli's install area")
5454
_serf_macos__find_package("gssapi" GSSAPI_ROOT "Path to GSSAPI's install area")
55+
_serf_macos__find_package("unbound" Unbound_ROOT "Path to Unbound's install area")
5556
endfunction()
5657

5758
#

build/serf.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ includedir=${prefix}/include/@INCLUDE_SUBDIR@
77
Name: serf
88
Description: HTTP client library
99
Version: @VERSION@
10-
Requires.private: libssl libcrypto
10+
Requires.private: libssl libcrypto @PC_REQUIRES@
1111
Libs: -L${libdir} -lserf-${SERF_MAJOR_VERSION}
1212
Libs.private: @LIBS@
1313
Cflags: -I${includedir}

0 commit comments

Comments
 (0)