From: Changcheng Liu Date: Mon, 13 Apr 2020 09:55:49 +0000 (+0800) Subject: cmake: use cmake module to integrate liburing X-Git-Tag: v17.0.0~2600^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=36918d7f781faf89b2ed3f3da8b0f4eb3e90b342;p=ceph.git cmake: use cmake module to integrate liburing 1. WITH_LIBURING is used to set HAVE_LIBURING to decide use liburing in KernelDevice or not. 2. WITH_SYSTEM_LIBURING is to choose use system installed liburing or build the liburing from source code. Signed-off-by: Changcheng Liu --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 41a8b7a15d0fb..1e59132ac6fb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,10 +187,13 @@ if(WITH_BLUESTORE) endif() include(CMakeDependentOption) -CMAKE_DEPENDENT_OPTION(WITH_LIBURING "Build with liburing library support" OFF +CMAKE_DEPENDENT_OPTION(WITH_LIBURING "Enable io_uring bluestore backend" OFF "WITH_BLUESTORE;HAVE_LIBAIO" OFF) set(HAVE_LIBURING ${WITH_LIBURING}) +CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_LIBURING "Require and build with system liburing" OFF + "HAVE_LIBAIO;WITH_BLUESTORE" OFF) + CMAKE_DEPENDENT_OPTION(WITH_BLUESTORE_PMEM "Enable PMDK libraries" OFF "WITH_BLUESTORE" OFF) diff --git a/cmake/modules/Builduring.cmake b/cmake/modules/Builduring.cmake new file mode 100644 index 0000000000000..d16e779a2f8d7 --- /dev/null +++ b/cmake/modules/Builduring.cmake @@ -0,0 +1,28 @@ +function(build_uring) + include(FindMake) + find_make("MAKE_EXECUTABLE" "make_cmd") + + include(ExternalProject) + ExternalProject_Add(liburing_ext + GIT_REPOSITORY http://git.kernel.dk/liburing + GIT_TAG "4e360f71131918c36774f51688e5c65dea8d43f2" + SOURCE_DIR ${CMAKE_BINARY_DIR}/src/liburing + CONFIGURE_COMMAND /configure + BUILD_COMMAND env CC=${CMAKE_C_COMPILER} ${make_cmd} -C src -s + BUILD_IN_SOURCE 1 + BUILD_BYPRODUCTS "/src/liburing.a" + INSTALL_COMMAND "") + unset(make_cmd) + + ExternalProject_Get_Property(liburing_ext source_dir) + set(URING_INCLUDE_DIR "${source_dir}/src/include") + set(URING_LIBRARY_DIR "${source_dir}/src") + + add_library(uring::uring STATIC IMPORTED GLOBAL) + add_dependencies(uring::uring liburing_ext) + file(MAKE_DIRECTORY ${URING_INCLUDE_DIR}) + set_target_properties(uring::uring PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${URING_INCLUDE_DIR} + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${URING_LIBRARY_DIR}/liburing.a") +endfunction() diff --git a/cmake/modules/Finduring.cmake b/cmake/modules/Finduring.cmake new file mode 100644 index 0000000000000..10c8de425501e --- /dev/null +++ b/cmake/modules/Finduring.cmake @@ -0,0 +1,21 @@ +# - Find uring +# +# URING_INCLUDE_DIR - Where to find liburing.h +# URING_LIBRARIES - List of libraries when using uring. +# uring_FOUND - True if uring found. + +find_path(URING_INCLUDE_DIR liburing.h) +find_library(URING_LIBRARIES liburing.a liburing) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(uring DEFAULT_MSG URING_LIBRARIES URING_INCLUDE_DIR) + +if(uring_FOUND AND NOT TARGET uring::uring) + add_library(uring::uring UNKNOWN IMPORTED) + set_target_properties(uring::uring PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${URING_INCLUDE_DIR}" + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${URING_LIBRARIES}") +endif() + +mark_as_advanced(URING_INCLUDE_DIR URING_LIBRARIES) diff --git a/src/os/CMakeLists.txt b/src/os/CMakeLists.txt index 51894fd9a3c95..22ff0b7883f55 100644 --- a/src/os/CMakeLists.txt +++ b/src/os/CMakeLists.txt @@ -134,27 +134,11 @@ if(WITH_EVENTTRACE) endif() if(WITH_LIBURING) - include(ExternalProject) - if("${CMAKE_GENERATOR}" MATCHES "Make") - set(make_cmd "$(MAKE)") + if(WITH_SYSTEM_LIBURING) + find_package(uring REQUIRED) else() - set(make_cmd "make") + include(Builduring) + build_uring() endif() - ExternalProject_Add(liburing_ext - DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/src/ - GIT_REPOSITORY http://git.kernel.dk/liburing - GIT_TAG "4e360f71131918c36774f51688e5c65dea8d43f2" - SOURCE_DIR ${CMAKE_BINARY_DIR}/src/liburing - CONFIGURE_COMMAND /configure - BUILD_COMMAND env CC=${CMAKE_C_COMPILER} ${make_cmd} -C src -s - BUILD_IN_SOURCE 1 - INSTALL_COMMAND "") - unset(make_cmd) - add_library(liburing STATIC IMPORTED GLOBAL) - add_dependencies(liburing liburing_ext) - set_target_properties(liburing PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/src/liburing/src/liburing.a") - target_link_libraries(os liburing) - target_include_directories(os SYSTEM PRIVATE "${CMAKE_BINARY_DIR}/src/liburing/src/include") -endif(WITH_LIBURING) + target_link_libraries(os uring::uring) +endif()