Skip to content

Commit

Permalink
build: use find_dependency() instead find_package() in config file
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Oct 17, 2024
1 parent 523750a commit 5c2943c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 0 additions & 3 deletions cmake/SeastarConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
# Copyright (C) 2018 Scylladb, Ltd.
#

# We would like to use `find_dependency`, but it is not supported properly until CMake 3.8.
#include (FindDependencyMacro)

list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

if (CMAKE_CXX_STANDARD)
Expand Down
25 changes: 22 additions & 3 deletions cmake/SeastarDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# Copyright (C) 2019 Scylladb, Ltd.
#

include(CMakeParseArguments)

#
# CMake bundles `FindBoost.cmake`, which is coupled to the Boost version. If
# we're on a system without a recent enough version of `FindBoost.cmake`, then
Expand Down Expand Up @@ -48,9 +50,26 @@ if (Boost_VERSION_STRING VERSION_LESS 1.81.0)
INTERFACE_COMPILE_DEFINITIONS "BOOST_NO_CXX98_FUNCTION_BASE")
endif ()

macro (seastar_find_dep package)
find_package (${package} ${ARGN})
endmacro ()
if (CMAKE_FIND_PACKAGE_NAME)
# used inside find_package(Seastar)
include (CMakeFindDependencyMacro)

macro (seastar_find_dep package)
cmake_parse_arguments(args "REQUIRED" "" "" ${ARGN})
if (arg_REQUIRED)
find_dependency (${package} ${arg_UNPARSED_ARGUMENTS})
else ()
# some packages are not REQUIRED, so we just check for them instead of
# populating "REQUIRED" from the original find_package() call.
find_package (${package} ${ARGN})
endif ()
endmacro ()
else()
macro (seastar_find_dep package)
# used when configuring Seastar
find_package (${package} ${ARGN})
endmacro ()
endif ()

macro (seastar_find_dependencies)
#
Expand Down

0 comments on commit 5c2943c

Please sign in to comment.