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

# Make ${Qt6_WebSockets} optional (doesn't require GUI)
if(TARGET Qt6::WebSockets)
  set(Qt6_WebSockets Qt6::WebSockets)
  set(BUILDINGCONTROLJSON_AVAILABLE TRUE)
else()
  set(Qt6_WebSockets "")
  set(BUILDINGCONTROLJSON_AVAILABLE FALSE)
endif()


# <logger.h> from the subdirectories (BSM, Json, VWM, ControlEffects) must
# resolve to this directory's logger.h (namespace BuildingControlUnit), as in
# the qt5 build. The root CMakeLists puts Lts/Proxies/TrainingAreaBase on the
# global include path, which would otherwise shadow it with
# TrainingAreaBase/logger.h (whose svctabcommon_export.h lives only in the
# build tree), breaking these targets.
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})

ADD_SUBDIRECTORY(BSM)
if(BUILDINGCONTROLJSON_AVAILABLE)
  ADD_SUBDIRECTORY(Json)
endif()
ADD_SUBDIRECTORY(VWM)
ADD_SUBDIRECTORY(ControlEffects)

SET(bcc_SRCS
  bcu_types.h
  bcu_xml_reader.cpp
  bcu_xml_reader.h
  logger.cpp
  logger.h
  settings.cpp
  settings.h
  web_socket_telegrams.cpp
  web_socket_telegrams.h
)

SET(bc_SRCS
  main.cpp
  main_handler.cpp
  main_handler.h
  handle_http_request.cpp
  handle_http_request.h
)

NGL_ADD_LIBRARY2(AAR SV BuildingControlCommon SHARED ${bcc_SRCS})
NGL_TARGET_LINK_LIBRARIES(BuildingControlCommon
  PRIVATE
    Qt6::Xml
    nglsettings
    ngltools
  PUBLIC
    NGLLogger
    Qt6::Core
    LtsUtilsCoreHeaderOnly
)
NGL_TARGET_INCLUDE_DIRECTORIES(BuildingControlCommon
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_BINARY_DIR}/Lts/Proxies/Buildings/BuildingControlUnit
    ${CMAKE_SOURCE_DIR}/Lts/Proxies/TrainingAreaBase
    ${CMAKE_BINARY_DIR}/Lts/Proxies/TrainingAreaBase
)

NGL_ADD_EXECUTABLE(AAR SV BuildingControlUnit ${bc_SRCS})
NGL_TARGET_LINK_LIBRARIES(BuildingControlUnit
  Qt6::Core
  ${Qt6_WebSockets}
#  Qt6::Test
  Qt6::Xml
  Qt6::Network
  Qt6::Concurrent
  BuildingControlBsm
  BuildingControlCommon
  $<$<BOOL:${BUILDINGCONTROLJSON_AVAILABLE}>:BuildingControlJson>
  BuildingControlVwm
  ControlEffects
  LtsCommandLineParser
  nglcoreapplication
)

NGL_INSTALL_TARGET(BuildingControlUnit)

NGL_INSTALL(AAR SV FILES log4cxx_bcu.props DESTINATION bin)

