Skip to content

Commit a726942

Browse files
committed
Merge 'build: use find_dependency() instead find_package() in config file' from Kefu Chai
SeastarDependencies.cmake is used in two scenarios: - configure Seastar library, when building Seastar itself. - configure Seastar library, when a parent project tries to detect Seastar library. when building the Seastar application. in the second case, we should respect the "REQUIRED" and "QUIET" options passed to `find_package(Seastar)`. and CMake provides `find_dependency()` macro for this purpose. in this change, we conditionally call `find_dependency()` when `SeastarDependencies.cmake` is used when this script is called when finding Seastar library. this provides a better developer experience to Seastar developers. Closes #2505 * https://github.com/scylladb/seastar: build: use find_dependency() instead find_package() in config file build: stop using a loop for finding dependencies
2 parents 66ee686 + 0ab6cca commit a726942

File tree

2 files changed

+50
-90
lines changed

2 files changed

+50
-90
lines changed

cmake/SeastarConfig.cmake.in

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
# Copyright (C) 2018 Scylladb, Ltd.
2121
#
2222

23-
# We would like to use `find_dependency`, but it is not supported properly until CMake 3.8.
24-
#include (FindDependencyMacro)
25-
2623
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
2724

2825
if (CMAKE_CXX_STANDARD)

cmake/SeastarDependencies.cmake

+50-87
Original file line numberDiff line numberDiff line change
@@ -39,103 +39,72 @@ if (Boost_VERSION_STRING VERSION_LESS 1.81.0)
3939
INTERFACE_COMPILE_DEFINITIONS "BOOST_NO_CXX98_FUNCTION_BASE")
4040
endif ()
4141

42-
# - set _seastar_dep_args_<package> for additional args for find_package().
43-
# add REQUIRED if the corresponding option is explicitly enabled, so
44-
# find_package() can stop the cmake generation.
45-
# - set _seastar_dep_skip_<package> if the option is explicitly disabled
46-
macro (seastar_set_dep_args package)
47-
cmake_parse_arguments(args "REQUIRED" "VERSION;OPTION" "COMPONENTS" ${ARGN})
48-
if (DEFINED args_VERSION)
49-
list (APPEND _seastar_dep_args_${package} ${args_VERSION})
50-
endif ()
51-
if (args_REQUIRED)
52-
list (APPEND _seastar_dep_args_${package} REQUIRED)
53-
elseif (DEFINED args_OPTION)
54-
if (args_OPTION)
55-
list (APPEND _seastar_dep_args_${package} REQUIRED)
42+
if (CMAKE_FIND_PACKAGE_NAME)
43+
# used inside find_package(Seastar)
44+
include (CMakeFindDependencyMacro)
45+
46+
macro (seastar_find_dep package)
47+
cmake_parse_arguments(args "REQUIRED" "" "" ${ARGN})
48+
if (arg_REQUIRED)
49+
find_dependency (${package} ${arg_UNPARSED_ARGUMENTS})
5650
else ()
57-
set (_seastar_dep_skip_${package} TRUE)
51+
# some packages are not REQUIRED, so we just check for them instead of
52+
# populating "REQUIRED" from the original find_package() call.
53+
find_package (${package} ${ARGN})
5854
endif ()
59-
endif ()
60-
if (args_COMPONENTS)
61-
list (APPEND _seastar_dep_args_${package} COMPONENTS
62-
${args_COMPONENTS})
63-
endif ()
64-
endmacro ()
55+
endmacro ()
56+
else()
57+
macro (seastar_find_dep package)
58+
# used when configuring Seastar
59+
find_package (${package} ${ARGN})
60+
endmacro ()
61+
endif ()
6562

