# QtSingleApplication solution from
# http://qt.nokia.com/products/appdev/add-on-products/catalog/4/Utilities/qtsingleapplication
# LGPL

# Make ${Qt6_Widgets} optional
if(QT6_GUI_AVAILABLE AND TARGET Qt6::Widgets)
  set(Qt6_Widgets ${Qt6_Widgets})
else()
  set(Qt6_Widgets "")
endif()


SET(qtsapp_common_SRCS
  qtlocalpeer.cpp
  qtlocalpeer.h
)
NGL_ADD_LIBRARY(WS AAR SV qtsa_common STATIC ${qtsapp_common_SRCS})
SET_TARGET_PROPERTIES(qtsa_common PROPERTIES POSITION_INDEPENDENT_CODE ON)
NGL_TARGET_LINK_LIBRARIES(qtsa_common
  PUBLIC
    Qt6::Network
    Qt6::Core
)

SET(qtsapp_SRCS
  qtsingleapplication.cpp
  qtsingleapplication.h

)
NGL_ADD_LIBRARY2(WS qtsingleapplication SHARED ${qtsapp_SRCS})
NGL_INSTALL_TARGET(qtsingleapplication)
NGL_TARGET_INCLUDE_DIRECTORIES(qtsingleapplication
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/..
)
NGL_TARGET_LINK_LIBRARIES(qtsingleapplication
  PRIVATE
    qtsa_common
  PUBLIC
    Qt6::Core
    Qt6::Gui
)

SET(qtscoreapp_SRCS
  qtsinglecoreapplication.h
  qtsinglecoreapplication.cpp
)
NGL_ADD_LIBRARY2(AAR SV qtsinglecoreapplication SHARED ${qtscoreapp_SRCS})
NGL_INSTALL_TARGET(qtsinglecoreapplication)
NGL_TARGET_INCLUDE_DIRECTORIES(qtsinglecoreapplication
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/..
)
NGL_TARGET_LINK_LIBRARIES(qtsinglecoreapplication
  PRIVATE
    qtsa_common
  PUBLIC
    Qt6::Core
)
