include_guard(GLOBAL)

function(qemby_append_default_qt_prefixes)
    set(_qemby_qt_prefixes)

    if(QEMBY_QT_ROOT)
        list(APPEND _qemby_qt_prefixes
            "${QEMBY_QT_ROOT}"
            "${QEMBY_QT_ROOT}/lib/cmake"
        )
    endif()

    if(DEFINED ENV{QTDIR} AND NOT "$ENV{QTDIR}" STREQUAL "")
        list(APPEND _qemby_qt_prefixes
            "$ENV{QTDIR}"
            "$ENV{QTDIR}/lib/cmake"
        )
    endif()

    foreach(_qemby_qt_prefix IN LISTS _qemby_qt_prefixes)
        if(EXISTS "${_qemby_qt_prefix}")
            list(APPEND CMAKE_PREFIX_PATH "${_qemby_qt_prefix}")
        endif()
    endforeach()

    if(CMAKE_PREFIX_PATH)
        list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH)
    endif()

    set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" PARENT_SCOPE)
endfunction()

function(qemby_link_libmpv target)
    if(NOT TARGET "${target}")
        message(FATAL_ERROR "qemby_link_libmpv: target '${target}' does not exist")
    endif()

    find_package(PkgConfig REQUIRED)
    pkg_check_modules(MPV REQUIRED IMPORTED_TARGET mpv)
    target_link_libraries("${target}" PRIVATE PkgConfig::MPV)
endfunction()
