#
# $Id$
# $HeadURL$
# $Author$
#

INCLUDE(MacroRTIDDSGen)
INCLUDE(MacroCodeGenIdl)

SET(xml_FILE ppm_service.xml)

#
# --- Library svcPpmCommon --------------------------------------------------------------------------------
#
SET(SRCS_common
  ppm_export.h
  ppm_common.cpp
  ppm_common.h
  ppm_db_impl_custom.cpp
  ppm_db_impl_custom.h
  logger.cpp
  logger.h
)

# Generate ppm_enums.idl / ppm.idl
CODEGEN_IDL_SVC(SRCS_common ${xml_FILE})
# Generate ppm_db_structs.cpp/.h
CODEGEN_DATABASE_STRUCTS(SRCS_common ${xml_FILE})
# Generate ppm_db.cpp, ppm_db_impl.cpp/.h
CODEGEN_DATABASE_SQL(SRCS_common ${xml_FILE})

# Generate *.cpp/*.hpp from idl
RTIDDSGEN(SRCS_common ppm_enums.idl)
RTIDDSGEN(SRCS_common ppm.idl)

# Generate ppm_dt[s,c]_types.h, ppm_ft[s,c]_types.h
CODEGEN_TOPIC_TYPEDEFS(SRCS_common ${xml_FILE})
# generate ppm_[d|f]tc.h
CODEGEN_CLIENT_TOPICS_IFC(SRCS_common ${xml_FILE})

NGL_ADD_LIBRARY(AAR SV WS HLA svcPpmCommon SHARED  ${SRCS_common})
NGL_TARGET_INCLUDE_DIRECTORIES(svcPpmCommon
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/../
    ${CMAKE_CURRENT_BINARY_DIR}/../
)
NGL_TARGET_LINK_LIBRARIES(svcPpmCommon
  PRIVATE
    RTI::nddscpp2
    LtsUtilsCore
  PUBLIC
    Qt5::Core
    Qt5::Gui
    ddscore
    NGLLogger
    svcPdmCommon
    LtsUtilsCore
    LtsCoordTrans
    ngldb
)
NGL_INSTALL_TARGET(svcPpmCommon)

#
# --- Library svcPpmClient --------------------------------------------------------------------------------
#
SET(SRCS_client
  ppm_export.h
  ppm_dtc_impl_custom.cpp
  ppm_dtc_impl_custom.h
)
# generate ppm_[d|f]tc_impl.[cpp|h]
CODEGEN_CLIENT_TOPICS_IMPL(SRCS_client ${xml_FILE})

NGL_ADD_LIBRARY(WS AAR SV HLA svcPpmClient SHARED ${SRCS_client})
NGL_TARGET_INCLUDE_DIRECTORIES(svcPpmClient
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/../
    ${CMAKE_CURRENT_BINARY_DIR}/../
)

NGL_TARGET_LINK_LIBRARIES(svcPpmClient
  PRIVATE
    RTI::nddscpp2
    ddsconnector
  PUBLIC
    svcPpmCommon
    ddsftc
)
NGL_INSTALL_TARGET(svcPpmClient)

#
# --- Library svcPpmServer --------------------------------------------------------------------------------
#
SET(SRCS_server
  ppm_export.h
  convert_db_to_dds.h

)
# generate ppm_[d|f]ts.h, ppm_[d|f]ts_impl.[cpp|h]
CODEGEN_SERVER_TOPICS(SRCS_server ${xml_FILE})

# WS for RecordReplayPlugin
NGL_ADD_LIBRARY(AAR SV WS svcPpmServer SHARED ${SRCS_server})
NGL_TARGET_INCLUDE_DIRECTORIES(svcPpmServer
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/../
    ${CMAKE_CURRENT_BINARY_DIR}/../
)

NGL_TARGET_LINK_LIBRARIES(svcPpmServer
  PRIVATE
    RTI::nddscpp2
    ddsconnector
    ddsfts
  PUBLIC
    svcPpmCommon
    ngldb
    LtsUtilsCore
)
NGL_INSTALL_TARGET(svcPpmServer)

#
# --- Topic Type Plugin --------------------------------------------------------------
#
CREATE_TOPIC_TYPE_PLUGIN(${xml_FILE})

#
# --- RecordReplayPlugin --------------------------------------------------------------
#
CREATE_RECORD_REPLAY_PLUGIN_SHARED(${xml_FILE})

IF (TARGET ppmRecordReplayPlugin)
  TARGET_SOURCES(ppmRecordReplayPlugin
    PRIVATE
      RecordReplay/participant_for_replay.h
      RecordReplay/participant_handler_for_replay.cpp
      RecordReplay/participant_handler_for_replay.h
      RecordReplay/ppm_record_replay_plugin_custom.cpp
      RecordReplay/ppm_record_replay_plugin_custom.h
      ParticipantHandling/participant_donator.h
      ParticipantHandling/participant.cpp
      ParticipantHandling/participant.h
      ParticipantHandling/participant_handler.cpp
      ParticipantHandling/participant_handler.h
      ParticipantHandling/unit_position_calculator.cpp
      ParticipantHandling/unit_position_calculator.h

      settings.cpp
      settings.h

      web_socket_handler.cpp
      web_socket_handler.h
  )
  TARGET_LINK_LIBRARIES(ppmRecordReplayPlugin
    Qt5::Concurrent
    Qt5::WebSockets
    tabRecordReplayPlugin
    svcBldClient
    svcPpmServer
    svcPdmClient
    LtsCoordTrans
    LtsUtilsCoreHeaderOnly # unit_position_calculator.cpp => LtsUtilsCore/qpoint3d.h
    nglsettings
    ngltools
  )
