Merge pull request #34535 from changchengx/refine_build_liburing

cmake: refactor liburing support

Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2020-04-18 11:39:32 +08:00 committed by GitHub
commit b557467df0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 23 deletions

View File

@ -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)

View File

@ -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 <SOURCE_DIR>/configure
BUILD_COMMAND env CC=${CMAKE_C_COMPILER} ${make_cmd} -C src -s
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS "<SOURCE_DIR>/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()

View File

@ -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)

View File

@ -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 <SOURCE_DIR>/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()