cmake_minimum_required(VERSION 3.25)
project(SmartCut64 VERSION 1.0.34 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(SMARTCUT_ENABLE_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON)
option(SMARTCUT_BUILD_GUI "Build the Qt Widgets desktop shell" OFF)
option(SMARTCUT_ENABLE_SANITIZERS "Enable address and undefined-behaviour sanitizers" OFF)
option(SMARTCUT_ENABLE_PACKAGING "Generate end-user ZIP and installer packages" OFF)
option(SMARTCUT_PRIVATE_BETA
  "Namespace an ARM64 package as a portable private beta with no production shell integration" OFF)
set(SMARTCUT_PRIVATE_BETA_SEQUENCE "1" CACHE STRING
  "Positive private-beta sequence used in the ARM64 portable package name")
option(SMARTCUT_ARM64_PORTABLE_RELEASE
  "Generate the supported Windows ARM64 production build as a portable ZIP only" OFF)
option(SMARTCUT_RUNTIME_HAS_X264 "Report the x264 runtime as included" ON)
option(SMARTCUT_RUNTIME_HAS_X265 "Report the x265 runtime as included" ON)
option(SMARTCUT_RUNTIME_HAS_LIBAOM "Report the libaom runtime as included" ON)
option(SMARTCUT_RUNTIME_HAS_LIBVPX "Report the libvpx runtime as included" ON)
option(SMARTCUT_RUNTIME_HAS_LIBDOVI "Report the libdovi runtime as included" ON)
option(SMARTCUT_MEDIA_ROOT_MSVC_ABI
  "Confirm that SMARTCUT_MEDIA_ROOT contains MSVC-compatible import libraries" OFF)
option(SMARTCUT_REQUIRE_TEST_FFMPEG
  "Fail configuration when the external FFmpeg regression-fixture generator is unavailable" OFF)
option(SMARTCUT_REQUIRE_UNC_TEST
  "Fail the UNC regression gate when no accessible test share is available" OFF)
set(SMARTCUT_UNC_TEST_ROOT "" CACHE STRING
  "Optional writable UNC share root used by the network-source regression gate")
option(SMARTCUT_REQUIRE_DAV1D
  "Require dav1d AV1 decoding in the codec capability regression gate" OFF)
set(SMARTCUT_MEDIA_ROOT "" CACHE PATH "M1 artifact root containing FFmpeg headers and import libraries")
set(SMARTCUT_MINGW_RUNTIME_ROOT "C:/msys642/ucrt64" CACHE PATH "MinGW runtime root used by the M1 DLLs")
set(SMARTCUT_DEPENDENCY_SOURCE_ROOT "${CMAKE_SOURCE_DIR}/build/dependencies-m1/source" CACHE PATH
  "Dependency source root used to install redistribution licences")
set(SMARTCUT_SBOM_FILE "${CMAKE_SOURCE_DIR}/dependencies/sbom.m1.json" CACHE FILEPATH
  "Software bill of materials installed with packaged builds")
set(SMARTCUT_TARGET_ARCHITECTURE "" CACHE STRING
  "Expected Windows PE architecture (x64 or arm64); inferred from the compiler when empty")
set_property(CACHE SMARTCUT_TARGET_ARCHITECTURE PROPERTY STRINGS x64 arm64)

if(WIN32)
  if(SMARTCUT_TARGET_ARCHITECTURE STREQUAL "")
    if(CMAKE_CXX_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64" OR
       CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM64|arm64|aarch64)$")
      set(SMARTCUT_TARGET_ARCHITECTURE "arm64")
    else()
      set(SMARTCUT_TARGET_ARCHITECTURE "x64")
    endif()
  endif()
  if(SMARTCUT_TARGET_ARCHITECTURE STREQUAL "arm64")
    set(SMARTCUT_EXPECTED_PE_MACHINE "AA64")
  elseif(SMARTCUT_TARGET_ARCHITECTURE STREQUAL "x64")
    set(SMARTCUT_EXPECTED_PE_MACHINE "8664")
  else()
    message(FATAL_ERROR "SMARTCUT_TARGET_ARCHITECTURE must be x64 or arm64")
  endif()
  if(MSVC AND SMARTCUT_TARGET_ARCHITECTURE STREQUAL "arm64" AND
     NOT CMAKE_CXX_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64")
    message(FATAL_ERROR
      "The ARM64 preset requires an ARM64 MSVC compiler environment; run vcvarsall.bat x64_arm64 first")
  endif()
endif()

if(SMARTCUT_ENABLE_PACKAGING AND NOT SMARTCUT_BUILD_GUI)
  message(FATAL_ERROR "End-user packaging requires SMARTCUT_BUILD_GUI=ON")
endif()
if(SMARTCUT_PRIVATE_BETA)
  if(NOT SMARTCUT_ENABLE_PACKAGING)
    message(FATAL_ERROR "SMARTCUT_PRIVATE_BETA requires SMARTCUT_ENABLE_PACKAGING=ON")
  endif()
  if(NOT SMARTCUT_TARGET_ARCHITECTURE STREQUAL "arm64")
    message(FATAL_ERROR "The private-beta packaging profile is reserved for Windows ARM64")
  endif()
  if(NOT SMARTCUT_PRIVATE_BETA_SEQUENCE MATCHES "^[1-9][0-9]*$")
    message(FATAL_ERROR "SMARTCUT_PRIVATE_BETA_SEQUENCE must be a positive integer")
  endif()
endif()
if(SMARTCUT_ARM64_PORTABLE_RELEASE)
  if(NOT SMARTCUT_ENABLE_PACKAGING)
    message(FATAL_ERROR "SMARTCUT_ARM64_PORTABLE_RELEASE requires SMARTCUT_ENABLE_PACKAGING=ON")
  endif()
  if(NOT SMARTCUT_TARGET_ARCHITECTURE STREQUAL "arm64")
    message(FATAL_ERROR "The ARM64 portable release profile is reserved for Windows ARM64")
  endif()
  if(SMARTCUT_PRIVATE_BETA)
    message(FATAL_ERROR "The ARM64 production and private-beta packaging profiles are mutually exclusive")
  endif()
endif()
if(SMARTCUT_ENABLE_PACKAGING)
  if(NOT IS_DIRECTORY "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}")
    message(FATAL_ERROR
      "End-user packaging requires the selected dependency source/licence root: ${SMARTCUT_DEPENDENCY_SOURCE_ROOT}")
  endif()
  if(NOT SMARTCUT_SBOM_FILE OR NOT EXISTS "${SMARTCUT_SBOM_FILE}")
    message(FATAL_ERROR
      "End-user packaging requires the selected architecture-specific SBOM: ${SMARTCUT_SBOM_FILE}")
  endif()
endif()

if(MSVC AND SMARTCUT_TARGET_ARCHITECTURE STREQUAL "arm64")
  set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
  include(InstallRequiredSystemLibraries)
  if(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
    message(FATAL_ERROR "The ARM64 Visual C++ runtime libraries could not be located")
  endif()
endif()

if(SMARTCUT_MEDIA_ROOT AND MSVC)
  if(NOT SMARTCUT_MEDIA_ROOT_MSVC_ABI)
    message(FATAL_ERROR
      "MSVC media roots require SMARTCUT_MEDIA_ROOT_MSVC_ABI=ON; the x64 M1 artifacts use the MinGW/UCRT ABI")
  endif()
  foreach(SMARTCUT_MEDIA_IMPORT_LIBRARY avformat avcodec avfilter avutil swscale swresample)
    if(NOT EXISTS "${SMARTCUT_MEDIA_ROOT}/lib/${SMARTCUT_MEDIA_IMPORT_LIBRARY}.lib")
      message(FATAL_ERROR
        "MSVC media import library is missing: ${SMARTCUT_MEDIA_ROOT}/lib/${SMARTCUT_MEDIA_IMPORT_LIBRARY}.lib")
    endif()
  endforeach()
elseif(SMARTCUT_MEDIA_ROOT AND NOT MINGW)
  message(FATAL_ERROR "The pinned M1 media artifacts require a compatible MinGW/UCRT or explicitly validated MSVC ABI")
endif()

if(SMARTCUT_ENABLE_SANITIZERS)
  if(MSVC)
    add_compile_options(/fsanitize=address)
  else()
    add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer)
    add_link_options(-fsanitize=address,undefined)
  endif()
endif()

if(MSVC)
  add_compile_options(/W4 /permissive- /EHsc /bigobj)
  add_compile_definitions(NOMINMAX _CRT_SECURE_NO_WARNINGS)
  if(SMARTCUT_ENABLE_WARNINGS_AS_ERRORS)
    add_compile_options(/WX)
  endif()
else()
  add_compile_options(-Wall -Wextra -Wpedantic)
  if(MINGW)
    include(CheckCXXCompilerFlag)
    check_cxx_compiler_flag("-fstack-protector-strong" SMARTCUT_HAS_STACK_PROTECTOR_STRONG)
    if(SMARTCUT_HAS_STACK_PROTECTOR_STRONG)
      add_compile_options(-fstack-protector-strong)
    endif()
    check_cxx_compiler_flag("-fcf-protection=full" SMARTCUT_HAS_CF_PROTECTION_FULL)
    if(SMARTCUT_HAS_CF_PROTECTION_FULL)
      add_compile_options(-fcf-protection=full)
    else()
      check_cxx_compiler_flag("-fcf-protection=branch" SMARTCUT_HAS_CF_PROTECTION_BRANCH)
      if(SMARTCUT_HAS_CF_PROTECTION_BRANCH)
        add_compile_options(-fcf-protection=branch)
      endif()
    endif()
    if(NOT SMARTCUT_ENABLE_SANITIZERS)
      add_compile_definitions($<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:_FORTIFY_SOURCE=2>)
    endif()
    add_link_options(-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va
                     -Wl,--enable-reloc-section)
  endif()
  if(SMARTCUT_ENABLE_WARNINGS_AS_ERRORS)
    add_compile_options(-Werror)
  endif()
endif()

set(SMARTCUT_LICENSE_PUBLIC_MODULUS_HEX "" CACHE STRING "RSA public modulus (big-endian hex) used to verify paid SmartCut64 licences")
set(SMARTCUT_LICENSE_PUBLIC_EXPONENT_HEX "010001" CACHE STRING "RSA public exponent (big-endian hex) used to verify paid SmartCut64 licences")
set(SMARTCUT_LICENSE_SERVICE_URL "" CACHE STRING "HTTPS base URL for optional Lemon Squeezy online activation")
if(NOT SMARTCUT_LICENSE_PUBLIC_EXPONENT_HEX MATCHES "^0*10001$")
  message(FATAL_ERROR "SMARTCUT_LICENSE_PUBLIC_EXPONENT_HEX must encode RSA exponent 65537")
endif()
if(NOT SMARTCUT_LICENSE_PUBLIC_MODULUS_HEX STREQUAL "")
  if(NOT SMARTCUT_LICENSE_PUBLIC_MODULUS_HEX MATCHES "^[0-9A-Fa-f]+$")
    message(FATAL_ERROR "SMARTCUT_LICENSE_PUBLIC_MODULUS_HEX must contain hexadecimal characters only")
  endif()
  string(LENGTH "${SMARTCUT_LICENSE_PUBLIC_MODULUS_HEX}" SMARTCUT_LICENSE_MODULUS_HEX_LENGTH)
  math(EXPR SMARTCUT_LICENSE_MODULUS_HEX_REMAINDER "${SMARTCUT_LICENSE_MODULUS_HEX_LENGTH} % 2")
  if(SMARTCUT_LICENSE_MODULUS_HEX_LENGTH LESS 512 OR NOT SMARTCUT_LICENSE_MODULUS_HEX_REMAINDER EQUAL 0)
    message(FATAL_ERROR
      "SMARTCUT_LICENSE_PUBLIC_MODULUS_HEX must be an even-length RSA modulus of at least 2048 bits")
  endif()
endif()
if(NOT SMARTCUT_LICENSE_SERVICE_URL STREQUAL "" AND
   NOT SMARTCUT_LICENSE_SERVICE_URL MATCHES "^https://[^ ]+$" AND
   NOT SMARTCUT_LICENSE_SERVICE_URL MATCHES "^http://(localhost|127\\.0\\.0\\.1|\\[::1\\])(:[0-9]+)?(/.*)?$")
  message(FATAL_ERROR
    "SMARTCUT_LICENSE_SERVICE_URL must use HTTPS (HTTP is accepted only for localhost tests)")
endif()
if(SMARTCUT_PRIVATE_BETA OR SMARTCUT_ARM64_PORTABLE_RELEASE)
  if(SMARTCUT_LICENSE_PUBLIC_MODULUS_HEX STREQUAL "")
    message(FATAL_ERROR
      "ARM64 end-user packaging requires the production licence public modulus")
  endif()
  if(NOT SMARTCUT_LICENSE_SERVICE_URL MATCHES "^https://[^ ]+$")
    message(FATAL_ERROR
      "ARM64 end-user packaging requires an HTTPS production licence service URL")
  endif()
endif()
configure_file(cmake/license_public_key.hpp.in "${CMAKE_CURRENT_BINARY_DIR}/generated/core/license_public_key.hpp" @ONLY)
configure_file(cmake/license_service_config.hpp.in "${CMAKE_CURRENT_BINARY_DIR}/generated/core/license_service_config.hpp" @ONLY)

add_library(smartcut-core STATIC src/core/source_identity.cpp src/core/path.cpp src/core/control_ipc.cpp src/core/preview_shared_memory.cpp src/core/entitlement.cpp src/core/project_model.cpp src/core/project_editor.cpp src/core/project_journal.cpp src/core/videoredo_project.cpp src/core/videoredo_batch.cpp src/core/videoredo_joiner.cpp src/core/render_plan.cpp src/core/render_report.cpp src/core/gop_planner.cpp src/media/nal_inventory.cpp src/media/access_unit_index.cpp src/media/index_cache.cpp src/media/video_frame_index.cpp src/media/av1_packet_mapping.cpp src/media/av1_mp4_navigation.cpp src/media/stream_probe.cpp src/media/audio_timing.cpp src/media/audio_playback.cpp src/media/audio_transform.cpp src/media/video_transform.cpp src/media/hardware_decode.cpp src/media/hardware_self_test.cpp src/media/ad_detective.cpp src/media/media_joiner.cpp src/media/title_media.cpp src/media/edit_export.cpp src/media/container_mux.cpp src/media/dimension_filter.cpp src/media/frame_decode.cpp src/media/preview_conversion.cpp src/media/mkv_copy.cpp src/media/mkv_timed_range.cpp src/media/boundary_encode.cpp src/media/boundary_fixture.cpp src/media/ffmpeg_inventory.cpp src/media/sei_injector.cpp src/media/rpu_injector.cpp src/media/mkv_roundtrip.cpp src/media/multitrack_fixture.cpp src/media/s337m_bridge.cpp)
target_sources(smartcut-core PRIVATE src/media/trial_watermark.cpp)
target_sources(smartcut-core PRIVATE src/core/export_cleanup.cpp)
target_sources(smartcut-core PRIVATE src/media/audio_loudness.cpp)
target_sources(smartcut-core PRIVATE src/media/latm_normalize.cpp)
target_sources(smartcut-core PRIVATE src/media/quickstream_recovery.cpp)
target_sources(smartcut-core PRIVATE src/media/subtitle_normalize.cpp src/media/broadcast_edit.cpp)
target_sources(smartcut-core PRIVATE src/media/legacy_timing.cpp)
target_sources(smartcut-core PRIVATE src/media/preview_decode_session.cpp)
target_sources(smartcut-core PRIVATE src/core/gpu_preview.cpp src/media/gpu_preview_export.cpp)
target_include_directories(smartcut-core PUBLIC src "${CMAKE_CURRENT_BINARY_DIR}/generated")
target_compile_definitions(smartcut-core PUBLIC
  SMARTCUT_RUNTIME_HAS_X264=$<BOOL:${SMARTCUT_RUNTIME_HAS_X264}>
  SMARTCUT_RUNTIME_HAS_X265=$<BOOL:${SMARTCUT_RUNTIME_HAS_X265}>
  SMARTCUT_RUNTIME_HAS_LIBAOM=$<BOOL:${SMARTCUT_RUNTIME_HAS_LIBAOM}>
  SMARTCUT_RUNTIME_HAS_LIBVPX=$<BOOL:${SMARTCUT_RUNTIME_HAS_LIBVPX}>
  SMARTCUT_RUNTIME_HAS_LIBDOVI=$<BOOL:${SMARTCUT_RUNTIME_HAS_LIBDOVI}>)
if(WIN32)
  target_link_libraries(smartcut-core PUBLIC bcrypt advapi32 crypt32)
  target_link_libraries(smartcut-core PUBLIC d3d11 dxgi d3dcompiler)
endif()
if(SMARTCUT_MEDIA_ROOT)
  # Treat vendor headers as external even when the SDK is staged outside the
  # Catch2 prefix; project warnings remain errors in every application target.
  target_include_directories(smartcut-core SYSTEM PUBLIC "${SMARTCUT_MEDIA_ROOT}/include")
  target_link_directories(smartcut-core PUBLIC "${SMARTCUT_MEDIA_ROOT}/bin" "${SMARTCUT_MEDIA_ROOT}/lib")
  target_link_libraries(smartcut-core PUBLIC avformat avcodec avfilter avutil swscale swresample winmm)
  target_compile_definitions(smartcut-core PUBLIC SMARTCUT_HAS_FFMPEG=1)
  if(SMARTCUT_ARM64_PORTABLE_RELEASE AND SMARTCUT_RUNTIME_HAS_LIBDOVI AND
      (NOT EXISTS "${SMARTCUT_MEDIA_ROOT}/include/libdovi/rpu_parser.h" OR
       NOT EXISTS "${SMARTCUT_MEDIA_ROOT}/lib/dovi.lib" OR
       NOT EXISTS "${SMARTCUT_MEDIA_ROOT}/bin/dovi.dll"))
    message(FATAL_ERROR "Production ARM64 Dolby Vision support requires the native libdovi SDK; run dependencies/scripts/build-libdovi-arm64.ps1")
  endif()
  if(EXISTS "${SMARTCUT_MEDIA_ROOT}/include/libdovi/rpu_parser.h")
    target_link_libraries(smartcut-core PUBLIC dovi)
    target_compile_definitions(smartcut-core PUBLIC SMARTCUT_HAS_LIBDOVI=1)
  endif()
  if(MSVC)
    target_compile_options(smartcut-core PRIVATE /wd4244)
  endif()
endif()

add_executable(smartcut-cli src/cli/main.cpp)
target_link_libraries(smartcut-cli PRIVATE smartcut-core)

add_executable(smartcut-worker src/worker/main.cpp)
target_link_libraries(smartcut-worker PRIVATE smartcut-core)

if(SMARTCUT_BUILD_GUI)
  find_package(Qt6 REQUIRED COMPONENTS Widgets Network)
  configure_file(cmake/qt.conf "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" COPYONLY)
  set(SMARTCUT_GUI_WINDOWS_RESOURCE)
  if(WIN32)
    enable_language(RC)
    file(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/assets/smartcut64-app-icon.ico" SMARTCUT_APP_ICON)
    if(NOT EXISTS "${SMARTCUT_APP_ICON}")
      message(FATAL_ERROR "SmartCut64 application icon is unavailable: ${SMARTCUT_APP_ICON}")
    endif()
    configure_file(cmake/smartcut64.rc.in "${CMAKE_CURRENT_BINARY_DIR}/smartcut64.rc" @ONLY)
    list(APPEND SMARTCUT_GUI_WINDOWS_RESOURCE "${CMAKE_CURRENT_BINARY_DIR}/smartcut64.rc")
  endif()
  add_executable(smartcut-gui WIN32 src/gui/main.cpp src/gui/resources.qrc ${SMARTCUT_GUI_WINDOWS_RESOURCE})
  target_sources(smartcut-gui PRIVATE src/gui/license_manager.cpp src/gui/process_diagnostics.cpp)
  target_sources(smartcut-gui PRIVATE src/gui/profile_backup.cpp)
  target_include_directories(smartcut-gui PRIVATE src)
  target_link_libraries(smartcut-gui PRIVATE Qt6::Widgets Qt6::Network smartcut-core)
  if(SMARTCUT_PRIVATE_BETA)
    target_compile_definitions(smartcut-gui PRIVATE SMARTCUT_PRIVATE_BETA=1)
  endif()
  if(WIN32)
    target_link_libraries(smartcut-gui PRIVATE winmm crypt32 dwmapi shell32 ole32)
  endif()
  set_target_properties(smartcut-gui PROPERTIES AUTOMOC ON AUTORCC ON)
endif()

# Keep every build-tree executable independently launchable from Explorer and a
# plain command prompt. Tests often inherit MSYS2's PATH, which can otherwise
# conceal missing runtime deployment until a user double-clicks the program.
if(MINGW)
  file(GLOB SMARTCUT_MEDIA_RUNTIME_DLLS "${SMARTCUT_MEDIA_ROOT}/bin/*.dll")
  set(SMARTCUT_TOOLCHAIN_RUNTIME_DLLS
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libgcc_s_seh-1.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libstdc++-6.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libwinpthread-1.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libb2-1.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libpcre2-16-0.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libzstd.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/zlib1.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libbrotlidec.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libbrotlicommon.dll")
  function(smartcut_deploy_build_runtime runtime_target)
    foreach(runtime_dll IN LISTS SMARTCUT_MEDIA_RUNTIME_DLLS SMARTCUT_TOOLCHAIN_RUNTIME_DLLS)
      if(EXISTS "${runtime_dll}")
        add_custom_command(TARGET ${runtime_target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${runtime_dll}" "$<TARGET_FILE_DIR:${runtime_target}>" VERBATIM)
      endif()
    endforeach()
  endfunction()
  function(smartcut_deploy_qt_runtime runtime_target)
    file(GLOB qt_runtime_dlls "${CMAKE_PREFIX_PATH}/bin/Qt6*.dll")
    foreach(runtime_dll IN LISTS qt_runtime_dlls)
      add_custom_command(TARGET ${runtime_target} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
          "${runtime_dll}" "$<TARGET_FILE_DIR:${runtime_target}>"
        VERBATIM)
    endforeach()
    foreach(plugin_group platforms tls)
      if(EXISTS "${CMAKE_PREFIX_PATH}/plugins/${plugin_group}")
        add_custom_command(TARGET ${runtime_target} POST_BUILD
          COMMAND ${CMAKE_COMMAND} -E make_directory
            "$<TARGET_FILE_DIR:${runtime_target}>/${plugin_group}"
          COMMAND ${CMAKE_COMMAND} -E copy_directory
            "${CMAKE_PREFIX_PATH}/plugins/${plugin_group}"
            "$<TARGET_FILE_DIR:${runtime_target}>/${plugin_group}"
          VERBATIM)
      endif()
    endforeach()
    add_custom_command(TARGET ${runtime_target} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "$<TARGET_FILE_DIR:${runtime_target}>/qt.conf"
      VERBATIM)
  endfunction()
  set(SMARTCUT_BUILD_TREE_TARGETS smartcut-cli smartcut-worker)
  if(SMARTCUT_BUILD_GUI)
    list(APPEND SMARTCUT_BUILD_TREE_TARGETS smartcut-gui)
  endif()
  foreach(runtime_target IN LISTS SMARTCUT_BUILD_TREE_TARGETS)
    smartcut_deploy_build_runtime(${runtime_target})
  endforeach()
  if(SMARTCUT_BUILD_GUI)
    smartcut_deploy_qt_runtime(smartcut-gui)
  endif()
elseif(MSVC AND SMARTCUT_MEDIA_ROOT)
  file(GLOB SMARTCUT_MEDIA_RUNTIME_DLLS "${SMARTCUT_MEDIA_ROOT}/bin/*.dll")
  function(smartcut_deploy_build_runtime runtime_target)
    foreach(runtime_dll IN LISTS SMARTCUT_MEDIA_RUNTIME_DLLS CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
      add_custom_command(TARGET ${runtime_target} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
          "${runtime_dll}" "$<TARGET_FILE_DIR:${runtime_target}>"
        VERBATIM)
    endforeach()
  endfunction()
  function(smartcut_deploy_qt_target runtime_target qt_target relative_directory)
    if(NOT TARGET ${qt_target})
      message(FATAL_ERROR "Required Qt runtime target is unavailable: ${qt_target}")
    endif()
    if(relative_directory STREQUAL "")
      set(runtime_destination "$<TARGET_FILE_DIR:${runtime_target}>")
    else()
      set(runtime_destination "$<TARGET_FILE_DIR:${runtime_target}>/${relative_directory}")
      add_custom_command(TARGET ${runtime_target} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E make_directory "${runtime_destination}"
        VERBATIM)
    endif()
    add_custom_command(TARGET ${runtime_target} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "$<TARGET_FILE:${qt_target}>" "${runtime_destination}"
      VERBATIM)
  endfunction()
  function(smartcut_deploy_qt_runtime runtime_target)
    foreach(qt_target Qt6::Core Qt6::Gui Qt6::Network Qt6::Widgets)
      smartcut_deploy_qt_target(${runtime_target} ${qt_target} "")
    endforeach()
    smartcut_deploy_qt_target(${runtime_target} Qt6::QWindowsIntegrationPlugin platforms)
    smartcut_deploy_qt_target(${runtime_target} Qt6::QSchannelBackendPlugin tls)
    smartcut_deploy_qt_target(${runtime_target} Qt6::QJpegPlugin imageformats)
    smartcut_deploy_qt_target(${runtime_target} Qt6::QGifPlugin imageformats)
    smartcut_deploy_qt_target(${runtime_target} Qt6::QICOPlugin imageformats)
    smartcut_deploy_qt_target(${runtime_target} Qt6::QTiffPlugin imageformats)
    smartcut_deploy_qt_target(${runtime_target} Qt6::QModernWindowsStylePlugin styles)
    add_custom_command(TARGET ${runtime_target} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" "$<TARGET_FILE_DIR:${runtime_target}>/qt.conf"
      VERBATIM)
  endfunction()
  set(SMARTCUT_BUILD_TREE_TARGETS smartcut-cli smartcut-worker)
  if(SMARTCUT_BUILD_GUI)
    list(APPEND SMARTCUT_BUILD_TREE_TARGETS smartcut-gui)
  endif()
  foreach(runtime_target IN LISTS SMARTCUT_BUILD_TREE_TARGETS)
    smartcut_deploy_build_runtime(${runtime_target})
  endforeach()
  if(SMARTCUT_BUILD_GUI)
    smartcut_deploy_qt_runtime(smartcut-gui)
  endif()
endif()

if(MINGW AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  set(SMARTCUT_SYMBOL_TARGETS smartcut-cli smartcut-worker)
  if(SMARTCUT_BUILD_GUI)
    list(APPEND SMARTCUT_SYMBOL_TARGETS smartcut-gui)
  endif()
  foreach(symbol_target IN LISTS SMARTCUT_SYMBOL_TARGETS)
    add_custom_command(TARGET ${symbol_target} POST_BUILD
      COMMAND "${CMAKE_OBJCOPY}" --only-keep-debug "$<TARGET_FILE:${symbol_target}>" "$<TARGET_FILE:${symbol_target}>.dbg"
      COMMAND "${CMAKE_OBJCOPY}" --strip-debug "$<TARGET_FILE:${symbol_target}>"
      COMMAND "${CMAKE_OBJCOPY}" --add-gnu-debuglink=$<TARGET_FILE_NAME:${symbol_target}>.dbg "$<TARGET_FILE:${symbol_target}>"
      VERBATIM)
    install(FILES "$<TARGET_FILE:${symbol_target}>.dbg" DESTINATION symbols)
  endforeach()
endif()

include(GNUInstallDirs)
if(SMARTCUT_BUILD_GUI AND WIN32)
  # Explicit local-only target: never installed by CPack or built implicitly.
  add_executable(smartcut-gui-qa WIN32 EXCLUDE_FROM_ALL src/gui/main.cpp
    src/gui/license_manager.cpp src/gui/profile_backup.cpp src/gui/resources.qrc ${SMARTCUT_GUI_WINDOWS_RESOURCE})
  target_include_directories(smartcut-gui-qa PRIVATE src)
  target_compile_definitions(smartcut-gui-qa PRIVATE SMARTCUT_LOCAL_QA_GUI=1)
  target_link_libraries(smartcut-gui-qa PRIVATE Qt6::Widgets Qt6::Network smartcut-core
    winmm crypt32 dwmapi shell32 ole32)
  set_target_properties(smartcut-gui-qa PROPERTIES AUTOMOC ON AUTORCC ON
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/local-qa/bin")
  if(MINGW)
    smartcut_deploy_build_runtime(smartcut-gui-qa)
    smartcut_deploy_qt_runtime(smartcut-gui-qa)
  endif()
endif()
install(TARGETS smartcut-cli smartcut-worker RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if(SMARTCUT_BUILD_GUI)
  install(TARGETS smartcut-gui RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
install(DIRECTORY schemas DESTINATION share/smartcut64)
install(FILES LICENSE COPYRIGHT README.md THIRD_PARTY.md COMMERCIAL_DISTRIBUTION.md
  PRIVACY.md CUSTOMER_TERMS.md REFUND_POLICY.md SUPPORT.md SECURITY.md DESTINATION .)
install(FILES docs/PAID_ENTITLEMENTS.md docs/PRODUCT_LISTING.md
  docs/LEMON_SQUEEZY_LAUNCH.md docs/EXTERNAL_RELEASE_BLOCKERS.md
  docs/RELEASE_NOTES.md docs/USER_GUIDE.md DESTINATION docs)
if(SMARTCUT_PRIVATE_BETA)
  install(FILES docs/WINDOWS_ARM64_PRIVATE_BETA.md DESTINATION docs)
elseif(SMARTCUT_ARM64_PORTABLE_RELEASE)
  install(FILES docs/WINDOWS_ARM64.md DESTINATION docs)
endif()
if(SMARTCUT_SBOM_FILE AND EXISTS "${SMARTCUT_SBOM_FILE}")
  install(FILES "${SMARTCUT_SBOM_FILE}" DESTINATION .)
endif()
if(SMARTCUT_MEDIA_ROOT AND EXISTS "${SMARTCUT_MEDIA_ROOT}/bin")
  install(DIRECTORY "${SMARTCUT_MEDIA_ROOT}/bin/" DESTINATION ${CMAKE_INSTALL_BINDIR} FILES_MATCHING PATTERN "*.dll")
endif()
if(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
  install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
if(SMARTCUT_BUILD_GUI AND MSVC)
  function(smartcut_install_qt_target qt_target relative_directory)
    if(NOT TARGET ${qt_target})
      message(FATAL_ERROR "Required Qt install target is unavailable: ${qt_target}")
    endif()
    if(relative_directory STREQUAL "")
      set(runtime_destination "${CMAKE_INSTALL_BINDIR}")
    else()
      set(runtime_destination "${CMAKE_INSTALL_BINDIR}/${relative_directory}")
    endif()
    install(FILES "$<TARGET_FILE:${qt_target}>" DESTINATION "${runtime_destination}")
  endfunction()
  foreach(qt_target Qt6::Core Qt6::Gui Qt6::Network Qt6::Widgets)
    smartcut_install_qt_target(${qt_target} "")
  endforeach()
  smartcut_install_qt_target(Qt6::QWindowsIntegrationPlugin platforms)
  smartcut_install_qt_target(Qt6::QSchannelBackendPlugin tls)
  smartcut_install_qt_target(Qt6::QJpegPlugin imageformats)
  smartcut_install_qt_target(Qt6::QGifPlugin imageformats)
  smartcut_install_qt_target(Qt6::QICOPlugin imageformats)
  smartcut_install_qt_target(Qt6::QTiffPlugin imageformats)
  smartcut_install_qt_target(Qt6::QModernWindowsStylePlugin styles)
  install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" DESTINATION ${CMAKE_INSTALL_BINDIR})
elseif(SMARTCUT_BUILD_GUI AND CMAKE_PREFIX_PATH AND EXISTS "${CMAKE_PREFIX_PATH}/bin")
  install(DIRECTORY "${CMAKE_PREFIX_PATH}/bin/" DESTINATION ${CMAKE_INSTALL_BINDIR} FILES_MATCHING PATTERN "Qt6*.dll")
  install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" DESTINATION ${CMAKE_INSTALL_BINDIR})
  foreach(plugin_group platforms tls)
    if(EXISTS "${CMAKE_PREFIX_PATH}/plugins/${plugin_group}")
      install(DIRECTORY "${CMAKE_PREFIX_PATH}/plugins/${plugin_group}"
        DESTINATION ${CMAKE_INSTALL_BINDIR})
    endif()
  endforeach()
endif()
if(MINGW AND EXISTS "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin")
  install(FILES
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libgcc_s_seh-1.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libstdc++-6.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libwinpthread-1.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libb2-1.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libpcre2-16-0.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libzstd.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/zlib1.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libbrotlidec.dll"
    "${SMARTCUT_MINGW_RUNTIME_ROOT}/bin/libbrotlicommon.dll"
    DESTINATION ${CMAKE_INSTALL_BINDIR})
  foreach(runtime_license gcc-libs libwinpthread libb2 pcre2 zstd zlib brotli libvpl ffnvcodec-headers amf-headers)
    if(EXISTS "${SMARTCUT_MINGW_RUNTIME_ROOT}/share/licenses/${runtime_license}")
      install(DIRECTORY "${SMARTCUT_MINGW_RUNTIME_ROOT}/share/licenses/${runtime_license}/"
        DESTINATION "licenses/runtime/${runtime_license}")
    endif()
  endforeach()
endif()
if(EXISTS "${SMARTCUT_MEDIA_ROOT}/share/licenses/dav1d/COPYING")
  install(FILES "${SMARTCUT_MEDIA_ROOT}/share/licenses/dav1d/COPYING" DESTINATION licenses/dav1d)
elseif(SMARTCUT_REQUIRE_DAV1D AND NOT EXISTS "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/dav1d/COPYING")
  message(FATAL_ERROR "The dav1d licence notice is required for this build")
endif()
if(EXISTS "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/ffmpeg")
  install(FILES
    "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/ffmpeg/COPYING.GPLv2"
    "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/ffmpeg/COPYING.GPLv3"
    "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/ffmpeg/COPYING.LGPLv2.1"
    "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/ffmpeg/COPYING.LGPLv3"
    DESTINATION licenses/ffmpeg)
endif()
foreach(dependency x264 x265 libaom dav1d libvpx libdovi libplacebo catch2)
  if(EXISTS "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/${dependency}/COPYING")
    install(FILES "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/${dependency}/COPYING" DESTINATION "licenses/${dependency}")
  elseif(EXISTS "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/${dependency}/LICENSE")
    install(FILES "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/${dependency}/LICENSE" DESTINATION "licenses/${dependency}")
  elseif(EXISTS "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/${dependency}/LICENSE.txt")
    install(FILES "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/${dependency}/LICENSE.txt" DESTINATION "licenses/${dependency}")
  endif()
endforeach()
if(EXISTS "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/qt/LICENSES")
  install(DIRECTORY "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/qt/LICENSES/" DESTINATION licenses/qt)
endif()
if(EXISTS "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/qtimageformats/LICENSES")
  install(DIRECTORY "${SMARTCUT_DEPENDENCY_SOURCE_ROOT}/qtimageformats/LICENSES/"
    DESTINATION licenses/qtimageformats)
endif()
if(SMARTCUT_BUILD_GUI AND MSVC AND EXISTS "${CMAKE_PREFIX_PATH}/sbom")
  foreach(qt_sbom
      qtbase-6.8.3.spdx
      qtbase-6.8.3.spdx.json
      qtbase-6.8.3.source.spdx
      qtimageformats-6.8.3.spdx
      qtimageformats-6.8.3.spdx.json
      qtimageformats-6.8.3.source.spdx)
    if(EXISTS "${CMAKE_PREFIX_PATH}/sbom/${qt_sbom}")
      install(FILES "${CMAKE_PREFIX_PATH}/sbom/${qt_sbom}" DESTINATION licenses/qt/sbom)
    endif()
  endforeach()
endif()
if(SMARTCUT_ENABLE_PACKAGING)
set(CPACK_PACKAGE_NAME "SmartCut64")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_VENDOR "LINEKERPANDI LIMITED")
set(CPACK_PACKAGE_CONTACT "support@linekerpandi.com")
set(CPACK_GENERATOR "ZIP;NSIS")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "SmartCut64")
set(CPACK_NSIS_DISPLAY_NAME "SmartCut64")
set(CPACK_NSIS_PACKAGE_NAME "SmartCut64")
set(CPACK_NSIS_INSTALL_ROOT "$LOCALAPPDATA")
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
set(CPACK_NSIS_MODIFY_PATH OFF)
set(CPACK_NSIS_EXECUTABLES_DIRECTORY "bin")
set(CPACK_NSIS_MENU_LINKS "bin/smartcut-gui.exe" "SmartCut64")
if(SMARTCUT_PRIVATE_BETA)
  # The first native ARM candidate is portable-only.  Its identity must not
  # collide with the supported x64 install, uninstall key, shortcuts or file
  # associations while it is being validated on real Windows-on-ARM systems.
  set(CPACK_GENERATOR "ZIP")
  set(CPACK_PACKAGE_NAME "SmartCut64 ARM64 Private Beta")
  set(CPACK_PACKAGE_INSTALL_DIRECTORY "SmartCut64 ARM64 Private Beta")
  set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "SmartCut64 ARM64 Private Beta")
  set(CPACK_NSIS_DISPLAY_NAME "SmartCut64 ARM64 Private Beta")
  set(CPACK_NSIS_PACKAGE_NAME "SmartCut64 ARM64 Private Beta")
  set(CPACK_NSIS_MENU_LINKS "")
  set(CPACK_PACKAGE_FILE_NAME
    "SmartCut64-${PROJECT_VERSION}-win-arm64-private-beta.${SMARTCUT_PRIVATE_BETA_SEQUENCE}")
elseif(SMARTCUT_ARM64_PORTABLE_RELEASE)
  # Windows ARM64 is intentionally portable-only.  It uses the normal product
  # and licence identity, but never emits an NSIS installer or modifies the
  # user's x64 installation as part of package extraction.
  set(CPACK_GENERATOR "ZIP")
  set(CPACK_PACKAGE_FILE_NAME "SmartCut64-${PROJECT_VERSION}-win-arm64")
else()
if(WIN32 AND SMARTCUT_BUILD_GUI)
  set(CPACK_NSIS_MUI_ICON "${SMARTCUT_APP_ICON}")
  set(CPACK_NSIS_MUI_UNIICON "${SMARTCUT_APP_ICON}")
endif()
# SmartCut64 Explorer upgrade hook. CPack's preinstall section runs after the
# old uninstaller, so preserve legacy choices at its exact invocation instead.
set(CPACK_NSIS_DEFINES [[
  Var SmartCutOldCommand
  Var SmartCutRegistryBackup
  !macro SmartCutBackupRegistration ID KEY COMMAND EXPECTED
    System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "Software\Classes\${KEY}", i 0, i 0x20019, *p .r4) i .r2'
    StrCmp $2 2 smartcut_backup_done_${ID}
    StrCmp $2 0 0 smartcut_upgrade_backup_failed
    ReadRegStr $0 HKCU "Software\Classes\${COMMAND}" ""
    ; Extension roots are shared: even our default can coexist with another
    ; application's OpenWithProgids or other metadata. Preserve both roots.
    !if "${ID}" != "project_ext"
      !if "${ID}" != "joiner_ext"
        StrCmp $0 "${EXPECTED}" smartcut_backup_close_${ID}
      !endif
    !endif
    System::Call 'advapi32::RegCreateKeyExW(p 0x80000001, w "$SmartCutRegistryBackup\${KEY}", i 0, p 0, i 0, i 0xF003F, p 0, *p .r1, p 0) i .r2'
    StrCmp $2 0 0 smartcut_upgrade_backup_failed
    System::Call 'advapi32::RegCopyTreeW(p r4, p 0, p r1) i .r2'
    System::Call 'advapi32::RegCloseKey(p r1)'
    StrCmp $2 0 0 smartcut_upgrade_backup_failed
    Goto smartcut_backup_close_${ID}
    smartcut_backup_close_${ID}:
      System::Call 'advapi32::RegCloseKey(p r4)'
    smartcut_backup_done_${ID}:
  !macroend
  !macro SmartCutRestoreRegistration ID KEY
    System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "$SmartCutRegistryBackup\${KEY}", i 0, i 0x20019, *p .r4) i .r2'
    StrCmp $2 2 smartcut_restore_done_${ID}
    StrCmp $2 0 0 smartcut_upgrade_restore_failed
    System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "Software\Classes\${KEY}", i 0, i 0x20019, *p .r1) i .r2'
    StrCmp $2 2 smartcut_restore_write_${ID}
    StrCmp $2 0 0 smartcut_upgrade_restore_failed
    System::Call 'advapi32::RegCloseKey(p r1)'
    Goto smartcut_restore_close_${ID}
    smartcut_restore_write_${ID}:
      System::Call 'advapi32::RegCreateKeyExW(p 0x80000001, w "Software\Classes\${KEY}", i 0, p 0, i 0, i 0xF003F, p 0, *p .r1, p 0) i .r2'
      StrCmp $2 0 0 smartcut_upgrade_restore_failed
      System::Call 'advapi32::RegCopyTreeW(p r4, p 0, p r1) i .r2'
      System::Call 'advapi32::RegCloseKey(p r1)'
      StrCmp $2 0 0 smartcut_upgrade_restore_failed
    smartcut_restore_close_${ID}:
      System::Call 'advapi32::RegCloseKey(p r4)'
    smartcut_restore_done_${ID}:
  !macroend
  !macro SmartCutFindLegacyOwner EXT
    ReadRegStr $0 HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64\command" ""
    StrCmp $0 $SmartCutOldCommand 0 +2
      StrCpy $5 1
  !macroend
  !macro SmartCutMigrateLegacyType EXT
    StrCpy $0 0
    ReadRegStr $1 HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64\command" ""
    StrCmp $1 $SmartCutOldCommand 0 +3
      StrCpy $0 1
      StrCpy $6 1
    ClearErrors
    WriteRegDWORD HKCU "Software\SmartCut64\SmartCut64\files\contextMenuExtensions" "${EXT}" $0
    IfErrors smartcut_upgrade_backup_failed
  !macroend
  Function SmartCutPreserveExplorerBeforeUpgrade
    Push $0
    Push $1
    Push $2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
    Push $8
    Push $9
    StrCpy $SmartCutOldCommand '"$3\bin\smartcut-gui.exe" "%1"'
    System::Call 'kernel32::GetCurrentProcessId() i .r0'
    StrCpy $SmartCutRegistryBackup "Software\SmartCut64\InstallerBackup-$0"
    System::Call 'advapi32::RegOpenKeyExW(p 0x80000001, w "$SmartCutRegistryBackup", i 0, i 0x20019, *p .r1) i .r2'
    StrCmp $2 2 smartcut_backup_root_unused
    StrCmp $2 0 0 smartcut_upgrade_backup_failed
    System::Call 'advapi32::RegCloseKey(p r1)'
    Goto smartcut_upgrade_backup_failed
    smartcut_backup_root_unused:
    ; Only the known SmartCut64 keys are copied, and only when not owned by
    ; the old install. Preserve entire values/subkeys, not just command text.
    !insertmacro SmartCutBackupRegistration "project" "SmartCut64.Project" "SmartCut64.Project\shell\open\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "project_ext" ".smartcut" ".smartcut" "SmartCut64.Project"
    !insertmacro SmartCutBackupRegistration "joiner" "SmartCut64.Joiner" "SmartCut64.Joiner\shell\open\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "joiner_ext" ".scjoin" ".scjoin" "SmartCut64.Joiner"
    !insertmacro SmartCutBackupRegistration "openwith" "Applications\smartcut-gui.exe" "Applications\smartcut-gui.exe\shell\open\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "mkv" "SystemFileAssociations\.mkv\shell\SmartCut64" "SystemFileAssociations\.mkv\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "mp4" "SystemFileAssociations\.mp4\shell\SmartCut64" "SystemFileAssociations\.mp4\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "mov" "SystemFileAssociations\.mov\shell\SmartCut64" "SystemFileAssociations\.mov\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "ts" "SystemFileAssociations\.ts\shell\SmartCut64" "SystemFileAssociations\.ts\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "m2ts" "SystemFileAssociations\.m2ts\shell\SmartCut64" "SystemFileAssociations\.m2ts\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "mts" "SystemFileAssociations\.mts\shell\SmartCut64" "SystemFileAssociations\.mts\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "mpg" "SystemFileAssociations\.mpg\shell\SmartCut64" "SystemFileAssociations\.mpg\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "mpeg" "SystemFileAssociations\.mpeg\shell\SmartCut64" "SystemFileAssociations\.mpeg\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "vob" "SystemFileAssociations\.vob\shell\SmartCut64" "SystemFileAssociations\.vob\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "avi" "SystemFileAssociations\.avi\shell\SmartCut64" "SystemFileAssociations\.avi\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "webm" "SystemFileAssociations\.webm\shell\SmartCut64" "SystemFileAssociations\.webm\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "VPrj" "SystemFileAssociations\.VPrj\shell\SmartCut64" "SystemFileAssociations\.VPrj\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "BPrj" "SystemFileAssociations\.BPrj\shell\SmartCut64" "SystemFileAssociations\.BPrj\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "VJnr" "SystemFileAssociations\.VJnr\shell\SmartCut64" "SystemFileAssociations\.VJnr\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "smartcut" "SystemFileAssociations\.smartcut\shell\SmartCut64" "SystemFileAssociations\.smartcut\shell\SmartCut64\command" "$SmartCutOldCommand"
    !insertmacro SmartCutBackupRegistration "scjoin" "SystemFileAssociations\.scjoin\shell\SmartCut64" "SystemFileAssociations\.scjoin\shell\SmartCut64\command" "$SmartCutOldCommand"
    ReadRegDWORD $0 HKCU "Software\SmartCut64\SmartCut64\files" "explorerContextMenuEnabled"
    StrCmp $0 "" 0 smartcut_upgrade_preserved
    StrCpy $5 0
    ReadRegStr $0 HKCU "Software\Classes\Applications\smartcut-gui.exe\shell\open\command" ""
    StrCmp $0 $SmartCutOldCommand 0 +2
      StrCpy $5 1
    ReadRegStr $0 HKCU "Software\Classes\SmartCut64.Project\shell\open\command" ""
    StrCmp $0 $SmartCutOldCommand 0 +2
      StrCpy $5 1
    !insertmacro SmartCutFindLegacyOwner "mkv"
    !insertmacro SmartCutFindLegacyOwner "mp4"
    !insertmacro SmartCutFindLegacyOwner "mov"
    !insertmacro SmartCutFindLegacyOwner "ts"
    !insertmacro SmartCutFindLegacyOwner "m2ts"
    !insertmacro SmartCutFindLegacyOwner "mts"
    !insertmacro SmartCutFindLegacyOwner "mpg"
    !insertmacro SmartCutFindLegacyOwner "mpeg"
    !insertmacro SmartCutFindLegacyOwner "vob"
    !insertmacro SmartCutFindLegacyOwner "avi"
    !insertmacro SmartCutFindLegacyOwner "webm"
    !insertmacro SmartCutFindLegacyOwner "VPrj"
    !insertmacro SmartCutFindLegacyOwner "BPrj"
    !insertmacro SmartCutFindLegacyOwner "VJnr"
    !insertmacro SmartCutFindLegacyOwner "smartcut"
    !insertmacro SmartCutFindLegacyOwner "scjoin"
    StrCmp $5 1 0 smartcut_upgrade_preserved
    StrCpy $6 0
    !insertmacro SmartCutMigrateLegacyType "mkv"
    !insertmacro SmartCutMigrateLegacyType "mp4"
    !insertmacro SmartCutMigrateLegacyType "mov"
    !insertmacro SmartCutMigrateLegacyType "ts"
    !insertmacro SmartCutMigrateLegacyType "m2ts"
    !insertmacro SmartCutMigrateLegacyType "mts"
    !insertmacro SmartCutMigrateLegacyType "mpg"
    !insertmacro SmartCutMigrateLegacyType "mpeg"
    !insertmacro SmartCutMigrateLegacyType "vob"
    !insertmacro SmartCutMigrateLegacyType "avi"
    !insertmacro SmartCutMigrateLegacyType "webm"
    !insertmacro SmartCutMigrateLegacyType "VPrj"
    !insertmacro SmartCutMigrateLegacyType "BPrj"
    !insertmacro SmartCutMigrateLegacyType "VJnr"
    !insertmacro SmartCutMigrateLegacyType "smartcut"
    !insertmacro SmartCutMigrateLegacyType "scjoin"
    ClearErrors
    WriteRegDWORD HKCU "Software\SmartCut64\SmartCut64\files" "explorerContextMenuEnabled" $6
    IfErrors smartcut_upgrade_backup_failed
    smartcut_upgrade_preserved:
    Pop $9
    Pop $8
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Pop $0
    Return
    smartcut_upgrade_backup_failed:
      MessageBox MB_OK|MB_ICONSTOP "SmartCut64 could not preserve Explorer registrations. The old version has not been uninstalled."
      Abort
  FunctionEnd
  !macro SmartCutRemoveOldOwnedVerb EXT
    ReadRegStr $0 HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64\command" ""
    StrCmp $0 $SmartCutOldCommand 0 +2
      DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64"
  !macroend
  Function SmartCutRemoveOldExplorerVerbsAfterUpgrade
    Push $0
    !insertmacro SmartCutRemoveOldOwnedVerb "mkv"
    !insertmacro SmartCutRemoveOldOwnedVerb "mp4"
    !insertmacro SmartCutRemoveOldOwnedVerb "mov"
    !insertmacro SmartCutRemoveOldOwnedVerb "ts"
    !insertmacro SmartCutRemoveOldOwnedVerb "m2ts"
    !insertmacro SmartCutRemoveOldOwnedVerb "mts"
    !insertmacro SmartCutRemoveOldOwnedVerb "mpg"
    !insertmacro SmartCutRemoveOldOwnedVerb "mpeg"
    !insertmacro SmartCutRemoveOldOwnedVerb "vob"
    !insertmacro SmartCutRemoveOldOwnedVerb "avi"
    !insertmacro SmartCutRemoveOldOwnedVerb "webm"
    !insertmacro SmartCutRemoveOldOwnedVerb "VPrj"
    !insertmacro SmartCutRemoveOldOwnedVerb "BPrj"
    !insertmacro SmartCutRemoveOldOwnedVerb "VJnr"
    !insertmacro SmartCutRemoveOldOwnedVerb "smartcut"
    !insertmacro SmartCutRemoveOldOwnedVerb "scjoin"
    Pop $0
  FunctionEnd
  Function SmartCutRestoreExplorerAfterUpgrade
    Push $0
    Push $1
    Push $2
    Push $3
    Push $4
    !insertmacro SmartCutRestoreRegistration "project" "SmartCut64.Project"
    !insertmacro SmartCutRestoreRegistration "project_ext" ".smartcut"
    !insertmacro SmartCutRestoreRegistration "joiner" "SmartCut64.Joiner"
    !insertmacro SmartCutRestoreRegistration "joiner_ext" ".scjoin"
    !insertmacro SmartCutRestoreRegistration "openwith" "Applications\smartcut-gui.exe"
    !insertmacro SmartCutRestoreRegistration "mkv" "SystemFileAssociations\.mkv\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "mp4" "SystemFileAssociations\.mp4\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "mov" "SystemFileAssociations\.mov\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "ts" "SystemFileAssociations\.ts\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "m2ts" "SystemFileAssociations\.m2ts\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "mts" "SystemFileAssociations\.mts\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "mpg" "SystemFileAssociations\.mpg\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "mpeg" "SystemFileAssociations\.mpeg\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "vob" "SystemFileAssociations\.vob\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "avi" "SystemFileAssociations\.avi\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "webm" "SystemFileAssociations\.webm\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "VPrj" "SystemFileAssociations\.VPrj\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "BPrj" "SystemFileAssociations\.BPrj\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "VJnr" "SystemFileAssociations\.VJnr\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "smartcut" "SystemFileAssociations\.smartcut\shell\SmartCut64"
    !insertmacro SmartCutRestoreRegistration "scjoin" "SystemFileAssociations\.scjoin\shell\SmartCut64"
    DeleteRegKey HKCU "$SmartCutRegistryBackup"
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Pop $0
    Return
    smartcut_upgrade_restore_failed:
      MessageBox MB_OK|MB_ICONSTOP "SmartCut64 could not restore another installation's Explorer registrations. The backup remains in HKCU\$SmartCutRegistryBackup."
      Abort
  FunctionEnd
]])
# Do not edit the installed toolchain template. Fail clearly if a future CMake
# version changes the uninstall call or makes its placement ambiguous.
set(_smartcut_nsis_template "${CMAKE_ROOT}/Modules/Internal/CPack/NSIS.template.in")
if(NOT EXISTS "${_smartcut_nsis_template}")
  set(_smartcut_nsis_template "${CMAKE_ROOT}/Modules/Internal/CPack/NSIS.template")
endif()
file(READ "${_smartcut_nsis_template}" _smartcut_nsis_text)
set(_smartcut_uninstall_call [[  ExecWait '"$0" /S _?=$3' ;Do not copy the uninstaller to a temp file]])
string(FIND "${_smartcut_nsis_text}" "${_smartcut_uninstall_call}" _smartcut_call_at)
string(REPLACE "${_smartcut_uninstall_call}" "" _smartcut_without_call "${_smartcut_nsis_text}")
string(LENGTH "${_smartcut_nsis_text}" _smartcut_before_length)
string(LENGTH "${_smartcut_without_call}" _smartcut_after_length)
string(LENGTH "${_smartcut_uninstall_call}" _smartcut_call_length)
math(EXPR _smartcut_removed_length "${_smartcut_before_length} - ${_smartcut_after_length}")
if(_smartcut_call_at LESS 0 OR NOT _smartcut_removed_length EQUAL _smartcut_call_length)
  message(FATAL_ERROR "The CPack NSIS uninstall hook changed; review Explorer preference migration before packaging.")
endif()
set(_smartcut_uninstall_hook [[  Call SmartCutPreserveExplorerBeforeUpgrade
  ClearErrors
  ExecWait '"$0" /S _?=$3' ;Do not copy the uninstaller to a temp file
  IfErrors 0 +3
    Call SmartCutRestoreExplorerAfterUpgrade
    Goto uninst_failed
  Call SmartCutRestoreExplorerAfterUpgrade
  Call SmartCutRemoveOldExplorerVerbsAfterUpgrade
  ClearErrors]])
string(REPLACE "${_smartcut_uninstall_call}" "${_smartcut_uninstall_hook}" _smartcut_nsis_text "${_smartcut_nsis_text}")
set(_smartcut_nsis_templates "${CMAKE_CURRENT_BINARY_DIR}/smartcut-nsis-templates")
file(MAKE_DIRECTORY "${_smartcut_nsis_templates}")
get_filename_component(_smartcut_template_name "${_smartcut_nsis_template}" NAME)
file(WRITE "${_smartcut_nsis_templates}/${_smartcut_template_name}" "${_smartcut_nsis_text}")
list(PREPEND CPACK_MODULE_PATH "${_smartcut_nsis_templates}")
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS [[
  ReadRegStr $2 HKCU "Software\Classes\SmartCut64.Project\shell\open\command" ""
  StrCmp $2 '"$INSTDIR\bin\smartcut-gui.exe" "%1"' smartcut_register_project
  StrCmp $2 "" 0 smartcut_skip_project
  ReadRegStr $2 HKCU "Software\Classes\SmartCut64.Project" ""
  StrCmp $2 "" 0 smartcut_skip_project
  EnumRegKey $2 HKCU "Software\Classes\SmartCut64.Project" 0
  StrCmp $2 "" 0 smartcut_skip_project
  ClearErrors
  EnumRegValue $2 HKCU "Software\Classes\SmartCut64.Project" 0
  IfErrors smartcut_register_project smartcut_skip_project
  smartcut_register_project:
  ReadRegStr $2 HKCU "Software\Classes\.smartcut" ""
  StrCmp $2 "" smartcut_write_smartcut_extension
  StrCmp $2 "SmartCut64.Project" 0 smartcut_keep_smartcut_extension
  smartcut_write_smartcut_extension:
  WriteRegStr HKCU "Software\Classes\.smartcut" "" "SmartCut64.Project"
  smartcut_keep_smartcut_extension:
  WriteRegStr HKCU "Software\Classes\SmartCut64.Project" "" "SmartCut64 Project"
  WriteRegStr HKCU "Software\Classes\SmartCut64.Project\DefaultIcon" "" "$INSTDIR\bin\smartcut-gui.exe,0"
  WriteRegStr HKCU "Software\Classes\SmartCut64.Project\shell\open\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  smartcut_skip_project:
  ReadRegStr $2 HKCU "Software\Classes\SmartCut64.Joiner\shell\open\command" ""
  StrCmp $2 '"$INSTDIR\bin\smartcut-gui.exe" "%1"' smartcut_register_joiner
  StrCmp $2 "" 0 smartcut_skip_joiner
  ReadRegStr $2 HKCU "Software\Classes\SmartCut64.Joiner" ""
  StrCmp $2 "" 0 smartcut_skip_joiner
  EnumRegKey $2 HKCU "Software\Classes\SmartCut64.Joiner" 0
  StrCmp $2 "" 0 smartcut_skip_joiner
  ClearErrors
  EnumRegValue $2 HKCU "Software\Classes\SmartCut64.Joiner" 0
  IfErrors smartcut_register_joiner smartcut_skip_joiner
  smartcut_register_joiner:
  ReadRegStr $2 HKCU "Software\Classes\.scjoin" ""
  StrCmp $2 "" smartcut_write_scjoin_extension
  StrCmp $2 "SmartCut64.Joiner" 0 smartcut_keep_scjoin_extension
  smartcut_write_scjoin_extension:
  WriteRegStr HKCU "Software\Classes\.scjoin" "" "SmartCut64.Joiner"
  smartcut_keep_scjoin_extension:
  WriteRegStr HKCU "Software\Classes\SmartCut64.Joiner" "" "SmartCut64 Joiner Project"
  WriteRegStr HKCU "Software\Classes\SmartCut64.Joiner\DefaultIcon" "" "$INSTDIR\bin\smartcut-gui.exe,0"
  WriteRegStr HKCU "Software\Classes\SmartCut64.Joiner\shell\open\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  smartcut_skip_joiner:
  ReadRegStr $2 HKCU "Software\Classes\Applications\smartcut-gui.exe\shell\open\command" ""
  StrCmp $2 '"$INSTDIR\bin\smartcut-gui.exe" "%1"' smartcut_register_open_with
  StrCmp $2 "" 0 smartcut_skip_open_with
  ReadRegStr $2 HKCU "Software\Classes\Applications\smartcut-gui.exe" ""
  StrCmp $2 "" 0 smartcut_skip_open_with
  EnumRegKey $2 HKCU "Software\Classes\Applications\smartcut-gui.exe" 0
  StrCmp $2 "" 0 smartcut_skip_open_with
  ClearErrors
  EnumRegValue $2 HKCU "Software\Classes\Applications\smartcut-gui.exe" 0
  IfErrors smartcut_register_open_with smartcut_skip_open_with
  smartcut_register_open_with:
  WriteRegStr HKCU "Software\Classes\Applications\smartcut-gui.exe" "FriendlyAppName" "SmartCut64"
  WriteRegStr HKCU "Software\Classes\Applications\smartcut-gui.exe\shell\open\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  smartcut_skip_open_with:
  ; Settings written by Options > File Types are intentionally not removed by
  ; the uninstaller. Missing values keep the previous installer defaults.
  !macro SmartCut64RemoveOwnedVerb EXT
    ReadRegStr $2 HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64\command" ""
    StrCmp $2 '"$INSTDIR\bin\smartcut-gui.exe" "%1"' 0 +2
      DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64"
  !macroend
  !macro SmartCut64InstallVerb EXT DEFAULT
    ReadRegDWORD $0 HKCU "Software\SmartCut64\SmartCut64\files" "explorerContextMenuEnabled"
    StrCmp $0 "0" smartcut_remove_${EXT}
    ReadRegDWORD $1 HKCU "Software\SmartCut64\SmartCut64\files\contextMenuExtensions" "${EXT}"
    StrCmp $1 "" 0 +2
      StrCpy $1 "${DEFAULT}"
    StrCmp $1 "0" smartcut_remove_${EXT}
    ReadRegStr $2 HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64\command" ""
    StrCmp $2 '"$INSTDIR\bin\smartcut-gui.exe" "%1"' smartcut_write_${EXT}
    StrCmp $2 "" 0 smartcut_done_${EXT}
    ReadRegStr $3 HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64" ""
    StrCmp $3 "" 0 smartcut_done_${EXT}
    EnumRegKey $3 HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64" 0
    StrCmp $3 "" 0 smartcut_done_${EXT}
    ClearErrors
    EnumRegValue $3 HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64" 0
    IfErrors smartcut_write_${EXT} smartcut_done_${EXT}
    smartcut_write_${EXT}:
      WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64" "" "Open with SmartCut64"
      WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64" "Icon" "$INSTDIR\bin\smartcut-gui.exe,0"
      WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.${EXT}\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
      Goto smartcut_done_${EXT}
    smartcut_remove_${EXT}:
      !insertmacro SmartCut64RemoveOwnedVerb "${EXT}"
    smartcut_done_${EXT}:
  !macroend
  !insertmacro SmartCut64InstallVerb "VPrj" 1
  !insertmacro SmartCut64InstallVerb "BPrj" 1
  !insertmacro SmartCut64InstallVerb "VJnr" 1
  !insertmacro SmartCut64InstallVerb "mkv" 1
  !insertmacro SmartCut64InstallVerb "mp4" 1
  !insertmacro SmartCut64InstallVerb "mov" 1
  !insertmacro SmartCut64InstallVerb "ts" 1
  !insertmacro SmartCut64InstallVerb "m2ts" 1
  !insertmacro SmartCut64InstallVerb "webm" 1
  !insertmacro SmartCut64InstallVerb "mts" 0
  !insertmacro SmartCut64InstallVerb "mpg" 0
  !insertmacro SmartCut64InstallVerb "mpeg" 0
  !insertmacro SmartCut64InstallVerb "vob" 0
  !insertmacro SmartCut64InstallVerb "avi" 0
  !insertmacro SmartCut64InstallVerb "smartcut" 0
  !insertmacro SmartCut64InstallVerb "scjoin" 0
  System::Call 'shell32::SHChangeNotify(i 0x08000000, i 0, p 0, p 0)'
]])
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS [[
  ReadRegStr $2 HKCU "Software\Classes\SmartCut64.Project\shell\open\command" ""
  StrCmp $2 '"$INSTDIR\bin\smartcut-gui.exe" "%1"' 0 smartcut_keep_project
    DeleteRegKey HKCU "Software\Classes\SmartCut64.Project"
    ReadRegStr $2 HKCU "Software\Classes\.smartcut" ""
    StrCmp $2 "SmartCut64.Project" 0 smartcut_keep_project
      DeleteRegValue HKCU "Software\Classes\.smartcut" ""
      DeleteRegKey /ifempty HKCU "Software\Classes\.smartcut"
  smartcut_keep_project:
  ReadRegStr $2 HKCU "Software\Classes\SmartCut64.Joiner\shell\open\command" ""
  StrCmp $2 '"$INSTDIR\bin\smartcut-gui.exe" "%1"' 0 smartcut_keep_joiner
    DeleteRegKey HKCU "Software\Classes\SmartCut64.Joiner"
    ReadRegStr $2 HKCU "Software\Classes\.scjoin" ""
    StrCmp $2 "SmartCut64.Joiner" 0 smartcut_keep_joiner
      DeleteRegValue HKCU "Software\Classes\.scjoin" ""
      DeleteRegKey /ifempty HKCU "Software\Classes\.scjoin"
  smartcut_keep_joiner:
  ReadRegStr $2 HKCU "Software\Classes\Applications\smartcut-gui.exe\shell\open\command" ""
  StrCmp $2 '"$INSTDIR\bin\smartcut-gui.exe" "%1"' 0 +2
    DeleteRegKey HKCU "Software\Classes\Applications\smartcut-gui.exe"
  !insertmacro SmartCut64RemoveOwnedVerb "VPrj"
  !insertmacro SmartCut64RemoveOwnedVerb "BPrj"
  !insertmacro SmartCut64RemoveOwnedVerb "VJnr"
  !insertmacro SmartCut64RemoveOwnedVerb "mkv"
  !insertmacro SmartCut64RemoveOwnedVerb "mp4"
  !insertmacro SmartCut64RemoveOwnedVerb "mov"
  !insertmacro SmartCut64RemoveOwnedVerb "ts"
  !insertmacro SmartCut64RemoveOwnedVerb "m2ts"
  !insertmacro SmartCut64RemoveOwnedVerb "webm"
  !insertmacro SmartCut64RemoveOwnedVerb "mts"
  !insertmacro SmartCut64RemoveOwnedVerb "mpg"
  !insertmacro SmartCut64RemoveOwnedVerb "mpeg"
  !insertmacro SmartCut64RemoveOwnedVerb "vob"
  !insertmacro SmartCut64RemoveOwnedVerb "avi"
  !insertmacro SmartCut64RemoveOwnedVerb "smartcut"
  !insertmacro SmartCut64RemoveOwnedVerb "scjoin"
  System::Call 'shell32::SHChangeNotify(i 0x08000000, i 0, p 0, p 0)'
]])
string(REPLACE "\\" "\\\\" CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}")
string(REPLACE "\"" "\\\"" CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}")
string(REPLACE "$" "\\$" CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}")
string(REPLACE "\\" "\\\\" CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}")
string(REPLACE "\"" "\\\"" CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}")
string(REPLACE "$" "\\$" CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}")
string(REPLACE "\\" "\\\\" CPACK_NSIS_DEFINES "${CPACK_NSIS_DEFINES}")
string(REPLACE "\"" "\\\"" CPACK_NSIS_DEFINES "${CPACK_NSIS_DEFINES}")
string(REPLACE "$" "\\$" CPACK_NSIS_DEFINES "${CPACK_NSIS_DEFINES}")
if(SMARTCUT_TARGET_ARCHITECTURE STREQUAL "arm64")
  set(CPACK_SYSTEM_NAME "win-arm64")
  set(CPACK_PACKAGE_FILE_NAME "SmartCut64-${PROJECT_VERSION}-win-arm64")
endif()
endif()
if(SMARTCUT_TARGET_ARCHITECTURE STREQUAL "arm64")
  set(CPACK_SYSTEM_NAME "win-arm64")
endif()
include(CPack)
else()
  # Prevent a previously package-enabled build directory from retaining a
  # callable CPack configuration after packaging is explicitly disabled.
  file(REMOVE "${CMAKE_BINARY_DIR}/CPackConfig.cmake"
              "${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake")
endif()

enable_testing()
# Production binaries enforce paid/evaluation delivery policy. Internal media
# regressions need clean outputs, so compile isolated, non-packaged CLI/worker
# binaries and a GUI harness whose application directory contains the internal
# worker under its normal runtime name. None of these targets has an install rule.
add_executable(smartcut-cli-test src/cli/main.cpp)
target_link_libraries(smartcut-cli-test PRIVATE smartcut-core)
target_compile_definitions(smartcut-cli-test PRIVATE SMARTCUT_INTERNAL_TEST_CLI=1)
add_executable(smartcut-worker-test src/worker/main.cpp)
target_link_libraries(smartcut-worker-test PRIVATE smartcut-core)
target_compile_definitions(smartcut-worker-test PRIVATE SMARTCUT_INTERNAL_TEST_WORKER=1)
if(COMMAND smartcut_deploy_build_runtime)
  smartcut_deploy_build_runtime(smartcut-cli-test)
  smartcut_deploy_build_runtime(smartcut-worker-test)
endif()
if(WIN32)
  add_executable(smartcut-export-cleanup-test tests/unit/export_cleanup_test.cpp)
  target_link_libraries(smartcut-export-cleanup-test PRIVATE smartcut-core)
  if(MINGW)
    smartcut_deploy_build_runtime(smartcut-export-cleanup-test)
  endif()
  add_test(NAME smartcut-export-cleanup COMMAND smartcut-export-cleanup-test
    "${CMAKE_CURRENT_BINARY_DIR}/test-results/export-cleanup")
  set_tests_properties(smartcut-export-cleanup PROPERTIES TIMEOUT 60 RUN_SERIAL TRUE)
endif()
if(TARGET smartcut-gui)
  add_executable(smartcut-profile-backup-test tests/profile_backup_tests.cpp src/gui/profile_backup.cpp)
  target_include_directories(smartcut-profile-backup-test PRIVATE src)
  target_link_libraries(smartcut-profile-backup-test PRIVATE Qt6::Core)
  if(WIN32)
    smartcut_deploy_build_runtime(smartcut-profile-backup-test)
    smartcut_deploy_qt_runtime(smartcut-profile-backup-test)
  endif()
  add_test(NAME smartcut-profile-backup COMMAND smartcut-profile-backup-test)
  set_tests_properties(smartcut-profile-backup PROPERTIES TIMEOUT 60)
  add_executable(smartcut-boundary-threads-test tests/unit/boundary_threads_test.cpp)
  target_include_directories(smartcut-boundary-threads-test PRIVATE src)
  if(WIN32)
    smartcut_deploy_build_runtime(smartcut-boundary-threads-test)
  endif()
  add_test(NAME smartcut-boundary-threads COMMAND $<TARGET_FILE:smartcut-boundary-threads-test>)
  add_executable(smartcut-hardware-test-process-test tests/unit/hardware_test_process_test.cpp)
  target_include_directories(smartcut-hardware-test-process-test PRIVATE src)
  target_link_libraries(smartcut-hardware-test-process-test PRIVATE Qt6::Widgets)
  if(WIN32)
    smartcut_deploy_build_runtime(smartcut-hardware-test-process-test)
    smartcut_deploy_qt_runtime(smartcut-hardware-test-process-test)
  endif()
  add_test(NAME smartcut-hardware-test-process COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" $<TARGET_FILE:smartcut-hardware-test-process-test>)
  set_tests_properties(smartcut-hardware-test-process PROPERTIES TIMEOUT 30 RUN_SERIAL TRUE)
  if(WIN32)
    add_executable(smartcut-explorer-integration-test tests/unit/explorer_integration_test.cpp)
    target_include_directories(smartcut-explorer-integration-test PRIVATE src)
    target_link_libraries(smartcut-explorer-integration-test PRIVATE Qt6::Core advapi32)
    smartcut_deploy_build_runtime(smartcut-explorer-integration-test)
    smartcut_deploy_qt_runtime(smartcut-explorer-integration-test)
    add_test(NAME smartcut-explorer-integration COMMAND smartcut-explorer-integration-test)
    set_tests_properties(smartcut-explorer-integration PROPERTIES TIMEOUT 30 RUN_SERIAL TRUE)
  endif()
  add_executable(smartcut-export-cleanup-process-test tests/unit/export_cleanup_process_test.cpp)
  target_include_directories(smartcut-export-cleanup-process-test PRIVATE src)
  target_link_libraries(smartcut-export-cleanup-process-test PRIVATE Qt6::Core)
  if(WIN32)
    smartcut_deploy_qt_runtime(smartcut-export-cleanup-process-test)
  endif()
  add_test(NAME smartcut-export-cleanup-process COMMAND smartcut-export-cleanup-process-test)
  set_tests_properties(smartcut-export-cleanup-process PROPERTIES TIMEOUT 30 RUN_SERIAL TRUE)
  add_executable(smartcut-gui-test WIN32 src/gui/main.cpp src/gui/resources.qrc ${SMARTCUT_GUI_WINDOWS_RESOURCE})
  target_sources(smartcut-gui-test PRIVATE src/gui/license_manager.cpp src/gui/process_diagnostics.cpp)
  target_sources(smartcut-gui-test PRIVATE src/gui/profile_backup.cpp)
  target_include_directories(smartcut-gui-test PRIVATE src)
  target_link_libraries(smartcut-gui-test PRIVATE Qt6::Widgets Qt6::Network smartcut-core)
  target_compile_definitions(smartcut-gui-test PRIVATE SMARTCUT_INTERNAL_TEST_GUI=1)
  if(SMARTCUT_PRIVATE_BETA)
    target_compile_definitions(smartcut-gui-test PRIVATE SMARTCUT_PRIVATE_BETA=1)
  endif()
  if(WIN32)
    target_link_libraries(smartcut-gui-test PRIVATE winmm crypt32 dwmapi shell32 ole32)
  endif()
  set_target_properties(smartcut-gui-test PROPERTIES
    AUTOMOC ON AUTORCC ON
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/internal-test-bin")
  add_dependencies(smartcut-gui-test smartcut-worker-test)
  add_custom_command(TARGET smartcut-gui-test POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
      "$<TARGET_FILE:smartcut-worker-test>"
      "$<TARGET_FILE_DIR:smartcut-gui-test>/smartcut-worker${CMAKE_EXECUTABLE_SUFFIX}"
    VERBATIM)
  if(COMMAND smartcut_deploy_build_runtime)
    smartcut_deploy_build_runtime(smartcut-gui-test)
  endif()
  if(COMMAND smartcut_deploy_qt_runtime)
    smartcut_deploy_qt_runtime(smartcut-gui-test)
  endif()

  add_executable(smartcut-qt-tls-probe tests/qt_tls_probe.cpp)
  if(WIN32)
    add_executable(smartcut-gpu-preview-test tests/gpu_preview_test.cpp)
    target_link_libraries(smartcut-gpu-preview-test PRIVATE Qt6::Widgets smartcut-core)
    if(MINGW)
      smartcut_deploy_build_runtime(smartcut-gpu-preview-test)
      smartcut_deploy_qt_runtime(smartcut-gpu-preview-test)
    endif()
  endif()
  target_link_libraries(smartcut-qt-tls-probe PRIVATE Qt6::Network)
  set_target_properties(smartcut-qt-tls-probe PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tls-probe-bin")
  if(COMMAND smartcut_deploy_build_runtime)
    smartcut_deploy_build_runtime(smartcut-qt-tls-probe)
  endif()
  if(COMMAND smartcut_deploy_qt_runtime)
    smartcut_deploy_qt_runtime(smartcut-qt-tls-probe)
  endif()
  add_test(NAME smartcut-qt-tls-backend COMMAND $<TARGET_FILE:smartcut-qt-tls-probe>)
endif()
add_executable(smartcut-unit-tests tests/unit/smoke_test.cpp)
add_executable(smartcut-preview-session-test tests/unit/preview_session_test.cpp)
add_executable(smartcut-latm-test tests/unit/latm_test.cpp)
target_link_libraries(smartcut-latm-test PRIVATE smartcut-core)
if(WIN32 AND SMARTCUT_MEDIA_ROOT)
  smartcut_deploy_build_runtime(smartcut-latm-test)
endif()
add_test(NAME smartcut-latm-parser COMMAND smartcut-latm-test)
add_executable(smartcut-legacy-timing-test tests/unit/legacy_timing_test.cpp)
target_link_libraries(smartcut-legacy-timing-test PRIVATE smartcut-core)
if(WIN32 AND SMARTCUT_MEDIA_ROOT)
  smartcut_deploy_build_runtime(smartcut-legacy-timing-test)
endif()
add_test(NAME smartcut-legacy-timing COMMAND smartcut-legacy-timing-test)
add_executable(smartcut-adts-transport-test tests/unit/adts_transport_test.cpp)
target_link_libraries(smartcut-adts-transport-test PRIVATE smartcut-core)
if(WIN32)
  smartcut_deploy_build_runtime(smartcut-adts-transport-test)
endif()
add_test(NAME smartcut-adts-transport COMMAND smartcut-adts-transport-test)

if(CMAKE_DL_LIBS)
  target_link_libraries(smartcut-core PUBLIC ${CMAKE_DL_LIBS})
endif()
add_executable(smartcut-av1-packet-mapping-test tests/unit/av1_packet_mapping_test.cpp)
target_link_libraries(smartcut-av1-packet-mapping-test PRIVATE smartcut-core)
if(SMARTCUT_MEDIA_ROOT)
  smartcut_deploy_build_runtime(smartcut-av1-packet-mapping-test)
endif()
add_test(NAME smartcut-av1-packet-mapping COMMAND smartcut-av1-packet-mapping-test)

# Opt-in compatibility gate needs an unpatched DLL as the comparison runtime.
set(SMARTCUT_TEST_STOCK_AVCODEC "" CACHE FILEPATH
  "Unpatched Windows avcodec DLL used to test optional AV1 proof compatibility")
if(WIN32 AND SMARTCUT_MEDIA_ROOT AND EXISTS "${SMARTCUT_TEST_STOCK_AVCODEC}")
  add_executable(smartcut-av1-indexing-proof-probe tests/av1_indexing_proof_probe.cpp)
  target_link_libraries(smartcut-av1-indexing-proof-probe PRIVATE smartcut-core)
  smartcut_deploy_build_runtime(smartcut-av1-indexing-proof-probe)
endif()

add_executable(smartcut-av1-mp4-navigation-probe tests/av1_mp4_navigation_probe.cpp)
target_link_libraries(smartcut-av1-mp4-navigation-probe PRIVATE smartcut-core)
if(SMARTCUT_MEDIA_ROOT)
  smartcut_deploy_build_runtime(smartcut-av1-mp4-navigation-probe)
endif()
add_executable(smartcut-av1-mp4-navigation-test tests/unit/av1_mp4_navigation_test.cpp src/media/av1_mp4_navigation.cpp)
target_include_directories(smartcut-av1-mp4-navigation-test PRIVATE src)
add_test(NAME smartcut-av1-mp4-tables COMMAND smartcut-av1-mp4-navigation-test)
add_executable(smartcut-navigation-timing-proof-test tests/unit/navigation_timing_proof_test.cpp)
target_link_libraries(smartcut-navigation-timing-proof-test PRIVATE smartcut-core)
if(WIN32)
  smartcut_deploy_build_runtime(smartcut-navigation-timing-proof-test)
endif()
add_executable(smartcut-joiner-validation-test tests/unit/joiner_validation_test.cpp)
target_link_libraries(smartcut-joiner-validation-test PRIVATE smartcut-core)
if(WIN32)
  smartcut_deploy_build_runtime(smartcut-joiner-validation-test)
endif()
add_executable(smartcut-h264-clock-probe tests/h264_decode_clock_probe.cpp)
target_link_libraries(smartcut-h264-clock-probe PRIVATE smartcut-core)
if(SMARTCUT_MEDIA_ROOT AND WIN32)
  smartcut_deploy_build_runtime(smartcut-h264-clock-probe)
endif()
add_executable(smartcut-hevc-config-test tests/unit/hevc_config_test.cpp)
target_link_libraries(smartcut-hevc-config-test PRIVATE smartcut-core)
if(WIN32)
  smartcut_deploy_build_runtime(smartcut-hevc-config-test)
endif()
add_test(NAME smartcut-hevc-config COMMAND smartcut-hevc-config-test)
add_executable(smartcut-stream-metadata-test tests/unit/stream_metadata_test.cpp)
target_link_libraries(smartcut-stream-metadata-test PRIVATE smartcut-core)
if(WIN32)
  smartcut_deploy_build_runtime(smartcut-stream-metadata-test)
endif()
add_test(NAME smartcut-stream-metadata COMMAND smartcut-stream-metadata-test)
if(SMARTCUT_MEDIA_ROOT)
add_executable(smartcut-broadcast-packet-audit-test tests/unit/broadcast_packet_audit_test.cpp)
target_link_libraries(smartcut-broadcast-packet-audit-test PRIVATE smartcut-core)
if(WIN32)
  smartcut_deploy_build_runtime(smartcut-broadcast-packet-audit-test)
endif()
add_test(NAME smartcut-broadcast-packet-audit COMMAND smartcut-broadcast-packet-audit-test)

endif()

add_executable(smartcut-cached-video-damage-test tests/unit/cached_video_damage_test.cpp)
target_link_libraries(smartcut-cached-video-damage-test PRIVATE smartcut-core)
if(WIN32)
  smartcut_deploy_build_runtime(smartcut-cached-video-damage-test)
endif()
add_test(NAME smartcut-cached-video-damage COMMAND smartcut-cached-video-damage-test
  ${CMAKE_CURRENT_BINARY_DIR}/test-results/cached-video-damage)


target_link_libraries(smartcut-preview-session-test PRIVATE smartcut-core)
if(WIN32 AND SMARTCUT_MEDIA_ROOT)
  smartcut_deploy_build_runtime(smartcut-preview-session-test)
endif()
target_link_libraries(smartcut-unit-tests PRIVATE smartcut-core)
if(COMMAND smartcut_deploy_build_runtime)
  smartcut_deploy_build_runtime(smartcut-unit-tests)
endif()
if(SMARTCUT_MEDIA_ROOT)
  find_package(Catch2 3.8.1 CONFIG REQUIRED PATHS "${SMARTCUT_MEDIA_ROOT}" NO_DEFAULT_PATH)
  target_link_libraries(smartcut-unit-tests PRIVATE Catch2::Catch2WithMain)
  target_compile_definitions(smartcut-unit-tests PRIVATE SMARTCUT_USE_CATCH2=1)
  add_test(NAME smartcut-unit-tests COMMAND ${CMAKE_COMMAND}
    -DPROGRAM=$<TARGET_FILE:smartcut-unit-tests>
    -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
    -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
    -P ${CMAKE_SOURCE_DIR}/cmake/run-with-media-path.cmake)
else()
  add_test(NAME smartcut-unit-tests COMMAND smartcut-unit-tests)
endif()

if(WIN32)
  if(TARGET smartcut-gui)
    if(SMARTCUT_PRIVATE_BETA)
      set(SMARTCUT_EXPECTED_APP_USER_MODEL_ID Linekerpandi.SmartCut64.ARM64PrivateBeta)
    else()
      set(SMARTCUT_EXPECTED_APP_USER_MODEL_ID Linekerpandi.SmartCut64)
    endif()
    set(SMARTCUT_GUI_ICON_GATE_ARGUMENTS
      -File ${CMAKE_SOURCE_DIR}/cmake/gui-icon-gate.ps1
      -Gui $<TARGET_FILE:smartcut-gui>
      -ExpectedAppUserModelId ${SMARTCUT_EXPECTED_APP_USER_MODEL_ID}
      -ExpectedMachine ${SMARTCUT_EXPECTED_PE_MACHINE})
    if(SMARTCUT_TARGET_ARCHITECTURE STREQUAL "arm64")
      list(APPEND SMARTCUT_GUI_ICON_GATE_ARGUMENTS -StaticOnly)
    endif()
    add_test(NAME smartcut-gui-icon-resource COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
      ${SMARTCUT_GUI_ICON_GATE_ARGUMENTS})
    set_tests_properties(smartcut-gui-icon-resource PROPERTIES TIMEOUT 45 RUN_SERIAL TRUE SKIP_RETURN_CODE 77)
  endif()
  set(SMARTCUT_INDEX_FIXTURE "${CMAKE_CURRENT_BINARY_DIR}/test-fixtures/m3-hevc-index-fixture.hevc")
  execute_process(
    COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
      -File "${CMAKE_SOURCE_DIR}/cmake/materialize-fixture.ps1"
      -SourcePath "${CMAKE_SOURCE_DIR}/tests/fixtures/m3-hevc-index-fixture.base64"
      -DestinationPath "${SMARTCUT_INDEX_FIXTURE}"
    RESULT_VARIABLE SMARTCUT_INDEX_FIXTURE_RESULT)
  if(NOT SMARTCUT_INDEX_FIXTURE_RESULT EQUAL 0)
    message(FATAL_ERROR "Failed to materialize the deterministic HEVC index fixture")
  endif()
  add_test(NAME smartcut-cli-${SMARTCUT_TARGET_ARCHITECTURE} COMMAND ${CMAKE_COMMAND}
    -DINPUT=$<TARGET_FILE:smartcut-cli>
    -DEXPECTED_MACHINE=${SMARTCUT_EXPECTED_PE_MACHINE}
    -DARCHITECTURE=${SMARTCUT_TARGET_ARCHITECTURE}
    -P ${CMAKE_SOURCE_DIR}/cmake/assert-pe-machine.cmake)
  add_test(NAME smartcut-worker-${SMARTCUT_TARGET_ARCHITECTURE} COMMAND ${CMAKE_COMMAND}
    -DINPUT=$<TARGET_FILE:smartcut-worker>
    -DEXPECTED_MACHINE=${SMARTCUT_EXPECTED_PE_MACHINE}
    -DARCHITECTURE=${SMARTCUT_TARGET_ARCHITECTURE}
    -P ${CMAKE_SOURCE_DIR}/cmake/assert-pe-machine.cmake)
  if(SMARTCUT_BUILD_GUI)
    add_test(NAME smartcut-gui-${SMARTCUT_TARGET_ARCHITECTURE} COMMAND ${CMAKE_COMMAND}
      -DINPUT=$<TARGET_FILE:smartcut-gui>
      -DEXPECTED_MACHINE=${SMARTCUT_EXPECTED_PE_MACHINE}
      -DARCHITECTURE=${SMARTCUT_TARGET_ARCHITECTURE}
      -P ${CMAKE_SOURCE_DIR}/cmake/assert-pe-machine.cmake)
  endif()
  add_test(NAME smartcut-control-ipc COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
    -File ${CMAKE_SOURCE_DIR}/cmake/control-ipc-gate.ps1
    -Worker $<TARGET_FILE:smartcut-worker>
    -Cli $<TARGET_FILE:smartcut-cli>)
  add_test(NAME smartcut-index-cache-integrity COMMAND ${CMAKE_COMMAND}
    -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
    -DINPUT=${SMARTCUT_INDEX_FIXTURE}
    -DCACHE=${CMAKE_CURRENT_BINARY_DIR}/test-results/m3-index-cache.json
    -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
    -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
    -P ${CMAKE_SOURCE_DIR}/cmake/index-cache-gate.cmake)
  add_test(NAME smartcut-trimmed-file-copy COMMAND ${CMAKE_COMMAND}
    -DPROGRAM=$<TARGET_FILE:smartcut-worker-test>
    -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results
    -P ${CMAKE_SOURCE_DIR}/cmake/trimmed-file-copy-gate.cmake)
  if(SMARTCUT_BUILD_GUI)
    file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/test-results")
    set(SMARTCUT_AV_FIXTURE "${CMAKE_CURRENT_BINARY_DIR}/test-fixtures/m4-av-fixture.mkv")
    set(SMARTCUT_MPEG2_SAFE_END_FIXTURE "${CMAKE_CURRENT_BINARY_DIR}/test-fixtures/mpeg2-safe-end.mkv")
    set(SMARTCUT_AD_FIXTURE "${CMAKE_CURRENT_BINARY_DIR}/test-fixtures/ad-scene-change.mkv")
    set(SMARTCUT_STREAM_SELECTION_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/test-results/stream-selection")
    set(SMARTCUT_DOVI_FIXTURE_ROOT "${CMAKE_CURRENT_BINARY_DIR}/test-fixtures/dovi-tool-source")
    set(SMARTCUT_DOVI_FIXTURE "${SMARTCUT_DOVI_FIXTURE_ROOT}/dovi_tool-2.3.0/assets/hevc_tests/regular.mkv")
    if(NOT EXISTS "${SMARTCUT_DOVI_FIXTURE}" AND EXISTS "${CMAKE_SOURCE_DIR}/dependencies/sources/libdovi.archive")
      file(MAKE_DIRECTORY "${SMARTCUT_DOVI_FIXTURE_ROOT}")
      execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_SOURCE_DIR}/dependencies/sources/libdovi.archive"
        WORKING_DIRECTORY "${SMARTCUT_DOVI_FIXTURE_ROOT}" RESULT_VARIABLE SMARTCUT_DOVI_FIXTURE_RESULT)
      if(NOT SMARTCUT_DOVI_FIXTURE_RESULT EQUAL 0)
        message(FATAL_ERROR "Failed to materialize the pinned libdovi Profile 8 fixture")
      endif()
    endif()
    execute_process(
      COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
        -File "${CMAKE_SOURCE_DIR}/cmake/materialize-fixture.ps1"
        -SourcePath "${CMAKE_SOURCE_DIR}/tests/fixtures/m4-av-fixture.mkv.base64"
        -DestinationPath "${SMARTCUT_AV_FIXTURE}"
      RESULT_VARIABLE SMARTCUT_FIXTURE_RESULT)
    if(NOT SMARTCUT_FIXTURE_RESULT EQUAL 0)
      message(FATAL_ERROR "Failed to materialize the deterministic A/V test fixture")
    endif()
    execute_process(
      COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
        -File "${CMAKE_SOURCE_DIR}/cmake/materialize-fixture.ps1"
        -SourcePath "${CMAKE_SOURCE_DIR}/tests/fixtures/mpeg2-safe-end.mkv.base64"
        -DestinationPath "${SMARTCUT_MPEG2_SAFE_END_FIXTURE}"
      RESULT_VARIABLE SMARTCUT_MPEG2_SAFE_END_FIXTURE_RESULT)
    if(NOT SMARTCUT_MPEG2_SAFE_END_FIXTURE_RESULT EQUAL 0)
      message(FATAL_ERROR "Failed to materialize the deterministic MPEG-2 endpoint fixture")
    endif()
    add_test(NAME smartcut-gui-hardware-test-guards COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" $<TARGET_FILE:smartcut-gui-test> --automation-hardware-test-guards)
    set_tests_properties(smartcut-gui-hardware-test-guards PROPERTIES TIMEOUT 15 RUN_SERIAL TRUE)
    add_test(NAME smartcut-gui-batch-lifecycle COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "SMARTCUT_DISABLE_HARDWARE_DECODE=1" $<TARGET_FILE:smartcut-gui-test> --automation-batch-lifecycle ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-batch-lifecycle.json)
    set_tests_properties(smartcut-gui-batch-lifecycle PROPERTIES TIMEOUT 30 RUN_SERIAL TRUE)
    add_test(NAME smartcut-gui-joiner-workflow COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "SMARTCUT_DISABLE_HARDWARE_DECODE=1" $<TARGET_FILE:smartcut-gui-test> --automation-joiner-workflow ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/joiner-workflow)
    set_tests_properties(smartcut-gui-joiner-workflow PROPERTIES TIMEOUT 240 RUN_SERIAL TRUE)
    add_test(NAME smartcut-gui-joiner-preparation COMMAND ${CMAKE_COMMAND} -E env
      "QT_QPA_PLATFORM=offscreen" "SMARTCUT_DISABLE_HARDWARE_DECODE=1"
      "SMARTCUT_TEST_SETTINGS_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results/joiner-preparation/settings"
      $<TARGET_FILE:smartcut-gui-test> --automation-joiner-preparation
      ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/joiner-preparation)
    set_tests_properties(smartcut-gui-joiner-preparation PROPERTIES TIMEOUT 60 RUN_SERIAL TRUE)
    add_test(NAME smartcut-gui-batch-layout COMMAND ${CMAKE_COMMAND} -E env
      "QT_QPA_PLATFORM=offscreen" "SMARTCUT_DISABLE_HARDWARE_DECODE=1"
      "SMARTCUT_TEST_SETTINGS_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results/batch-layout/settings"
      $<TARGET_FILE:smartcut-gui-test> --automation-batch-layout
      ${CMAKE_CURRENT_BINARY_DIR}/test-results/batch-layout)
    set_tests_properties(smartcut-gui-batch-layout PROPERTIES TIMEOUT 60 RUN_SERIAL TRUE)
    add_test(NAME smartcut-gui-smoke COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --smoke-test)
    add_test(NAME smartcut-videoredo-title-template-interchange COMMAND ${CMAKE_COMMAND} -E env
      "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin"
      $<TARGET_FILE:smartcut-gui-test> --automation-title-template
      ${CMAKE_CURRENT_BINARY_DIR}/test-results/videoredo-title-template.TT.xml
      ${CMAKE_CURRENT_BINARY_DIR}/test-results/videoredo-title-template.json)
    add_executable(smartcut-navigation-locale-test tests/unit/navigation_locale_test.cpp)
    target_link_libraries(smartcut-navigation-locale-test PRIVATE smartcut-core Qt6::Core)
    smartcut_deploy_build_runtime(smartcut-navigation-locale-test)
    add_test(NAME smartcut-navigation-locale COMMAND ${CMAKE_COMMAND} -E env
      "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin"
      $<TARGET_FILE:smartcut-navigation-locale-test> ${SMARTCUT_AV_FIXTURE})
    set_tests_properties(smartcut-navigation-locale PROPERTIES TIMEOUT 120 RUN_SERIAL TRUE)
    add_test(NAME smartcut-gui-navigation-stress COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-navigation-stress)
    add_test(NAME smartcut-gui-progressive-navigation COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" $<TARGET_FILE:smartcut-gui-test> --automation-progressive-navigation)
    set_tests_properties(smartcut-gui-progressive-navigation PROPERTIES TIMEOUT 20 RUN_SERIAL TRUE)
    add_test(NAME smartcut-gui-navigation-failure COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" $<TARGET_FILE:smartcut-gui-test> --automation-navigation-failure)
    set_tests_properties(smartcut-gui-navigation-failure PROPERTIES TIMEOUT 20 RUN_SERIAL TRUE)
    set_tests_properties(smartcut-gui-navigation-stress PROPERTIES TIMEOUT 10)
    add_test(NAME smartcut-gui-process-diagnostics COMMAND ${CMAKE_COMMAND} -E env
      "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin"
      $<TARGET_FILE:smartcut-gui-test> --automation-process-diagnostics
      ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-process-diagnostics
      ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-process-diagnostics.json)
    set_tests_properties(smartcut-gui-process-diagnostics PROPERTIES TIMEOUT 15)
    if(COMMAND smartcut_deploy_build_runtime)
      add_test(NAME smartcut-build-tree-isolated-runtime COMMAND ${CMAKE_COMMAND}
        -DGUI=$<TARGET_FILE:smartcut-gui>
        -DUNIT_TESTS=$<TARGET_FILE:smartcut-unit-tests>
        -P ${CMAKE_SOURCE_DIR}/cmake/isolated-build-tree-gate.cmake)
      set_tests_properties(smartcut-unit-tests smartcut-build-tree-isolated-runtime
        PROPERTIES RESOURCE_LOCK smartcut-unit-test-temp-files)
    endif()
    if(EXISTS "${SMARTCUT_AV_FIXTURE}")
      add_test(NAME smartcut-worker-argument-validation COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -P ${CMAKE_SOURCE_DIR}/cmake/worker-argument-validation-gate.cmake)
      add_test(NAME smartcut-navigation-info COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/navigation-info-gate.cmake)
      add_test(NAME smartcut-index-sample COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DGUI=$<TARGET_FILE:smartcut-gui-test>
        -DGUI_QT_BIN=${CMAKE_PREFIX_PATH}/bin
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results/index-sample
        -P ${CMAKE_SOURCE_DIR}/cmake/index-sample-gate.cmake)
      set_tests_properties(smartcut-index-sample PROPERTIES TIMEOUT 60 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-hardware-test-prompt COMMAND ${CMAKE_COMMAND} -E env
        "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin"
        $<TARGET_FILE:smartcut-gui-test> --automation-hardware-test-prompt)
      set_tests_properties(smartcut-gui-hardware-test-prompt PROPERTIES TIMEOUT 15 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-responsive-layout COMMAND ${CMAKE_COMMAND} -E env
        "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin"
        $<TARGET_FILE:smartcut-gui-test> --automation-responsive-layout
        ${CMAKE_CURRENT_BINARY_DIR}/test-results/responsive-layout)
      set_tests_properties(smartcut-gui-responsive-layout PROPERTIES TIMEOUT 60 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-profile-manager COMMAND ${CMAKE_COMMAND} -E env
        "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\;${CMAKE_PREFIX_PATH}/bin"
        $<TARGET_FILE:smartcut-gui-test> --automation-profile-manager
        ${CMAKE_CURRENT_BINARY_DIR}/test-results/profile-manager)
      set_tests_properties(smartcut-gui-profile-manager PROPERTIES TIMEOUT 60 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-native-profile-backup COMMAND ${CMAKE_COMMAND} -E env
        "QT_QPA_PLATFORM=offscreen"
        "SMARTCUT_TEST_SETTINGS_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results/native-profile-backup/settings"
        "LOCALAPPDATA=${CMAKE_CURRENT_BINARY_DIR}/test-results/native-profile-backup/local"
        "APPDATA=${CMAKE_CURRENT_BINARY_DIR}/test-results/native-profile-backup/roaming"
        $<TARGET_FILE:smartcut-gui-test> --automation-native-profile-backup
        ${CMAKE_CURRENT_BINARY_DIR}/test-results/native-profile-backup)
      set_tests_properties(smartcut-gui-native-profile-backup PROPERTIES TIMEOUT 120 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-evaluation-licensing COMMAND ${CMAKE_COMMAND} -E env
        "QT_QPA_PLATFORM=offscreen"
        "SMARTCUT64_LICENSE_FILE=${CMAKE_CURRENT_BINARY_DIR}/test-results/evaluation-licensing/missing.sc64"
        "LOCALAPPDATA=${CMAKE_CURRENT_BINARY_DIR}/test-results/evaluation-licensing/local"
        "APPDATA=${CMAKE_CURRENT_BINARY_DIR}/test-results/evaluation-licensing/roaming"
        $<TARGET_FILE:smartcut-gui-test> --automation-evaluation-licensing
        ${CMAKE_CURRENT_BINARY_DIR}/test-results/evaluation-licensing)
      set_tests_properties(smartcut-gui-evaluation-licensing PROPERTIES TIMEOUT 30 RUN_SERIAL TRUE)
      add_test(NAME smartcut-evaluation-release-contents COMMAND powershell
        -NoProfile -NonInteractive -ExecutionPolicy Bypass
        -File ${CMAKE_CURRENT_SOURCE_DIR}/scripts/check-evaluation-release.ps1
        -BuildRoot ${CMAKE_CURRENT_BINARY_DIR})
      set_tests_properties(smartcut-evaluation-release-contents PROPERTIES TIMEOUT 120 RUN_SERIAL TRUE)
      add_test(NAME smartcut-videoredo-project-interchange COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results
        -P ${CMAKE_SOURCE_DIR}/cmake/videoredo-project-gate.cmake)
      add_test(NAME smartcut-videoredo-batch-interchange COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results/videoredo-batch
        -P ${CMAKE_SOURCE_DIR}/cmake/videoredo-batch-gate.cmake)
      set_tests_properties(smartcut-videoredo-batch-interchange PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-unc-source COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
        -File ${CMAKE_SOURCE_DIR}/cmake/unc-source-gate.ps1
        -Worker $<TARGET_FILE:smartcut-worker-test>
        -Gui $<TARGET_FILE:smartcut-gui-test>
        -InputPath ${SMARTCUT_AV_FIXTURE}
        -ReportPath ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-open-source-unc.json
        -MediaBin ${SMARTCUT_MEDIA_ROOT}/bin
        -MingwBin ${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -Require ${SMARTCUT_REQUIRE_UNC_TEST}
        -UncRoot "${SMARTCUT_UNC_TEST_ROOT}")
      set_tests_properties(smartcut-unc-source PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 180)
      add_test(NAME smartcut-gui-open-source COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-open-source ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-open-source.json)
      add_test(NAME smartcut-gui-explorer-startup COMMAND ${CMAKE_COMMAND} -E env
        "QT_QPA_PLATFORM=offscreen"
        "SMARTCUT_TEST_STARTUP_REPORT=${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-explorer-startup.json"
        $<TARGET_FILE:smartcut-gui-test> ${SMARTCUT_AV_FIXTURE})
      set_tests_properties(smartcut-gui-explorer-startup PROPERTIES TIMEOUT 40 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-control-restart COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-control-restart ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-control-restart.json)
      add_test(NAME smartcut-gui-multi-open COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-multi-open ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-multi-open.json)
      set_tests_properties(smartcut-gui-multi-open PROPERTIES DEPENDS smartcut-media-joiner TIMEOUT 60)
      set_tests_properties(smartcut-gui-open-source PROPERTIES TIMEOUT 35)
      add_test(NAME smartcut-gui-reload-retains-edits COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-reload ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-reload.json)
      set_tests_properties(smartcut-gui-reload-retains-edits PROPERTIES TIMEOUT 35)
      foreach(navigation_case slow replace)
        add_test(NAME smartcut-gui-${navigation_case}-navigation COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-${navigation_case}-navigation ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-${navigation_case}-navigation.json)
        set_tests_properties(smartcut-gui-${navigation_case}-navigation PROPERTIES TIMEOUT 30)
      endforeach()
      add_test(NAME smartcut-production-entitlement-delivery COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker>
        -DCLI=$<TARGET_FILE:smartcut-cli>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/production-entitlement
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/entitlement-delivery-gate.cmake)
      set_tests_properties(smartcut-production-entitlement-delivery PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-gui-joiner-edited-project COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-joiner-project ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-joiner-project.json)
      set_tests_properties(smartcut-gui-joiner-edited-project PROPERTIES TIMEOUT 60)
      add_test(NAME smartcut-videoredo-joiner-interchange COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-joiner-project ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-videoredo-joiner.json)
      set_tests_properties(smartcut-videoredo-joiner-interchange PROPERTIES TIMEOUT 60)
      add_test(NAME smartcut-gui-title-join COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-title-join ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-title-joined.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-title-join.json)
      set_tests_properties(smartcut-gui-title-join PROPERTIES DEPENDS smartcut-media-joiner TIMEOUT 120)
      add_test(NAME smartcut-gui-quickstream-fix COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-quickstream-fix ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-quickstream-fixed.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-quickstream-fix.json)
      set_tests_properties(smartcut-gui-quickstream-fix PROPERTIES TIMEOUT 35)
      add_test(NAME smartcut-gui-recovery-dialog COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-recovery-dialog ${CMAKE_CURRENT_BINARY_DIR}/test-results/quickstream-recovery-ui)
      set_tests_properties(smartcut-gui-recovery-dialog PROPERTIES TIMEOUT 35 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-qsf-destination-protection COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-qsf-destination-protection ${CMAKE_CURRENT_BINARY_DIR}/test-results/qsf-destination-protection.json)
      set_tests_properties(smartcut-gui-qsf-destination-protection PROPERTIES TIMEOUT 35 RUN_SERIAL TRUE)
      add_test(NAME smartcut-quickstream-dimension-filter COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/quickstream-dimension
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/dimension-filter-gate.cmake)
      set_tests_properties(smartcut-quickstream-dimension-filter PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-video-profile-transforms COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/video-profile
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/video-transform-gate.cmake)
      set_tests_properties(smartcut-video-profile-transforms PROPERTIES TIMEOUT 240)
      add_test(NAME smartcut-ffmpeg9-vulkan-codecs COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/ffmpeg9-vulkan
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/ffmpeg9-vulkan-codec-gate.cmake)
      set_tests_properties(smartcut-ffmpeg9-vulkan-codecs PROPERTIES TIMEOUT 240)
      add_test(NAME smartcut-hardware-self-test COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/hardware-self-test-gate.cmake)
      set_tests_properties(smartcut-hardware-self-test PROPERTIES TIMEOUT 240)
      add_test(NAME smartcut-transport-stream-mux-controls COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/custom-transport-stream.ts
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/transport-stream-mux-gate.cmake)
      set_tests_properties(smartcut-transport-stream-mux-controls PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-m2ts-dvd-subtitle-private-stream COMMAND ${CMAKE_COMMAND}
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/m2ts-dvd-subtitle
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/m2ts-dvd-subtitle-gate.cmake)
      set_tests_properties(smartcut-m2ts-dvd-subtitle-private-stream PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-transport-compatibility-transcodes COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/transport-compatible
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/transport-compatibility-transcode-gate.cmake)
      set_tests_properties(smartcut-transport-compatibility-transcodes PROPERTIES TIMEOUT 240)
      find_program(SMARTCUT_TEST_FFMPEG NAMES ffmpeg ffmpeg.exe PATHS "C:/ffmpeg_latest")
      add_test(NAME smartcut-mpeg-program-stream-output COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/mpeg-program-stream
        -P ${CMAKE_SOURCE_DIR}/cmake/mpeg-program-stream-gate.cmake)
      set_tests_properties(smartcut-mpeg-program-stream-output PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-legacy-container-outputs COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/legacy-container
        -P ${CMAKE_SOURCE_DIR}/cmake/legacy-container-output-gate.cmake)
      set_tests_properties(smartcut-legacy-container-outputs PROPERTIES TIMEOUT 180)
      add_test(NAME smartcut-elementary-stream-multiplexer COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/elementary-multiplex
        -P ${CMAKE_SOURCE_DIR}/cmake/elementary-multiplex-gate.cmake)
      set_tests_properties(smartcut-elementary-stream-multiplexer PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-elementary-stream-demultiplex COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/elementary-demultiplex
        -P ${CMAKE_SOURCE_DIR}/cmake/elementary-demultiplex-gate.cmake)
      set_tests_properties(smartcut-elementary-stream-demultiplex PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-gui-elementary-stream-multiplexer COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-elementary-mux ${CMAKE_CURRENT_BINARY_DIR}/test-results/elementary-multiplex-video.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/elementary-multiplex-audio.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-elementary-multiplex.ts ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-elementary-multiplex.json)
      set_tests_properties(smartcut-gui-elementary-stream-multiplexer PROPERTIES DEPENDS smartcut-elementary-stream-multiplexer TIMEOUT 60)
      add_test(NAME smartcut-gui-batch COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-batch ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-batch-output.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-batch.json)
      set_tests_properties(smartcut-gui-batch PROPERTIES TIMEOUT 35)
      add_test(NAME smartcut-gui-watch-folder COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-watch-folder ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-watch-folder-output.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-watch-folder.json)
      set_tests_properties(smartcut-gui-watch-folder PROPERTIES TIMEOUT 35)
      add_test(NAME smartcut-batch-project-export COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/batch-project
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/batch-project-gate.cmake)
      set_tests_properties(smartcut-batch-project-export PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-stream-selection-backend COMMAND ${CMAKE_COMMAND}
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${SMARTCUT_STREAM_SELECTION_PREFIX}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/stream-selection-gate.cmake)
      add_test(NAME smartcut-edit-export COMMAND ${CMAKE_COMMAND}
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/edit-export
        -DEXPECTED_VERSION=${PROJECT_VERSION}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/edit-export-gate.cmake)
      add_test(NAME smartcut-container-output COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/container-output
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/container-output-gate.cmake)
      set_tests_properties(smartcut-container-output PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-gui-edit-export COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-edit-export ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-edit-export.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-edit-export.json)
      set_tests_properties(smartcut-gui-edit-export PROPERTIES DEPENDS smartcut-edit-export TIMEOUT 60)
      add_test(NAME smartcut-gui-project-roundtrip COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-project-roundtrip ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-project-roundtrip.json ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-project-roundtrip-report.json)
      set_tests_properties(smartcut-gui-project-roundtrip PROPERTIES TIMEOUT 60)
      add_test(NAME smartcut-gui-stream-selection COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-stream-selection ${SMARTCUT_STREAM_SELECTION_PREFIX}-source.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-stream-selection-output.mkv ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-stream-selection.json)
      set_tests_properties(smartcut-gui-stream-selection PROPERTIES DEPENDS smartcut-stream-selection-backend TIMEOUT 35)
      add_test(NAME smartcut-ad-fixture COMMAND $<TARGET_FILE:smartcut-cli-test> make-ad-fixture --output ${SMARTCUT_AD_FIXTURE})
      add_test(NAME smartcut-gui-video-restart-guard COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-video-restart-guard ${SMARTCUT_AD_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-video-restart-guard.json)
      set_tests_properties(smartcut-gui-video-restart-guard PROPERTIES DEPENDS smartcut-ad-fixture TIMEOUT 15)
      add_test(NAME smartcut-gui-main-timeline-seek-resume COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-navigation-seek-resume main ${SMARTCUT_MPEG2_SAFE_END_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-main-timeline-seek-resume.json)
      add_test(NAME smartcut-gui-fine-navigation-seek-resume COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-navigation-seek-resume fine ${SMARTCUT_MPEG2_SAFE_END_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-fine-navigation-seek-resume.json)
      set_tests_properties(smartcut-gui-main-timeline-seek-resume smartcut-gui-fine-navigation-seek-resume PROPERTIES TIMEOUT 15 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-waveform-lifecycle COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-waveform-lifecycle ${SMARTCUT_MPEG2_SAFE_END_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-waveform-lifecycle.json)
      set_tests_properties(smartcut-gui-waveform-lifecycle PROPERTIES TIMEOUT 35 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-ad-detective COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-ad-detective ${SMARTCUT_AD_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-ad-detective.json)
      set_tests_properties(smartcut-gui-ad-detective PROPERTIES DEPENDS smartcut-ad-fixture)
      set_tests_properties(smartcut-gui-ad-detective PROPERTIES TIMEOUT 35)
      add_test(NAME smartcut-gui-ad-detective-batch COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-ad-batch ${SMARTCUT_AD_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-ad-batch-project.json ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-ad-batch-report.json)
      set_tests_properties(smartcut-gui-ad-detective-batch PROPERTIES DEPENDS smartcut-ad-fixture TIMEOUT 35)
      add_test(NAME smartcut-ad-detective-batch-frame-rate COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AD_FIXTURE}
        -DPROJECT=${CMAKE_CURRENT_BINARY_DIR}/test-results/ad-batch-rate-project.json
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/ad-detective-batch-rate-gate.cmake)
      set_tests_properties(smartcut-ad-detective-batch-frame-rate PROPERTIES DEPENDS smartcut-ad-fixture TIMEOUT 35)
      add_test(NAME smartcut-ad-detective-batch-project-validation COMMAND $<TARGET_FILE:smartcut-worker-test> --validate-project --project ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-ad-batch-project.json)
      set_tests_properties(smartcut-ad-detective-batch-project-validation PROPERTIES DEPENDS smartcut-gui-ad-detective-batch TIMEOUT 15)
      add_test(NAME smartcut-gui-preview-stress COMMAND ${CMAKE_COMMAND} -E env "QT_QPA_PLATFORM=offscreen" "PATH=C:/msys642/ucrt64/bin\\;${CMAKE_PREFIX_PATH}/bin" $<TARGET_FILE:smartcut-gui-test> --automation-preview-stress ${SMARTCUT_AV_FIXTURE} ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-preview-stress.json)
      set_tests_properties(smartcut-gui-preview-stress PROPERTIES TIMEOUT 35)
      add_test(NAME smartcut-gui-preview-session COMMAND ${CMAKE_COMMAND} -E env
        "QT_QPA_PLATFORM=offscreen" $<TARGET_FILE:smartcut-gui-test>
        --automation-preview-session ${SMARTCUT_AV_FIXTURE}
        ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-preview-session.json)
      set_tests_properties(smartcut-gui-preview-session PROPERTIES TIMEOUT 35 RUN_SERIAL TRUE)
      add_test(NAME smartcut-gui-thumbnail-session COMMAND ${CMAKE_COMMAND} -E env
        "QT_QPA_PLATFORM=offscreen"
        $<TARGET_FILE:smartcut-gui-test> --automation-thumbnail-session ${SMARTCUT_AV_FIXTURE}
        ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-thumbnail-session.json)
      set_tests_properties(smartcut-gui-thumbnail-session PROPERTIES TIMEOUT 35 RUN_SERIAL TRUE)
      add_test(NAME smartcut-preview-stream COMMAND $<TARGET_FILE:smartcut-worker-test>
        --preview-stream-benchmark --input ${SMARTCUT_AV_FIXTURE}
        --start-frame 0 --start-pts 0 --frames 4)
      set_tests_properties(smartcut-preview-stream PROPERTIES TIMEOUT 15)
      add_test(NAME smartcut-probe-metadata COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/probe-metadata-gate.cmake)
      add_test(NAME smartcut-metadata-edit COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/metadata-edit.mkv
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/metadata-edit-gate.cmake)
      add_test(NAME smartcut-codec-capabilities COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DREQUIRE_DAV1D=${SMARTCUT_REQUIRE_DAV1D}
        -DEXPECT_LIBAOM=${SMARTCUT_RUNTIME_HAS_LIBAOM}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/codec-capabilities-gate.cmake)
      add_test(NAME smartcut-hardware-acceleration COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/hardware-preview.ppm
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/hardware-acceleration-gate.cmake)
      add_test(NAME smartcut-frame-index COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DCACHE=${CMAKE_CURRENT_BINARY_DIR}/test-results/video-frame-index-cache.json
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/frame-index-gate.cmake)
      add_test(NAME smartcut-audio-pcm COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/audio-pcm-gate.cmake)
      add_test(NAME smartcut-audio-waveform COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/audio-waveform-gate.cmake)
      add_test(NAME smartcut-audio-synchronization COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/audio-synchronization.mkv
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/audio-sync-gate.cmake)
      add_test(NAME smartcut-audio-output-profiles COMMAND ${CMAKE_COMMAND}
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/audio-profile
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/audio-profile-gate.cmake)
      set_tests_properties(smartcut-audio-output-profiles PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-ad-detective COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/ad-detective-gate.cmake)
      add_test(NAME smartcut-joiner-validation COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-worker-test>
        -DVALIDATOR=$<TARGET_FILE:smartcut-joiner-validation-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DROOT=${CMAKE_CURRENT_BINARY_DIR}/test-results/joiner-validation
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/joiner-validation-gate.cmake)
      set_tests_properties(smartcut-joiner-validation PROPERTIES TIMEOUT 120)
      add_test(NAME smartcut-media-joiner COMMAND ${CMAKE_COMMAND}
        -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DPROGRAM=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/joiner-output.mkv
        -DLIST=${CMAKE_CURRENT_BINARY_DIR}/test-results/joiner-list.txt
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/media-joiner-gate.cmake)
      add_test(NAME smartcut-copy-mkv COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/m6-copy-gate.mkv
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/copy-mkv-gate.cmake)
      add_test(NAME smartcut-boundary-encode COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/m7-boundary-gate.mkv
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/boundary-encode-gate.cmake)
      add_test(NAME smartcut-boundary-deep-seek COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DFIXTURE=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-deep-seek-source.mkv
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-deep-seek-output.mkv
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/boundary-deep-seek-gate.cmake)
      set_tests_properties(smartcut-boundary-deep-seek PROPERTIES TIMEOUT 60)
      if(SMARTCUT_REQUIRE_TEST_FFMPEG AND
         (NOT SMARTCUT_TEST_FFMPEG OR NOT EXISTS "${SMARTCUT_TEST_FFMPEG}"))
        message(FATAL_ERROR
          "SMARTCUT_REQUIRE_TEST_FFMPEG is ON, but the FFmpeg regression-fixture generator was not found")
      endif()
      if(SMARTCUT_TEST_FFMPEG AND EXISTS "${SMARTCUT_TEST_FFMPEG}")
        find_package(Python3 COMPONENTS Interpreter QUIET)
        get_filename_component(SMARTCUT_TEST_FFMPEG_DIR "${SMARTCUT_TEST_FFMPEG}" DIRECTORY)
        find_program(SMARTCUT_TEST_FFPROBE NAMES ffprobe HINTS "${SMARTCUT_TEST_FFMPEG_DIR}")
        if(Python3_Interpreter_FOUND AND SMARTCUT_TEST_FFPROBE)
          add_test(NAME smartcut-forum-media-regressions COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-forum-media-regressions.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/forum-media)
          set_tests_properties(smartcut-forum-media-regressions PROPERTIES TIMEOUT 600 RUN_SERIAL TRUE)
          add_test(NAME smartcut-mkv-failure-cleanup COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-mkv-failure-cleanup.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/mkv-failure-cleanup)
          set_tests_properties(smartcut-mkv-failure-cleanup PROPERTIES TIMEOUT 120)
          add_test(NAME smartcut-ts-null-pid COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-ts-null-pid.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/ts-null-pid)
          set_tests_properties(smartcut-ts-null-pid PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-broadcast-audio-profile COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-broadcast-audio-profile.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/broadcast-audio-profile)
          set_tests_properties(smartcut-broadcast-audio-profile PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-teletext-recovery COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-teletext-recovery.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/teletext-recovery)
          set_tests_properties(smartcut-teletext-recovery PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-teletext-qsf COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-teletext-qsf.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/teletext-qsf)
          set_tests_properties(smartcut-teletext-qsf PROPERTIES TIMEOUT 240 RUN_SERIAL TRUE)
          add_test(NAME smartcut-chris-export-regressions COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-chris-export-regressions.py
            --worker $<TARGET_FILE:smartcut-worker-test> --cli $<TARGET_FILE:smartcut-cli-test>
            --clock-probe $<TARGET_FILE:smartcut-h264-clock-probe>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/chris-export)
          set_tests_properties(smartcut-chris-export-regressions PROPERTIES TIMEOUT 240 RUN_SERIAL TRUE)
          add_test(NAME smartcut-audio-tools COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-audio-tools.py
            --worker $<TARGET_FILE:smartcut-worker-test> --gui $<TARGET_FILE:smartcut-gui-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/audio-tools)
          set_tests_properties(smartcut-audio-tools PROPERTIES TIMEOUT 240 RUN_SERIAL TRUE)
          add_test(NAME smartcut-audio-sync-gain COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-audio-sync-gain.py
            --worker $<TARGET_FILE:smartcut-worker-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/audio-sync-gain)
          set_tests_properties(smartcut-audio-sync-gain PROPERTIES TIMEOUT 120 RUN_SERIAL TRUE)
          add_test(NAME smartcut-modern-codec-smart-render COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-modern-codec-smart-render.py
            --cli $<TARGET_FILE:smartcut-cli-test> --worker $<TARGET_FILE:smartcut-worker-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/modern-codec-smart-render)
          set_tests_properties(smartcut-modern-codec-smart-render PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-copy-track-metadata COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-copy-track-metadata.py
            --cli $<TARGET_FILE:smartcut-cli-test> --worker $<TARGET_FILE:smartcut-worker-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/copy-track-metadata)
          set_tests_properties(smartcut-copy-track-metadata PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          add_test(NAME smartcut-subtitle-chapter-artwork-regression COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-alma-edit-regressions.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/subtitle-chapter-artwork)
          set_tests_properties(smartcut-subtitle-chapter-artwork-regression PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-legacy-timing-export COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-legacy-timing.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/legacy-timing)
          set_tests_properties(smartcut-legacy-timing-export PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-mpeg4-avi-smart-render COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-mpeg4-avi-smart-render.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/mpeg4-avi-smart-render)
          set_tests_properties(smartcut-mpeg4-avi-smart-render PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-range-stream-selection COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-range-stream-selection.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/range-stream-selection)
          set_tests_properties(smartcut-range-stream-selection PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)

          add_test(NAME smartcut-latm-conversion COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-latm-conversion.py
            --tester $<TARGET_FILE:smartcut-latm-test> --worker $<TARGET_FILE:smartcut-worker-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/latm-conversion)
          set_tests_properties(smartcut-latm-conversion PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-profile-fades COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-profile-fades.py
            --worker $<TARGET_FILE:smartcut-worker-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/profile-fades)
          set_tests_properties(smartcut-profile-fades PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          add_test(NAME smartcut-smart-fades COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-smart-fades.py
            --worker $<TARGET_FILE:smartcut-worker-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/smart-fades)
          set_tests_properties(smartcut-smart-fades PROPERTIES TIMEOUT 600 RUN_SERIAL TRUE)
          add_test(NAME smartcut-recovery-smart-render COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-recovery-smart-render.py
            --worker $<TARGET_FILE:smartcut-worker-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/recovery-smart-render)
          set_tests_properties(smartcut-recovery-smart-render PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          set(SMARTCUT_RECOVERY_TEST_EDITION_ARGS)
          if(SMARTCUT_DEVELOPER_EDITION)
            list(APPEND SMARTCUT_RECOVERY_TEST_EDITION_ARGS --developer-edition)
          endif()
          add_test(NAME smartcut-quickstream-recovery COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-quickstream-recovery.py
            --worker $<TARGET_FILE:smartcut-worker-test> --retail-worker $<TARGET_FILE:smartcut-worker>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/quickstream-recovery ${SMARTCUT_RECOVERY_TEST_EDITION_ARGS})
          set_tests_properties(smartcut-quickstream-recovery PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-transcode-indexed-seek COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-transcode-seek.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/transcode-indexed-seek)
          set_tests_properties(smartcut-transcode-indexed-seek PROPERTIES TIMEOUT 300 RUN_SERIAL TRUE)
          add_test(NAME smartcut-navigation-policy COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-navigation-policy.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/navigation-policy)
          set_tests_properties(smartcut-navigation-policy PROPERTIES TIMEOUT 300)
          add_test(NAME smartcut-navigation-reorder COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-navigation-reorder.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/navigation-reorder)
          set_tests_properties(smartcut-navigation-reorder PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          if(TARGET smartcut-av1-indexing-proof-probe)
            add_test(NAME smartcut-av1-indexing-proof COMMAND ${Python3_EXECUTABLE}
              ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-av1-indexing-proof.py
              --worker $<TARGET_FILE:smartcut-worker-test>
              --parser-probe $<TARGET_FILE:smartcut-av1-indexing-proof-probe>
              --navigation-probe $<TARGET_FILE:smartcut-av1-mp4-navigation-probe>
              --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
              --stock-avcodec ${SMARTCUT_TEST_STOCK_AVCODEC}
              --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/av1-indexing-proof)
            set_tests_properties(smartcut-av1-indexing-proof PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          endif()
          add_test(NAME smartcut-navigation-vfr COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-navigation-vfr.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --timing-proof $<TARGET_FILE:smartcut-navigation-timing-proof-test>
            --av1-proof $<TARGET_FILE:smartcut-av1-packet-mapping-test>
            --navigation-probe $<TARGET_FILE:smartcut-av1-mp4-navigation-probe>
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/navigation-vfr)
          set_tests_properties(smartcut-navigation-vfr PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          add_test(NAME smartcut-av1-mp4-navigation COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-av1-mp4-navigation.py
            --worker $<TARGET_FILE:smartcut-worker-test>
            --cli $<TARGET_FILE:smartcut-cli-test>
            --probe $<TARGET_FILE:smartcut-av1-mp4-navigation-probe>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/av1-mp4-navigation)
          set_tests_properties(smartcut-av1-mp4-navigation PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          add_test(NAME smartcut-h264-mp4-navigation COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-h264-mp4-navigation.py
            --worker $<TARGET_FILE:smartcut-worker-test>
            --probe $<TARGET_FILE:smartcut-av1-mp4-navigation-probe>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/h264-mp4-navigation)
          set_tests_properties(smartcut-h264-mp4-navigation PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          add_test(NAME smartcut-smart-render-progress COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/scripts/test-smart-render-progress.py
            --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
            --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/smart-render-progress)
          set_tests_properties(smartcut-smart-render-progress PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          add_test(NAME smartcut-timeline-indicators COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/dependencies/scripts/test-timeline-indicators.py
            ${CMAKE_CURRENT_BINARY_DIR} ${SMARTCUT_MEDIA_ROOT} ${SMARTCUT_TEST_FFMPEG})
          set_tests_properties(smartcut-timeline-indicators PROPERTIES TIMEOUT 180 RUN_SERIAL TRUE)
          add_test(NAME smartcut-customer-suggestions COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/dependencies/scripts/test-customer-suggestions.py
            ${CMAKE_CURRENT_BINARY_DIR} ${SMARTCUT_MEDIA_ROOT} ${SMARTCUT_TEST_FFMPEG} ${SMARTCUT_TEST_FFPROBE})
          set_tests_properties(smartcut-customer-suggestions PROPERTIES TIMEOUT 240 RUN_SERIAL TRUE)
          add_test(NAME smartcut-preview-session COMMAND ${Python3_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/dependencies/scripts/test-preview-session.py
            --tester $<TARGET_FILE:smartcut-preview-session-test>
            --ffmpeg ${SMARTCUT_TEST_FFMPEG} --ffprobe ${SMARTCUT_TEST_FFPROBE}
            --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/preview-session)
          set_tests_properties(smartcut-preview-session PROPERTIES TIMEOUT 600 RUN_SERIAL TRUE)
          if(WIN32 AND TARGET smartcut-gpu-preview-test)
            add_test(NAME smartcut-gpu-direct-preview COMMAND ${Python3_EXECUTABLE}
              ${CMAKE_SOURCE_DIR}/dependencies/scripts/test-gpu-preview.py
              --tester $<TARGET_FILE:smartcut-gpu-preview-test>
              --worker $<TARGET_FILE:smartcut-worker-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
              --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/gpu-direct-preview)
            set_tests_properties(smartcut-gpu-direct-preview PROPERTIES TIMEOUT 600 RUN_SERIAL TRUE LABELS "gpu;native-display")
            add_test(NAME smartcut-gui-gpu-preview COMMAND ${Python3_EXECUTABLE}
              ${CMAKE_SOURCE_DIR}/dependencies/scripts/test-gui-gpu-preview.py
              --gui $<TARGET_FILE:smartcut-gui-test> --ffmpeg ${SMARTCUT_TEST_FFMPEG}
              --output ${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-gpu-preview)
            set_tests_properties(smartcut-gui-gpu-preview PROPERTIES TIMEOUT 600 RUN_SERIAL TRUE LABELS "gpu;native-display")
          endif()
        endif()
        add_test(NAME smartcut-source-aware-recode COMMAND ${CMAKE_COMMAND}
          -DWORKER=$<TARGET_FILE:smartcut-worker-test>
          -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
          -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results/source-aware-recode
          -P ${CMAKE_SOURCE_DIR}/cmake/source-aware-recode-gate.cmake)
        set_tests_properties(smartcut-source-aware-recode PROPERTIES TIMEOUT 120)
        add_test(NAME smartcut-preview-software-fallback COMMAND ${CMAKE_COMMAND}
          -DWORKER=$<TARGET_FILE:smartcut-worker-test>
          -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
          -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results/preview-fallback
          -P ${CMAKE_SOURCE_DIR}/cmake/preview-fallback-gate.cmake)
        set_tests_properties(smartcut-preview-software-fallback PROPERTIES TIMEOUT 60)
        add_test(NAME smartcut-frame-navigation-cadence COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
          -File ${CMAKE_SOURCE_DIR}/cmake/frame-navigation-cadence-gate.ps1
          -Worker $<TARGET_FILE:smartcut-worker-test>
          -Ffmpeg ${SMARTCUT_TEST_FFMPEG}
          -WorkDir ${CMAKE_CURRENT_BINARY_DIR}/test-results/frame-navigation-cadence
          -MediaBin ${SMARTCUT_MEDIA_ROOT}/bin
          -MingwBin ${SMARTCUT_MINGW_RUNTIME_ROOT}/bin)
        set_tests_properties(smartcut-frame-navigation-cadence PROPERTIES TIMEOUT 120)
        add_test(NAME smartcut-gui-coarse-timebase-seeking COMMAND ${CMAKE_COMMAND}
          -DGUI=$<TARGET_FILE:smartcut-gui-test>
          -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
          -DFFPROBE=${SMARTCUT_TEST_FFPROBE}
          -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results/coarse-timebase-seeking
          -P ${CMAKE_SOURCE_DIR}/cmake/coarse-timebase-seeking-gate.cmake)
        set_tests_properties(smartcut-gui-coarse-timebase-seeking PROPERTIES TIMEOUT 120 RUN_SERIAL TRUE)
        add_test(NAME smartcut-chapters-aspect-regression COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
          -File ${CMAKE_SOURCE_DIR}/cmake/chapter-aspect-gate.ps1
          -Worker $<TARGET_FILE:smartcut-worker-test>
          -Gui $<TARGET_FILE:smartcut-gui-test>
          -Ffmpeg ${SMARTCUT_TEST_FFMPEG}
          -WorkDir ${CMAKE_CURRENT_BINARY_DIR}/test-results/chapters-aspect
          -MediaBin ${SMARTCUT_MEDIA_ROOT}/bin
          -MingwBin ${SMARTCUT_MINGW_RUNTIME_ROOT}/bin)
        set_tests_properties(smartcut-chapters-aspect-regression PROPERTIES TIMEOUT 240)
        foreach(SMARTCUT_MAKEMKV_CASE IN ITEMS exports metadata diagnostics recovery)
          add_test(NAME smartcut-makemkv-${SMARTCUT_MAKEMKV_CASE} COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
            -File ${CMAKE_SOURCE_DIR}/cmake/makemkv-export-gate.ps1
            -Worker $<TARGET_FILE:smartcut-worker-test>
            -Cli $<TARGET_FILE:smartcut-cli-test>
            -Gui $<TARGET_FILE:smartcut-gui-test>
            -Ffmpeg ${SMARTCUT_TEST_FFMPEG}
            -WorkDir ${CMAKE_CURRENT_BINARY_DIR}/test-results/makemkv-export
            -MediaBin ${SMARTCUT_MEDIA_ROOT}/bin
            -MingwBin ${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
            -Case ${SMARTCUT_MAKEMKV_CASE})
          set_tests_properties(smartcut-makemkv-${SMARTCUT_MAKEMKV_CASE} PROPERTIES TIMEOUT 120)
        endforeach()
        add_test(NAME smartcut-boundary-timestamp-gap COMMAND ${CMAKE_COMMAND}
          -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
          -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
          -DSOURCE=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-timestamp-gap-source.mkv
          -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-timestamp-gap-output.mkv
          -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results
          -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
          -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
          -P ${CMAKE_SOURCE_DIR}/cmake/boundary-timestamp-gap-gate.cmake)
        set_tests_properties(smartcut-boundary-timestamp-gap PROPERTIES TIMEOUT 60)
        add_test(NAME smartcut-boundary-timestamp-reset COMMAND ${CMAKE_COMMAND}
          -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
          -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
          -DSOURCE=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-timestamp-reset-source.ts
          -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-timestamp-reset-output.mkv
          -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results
          -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
          -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
          -P ${CMAKE_SOURCE_DIR}/cmake/boundary-timestamp-reset-gate.cmake)
        set_tests_properties(smartcut-boundary-timestamp-reset PROPERTIES TIMEOUT 60)
        add_test(NAME smartcut-boundary-pts-outlier COMMAND ${CMAKE_COMMAND}
          -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
          -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
          -DSOURCE=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-pts-outlier-source.mp4
          -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-pts-outlier-output.mkv
          -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results
          -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
          -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
          -P ${CMAKE_SOURCE_DIR}/cmake/boundary-pts-outlier-gate.cmake)
        set_tests_properties(smartcut-boundary-pts-outlier PROPERTIES TIMEOUT 60)
        add_test(NAME smartcut-boundary-attached-picture COMMAND ${CMAKE_COMMAND}
          -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
          -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
          -DSOURCE=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-attached-picture-source.mp4
          -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/boundary-attached-picture-output.mkv
          -DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results
          -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
          -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
          -P ${CMAKE_SOURCE_DIR}/cmake/boundary-attached-picture-gate.cmake)
        set_tests_properties(smartcut-boundary-attached-picture PROPERTIES TIMEOUT 60)
      endif()
      add_test(NAME smartcut-boundary-join COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/m7-join-gate
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/boundary-join-gate.cmake)
      add_test(NAME smartcut-nonkey-smart-export COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/nonkey-smart-export.mkv
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/nonkey-smart-export-gate.cmake)
      add_test(NAME smartcut-mpeg2-safe-end-copy COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_MPEG2_SAFE_END_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/mpeg2-safe-end
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/mpeg2-safe-end-gate.cmake)
      add_test(NAME smartcut-hdr10-boundary COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/m8-hdr10-gate
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/hdr10-boundary-gate.cmake)
      add_test(NAME smartcut-hdr10plus-boundary COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/m9-hdr10plus-gate
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/hdr10plus-boundary-gate.cmake)
      add_test(NAME smartcut-hlg-high-chroma-captions COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/hlg-high-chroma-caption-gate
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/hlg-high-chroma-caption-gate.cmake)
      add_test(NAME smartcut-subtitle-conversion COMMAND ${CMAKE_COMMAND}
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/subtitle-conversion-gate
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/subtitle-conversion-gate.cmake)
      add_test(NAME smartcut-dolby-e-bridge COMMAND ${CMAKE_COMMAND}
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/dolby-e-bridge-gate
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/dolby-e-bridge-gate.cmake)
      if(EXISTS "${SMARTCUT_DOVI_FIXTURE}" AND EXISTS "${SMARTCUT_MEDIA_ROOT}/bin/dovi_tool.exe")
      add_test(NAME smartcut-dovi-p81-boundary COMMAND ${CMAKE_COMMAND}
          -DWORKER=$<TARGET_FILE:smartcut-worker-test>
          -DFFMPEG=${SMARTCUT_TEST_FFMPEG}
          -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
          -DINPUT=${SMARTCUT_DOVI_FIXTURE}
          -DDOVI_TOOL=${SMARTCUT_MEDIA_ROOT}/bin/dovi_tool.exe
          -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/m10-dovi-p81-gate
          -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
          -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
          -P ${CMAKE_SOURCE_DIR}/cmake/dovi-p81-boundary-gate.cmake)
      endif()
      add_test(NAME smartcut-m11-multitrack-copy COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/m11-multitrack-copy
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/m11-multitrack-copy-gate.cmake)
      add_test(NAME smartcut-m11-timed-range COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/m11-timed-range
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/m11-timed-range-gate.cmake)
      add_test(NAME smartcut-seek-stress COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-cli-test>
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -DINPUT=${SMARTCUT_AV_FIXTURE}
        -DITERATIONS=10000
        -P ${CMAKE_SOURCE_DIR}/cmake/run-seek-stress.cmake)
      add_test(NAME smartcut-gui-project-summary-smoke COMMAND ${CMAKE_COMMAND}
        -DGUI=$<TARGET_FILE:smartcut-gui-test>
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DSOURCE=${SMARTCUT_AV_FIXTURE}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DQT_BIN=${CMAKE_PREFIX_PATH}/bin
        -DREPORT_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results
        -P ${CMAKE_SOURCE_DIR}/cmake/gui-project-smoke.cmake)
      add_test(NAME smartcut-gui-blocked-export-smoke COMMAND ${CMAKE_COMMAND}
        -DGUI=$<TARGET_FILE:smartcut-gui-test>
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DSOURCE=${SMARTCUT_AV_FIXTURE}
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DQT_BIN=${CMAKE_PREFIX_PATH}/bin
        -DREPORT_DIR=${CMAKE_CURRENT_BINARY_DIR}/test-results
        -DBLOCKED=1
        -P ${CMAKE_SOURCE_DIR}/cmake/gui-project-smoke.cmake)
      add_test(NAME smartcut-gui-smoke-invalid-probe COMMAND ${CMAKE_COMMAND}
        -DTEST_SCRIPT=${CMAKE_SOURCE_DIR}/cmake/gui-project-smoke.cmake
        -P ${CMAKE_SOURCE_DIR}/cmake/expect-smoke-generator-failure.cmake)
      add_test(NAME smartcut-gui-smoke-invalid-identity COMMAND ${CMAKE_COMMAND}
        -DTEST_SCRIPT=${CMAKE_SOURCE_DIR}/cmake/gui-project-smoke.cmake
        -DIDENTITY=1
        -P ${CMAKE_SOURCE_DIR}/cmake/expect-smoke-generator-failure.cmake)
      add_test(NAME smartcut-gui-smoke-invalid-summary COMMAND ${CMAKE_COMMAND}
        -DTEST_SCRIPT=${CMAKE_SOURCE_DIR}/cmake/gui-project-smoke.cmake
        -DSUMMARY=1
        -P ${CMAKE_SOURCE_DIR}/cmake/expect-smoke-generator-failure.cmake)
      add_test(NAME smartcut-gui-probe-contract-release-gate COMMAND ${CMAKE_COMMAND}
        -DREPORT=${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-probe-contract.json
        -P ${CMAKE_SOURCE_DIR}/cmake/check-probe-contract.cmake)
      set_tests_properties(smartcut-gui-probe-contract-release-gate PROPERTIES DEPENDS smartcut-gui-project-summary-smoke)
      add_test(NAME smartcut-gui-release-summary-gate COMMAND ${CMAKE_COMMAND}
        -DSUMMARY=${CMAKE_CURRENT_BINARY_DIR}/test-results/gui-probe-contract.json.release-summary.json
        -P ${CMAKE_SOURCE_DIR}/cmake/check-release-summary.cmake)
      set_tests_properties(smartcut-gui-release-summary-gate PROPERTIES DEPENDS smartcut-gui-probe-contract-release-gate)
      add_test(NAME smartcut-m12-gui-plan-equivalence COMMAND ${CMAKE_COMMAND}
        -DGUI=$<TARGET_FILE:smartcut-gui-test>
        -DCLI=$<TARGET_FILE:smartcut-cli-test>
        -DSOURCE=${SMARTCUT_AV_FIXTURE}
        -DOUTPUT_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test-results/m12-gui
        -DPROGRAM_BIN=$<TARGET_FILE_DIR:smartcut-worker>
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -DQT_BIN=${CMAKE_PREFIX_PATH}/bin
        -P ${CMAKE_SOURCE_DIR}/cmake/m12-gui-plan-gate.cmake)
      add_test(NAME smartcut-m13-failure-fuzz COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
        -File ${CMAKE_SOURCE_DIR}/cmake/m13-failure-fuzz-gate.ps1
        -Worker $<TARGET_FILE:smartcut-worker-test>
        -Gui $<TARGET_FILE:smartcut-gui-test>
        -Source ${SMARTCUT_AV_FIXTURE}
        -WorkDir ${CMAKE_CURRENT_BINARY_DIR}/test-results/m13-failure-fuzz
        -MediaBin ${SMARTCUT_MEDIA_ROOT}/bin
        -QtBin ${CMAKE_PREFIX_PATH}/bin
        -MingwBin ${SMARTCUT_MINGW_RUNTIME_ROOT}/bin)
      add_test(NAME smartcut-m13-appverifier COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
        -File ${CMAKE_SOURCE_DIR}/cmake/m13-appverifier-gate.ps1
        -Worker $<TARGET_FILE:smartcut-worker-test>
        -Source ${SMARTCUT_AV_FIXTURE}
        -Report ${CMAKE_CURRENT_BINARY_DIR}/test-results/m13-appverifier.xml
        -MediaBin ${SMARTCUT_MEDIA_ROOT}/bin
        -MingwBin ${SMARTCUT_MINGW_RUNTIME_ROOT}/bin)
      set_tests_properties(smartcut-m13-appverifier PROPERTIES SKIP_RETURN_CODE 125)
      add_test(NAME smartcut-m13-uhd-memory COMMAND powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass
        -File ${CMAKE_SOURCE_DIR}/cmake/m13-uhd-memory-gate.ps1
        -Cli $<TARGET_FILE:smartcut-cli-test>
        -Worker $<TARGET_FILE:smartcut-worker-test>
        -WorkDir ${CMAKE_CURRENT_BINARY_DIR}/test-results/m13-uhd-memory
        -MediaBin ${SMARTCUT_MEDIA_ROOT}/bin
        -MingwBin ${SMARTCUT_MINGW_RUNTIME_ROOT}/bin)
      find_program(SMARTCUT_FFPLAY ffplay PATHS "C:/ffmpeg_latest")
      if(SMARTCUT_FFPLAY)
        add_test(NAME smartcut-m13-ffplay-interoperability COMMAND ${CMAKE_COMMAND}
          -DCLI=$<TARGET_FILE:smartcut-cli-test>
          -DFFPLAY=${SMARTCUT_FFPLAY}
          -DSOURCE=${SMARTCUT_AV_FIXTURE}
          -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/test-results/m13-ffplay.mkv
          -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
          -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
          -P ${CMAKE_SOURCE_DIR}/cmake/m13-ffplay-gate.cmake)
      endif()
    endif()
    if(SMARTCUT_MEDIA_ROOT)
      add_test(NAME smartcut-project-validation-negative COMMAND ${CMAKE_COMMAND}
        -DPROGRAM=$<TARGET_FILE:smartcut-worker-test>
        -DMEDIA_BIN=${SMARTCUT_MEDIA_ROOT}/bin
        -DMINGW_BIN=${SMARTCUT_MINGW_RUNTIME_ROOT}/bin
        -DSOURCE=${SMARTCUT_AV_FIXTURE}
        -P ${CMAKE_SOURCE_DIR}/cmake/validate-project-negative.cmake)
      add_test(NAME smartcut-project-journal-recovery COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -DJOURNAL=${CMAKE_CURRENT_BINARY_DIR}/test-results/project-recovery.journal
        -P ${CMAKE_SOURCE_DIR}/cmake/project-journal-gate.cmake)
    endif()
  endif()
endif()

if(MSVC AND SMARTCUT_ENABLE_SANITIZERS)
  file(GLOB SMARTCUT_ASAN_RUNTIME_CANDIDATES
    "$ENV{VCToolsInstallDir}/bin/Hostx64/x64/clang_rt.asan_dynamic-x86_64.dll"
    "C:/Program Files/Microsoft Visual Studio/*/*/VC/Tools/MSVC/*/bin/Hostx64/x64/clang_rt.asan_dynamic-x86_64.dll")
  if(NOT SMARTCUT_ASAN_RUNTIME_CANDIDATES)
    message(FATAL_ERROR "MSVC AddressSanitizer runtime was not found")
  endif()
  list(SORT SMARTCUT_ASAN_RUNTIME_CANDIDATES COMPARE NATURAL ORDER DESCENDING)
  list(GET SMARTCUT_ASAN_RUNTIME_CANDIDATES 0 SMARTCUT_ASAN_RUNTIME)
  get_filename_component(SMARTCUT_ASAN_RUNTIME_DIR "${SMARTCUT_ASAN_RUNTIME}" DIRECTORY)
  get_property(SMARTCUT_ASAN_TESTS DIRECTORY PROPERTY TESTS)
  if(SMARTCUT_ASAN_TESTS)
    set_tests_properties(${SMARTCUT_ASAN_TESTS} PROPERTIES
      ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${SMARTCUT_ASAN_RUNTIME_DIR}")
  endif()
endif()

