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

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

########### next target ###############
set(darkly_PART_SRCS
    animations/darklyanimation.cpp
    animations/darklyanimations.cpp
    animations/darklyanimationdata.cpp
    animations/darklybaseengine.cpp
    animations/darklybusyindicatordata.cpp
    animations/darklybusyindicatorengine.cpp
    animations/darklydialdata.cpp
    animations/darklydialengine.cpp
    animations/darklyenabledata.cpp
    animations/darklygenericdata.cpp
    animations/darklyheaderviewdata.cpp
    animations/darklyheaderviewengine.cpp
    animations/darklyscrollbardata.cpp
    animations/darklyscrollbarengine.cpp
    animations/darklyspinboxengine.cpp
    animations/darklyspinboxdata.cpp
    animations/darklystackedwidgetdata.cpp
    animations/darklystackedwidgetengine.cpp
    animations/darklytabbarengine.cpp
    animations/darklytabbardata.cpp
    animations/darklytoolboxengine.cpp
    animations/darklytransitiondata.cpp
    animations/darklytransitionwidget.cpp
    animations/darklywidgetstateengine.cpp
    animations/darklywidgetstatedata.cpp
    debug/darklywidgetexplorer.cpp
    darklyaddeventfilter.cpp
    darklyblurhelper.cpp
    darklyframeshadow.cpp
    darklyhelper.cpp
    darklymdiwindowshadow.cpp
    darklymnemonics.cpp
    darklypropertynames.cpp
    darklyshadowhelper.cpp
    darklysplitterproxy.cpp
    darklystyle.cpp
    darklystyleplugin.cpp
    darklytileset.cpp
    darklywindowmanager.cpp
    darklytoolsareamanager.cpp
)

kconfig_add_kcfg_files(darkly_PART_SRCS ../kdecoration/darklysettings.kcfgc)
kconfig_add_kcfg_files(darkly_PART_SRCS darklystyleconfigdata.kcfgc)

add_library(lingmostyle${QT_MAJOR_VERSION} MODULE ${darkly_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(lingmostyle${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( DARKLY_HAVE_QTQUICK )
    target_link_libraries(lingmostyle${QT_MAJOR_VERSION}
        PRIVATE
            Qt${QT_MAJOR_VERSION}::QuickWidgets
            KF${QT_MAJOR_VERSION}::CoreAddons
    )
endif()

################# link KDE Frameworks #################
target_link_libraries(lingmostyle${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(lingmostyle${QT_MAJOR_VERSION} PRIVATE KF5::ConfigWidgets)
    if(DARKLY_HAVE_QTQUICK)
        target_link_libraries(lingmostyle${QT_MAJOR_VERSION} PRIVATE KF5::Kirigami2)
    endif()
else()
    target_link_libraries(lingmostyle${QT_MAJOR_VERSION} PRIVATE KF6::ColorScheme)
    if(DARKLY_HAVE_QTQUICK)
        target_link_libraries(lingmostyle${QT_MAJOR_VERSION} PRIVATE KF6::KirigamiPlatform)
    endif()
endif()

################# link internal library #################
target_link_libraries(lingmostyle${QT_MAJOR_VERSION} PRIVATE lingmoappearancecommon${QT_MAJOR_VERSION})

################# KDE style integration #################
if(KF${QT_MAJOR_VERSION}FrameworkIntegration_FOUND)
    target_link_libraries(lingmostyle${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(lingmostyle${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()
if(QT_MAJOR_VERSION EQUAL 6)
    set(LINGMO_STYLE_INSTALL_COMPONENT Qt6Style)
else()
    set(LINGMO_STYLE_INSTALL_COMPONENT Qt5Style)
endif()
install(TARGETS lingmostyle${QT_MAJOR_VERSION}
        DESTINATION ${LIB_TARGET}
        COMPONENT ${LINGMO_STYLE_INSTALL_COMPONENT})

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

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

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

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