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 <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2017-06-26 11:58:28 +08:00
parent e34e22b6ef
commit f8d5f74663
4 changed files with 61 additions and 17 deletions

View File

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

View File

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

View File

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

View File

@ -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 $<TARGET_OBJECTS:os_zfs_objs>)
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}