From: Kefu Chai Date: Mon, 26 Jun 2017 03:58:28 +0000 (+0800) Subject: cmake: compile libzfs backend conditionally X-Git-Tag: v12.1.2~1^2~16^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f8d5f7466326fa20fa1d150283c79ff7172a2008;p=ceph.git cmake: compile libzfs backend conditionally * do not REQUIRE libzfs if it is enabled, this follows the way how we handle `WITH_XFS` option. * also refactor the cmake script related to libxfs backend support a little bit. Signed-off-by: Kefu Chai --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f0dab6f82d9..4903fbe945b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,10 +214,16 @@ set(HAVE_LIBFUSE ${FUSE_FOUND}) endif(${WITH_FUSE}) option(WITH_XFS "XFS is here" ON) -if(${WITH_XFS}) -find_package(xfs) -set(HAVE_LIBXFS ${XFS_FOUND}) -endif(${WITH_XFS}) +if(WITH_XFS) + find_package(xfs) + set(HAVE_LIBXFS ${XFS_FOUND}) +endif() + +option(WITH_ZFS "enable LibZFS if found" OFF) +if(WITH_ZFS) + find_package(zfs) + set(HAVE_LIBZFS ${ZFS_FOUND}) +endif() option(WITH_SPDK "Enable SPDK" OFF) if(WITH_SPDK) @@ -463,7 +469,6 @@ if(${HAVE_BABELTRACE}) endif(${HAVE_BABELTRACE}) option(DEBUG_GATHER "C_Gather debugging is enabled" ON) -option(HAVE_LIBZFS "LibZFS is enabled" OFF) option(ENABLE_COVERAGE "Coverage is enabled" OFF) option(PG_DEBUG_REFS "PG Ref debugging is enabled" OFF) diff --git a/cmake/modules/Findxfs.cmake b/cmake/modules/Findxfs.cmake index ecbf91c05978..6171e32895e9 100644 --- a/cmake/modules/Findxfs.cmake +++ b/cmake/modules/Findxfs.cmake @@ -1,9 +1,9 @@ # Try to find xfs # Once done, this will define # -# XFS_FOUND - system has Profiler -# XFS_INCLUDE_DIR - the Profiler include directories -# XFS_LIBRARIES - link these to use Profiler +# XFS_FOUND - system has libxfs +# XFS_INCLUDE_DIR - the libxfs include directories +# XFS_LIBRARIES - link these to use libxfs if(XFS_INCLUDE_DIR AND XFS_LIBRARIES) set(XFS_FIND_QUIETLY TRUE) diff --git a/cmake/modules/Findzfs.cmake b/cmake/modules/Findzfs.cmake new file mode 100644 index 000000000000..d92dd1fb04c3 --- /dev/null +++ b/cmake/modules/Findzfs.cmake @@ -0,0 +1,28 @@ +# find libzfs or libzfslinux +# Once done, this will define +# +# ZFS_FOUND - system has libzfs +# ZFS_INCLUDE_DIR - the libzfs include directories +# ZFS_LIBRARIES - link these to use libzfs + +find_package(PkgConfig) +if(PKG_CONFIG_FOUND) + pkg_check_modules(ZFS QUIET libzfs) +else() + find_path(ZFS_INCLUDE_DIR libzfs.h + HINTS + ENV ZFS_DIR + PATH_SUFFIXES libzfs) + + find_library(ZFS_LIBRARIES + NAMES zfs + HINTS + ENV ZFS_DIR) + set(XFS_LIBRARIES ${LIBXFS}) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(zfs DEFAULT_MSG + ZFS_INCLUDE_DIRS ZFS_LIBRARIES) + +mark_as_advanced(ZFS_INCLUDE_DIRS XFS_LIBRARIES) diff --git a/src/os/CMakeLists.txt b/src/os/CMakeLists.txt index feda6a23bc1f..5edbb2db96a8 100644 --- a/src/os/CMakeLists.txt +++ b/src/os/CMakeLists.txt @@ -1,9 +1,3 @@ -if(HAVE_LIBXFS) - set(libos_xfs_srcs - filestore/XfsFileStoreBackend.cc - fs/XFS.cc) -endif(HAVE_LIBXFS) - set(libos_srcs ObjectStore.cc Transaction.cc @@ -19,13 +13,11 @@ set(libos_srcs filestore/IndexManager.cc filestore/LFNIndex.cc filestore/WBThrottle.cc - filestore/ZFSFileStoreBackend.cc memstore/MemStore.cc kstore/KStore.cc kstore/kstore_types.cc fs/FS.cc - fs/aio.cc - ${libos_xfs_srcs}) + fs/aio.cc) if(HAVE_LIBAIO) list(APPEND libos_srcs @@ -55,6 +47,21 @@ if(WITH_PMEM) bluestore/PMEMDevice.cc) endif(WITH_PMEM) +if(HAVE_LIBXFS) + list(APPEND libos_srcs + filestore/XfsFileStoreBackend.cc + fs/XFS.cc) +endif() + +if(HAVE_LIBZFS) + add_library(os_zfs_objs OBJECT + filestore/ZFSFileStoreBackend.cc + fs/ZFS.cc) + target_include_directories(os_zfs_objs PRIVATE + ${ZFS_INCLUDE_DIRS}) + list(APPEND libos_srcs $) +endif() + if(WITH_SPDK) list(APPEND libos_srcs bluestore/NVMEDevice.cc) @@ -76,6 +83,10 @@ if(WITH_PMEM) target_link_libraries(os ${PMEM_LIBRARY}) endif() +if(HAVE_LIBZFS) + target_link_libraries(os ${ZFS_LIBRARIES}) +endif() + if(WITH_SPDK) target_link_libraries(os ${SPDK_LIBRARIES}