add_custom_target(benchmark)

if(FOLLY_SHARED)
    find_library(FOLLY_BENCHMARK_LIBRARIES NAMES libfollybenchmark.so)
else(FOLLY_SHARED)
    find_library(FOLLY_BENCHMARK_LIBRARIES NAMES libfollybenchmark.a)
endif(FOLLY_SHARED)

find_library(GFLAGS_LIBRARY gflags)

set(CLIENT_BENCHMARK_LIBRARIES
    libmacaroons-cpp
    ${PLATFORM_EXTRA_LIBS}
    ${FOLLY_LIBRARIES}
    ${GLOG_LIBRARY}
    ${GFLAGS_LIBRARY}
    ${FUSE_LIBRARIES}
    ${Boost_LIBRARIES}
    ${CLPROTO_LIBRARIES}
    ${TBB_LIBRARIES}
    ${SODIUM_LIBRARIES}
    ${PROTOBUF_LIBRARIES}
    ${NSS_LIBRARIES}
    ${OPENSSL_LIBRARIES}
    ${FOLLY_BENCHMARK_LIBRARIES}
    ${BACKWARD_CPP_LIBRARIES}
    )

add_library(clientBenchmarkShared SHARED ${CLIENT_SOURCES})

if(WITH_CEPH)
    list(APPEND CLIENT_BENCHMARK_LIBRARIES ${RADOS_LIBRARY} ${RADOSSTRIPER_LIBRARY})
endif(WITH_CEPH)

if(WITH_S3)
    list(APPEND CLIENT_BENCHMARK_LIBRARIES ${AWS_SDK_LIBRARIES})
endif(WITH_S3)

if(WITH_SWIFT)
    list(APPEND CLIENT_BENCHMARK_LIBRARIES ${SWIFT_SDK_LIBRARIES})
endif(WITH_SWIFT)

if(WITH_GLUSTERFS)
    list(APPEND CLIENT_BENCHMARK_LIBRARIES ${GLUSTERFSAPI_LIBRARIES})
endif(WITH_GLUSTERFS)

if(WITH_WEBDAV)
    list(APPEND CLIENT_BENCHMARK_LIBRARIES ${PROXYGEN_LIBRARY} ${WANGLE_LIBRARIES})
endif(WITH_WEBDAV)

if(WITH_XROOTD)
    list(APPEND CLIENT_BENCHMARK_LIBRARIES ${XROOTD_LIBRARIES})
endif(WITH_XROOTD)

if(WITH_NFS)
    list(APPEND CLIENT_BENCHMARK_LIBRARIES ${NFS_LIBRARIES})
endif(WITH_NFS)


list(APPEND CLIENT_BENCHMARK_LIBRARIES ${SPDLOG_LIBRARY} ${FMT_LIBRARY})

target_link_libraries(clientBenchmarkShared PUBLIC ${CLIENT_BENCHMARK_LIBRARIES})


file(GLOB_RECURSE TEST_SOURCES *_benchmark.cc)

foreach(TEST_SRC ${TEST_SOURCES})
    get_filename_component(TEST_NAME ${TEST_SRC} NAME_WE)
    add_executable(${TEST_NAME}
	    ${TEST_SRC}
	    ${TEST_HEADERS})
    target_link_libraries(${TEST_NAME} PRIVATE
        clientBenchmarkShared)
    add_custom_target(${TEST_NAME}_runbenchmark
        COMMAND ${TEST_NAME}
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
    add_dependencies(benchmark ${TEST_NAME}_runbenchmark)
endforeach()
