# Set up helpers
set(HELPERS_SYSTEM_INCLUDE_DIRS
    ${ASIO_INCLUDE_DIRS}
    ${CPPMETRICS_INCLUDE_DIRS}
    ${FUSE_INCLUDE_DIRS}
    ${FUSE_INCLUDE_DIRS}/..
    ${PROTOBUF_INCLUDE_DIR}
    ${TBB_INCLUDE_DIRS}
    ${Boost_INCLUDE_DIRS}
    ${CLPROTO_SYSTEM_INCLUDE_DIRS}
    ${GLOG_INCLUDE_DIRS}
    ${FOLLY_INCLUDE_DIR}
    ${WANGLE_INCLUDE_DIR}
    ${OPENSSL_INCLUDE_DIR})

#
# Add Swift include dir when building with Swift helper
#
if(WITH_SWIFT)
    list(APPEND HELPERS_SYSTEM_INCLUDE_DIRS ${SWIFT_SDK_INCLUDE_DIRS})
endif(WITH_SWIFT)

#
# Add GlusterFS include dir when building with GlusterFS helper
#
if(WITH_GLUSTERFS)
    list(APPEND HELPERS_SYSTEM_INCLUDE_DIRS ${GLUSTERFSAPI_INCLUDEDIR})
endif(WITH_GLUSTERFS)

set(HELPERS_INCLUDE_DIRS
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/../include)

file(GLOB_RECURSE HELPER_SOURCES *.cc *.h
                  ${CMAKE_CURRENT_SOURCE_DIR}/../deps/cppmetrics/cppmetrics/*.cpp)

#
# Remove helper sources when building without them
#
if(NOT WITH_CEPH)
    list(REMOVE_ITEM HELPER_SOURCES  ${CMAKE_CURRENT_SOURCE_DIR}/cephHelper.cc)
    list(REMOVE_ITEM HELPER_SOURCES  ${CMAKE_CURRENT_SOURCE_DIR}/cephRadosHelper.cc)
endif(NOT WITH_CEPH)

if(NOT WITH_S3)
    list(REMOVE_ITEM HELPER_SOURCES  ${CMAKE_CURRENT_SOURCE_DIR}/s3Helper.cc)
endif(NOT WITH_S3)

if(NOT WITH_SWIFT)
    list(REMOVE_ITEM HELPER_SOURCES  ${CMAKE_CURRENT_SOURCE_DIR}/swiftHelper.cc)
endif(NOT WITH_SWIFT)

if(NOT WITH_GLUSTERFS)
    list(REMOVE_ITEM HELPER_SOURCES  ${CMAKE_CURRENT_SOURCE_DIR}/glusterfsHelper.cc)
endif(NOT WITH_GLUSTERFS)

if(NOT WITH_WEBDAV)
    list(REMOVE_ITEM HELPER_SOURCES  ${CMAKE_CURRENT_SOURCE_DIR}/webDAVHelper.cc)
    list(REMOVE_ITEM HELPER_SOURCES  ${CMAKE_CURRENT_SOURCE_DIR}/webDAVHelperParams.cc)
endif(NOT WITH_WEBDAV)

add_library(helpers OBJECT ${HELPER_SOURCES})
add_dependencies(helpers clproto)
target_include_directories(helpers SYSTEM PRIVATE
    ${HELPERS_SYSTEM_INCLUDE_DIRS})
target_include_directories(helpers PUBLIC
    ${HELPERS_INCLUDE_DIRS})

set(HELPERS_INCLUDE_DIRS
    ${HELPERS_INCLUDE_DIRS}
    PARENT_SCOPE)

set(HELPERS_SYSTEM_INCLUDE_DIRS
    ${HELPERS_SYSTEM_INCLUDE_DIRS}
    PARENT_SCOPE)

set(HELPERS_LIBRARIES
    ${Boost_LIBRARIES}
    ${FUSE_LIBRARIES}
    ${GLOG_LIBRARIES}
    ${PLATFORM_EXTRA_LIBS}
    ${TBB_LIBRARIES}
    ${CLPROTO_LIBRARIES}
    ${NSS_LIBRARIES}
    ${FOLLY_LIBRARIES}
    ${WANGLE_LIBRARIES}
    ${OPENSSL_LIBRARIES}
    PARENT_SCOPE)

set(PROJECT_SOURCES
    $<TARGET_OBJECTS:helpers>
    ${PROJECT_SOURCES}
    PARENT_SCOPE)
