]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: use cmake module to integrate liburing 34535/head
authorChangcheng Liu <changcheng.liu@aliyun.com>
Mon, 13 Apr 2020 09:55:49 +0000 (17:55 +0800)
committerChangcheng Liu <changcheng.liu@aliyun.com>
Fri, 17 Apr 2020 15:22:56 +0000 (23:22 +0800)
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 <changcheng.liu@aliyun.com>
CMakeLists.txt
cmake/modules/Builduring.cmake [new file with mode: 0644]
cmake/modules/Finduring.cmake [new file with mode: 0644]
src/os/CMakeLists.txt

index 41a8b7a15d0fb4e6365cb73c1140fb872aca6d28..1e59132ac6fb9f46fa5c40e9c0dd8fba5ccec268 100644 (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)
 
diff --git a/cmake/modules/Builduring.cmake b/cmake/modules/Builduring.cmake
new file mode 100644 (file)
index 0000000..d16e779
--- /dev/null
@@ -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()
diff --git a/cmake/modules/Finduring.cmake b/cmake/modules/Finduring.cmake
new file mode 100644 (file)
index 0000000..10c8de4
--- /dev/null
@@ -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)
index 51894fd9a3c9560dd46922a598886d5061e1f7f2..22ff0b7883f55d494c542d2f7692b61c819fa3a8 100644 (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()