ENDIF()

#
# --- Executable svcParticipantManagement (sPPM) -------------------------------------------------
#
LIST(APPEND SRCS_exe
  BiteHandling/bite_handler.cpp
  BiteHandling/bite_handler.h

  dds_handler.cpp
  dds_handler.h

  EquipmentEventHandling/equipment_event_handler.cpp
  EquipmentEventHandling/equipment_event_handler.h

  exercise_time.cpp
  exercise_time.h
  main.cpp
  main_handler.cpp
  main_handler.h

  ParticipantHandling/firing_unit_validator.cpp
  ParticipantHandling/firing_unit_validator.h
  ParticipantHandling/get_participants.cpp
  ParticipantHandling/get_participants.h
  ParticipantHandling/participant_donator.h
  ParticipantHandling/participant.cpp
  ParticipantHandling/participant.h
  ParticipantHandling/participant_for_exercise.cpp
  ParticipantHandling/participant_for_exercise.h
  ParticipantHandling/participant_handler.cpp
  ParticipantHandling/participant_handler.h
  ParticipantHandling/participant_handler_for_exercise.cpp
  ParticipantHandling/participant_handler_for_exercise.h
  ParticipantHandling/proxy_listener.cpp
  ParticipantHandling/proxy_listener.h
  ParticipantHandling/unit_position_calculator.cpp
  ParticipantHandling/unit_position_calculator.h

  PartyHandling/party.cpp
  PartyHandling/party_donator.h
  PartyHandling/party.h
  PartyHandling/party_handler.cpp
  PartyHandling/party_handler.h

  settings.cpp
  settings.h

  TargetHandling/object_target_information.cpp
  TargetHandling/object_target_information.h
  TargetHandling/handler_target_information.cpp
  TargetHandling/handler_target_information.h

  TemplateHandling/template.cpp
  TemplateHandling/template.h
  TemplateHandling/template_handler.cpp
  TemplateHandling/template_handler.h

  TypeHandling/type_donator.h
  TypeHandling/type_handler.cpp
  TypeHandling/type_handler_exercise.cpp
  TypeHandling/type_handler_exercise.h
  TypeHandling/type_handler_global.cpp
  TypeHandling/type_handler_global.h
  TypeHandling/type_handler.h

  UasHandling/uas.cpp
  UasHandling/uas.h
  UasHandling/uas_handler.cpp
  UasHandling/uas_handler.h

  UasHandling/mission_plan_handler.h
  UasHandling/mission_plan_handler.cpp
  UasHandling/object_mission_plan.cpp
  UasHandling/object_mission_plan.h

  WebSocketInterface/data_manager.cpp
  WebSocketInterface/data_manager.h
  WebSocketInterface/json_keys.h
  WebSocketInterface/websocket_interface_handler.cpp
  WebSocketInterface/websocket_interface_handler.h
  WebSocketInterface/Messages/client_message.cpp
  WebSocketInterface/Messages/client_message.h
  WebSocketInterface/Messages/reply_message.cpp
  WebSocketInterface/Messages/reply_message.h

  web_socket_handler.cpp
  web_socket_handler.h  

  ${xml_FILE}
)

# Generate ppm.sql, ppm.xml
CODEGEN_SQL(SRCS_exe ${xml_FILE})

NGL_ADD_SVC_ICON(SRCS_exe)
NGL_ADD_EXECUTABLE(AAR SV svcParticipantManagement ${SRCS_exe})
NGL_TARGET_LINK_LIBRARIES(svcParticipantManagement
  ppmRecordReplayPlugin
  Qt5::Core
  Qt5::Concurrent
  Qt5::WebSockets
  ddsconnector
  LtsCommandLineParser
  nglsettings
  nglcoreapplication
  NGLLogger
  ProjectConfig
  svcCoreClient
  svcPdmClient
  svcPpmCommon
  svcPpmServer
  svcPpmClient
  svcTabClient
  svcAesClient
  svcCesServer
  svcCesClient
  svcBldClient
  svcTabServer
  svcExmClient
  ngltools
  LtsCoordTrans
  LtsWebSocketServer
)

NGL_INSTALL_TARGET(svcParticipantManagement)
NGL_INSTALL(AAR SV FILES log4cxx_ppm.props DESTINATION bin)
NGL_ADD_TARGET_LINK(svcParticipantManagement sPPM)

# copy ppm_predefined_data.sql to share
SET(in_file_sql  "ppm_predefined_data.sql")
NGL_INSTALL(AAR SV FILES ppm_predefined_data.sql DESTINATION share/Lts/sql)


# Uncomment if necessary
#ADD_SUBDIRECTORY(UnitTests)
ADD_SUBDIRECTORY(ModuleTests)
