if(APPLE)
    if (SPARKLE_FOUND)
        list(APPEND QSFERA_BUNDLED_RESOURCES
            "${PROJECT_SOURCE_DIR}/admin/osx/deny_autoupdate_eu.qsfera.desktop.plist"
            "${PROJECT_SOURCE_DIR}/admin/osx/sparkle/dsa_pub.pem")
        set(QSFERA_BUNDLED_RESOURCES ${QSFERA_BUNDLED_RESOURCES} PARENT_SCOPE)
    endif()
endif()

target_sources(QSferaGui PRIVATE
    ocupdater.cpp
    ocupdater.h
    newversionavailablewidget.cpp
    newversionavailablewidget.h
    newversionavailablewidget.ui
    updateinfo.cpp
    updateinfo.h
    updater.cpp
    updater.h
    updatedownloadedwidget.cpp
    updatedownloadedwidget.h
    updatedownloadedwidget.ui
)

if(SPARKLE_FOUND)
    # Define this, we need to check in updater.cpp
    target_compile_definitions(QSferaGui PUBLIC HAVE_SPARKLE)
    target_sources(QSferaGui PRIVATE
        sparkleupdater_mac.mm
        sparkleupdater.h
    )
    target_link_libraries(QSferaGui PRIVATE ${SPARKLE_LIBRARY})
endif()

if(WITH_APPIMAGEUPDATER)
    message(STATUS "Including built-in libappimageupdate based updater")

    set(appimageupdater_sources
        ${CMAKE_CURRENT_SOURCE_DIR}/appimageupdateavailablewidget.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/appimageupdateavailablewidget.h
        ${CMAKE_CURRENT_SOURCE_DIR}/appimageupdateavailablewidget.ui
        ${CMAKE_CURRENT_SOURCE_DIR}/appimageupdater.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/appimageupdater.h
    )

    target_sources(QSferaGui PRIVATE ${appimageupdater_sources})

    # as libappimageupdate uses exceptions, we define a shim that catches all incoming exceptions
    # and handles them in a suitable way
    # we have to enable exceptions for this one compilation unit
    set_source_files_properties(${appimageupdater_sources}
        TARGET_DIRECTORY QSferaGui
        PROPERTIES COMPILE_OPTIONS "-fexceptions"
    )

    target_compile_definitions(QSferaGui PRIVATE WITH_APPIMAGEUPDATER)
    target_link_libraries(QSferaGui PRIVATE libappimageupdate)

    find_package(Threads REQUIRED)
    target_link_libraries(QSferaGui PUBLIC ${CMAKE_THREAD_LIBS_INIT})
endif()
