include(FindPkgConfig)
pkg_check_modules(EXIV2 REQUIRED exiv2)             # photoeditor

set(PLUGIN_SRC
    components.cpp
)

set(EXAMPLE_PLUGIN_SRC
    example/example-model.cpp
)

set(PHOTO_EDITOR_PLUGIN_SRC
    photoeditor/file-utils.cpp
    photoeditor/orientation.cpp
    photoeditor/photo-data.cpp
    photoeditor/photo-image-provider.cpp
    photoeditor/photo-metadata.cpp
    photoeditor/imaging.cpp
    photoeditor/photo-edit-thread.cpp
    )

set(TABS_BAR_PLUGIN_SRC
    tabsbar/drag-helper.cpp
)

include_directories(
    ${CMAKE_BINARY_DIR}
)

add_library(lomiri-ui-extras-plugin SHARED ${PLUGIN_SRC} ${PLUGIN_HDRS}
            ${EXAMPLE_PLUGIN_SRC} ${PHOTO_EDITOR_PLUGIN_SRC} ${TABS_BAR_PLUGIN_SRC})
target_link_libraries(lomiri-ui-extras-plugin
    ${EXIV2_LIBRARIES}
    Qt::Core
    Qt::Qml
    Qt::Quick
    Qt::Xml
    Qt::Widgets
)


if (ENABLE_QT6)
    find_package(Qt6 COMPONENTS ShaderToolsTools CONFIG REQUIRED)
    get_target_property(QSB_BIN Qt6::qsb LOCATION)
    if (NOT QSB_BIN)
        message(FATAL_ERROR "qsb not found")
    endif()

    add_custom_command(
        OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tabsbar/tab-contour.frag.qsb
        COMMAND ${QSB_BIN} --glsl "100 es,120,150" --hlsl 50 --msl 12 -o tabsbar/tab-contour.frag.qsb ${CMAKE_CURRENT_SOURCE_DIR}/tabsbar/tab-contour.frag
        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tabsbar/tab-contour.frag
        VERBATIM
    )
    qt_add_resources(lomiri-ui-extras-plugin "tabs_bar"
        PREFIX "/shaders"
        BASE ${CMAKE_CURRENT_BINARY_DIR}
        FILES ${CMAKE_CURRENT_BINARY_DIR}/tabsbar/tab-contour.frag.qsb
    )
endif()

set(QT_IMPORTS_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/qml")

set(PLUGIN_DIR ${QT_IMPORTS_DIR}/Lomiri/Components/Extras)
install(TARGETS lomiri-ui-extras-plugin DESTINATION ${PLUGIN_DIR})

# copy the product of the build (plugin binary) to the test directory before
# unit tests are run, so it can be loaded by them.
# Also copy it one directory up so it can be loaded by autopilot tests when
# running them uninstalled.
add_custom_command(
            TARGET lomiri-ui-extras-plugin
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy
                $<TARGET_FILE:lomiri-ui-extras-plugin>
                ${CMAKE_BINARY_DIR}/tests/unittests/Lomiri/Components/Extras/)
add_custom_command(
            TARGET lomiri-ui-extras-plugin
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy
                $<TARGET_FILE:lomiri-ui-extras-plugin>
                ../)
