From: Kefu Chai Date: Wed, 4 Mar 2026 07:36:59 +0000 (+0800) Subject: cmake: create Boost::asio target with conditional uring support X-Git-Tag: v21.0.0~72^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9b617f518f08f5d38a3a1efdf10245d342d375cf;p=ceph.git cmake: create Boost::asio target with conditional uring support BOOST_ASIO_HAS_IO_URING is a user-defined macro that enables io_uring support in Boost.Asio for specific operations that explicitly opt in, such as file I/O via basic_file (BOOST_ASIO_HAS_FILE) and buffer registration. Unlike BOOST_ASIO_HAS_IO_URING_AS_DEFAULT, it does NOT replace epoll as the default event loop. Currently, Ceph does not use Boost.Asio to perform file I/O, so this macro only affects compilation, not runtime behavior. When BOOST_ASIO_HAS_IO_URING is defined, the umbrella header boost/asio.hpp pulls in via: boost/asio.hpp -> boost/asio/basic_file.hpp (guarded by BOOST_ASIO_HAS_FILE) -> boost/asio/detail/io_uring_file_service.hpp -> boost/asio/detail/io_uring_descriptor_service.hpp -> boost/asio/detail/io_uring_service.hpp -> PR #50821 introduced BOOST_ASIO_HAS_IO_URING (commit 05c341b30de) as preparation for uring-based file I/O in rgw/posix. To avoid pulling liburing headers (which define macros like BLOCK_SIZE and DATA_OFFSET that conflict with Ceph code) into unrelated translation units, that PR also converted many files to use granular Boost.Asio includes instead of the umbrella boost/asio.hpp. However, BOOST_ASIO_HAS_IO_URING was added as a global compile definition, and individual targets linked uring::uring directly. This has two problems: 1. The uring::uring CMake target only exists when WITH_LIBURING=ON, so targets that link it unconditionally break when WITH_LIBURING=OFF. 2. The global definition causes all translation units to see BOOST_ASIO_HAS_IO_URING, even those that don't need io_uring. Since neither CMake's FindBoost module nor Boost's CMake config file defines a Boost::asio target, introduce one as an INTERFACE IMPORTED library. When WITH_LIBURING=ON, the Boost::asio target carries the BOOST_ASIO_HAS_IO_URING definition and uring::uring dependency; when WITH_LIBURING=OFF, it is an empty interface. Targets that don't need io_uring should use Boost::headers or Boost::boost instead. This also improves code organization: - Scope the BOOST_ASIO_HAS_IO_URING compile definition to Boost::asio instead of adding it globally, so only targets that actually use Boost.Asio with io_uring see the definition. - Place the uring-in-Boost::asio configuration next to where we build/detect Boost libraries for better readability. - Set the Boost::asio properties in a single place for better maintainability. See also - 05c341b30deab327444eac464e24a840dae25083 - f479bbc4bc118989849fb663b5dcf5f46f05097d Signed-off-by: Kefu Chai --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f068cf7fb6c..82f49cab089 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -288,11 +288,6 @@ if(WITH_LIBURING) include(Builduring) build_uring() endif() - # enable uring in boost::asio - - if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "5.10") - add_compile_definitions("BOOST_ASIO_HAS_IO_URING") - endif() endif() CMAKE_DEPENDENT_OPTION(WITH_BLUESTORE_PMEM "Enable PMDK libraries" OFF @@ -806,6 +801,13 @@ else() COMPONENTS ${BOOST_COMPONENTS} ${BOOST_HEADER_COMPONENTS}) endif() include_directories(BEFORE SYSTEM ${Boost_INCLUDE_DIRS}) +add_library(Boost::asio INTERFACE IMPORTED) +if(WITH_LIBURING AND CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL "5.10") + # enable uring in boost::asio + set_target_properties(Boost::asio PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "BOOST_ASIO_HAS_IO_URING" + INTERFACE_LINK_LIBRARIES "Boost::headers;uring::uring") +endif() # dashboard angular2 frontend option(WITH_MGR_DASHBOARD_FRONTEND "Build the mgr/dashboard frontend using `npm`" ON)