if("${QT_VERSION_MAJOR}" STREQUAL "5")
    pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) #Dtk6 removed.
endif()
pkg_check_modules(XcbUtil REQUIRED IMPORTED_TARGET xcb-util)
pkg_check_modules(StartupNotification REQUIRED IMPORTED_TARGET libstartup-notification-1.0)
pkg_check_modules(Xext REQUIRED IMPORTED_TARGET xext)
pkg_check_modules(Xi REQUIRED IMPORTED_TARGET xi)
pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11)

include(util/util.cmake)
include(widgets/widgets.cmake)

file(GLOB TS_FILES translations/*.ts)

add_library(${LIB_NAME} SHARED
    ${WIDGETS}
    ${UTIL}
    ${PUBLIC_HEADERS}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_add_translations(${LIB_NAME}
        TS_FILES ${TS_FILES}
        QM_FILES_OUTPUT_VARIABLE QM_FILES
        LUPDATE_OPTIONS -no-ui-lines -locations none
    )
else()
    qt5_add_translation(QM_FILES ${TS_FILES})
    add_custom_target(translations ALL DEPENDS ${QM_FILES})
    target_sources(${LIB_NAME} PRIVATE ${QM_FILES})
endif()

set(TRANSLATIONS_INSTALL_DIR
    "dtk${DTK_VERSION_MAJOR}/DWidget/translations"
)

target_compile_definitions(${LIB_NAME} PRIVATE
    SN_API_NOT_YET_FROZEN
    DTK_NO_MULTIMEDIA
    DWIDGET_TRANSLATIONS_DIR="${TRANSLATIONS_INSTALL_DIR}"
    LIBDTKWIDGET_LIBRARY
    D_IGNORE_DEPRECATIONS
)

if(DTK_STATIC_TRANSLATION)
target_compile_definitions(${LIB_NAME} PRIVATE
    DTK_STATIC_TRANSLATION
)
endif()

target_include_directories(${LIB_NAME}
PUBLIC
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/DWidget>
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/util>
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/widgets>
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/global>
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
    $<BUILD_INTERFACE:${CONFIG_INCLUDE}>
INTERFACE
    $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
)

target_link_libraries(${LIB_NAME}
PUBLIC
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Network
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::DBus
    Qt${QT_VERSION_MAJOR}::PrintSupport
    Dtk${DTK_NAME_SUFFIX}::Gui
    Dtk${DTK_NAME_SUFFIX}::Core
PRIVATE
    Qt${QT_VERSION_MAJOR}::Concurrent
    Qt${QT_VERSION_MAJOR}::GuiPrivate
    Qt${QT_VERSION_MAJOR}::WidgetsPrivate
    Qt${QT_VERSION_MAJOR}::PrintSupportPrivate
    PkgConfig::StartupNotification
    PkgConfig::Xext
    PkgConfig::Xi
    PkgConfig::X11
    PkgConfig::XcbUtil
)

if("${QT_VERSION_MAJOR}" STREQUAL "5")
    target_link_libraries(${LIB_NAME} PRIVATE
        PkgConfig::QGSettings
        Qt5::X11Extras
    )
endif()

target_link_directories(${LIB_NAME} INTERFACE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
    $<INSTALL_INTERFACE:${LIBRARY_INSTALL_DIR}>
)

set_target_properties(${LIB_NAME}
    PROPERTIES
    VERSION ${DTK_VERSION}
    SOVERSION ${DTK_VERSION_MAJOR}
    EXPORT_NAME Widget
    PUBLIC_HEADER "${PUBLIC_HEADERS}"
)
install(
    TARGETS ${LIB_NAME}
    EXPORT ${DtkWidget}Targets
    DESTINATION ${LIBRARY_INSTALL_DIR}
    PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}
)

install(
    EXPORT ${DtkWidget}Targets 
    NAMESPACE Dtk${DTK_NAME_SUFFIX}:: 
    FILE ${DtkWidget}Targets.cmake 
    DESTINATION "${CONFIG_CMAKE_INSTALL_DIR}"
)

install(FILES ${QM_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/${TRANSLATIONS_INSTALL_DIR}")
