#
# $Id$
# $HeadURL$
# $Author$
# Created by Philipp Dassow, SLST, 2017-11-28

#
# --- Library LtsWebSocketCommon --------------------------------------------------------------------------------
#
# Make ${Qt6_WebSockets} optional
# Link the real WebSockets module whenever the websocket code path is
# compiled: QT6_WEBSOCKETS_AVAILABLE (root CMakeLists) and the manual
# Qt6::WebSockets import are set when the real module was found. The old
# QT6_GUI_AVAILABLE condition never held in this environment (Qt6
# discovery takes the minimal path) and the Qt6_WebSockets variable was
# never defined, so the websocket code compiled without the module on
# the link line.
if(QT6_WEBSOCKETS_REAL_FOUND OR Qt6WebSockets_FOUND)
  set(Qt6_WebSockets Qt6::WebSockets)
else()
  set(Qt6_WebSockets "")
endif()


SET(LtsWebSocketCommon_SRCS
  client_message_factory.cpp
  client_message_factory.h
  client_message.cpp
  client_message.h
  reply_message.cpp
  reply_message.h
  data_manager_base_dl.h
  json_keys.h

  logger.cpp
  logger.h
)

NGL_ADD_LIBRARY2(WS AAR SV LtsWebSocketCommon SHARED ${LtsWebSocketCommon_SRCS})

NGL_TARGET_INCLUDE_DIRECTORIES(LtsWebSocketCommon
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/../
)

NGL_TARGET_LINK_LIBRARIES(LtsWebSocketCommon
  Qt6::Core
  ${Qt6_WebSockets}
  NGLLogger
)

#
# --- Library ltsWebSocketServer --------------------------------------------------------------------------------
#
SET(LtsWebSocketServer_SRCS
  client_connection.cpp
  client_connection.h
  connection_handler.cpp
  connection_handler.h
  lts_web_socket_server.cpp
  lts_web_socket_server.h
)

NGL_ADD_LIBRARY2(WS AAR SV LtsWebSocketServer SHARED ${LtsWebSocketServer_SRCS})

NGL_TARGET_INCLUDE_DIRECTORIES(LtsWebSocketServer
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/../
)

NGL_TARGET_LINK_LIBRARIES(LtsWebSocketServer
  Qt6::Core
  LtsWebSocketCommon
)

#
# --- Library ltsWebSocketClient --------------------------------------------------------------------------------
#
SET(LtsWebSocketClient_SRCS
  lts_web_socket_client.cpp
  lts_web_socket_client.h
)

NGL_ADD_LIBRARY2(WS AAR SV LtsWebSocketClient SHARED ${LtsWebSocketClient_SRCS})

NGL_TARGET_INCLUDE_DIRECTORIES(LtsWebSocketClient
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/../
)

NGL_TARGET_LINK_LIBRARIES(LtsWebSocketClient
  Qt6::Core
  LtsWebSocketCommon
)
