# SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
# SPDX-License-Identifier: BSD-2-Clause

add_library(arianna_static STATIC)

ecm_qt_declare_logging_category(arianna_static
    HEADER arianna_debug.h
    IDENTIFIER ARIANNA_LOG
    CATEGORY_NAME org.kde.arianna
    DESCRIPTION "arianna"
    DEFAULT_SEVERITY Warning
    EXPORT ARIANNA
)

target_sources(arianna_static PRIVATE
    clipboard.cpp
    clipboard.h
    format.cpp
    format.h
    bookdatabase.cpp
    bookdatabase.h
    categoryentriesmodel.cpp
    categoryentriesmodel.h
    propertycontainer.cpp
    propertycontainer.h
    booklistmodel.cpp
    booklistmodel.h
    epubcontainer.cpp
    epubcontainer.h
    tableofcontentmodel.cpp
    tableofcontentmodel.h

    navigation.h
    navigation.cpp

    contentlist/contentlist.cpp
    contentlist/contentlist.h
    contentlist/contentquery.cpp
    contentlist/contentquery.h
    contentlist/contentlisterbase.cpp
    contentlist/contentlisterbase.h
    contentlist/filesystemcontentlister.cpp
    contentlist/filesystemcontentlister.h
    contentlist/manualcontentlister.cpp
    contentlist/manualcontentlister.h
    ${debug_files_SRCS}
)

kconfig_add_kcfg_files(arianna_static GENERATE_MOC config.kcfgc)

target_link_libraries(arianna_static PUBLIC
    Qt::Quick
    Qt::Qml
    Qt::Gui
    Qt::Network
    Qt::WebSockets
    Qt::QuickControls2
    Qt::Svg
    Qt::Sql
    Qt::Xml
    Qt::Widgets
    KF${QT_MAJOR_VERSION}::I18n
    KF${QT_MAJOR_VERSION}::Kirigami2
    KF${QT_MAJOR_VERSION}::ConfigCore
    KF${QT_MAJOR_VERSION}::ConfigGui
    KF${QT_MAJOR_VERSION}::WindowSystem
    KF${QT_MAJOR_VERSION}::DBusAddons
    KF${QT_MAJOR_VERSION}::FileMetaData
    KF${QT_MAJOR_VERSION}::Archive
    KF${QT_MAJOR_VERSION}::CoreAddons)

if (${QT_MAJOR_VERSION} STREQUAL 5)
    target_link_libraries(arianna_static PUBLIC Qt::WebEngine)
else()
    target_link_libraries(arianna_static PUBLIC Qt::WebEngineQuick)
endif()

if (NOT WIN32)
    target_link_libraries(arianna_static PUBLIC KF${QT_MAJOR_VERSION}::Baloo)
    target_sources(arianna_static PRIVATE contentlist/baloocontentlister.cpp contentlist/baloocontentlister.h)
    target_compile_definitions(arianna_static PUBLIC -DHAVE_BALOO)
endif()

if (BUILD_TESTING)
    add_subdirectory(autotests)
endif()

if(QT_MAJOR_VERSION STREQUAL "5")
       set(QML_QTGRAPHICAL_EFFECTS_IMPORT "QtGraphicalEffects 1.15")
       set(KIRIGAMI_PLACEITEM_ICON "icon")
       set(KIRIGAMI_ACTIONS "actions.main")
       set(QTQUICKDIALOG_VERSION "1.3")
       set(DIALOG_FONTDIALOG_FONT "font")
else()
       set(QML_QTGRAPHICAL_EFFECTS_IMPORT "Qt5Compat.GraphicalEffects")
       set(KIRIGAMI_PLACEITEM_ICON "icon.name")
       set(KIRIGAMI_ACTIONS "actions")
       set(QTQUICKDIALOG_VERSION "")
       set(DIALOG_FONTDIALOG_FONT "currentFont")
endif()

configure_file(content/ui/GridBrowserDelegate.qml ${CMAKE_CURRENT_BINARY_DIR}/content/ui/GridBrowserDelegate.qml)
configure_file(content/ui/main.qml ${CMAKE_CURRENT_BINARY_DIR}/content/ui/main.qml)
configure_file(content/ui/LibraryPage.qml ${CMAKE_CURRENT_BINARY_DIR}/content/ui/LibraryPage.qml)
configure_file(content/ui/SettingsPage.qml ${CMAKE_CURRENT_BINARY_DIR}/content/ui/SettingsPage.qml)
configure_file(resources.qrc.in ${CMAKE_CURRENT_SOURCE_DIR}/resources.qrc)

add_executable(arianna
    main.cpp
    ${CMAKE_CURRENT_SOURCE_DIR}/resources.qrc
)

target_include_directories(arianna PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(arianna PRIVATE arianna_static)

install(TARGETS arianna ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
