#  Copyright (C) GridGain Systems. All Rights Reserved.
#  _________        _____ __________________        _____
#  __  ____/___________(_)______  /__  ____/______ ____(_)_______
#  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
#  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
#  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/

set(TARGET ${PROJECT_NAME}-client)

set(SOURCES
    cancel_handle.cpp
    ignite_client.cpp
    ignite_client_configuration.cpp
    compute/broadcast_job_target.cpp
    compute/compute.cpp
    compute/job_execution.cpp
    compute/job_target.cpp
    continuous_query/continuous_query.cpp
    continuous_query/continuous_query_watermark.cpp
    sql/sql.cpp
    sql/result_set.cpp
    table/key_value_view.cpp
    table/qualified_name.cpp
    table/record_view.cpp
    table/table.cpp
    table/tables.cpp
    transaction/transaction.cpp
    transaction/transactions.cpp
    detail/cancellation_token_impl.cpp
    detail/cluster_connection.cpp
    detail/ignite_client_impl.cpp
    detail/utils.cpp
    detail/node_connection.cpp
    detail/compute/compute_impl.cpp
    detail/compute/job_execution_impl.cpp
    detail/sql/sql_impl.cpp
    detail/table/packed_tuple.cpp
    detail/table/table_impl.cpp
    detail/table/tables_impl.cpp
    detail/table_api_ex.cpp
    schema_view.cpp
)

set(PUBLIC_HEADERS
    basic_authenticator.h
    cancel_handle.h
    cancellation_token.h
    ignite_client.h
    ignite_client_authenticator.h
    ignite_client_configuration.h
    ignite_logger.h
    ssl_mode.h
    type_mapping.h
    compute/broadcast_execution.h
    compute/broadcast_job_target.h
    compute/compute.h
    compute/deployment_unit.h
    compute/job_descriptor.h
    compute/job_execution.h
    compute/job_execution_options.h
    compute/job_state.h
    compute/job_status.h
    compute/job_target.h
    continuous_query/continuous_query.h
    continuous_query/continuous_query_options.h
    continuous_query/continuous_query_watermark.h
    detail/continuous_query/continuous_query_event_consumer.h
    detail/compute/job_target_type.h
    detail/table/packed_tuple.h
    detail/type_mapping_utils.h
    network/cluster_node.h
    sql/column_metadata.h
    sql/column_origin.h
    sql/result_set.h
    sql/result_set_metadata.h
    sql/sql.h
    sql/sql_statement.h
    table/ignite_tuple.h
    table/key_value_view.h
    table/qualified_name.h
    table/record_view.h
    table/table.h
    table/table_row_event.h
    table/table_row_event_batch.h
    table/tables.h
    transaction/transaction.h
    transaction/transactions.h
    transaction/transaction_options.h
)

set(PRIVATE_HEADERS
    detail/argument_check_utils.h
    detail/cancellation_token_impl.h
    detail/client_error_flags.h
    detail/cluster_connection.h
    detail/compute/any_node_job_target.h
    detail/compute/colocated_job_target.h
    detail/compute/compute_impl.h
    detail/compute/job_execution_impl.h
    detail/compute/nodes_broadcast_job_target.h
    detail/connection_event_handler.h
    detail/ignite_client_impl.h
    detail/logger_wrapper.h
    detail/node_connection.h
    detail/response_handler.h
    detail/sql/result_set_impl.h
    detail/sql/result_set_meta_reader.h
    detail/sql/result_set_raw_impl.h
    detail/sql/sql_impl.h
    detail/table/name_utils.h
    detail/table/schema.h
    detail/table/table_impl.h
    detail/table/tables_impl.h
    detail/transaction/transaction_impl.h
    detail/transaction/transactions_impl.h
    detail/table_api_ex.h
    detail/utils.h
    binary_tuple_reader.h
    binary_tuple_traits.h
    binary_tuple_writer.h
    ignite_tuple_traits.h
    schema_view.h
)

ignite_check_headers(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${PUBLIC_HEADERS} PRIVATE ${PRIVATE_HEADERS})

ignite_collect_public_headers(client PUBLIC_HEADERS)

add_library(${TARGET}-obj OBJECT ${SOURCES})
target_include_directories(${TARGET}-obj PUBLIC ${IGNITE_CMAKE_TOP_DIR})

add_library(${TARGET} SHARED ${SOURCES})
set_target_properties(${TARGET} PROPERTIES EXPORT_NAME client)

add_library(${TARGET}-static STATIC ${SOURCES})
set_target_properties(${TARGET}-static PROPERTIES EXPORT_NAME client-static)

set(LIBRARIES
    gridgain-common
    gridgain-tuple
    gridgain-network
    gridgain-protocol
    uni-algo::uni-algo
)

set(_target_libs ${TARGET} ${TARGET}-obj ${TARGET}-static)

foreach(_target_lib IN LISTS _target_libs)
    set_target_properties(${_target_lib} PROPERTIES VERSION ${IGNITE_VERSION_3})
    set_target_properties(${_target_lib} PROPERTIES POSITION_INDEPENDENT_CODE 1)

    target_link_libraries(${_target_lib} PRIVATE ${LIBRARIES})
    target_include_directories(${_target_lib}
        PUBLIC $<BUILD_INTERFACE:${IGNITE_CMAKE_TOP_DIR}/>
               $<INSTALL_INTERFACE:${IGNITE_INSTALL_INCLUDE_DIR}/>
    )
endforeach()
unset(_target_libs)

add_library(gridgain::client ALIAS ${TARGET})
add_library(gridgain::client-static ALIAS ${TARGET}-static)

install(TARGETS ${TARGET}
    EXPORT gridgain-client-targets
    COMPONENT client
    ARCHIVE DESTINATION ${IGNITE_INSTALL_ARCHIVE_DIR}
    LIBRARY DESTINATION ${IGNITE_INSTALL_LIBRARY_DIR}
    RUNTIME DESTINATION ${IGNITE_INSTALL_RUNTIME_DIR}
    INCLUDES DESTINATION ${IGNITE_INSTALL_INCLUDE_DIR}
)

export(
    EXPORT gridgain-client-targets
    NAMESPACE gridgain::
    FILE "${CMAKE_BINARY_DIR}/cmake/gridgain-client-targets.cmake"
)

install(
    EXPORT gridgain-client-targets
    NAMESPACE gridgain::
    DESTINATION "${IGNITE_INSTALL_LIBRARY_DIR}/cmake/gridgain"
    COMPONENT client
    FILE "gridgain-client-targets.cmake"
)

ignite_install_headers(FILES ${PUBLIC_HEADERS} DESTINATION ${IGNITE_INCLUDEDIR}/client COMPONENT client)

ignite_test(utils_test DISCOVER SOURCES detail/utils_test.cpp LIBS ${TARGET}-obj ${LIBRARIES})
ignite_test(continuous_query_watermark_test DISCOVER SOURCES continuous_query/continuous_query_watermark_test.cpp LIBS ${TARGET}-obj ${LIBRARIES})
ignite_test(qualified_name_test DISCOVER SOURCES table/qualified_name_test.cpp LIBS ${TARGET}-obj ${LIBRARIES})
ignite_test(blocking_queue_test DISCOVER SOURCES detail/blocking_queue_test.cpp LIBS ${TARGET}-obj ${LIBRARIES})
