From 5c2943c180bc5d6f2d6c0e26a33df1819fd0c956 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 17 Oct 2024 21:40:02 +0800 Subject: [PATCH] build: use find_dependency() instead find_package() in config file 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 --- cmake/SeastarConfig.cmake.in | 3 --- cmake/SeastarDependencies.cmake | 25 ++++++++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/cmake/SeastarConfig.cmake.in b/cmake/SeastarConfig.cmake.in index 7d4e868338..967c687f70 100644 --- a/cmake/SeastarConfig.cmake.in +++ b/cmake/SeastarConfig.cmake.in @@ -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) diff --git a/cmake/SeastarDependencies.cmake b/cmake/SeastarDependencies.cmake index c4d32b3eeb..df3ea09284 100644 --- a/cmake/SeastarDependencies.cmake +++ b/cmake/SeastarDependencies.cmake @@ -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 @@ -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) #