#
# $Id$
# $HeadURL$
# $Author$
#
# Created by Christian Ehrlicher, SLSE, 2017-12-05
#

if(QT6_GUI_AVAILABLE)
  find_package(KDReports QUIET)
endif()

SET(SRCS
  printing_base.cpp
  printing_base.h
  printing.cpp
  printing.h
)

# Legacy always built the real LtsPrinting when KDReports was available
# (FIND_PACKAGE(KDReports REQUIRED)); it is a common lib consumed by many
# targets (e.g. SitmapGuiPlugin::doPrint -> LtsPrinting::printImage), so it must
# NOT be gated on the BUILD_CODIFICATION product flag (which only bundles the
# CodificationManagement/ReportViewer plugins). Build the real lib whenever
# KDReports is found; keep the stub only as a KDReports-absent fallback.
if (KDReports_FOUND AND QT6_GUI_AVAILABLE)
  NGL_ADD_LIBRARY2(WS LtsPrinting SHARED ${SRCS})
  NGL_TARGET_INCLUDE_DIRECTORIES(LtsPrinting
    PUBLIC
      ${CMAKE_CURRENT_SOURCE_DIR}/../
  )
if(QT6_GUI_AVAILABLE)
    NGL_TARGET_LINK_LIBRARIES(LtsPrinting
      PRIVATE
        KDReports::KDReports
        LtsSessionData
        LtsSession
        nglsettings
        ngltools
      PUBLIC
        Qt6::PrintSupport
        Qt6::Core
    )
endif()
  NGL_INSTALL_TARGET(LtsPrinting)
else()
  message(STATUS "KDReports not found or Qt6 GUI unavailable; building LtsPrinting stub (link-only, no printing symbols)")
  add_library(LtsPrinting SHARED lts_printing_stub.cpp)
  NGL_INSTALL_TARGET(LtsPrinting)
endif()