66-
#
67-
# Iterate through the dependency list defined below and execute `find_package`
68-
# with the corresponding configuration for each 3rd-party dependency.
69-
#
7063
macro (seastar_find_dependencies)
7164
#
7265
# List of Seastar dependencies that is meant to be used
7366
# both in Seastar configuration and by clients which
7467
# consume Seastar via SeastarConfig.cmake.
7568
#
76-
set (_seastar_all_dependencies
77-
# Public dependencies.
78-
Boost
79-
c-ares
80-
dpdk # No version information published.
81-
fmt
82-
lz4
83-
# Private and private/public dependencies.
84-
GnuTLS
85-
LibUring
86-
LinuxMembarrier
87-
# Protobuf is searched manually.
88-
Sanitizers
89-
SourceLocation
90-
StdAtomic
91-
SystemTap-SDT
92-
hwloc
93-
lksctp-tools # No version information published.
94-
rt
95-
ucontext
96-
yaml-cpp)
97-
98-
# Arguments to `find_package` for each 3rd-party dependency.
99-
# Note that the version specification is a "minimal" version requirement.
100-
10169
# `unit_test_framework` is not required in the case we are building Seastar
10270
# without the testing library, however the component is always specified as required
10371
# to keep the CMake code minimalistic and easy-to-use.
104-
seastar_set_dep_args (Boost REQUIRED
105-
VERSION ${_seastar_boost_version}
72+
seastar_find_dep (Boost ${_seastar_boost_version} REQUIRED
10673
COMPONENTS
10774
filesystem
10875
program_options
10976
thread
11077
unit_test_framework)
111-
seastar_set_dep_args (c-ares REQUIRED
112-
VERSION 1.13)
113-
seastar_set_dep_args (dpdk
114-
OPTION ${Seastar_DPDK})
115-
seastar_set_dep_args (fmt REQUIRED
116-
VERSION 8.1.1)
117-
seastar_set_dep_args (lz4 REQUIRED
118-
VERSION 1.7.3)
119-
seastar_set_dep_args (GnuTLS REQUIRED
120-
VERSION 3.3.26)
121-
seastar_set_dep_args (LibUring
122-
VERSION 2.0
123-
OPTION ${Seastar_IO_URING})
124-
seastar_set_dep_args (StdAtomic REQUIRED)
125-
seastar_set_dep_args (hwloc
126-
VERSION 1.11.2
127-
OPTION ${Seastar_HWLOC})
128-
seastar_set_dep_args (lksctp-tools REQUIRED)
129-
seastar_set_dep_args (rt REQUIRED)
130-
seastar_set_dep_args (ucontext REQUIRED)
131-
seastar_set_dep_args (yaml-cpp REQUIRED
132-
VERSION 0.5.1)
78+
seastar_find_dep (c-ares 1.13 REQUIRED)
79+
if (c-ares_VERSION VERSION_GREATER_EQUAL 1.33.0 AND c-ares_VERSION VERSION_LESS 1.34.1)
80+
# https://github.com/scylladb/seastar/issues/2472
81+
message (FATAL_ERROR
82+
"c-ares ${c-ares_VERSION} is not supported. "
83+
"Seastar requires c-ares version <1.33 or >=1.34.1 ")
84+
endif ()
13385

134-
foreach (third_party ${_seastar_all_dependencies})
135-
if (NOT _seastar_dep_skip_${third_party})
136-
find_package ("${third_party}" ${_seastar_dep_args_${third_party}})
137-
endif ()
138-
endforeach ()
86+
if (Seastar_DPDK)
87+
seastar_find_dep (dpdk)
88+
endif()
89+
seastar_find_dep (fmt 8.1.1 REQUIRED)
90+
seastar_find_dep (lz4 1.7.3 REQUIRED)
91+
seastar_find_dep (GnuTLS 3.3.26 REQUIRED)
92+
if (Seastar_IO_URING)
93+
seastar_find_dep (LibUring 2.0 REQUIRED)
94+
endif()
95+
seastar_find_dep (LinuxMembarrier)
96+
seastar_find_dep (Sanitizers)
97+
seastar_find_dep (SourceLocation)
98+
seastar_find_dep (StdAtomic REQUIRED)
99+
seastar_find_dep (SystemTap-SDT)
100+
if (Seastar_HWLOC)
101+
seastar_find_dep (hwloc 1.11.2 REQUIRED)
102+
endif()
103+
seastar_find_dep (lksctp-tools REQUIRED)
104+
seastar_find_dep (rt REQUIRED)
105+
seastar_find_dep (ucontext REQUIRED)
106+
seastar_find_dep (yaml-cpp REQUIRED
107+
VERSION 0.5.1)
139108

140109
# workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/25079
141110
# since protobuf v22.0, it started using abseil, see
@@ -148,15 +117,9 @@ macro (seastar_find_dependencies)
148117
find_package (Protobuf QUIET CONFIG)
149118
if (Protobuf_FOUND AND Protobuf_VERSION VERSION_GREATER_EQUAL 2.5.0)
150119
# do it again, so the message is printed when the package is found
151-
find_package(Protobuf CONFIG REQUIRED)
120+
seastar_find_dep (Protobuf CONFIG REQUIRED)
152121
else ()
153-
find_package(Protobuf 2.5.0 REQUIRED)
122+
seastar_find_dep (Protobuf 2.5.0 REQUIRED)
154123
endif ()
155124

156-
if (c-ares_VERSION VERSION_GREATER_EQUAL 1.33.0 AND c-ares_VERSION VERSION_LESS 1.34.1)
157-
# https://github.com/scylladb/seastar/issues/2472
158-
message (FATAL_ERROR
159-
"c-ares ${c-ares_VERSION} is not supported. "
160-
"Seastar requires c-ares version <1.33 or >=1.34.1 ")
161-
endif ()
162125
endmacro ()

0 commit comments

Comments
 (0)