cmake_minimum_required(VERSION 3.30)
project(KConfigReceiptFixture LANGUAGES NONE)
get_filename_component(repository "${CMAKE_CURRENT_SOURCE_DIR}/../../.." ABSOLUTE)
set(CMAKE_BUILD_TYPE Release)
set(Qt6_ROOT "${CMAKE_CURRENT_BINARY_DIR}/qt")
set(prefix "${CMAKE_CURRENT_BINARY_DIR}/prefix")
file(MAKE_DIRECTORY "${Qt6_ROOT}/bin" "${prefix}/bin")
file(WRITE "${Qt6_ROOT}/bin/Qt6Core.dll" "synthetic Qt fixture")
add_library(Qt6::Core SHARED IMPORTED)
set_target_properties(Qt6::Core PROPERTIES
    IMPORTED_LOCATION_RELEASE "${Qt6_ROOT}/bin/Qt6Core.dll")
include("${repository}/cmake/ModifiedDependencyReceipt.cmake")
file(READ "${repository}/cmake/dependencies.json" manifest)
foreach(dependency IN ITEMS kio kimap ksmtp kmime kcodecs kconfig kcrash)
    if(dependency STREQUAL kio)
        set(target KF6::KIOCore)
        set(patch kio/6.31.0-smoothmail-portable-core.patch)
    elseif(dependency STREQUAL kimap)
        set(target KPim6::IMAP)
        set(patch kimap/26.08.3-fix-sasl-continuation.patch)
    elseif(dependency STREQUAL ksmtp)
        set(target KPim6::SMTP)
        set(patch ksmtp/26.08.3-reset-ehlo-capabilities.patch)
    elseif(dependency STREQUAL kmime)
        set(target KF6::Mime)
        set(patch kmime/6.31.0-safe-ctype.patch)
    elseif(dependency STREQUAL kcodecs)
        set(target KF6::Codecs)
        set(patch kcodecs/6.31.0-safe-ctype.patch)
    elseif(dependency STREQUAL kcrash)
        set(target KF6::Crash)
        set(patch kcrash/6.31.0-windows-runtime-paths.patch)
    else()
        set(target KF6::ConfigCore)
        set(patch kconfig/6.31.0-optional-check-update.patch)
    endif()
    set(artifact "${prefix}/bin/${dependency}.dll")
    file(WRITE "${artifact}" "synthetic ${dependency} fixture")
    add_library(${target} SHARED IMPORTED)
    set_target_properties(${target} PROPERTIES IMPORTED_LOCATION_RELEASE "${artifact}")
    string(JSON commit GET "${manifest}" "${dependency}" commit)
    file(MAKE_DIRECTORY "${prefix}/share/licenses/${dependency}")
    if(NOT ((dependency STREQUAL kconfig AND MODE STREQUAL missing)
            OR (dependency STREQUAL kcrash AND MODE STREQUAL missing-crash)))
        smoothmail_write_modified_receipt("${prefix}/share/licenses/${dependency}"
            "${artifact}" "${commit}" "${repository}/patches/${patch}")
    endif()
    if(dependency STREQUAL kconfig AND MODE STREQUAL replaced)
        file(WRITE "${artifact}" "replaced synthetic fixture")
    endif()
    if(dependency STREQUAL kio AND MODE STREQUAL old-kio)
        smoothmail_write_modified_receipt("${prefix}/share/licenses/kio" "${artifact}" "${commit}"
            "${repository}/patches/kio/6.31.0-disable-favicon-cache.patch")
    endif()
endforeach()
include("${repository}/cmake/ValidateMailDependencies.cmake")
