]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: build qat from source when WITH_SYSTEM_QATLIB=OFF
authorCasey Bodley <cbodley@redhat.com>
Thu, 23 Nov 2023 00:10:59 +0000 (19:10 -0500)
committerCasey Bodley <cbodley@redhat.com>
Wed, 7 Feb 2024 16:09:49 +0000 (11:09 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
CMakeLists.txt
cmake/modules/BuildQAT.cmake [new file with mode: 0644]

index edb653a68fda217d7e4d6f1a2125e8efcd4102b9..1f9bc746f884fb22ccf282d5ade8d846f03ddf80 100644 (file)
@@ -308,6 +308,7 @@ endif()
 option(WITH_BLUEFS "libbluefs library" OFF)
 
 option(WITH_QATLIB "Enable QAT with qatlib" OFF)
+option(WITH_SYSTEM_QATLIB "Use system packages for qatlib" OFF)
 option(WITH_QATDRV "Enable QAT with out-of-tree driver" OFF)
 option(WITH_QATZIP "Enable QATzip" OFF)
 
@@ -315,7 +316,15 @@ if(WITH_QATDRV)
   find_package(QatDrv REQUIRED COMPONENTS qat_s usdm_drv_s)
   set(HAVE_QAT TRUE)
 elseif(WITH_QATLIB)
+  if(NOT WITH_SYSTEM_QAT)
+    include(BuildQAT)
+    build_qat()
+  endif()
   find_package(QAT REQUIRED)
+  if(NOT WITH_SYSTEM_QAT)
+    add_dependencies(QAT::qat qatlib_ext)
+    add_dependencies(QAT::usdm qatlib_ext)
+  endif()
   set(HAVE_QAT TRUE)
 endif()
 
diff --git a/cmake/modules/BuildQAT.cmake b/cmake/modules/BuildQAT.cmake
new file mode 100644 (file)
index 0000000..9296a05
--- /dev/null
@@ -0,0 +1,56 @@
+function(build_qat)
+  set(QAT_REPO https://github.com/intel/qatlib.git)
+  set(QAT_TAG "23.11.0")
+
+  set(QAT_SOURCE_DIR ${CMAKE_BINARY_DIR}/src/qatlib)
+  set(QAT_INSTALL_DIR ${QAT_SOURCE_DIR}/install)
+  set(QAT_INCLUDE_DIR ${QAT_INSTALL_DIR}/include)
+  set(QAT_LIBRARY_DIR ${QAT_INSTALL_DIR}/lib)
+  set(QAT_LIBRARY ${QAT_LIBRARY_DIR}/libqat.a)
+  set(QAT_USDM_LIBRARY ${QAT_LIBRARY_DIR}/libusdm.a)
+
+  # this include directory won't exist until the install step, but the
+  # imported targets need it early for INTERFACE_INCLUDE_DIRECTORIES
+  file(MAKE_DIRECTORY "${QAT_INCLUDE_DIR}")
+
+  set(configure_cmd env CC=${CMAKE_C_COMPILER} ./configure --prefix=${QAT_INSTALL_DIR})
+  # disable systemd or 'make install' tries to write /usr/lib/systemd/system/qat.service
+  list(APPEND configure_cmd --disable-systemd)
+  # samples don't build on arm64
+  list(APPEND configure_cmd --disable-samples)
+  # build a static library with -fPIC that we can link into crypto/compressor plugins
+  list(APPEND configure_cmd --with-pic --enable-static --disable-shared)
+
+  set(source_dir_args
+    SOURCE_DIR ${QAT_SOURCE_DIR}
+    GIT_REPOSITORY ${QAT_REPO}
+    GIT_TAG ${QAT_TAG}
+    GIT_SHALLOW TRUE
+    GIT_CONFIG advice.detachedHead=false)
+
+  # clear the DESTDIR environment variable from debian/rules,
+  # because it messes with the internal install paths of arrow's bundled deps
+  set(NO_DESTDIR_COMMAND ${CMAKE_COMMAND} -E env --unset=DESTDIR)
+
+  include(ExternalProject)
+  ExternalProject_Add(qatlib_ext
+    ${source_dir_args}
+    CONFIGURE_COMMAND ./autogen.sh COMMAND ${configure_cmd}
+    BUILD_COMMAND ${NO_DESTDIR_COMMAND} make -j3
+    BUILD_IN_SOURCE 1
+    BUILD_BYPRODUCTS ${QAT_LIBRARY} ${QAT_USDM_LIBRARY}
+    INSTALL_COMMAND ${NO_DESTDIR_COMMAND} make install
+    UPDATE_COMMAND ""
+    LOG_CONFIGURE ON
+    LOG_BUILD ON
+    LOG_INSTALL ON
+    LOG_MERGED_STDOUTERR ON
+    LOG_OUTPUT_ON_FAILURE ON)
+
+  # export vars for find_package(QAT)
+  set(QAT_LIBRARY ${QAT_LIBRARY} PARENT_SCOPE)
+  set(QAT_USDM_LIBRARY ${QAT_USDM_LIBRARY} PARENT_SCOPE)
+  set(QAT_INCLUDE_DIR ${QAT_INCLUDE_DIR} PARENT_SCOPE)
+  # library dir for BuildQATzip.cmake
+  set(QAT_LIBRARY_DIR ${QAT_LIBRARY_DIR} PARENT_SCOPE)
+endfunction()