# Modified CMakeLists.txt from github.com/wille-io/httq

# 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 AbstractServer.cpp compiled the websocket code
# without the module on the link line (undefined reference to
# QWebSocketServer::handleConnection).
if(QT6_WEBSOCKETS_REAL_FOUND OR Qt6WebSockets_FOUND)
  set(Qt6_WebSockets Qt6::WebSockets)
else()
  set(Qt6_WebSockets "")
endif()


set(src
  include/http_parser.h
  include/http_parser.c # TODO: move out of include dir

  include/httq/AbstractServer.h
  include/httq/DataStream.h
  include/httq/HttpRequest.h
  include/httq/Logger.h

  AbstractServer.cpp
  DataStream.cpp
  HttpRequest.cpp
  Logger.cpp
)

NGL_ADD_LIBRARY2(SV WS httq SHARED ${src})

NGL_TARGET_INCLUDE_DIRECTORIES(httq
  PUBLIC
    ${CMAKE_CURRENT_BINARY_DIR}/../ # export file
    ${CMAKE_CURRENT_SOURCE_DIR}/include/
)

NGL_TARGET_LINK_LIBRARIES(httq
  Qt6::Core
  Qt6::Network
  ${Qt6_WebSockets}
)

NGL_INSTALL_TARGET(httq)
