################# includes #################
include_directories(
    animations
    debug
    ${CMAKE_SOURCE_DIR}/libveloracommon
    ${CMAKE_BINARY_DIR}/libveloracommon
)

################# configuration #################
configure_file(config-velora.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-velora.h)

########### next target ###############
set(velora_PART_SRCS
    animations/veloraanimation.cpp
    animations/veloraanimations.cpp
    animations/veloraanimationdata.cpp
    animations/velorabaseengine.cpp
    animations/velorabusyindicatordata.cpp
    animations/velorabusyindicatorengine.cpp
    animations/veloradialdata.cpp
    animations/veloradialengine.cpp
    animations/veloraenabledata.cpp
    animations/veloragenericdata.cpp
    animations/veloraheaderviewdata.cpp
    animations/veloraheaderviewengine.cpp
    animations/velorascrollbardata.cpp
    animations/velorascrollbarengine.cpp
    animations/veloraspinboxengine.cpp
    animations/veloraspinboxdata.cpp
    animations/velorastackedwidgetdata.cpp
    animations/velorastackedwidgetengine.cpp
    animations/veloratabbarengine.cpp
    animations/veloratabbardata.cpp
    animations/veloratoolboxengine.cpp
    animations/veloratransitiondata.cpp
    animations/veloratransitionwidget.cpp
    animations/velorawidgetstateengine.cpp
    animations/velorawidgetstatedata.cpp
    debug/velorawidgetexplorer.cpp
    veloraaddeventfilter.cpp
    velorablurhelper.cpp
    veloraframeshadow.cpp
    velorahelper.cpp
    veloramdiwindowshadow.cpp
    veloramnemonics.cpp
    velorapropertynames.cpp
    velorashadowhelper.cpp
    velorasplitterproxy.cpp
    velorastyle.cpp
    velorastyleplugin.cpp
    veloratileset.cpp
    velorawindowmanager.cpp
    veloratoolsareamanager.cpp
)

kconfig_add_kcfg_files(velora_PART_SRCS ../kdecoration/velorasettings.kcfgc)
kconfig_add_kcfg_files(velora_PART_SRCS velorastyleconfigdata.kcfgc)

add_library(velora${QT_MAJOR_VERSION} MODULE ${velora_PART_SRCS})

################# find Qt modules #################
if(QT_MAJOR_VERSION EQUAL 6)
    find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Quick QuickWidgets)
else()
    find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Quick QuickWidgets)
endif()

################# link Qt libraries #################
target_link_libraries(velora${QT_MAJOR_VERSION}
    PRIVATE
    Qt${QT_MAJOR_VERSION}::Core
    Qt${QT_MAJOR_VERSION}::Gui
    Qt${QT_MAJOR_VERSION}::Widgets
    Qt${QT_MAJOR_VERSION}::DBus
    Qt${QT_MAJOR_VERSION}::Quick
)

if( VELORA_HAVE_QTQUICK )
    target_link_libraries(velora${QT_MAJOR_VERSION}
        PRIVATE
            Qt${QT_MAJOR_VERSION}::QuickWidgets
            KF${QT_MAJOR_VERSION}::CoreAddons
    )
endif()

################# link KDE Frameworks #################
target_link_libraries(velora${QT_MAJOR_VERSION}
    PRIVATE
    KF${QT_MAJOR_VERSION}::CoreAddons
    KF${QT_MAJOR_VERSION}::ConfigCore
    KF${QT_MAJOR_VERSION}::ConfigGui
    KF${QT_MAJOR_VERSION}::GuiAddons
    KF${QT_MAJOR_VERSION}::IconThemes
    KF${QT_MAJOR_VERSION}::WindowSystem
)

if(QT_MAJOR_VERSION STREQUAL "5")
    target_link_libraries(velora${QT_MAJOR_VERSION} PRIVATE KF5::ConfigWidgets)
    if(VELORA_HAVE_QTQUICK)
        target_link_libraries(velora${QT_MAJOR_VERSION} PRIVATE KF5::Kirigami2)
    endif()
else()
    target_link_libraries(velora${QT_MAJOR_VERSION} PRIVATE KF6::ColorScheme)
    if(VELORA_HAVE_QTQUICK)
        target_link_libraries(velora${QT_MAJOR_VERSION} PRIVATE KF6::KirigamiPlatform)
    endif()
endif()

################# link internal library #################
target_link_libraries(velora${QT_MAJOR_VERSION} PRIVATE veloracommon${QT_MAJOR_VERSION})

################# KDE style integration #################
if(KF${QT_MAJOR_VERSION}FrameworkIntegration_FOUND)
    target_link_libraries(velora${QT_MAJOR_VERSION} PRIVATE KF${QT_MAJOR_VERSION}::Style)
endif()

if (WIN32)
    # As stated in https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants M_PI only gets defined
    # when if _USE_MATH_DEFINES is defined
    target_compile_definitions(velora${QT_MAJOR_VERSION} PRIVATE _USE_MATH_DEFINES _BSD_SOURCE)
endif()


########### install files ###############
if (FOR_FLATPAK)
    set(LIB_TARGET ${QT_PLUGINS_DIR}/styles/)
else()
    set(LIB_TARGET ${KDE_INSTALL_QTPLUGINDIR}/styles/)
endif()
install(TARGETS velora${QT_MAJOR_VERSION} DESTINATION ${LIB_TARGET})

if (NOT FOR_FLATPAK)
    install(FILES velora.themerc  DESTINATION  ${KDE_INSTALL_DATADIR}/kstyle/themes)
endif()

########### subdirectories ###############

if (QT_MAJOR_VERSION EQUAL "6" AND TARGET "KF6::KCMUtils" AND NOT FOR_FLATPAK)
    add_subdirectory(config)
endif()

########### tests ###############
include(CTest)
if(BUILD_TESTING)
    add_subdirectory(tests)
endif()
