﻿cmake_minimum_required(VERSION 3.25)
project(SmartCut64 VERSION 1.0.3 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_REQUIRE_TEST_FFMPEG
  "Fail configuration when the external FFmpeg regression-fixture generator is unavailable" 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")

if(SMARTCUT_MEDIA_ROOT AND NOT MINGW)
  message(FATAL_ERROR "The pinned M1 media artifacts use the MinGW/UCRT ABI; clear SMARTCUT_MEDIA_ROOT for MSVC builds")
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)
  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()
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/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/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_include_directories(smartcut-core PUBLIC src "${CMAKE_CURRENT_BINARY_DIR}/generated")
if(WIN32)
  target_link_libraries(smartcut-core PUBLIC bcrypt advapi32)
endif()
if(SMARTCUT_MEDIA_ROOT)
  target_include_directories(smartcut-core 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(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)
  add_executable(smartcut-gui WIN32 src/gui/main.cpp src/gui/resources.qrc)
  target_sources(smartcut-gui PRIVATE src/gui/license_manager.cpp)
  target_include_directories(smartcut-gui PRIVATE src)
  target_link_libraries(smartcut-gui PRIVATE Qt6::Widgets Qt6::Network smartcut-core)
  if(WIN32)
    target_link_libraries(smartcut-gui PRIVATE winmm crypt32 dwmapi)
  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()
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)
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(EXISTS "${CMAKE_SOURCE_DIR}/dependencies/sbom.m1.json")
  install(FILES "${CMAKE_SOURCE_DIR}/dependencies/sbom.m1.json" 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(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()
set(SMARTCUT_DEPENDENCY_SOURCE_ROOT "${CMAKE_SOURCE_DIR}/build/dependencies-m1/source")
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 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()
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")
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS [[
  WriteRegStr HKCU "Software\Classes\.smartcut" "" "SmartCut64.Project"
  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"'
  WriteRegStr HKCU "Software\Classes\.scjoin" "" "SmartCut64.Joiner"
  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"'
  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"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.VPrj\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.VPrj\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.BPrj\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.BPrj\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.VJnr\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.VJnr\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.mkv\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.mkv\shell\SmartCut64" "Icon" "$INSTDIR\bin\smartcut-gui.exe,0"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.mkv\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.mp4\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.mp4\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.mov\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.mov\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.ts\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.ts\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.m2ts\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.m2ts\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.webm\shell\SmartCut64" "" "Open with SmartCut64"
  WriteRegStr HKCU "Software\Classes\SystemFileAssociations\.webm\shell\SmartCut64\command" "" '"$INSTDIR\bin\smartcut-gui.exe" "%1"'
  System::Call 'shell32::SHChangeNotify(i 0x08000000, i 0, p 0, p 0)'
]])
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS [[
  DeleteRegKey HKCU "Software\Classes\.smartcut"
  DeleteRegKey HKCU "Software\Classes\SmartCut64.Project"
  DeleteRegKey HKCU "Software\Classes\.scjoin"
  DeleteRegKey HKCU "Software\Classes\SmartCut64.Joiner"
  DeleteRegKey HKCU "Software\Classes\Applications\smartcut-gui.exe"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.VPrj\shell\SmartCut64"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.BPrj\shell\SmartCut64"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.VJnr\shell\SmartCut64"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.mkv\shell\SmartCut64"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.mp4\shell\SmartCut64"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.mov\shell\SmartCut64"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.ts\shell\SmartCut64"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.m2ts\shell\SmartCut64"
  DeleteRegKey HKCU "Software\Classes\SystemFileAssociations\.webm\shell\SmartCut64"
  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_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}")
string(REPLACE "\"" "\\\"" CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}")
include(CPack)

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(MINGW)
  smartcut_deploy_build_runtime(smartcut-cli-test)
  smartcut_deploy_build_runtime(smartcut-worker-test)
endif()
if(TARGET smartcut-gui)
  add_executable(smartcut-gui-test WIN32 src/gui/main.cpp src/gui/resources.qrc)
  target_sources(smartcut-gui-test PRIVATE src/gui/license_manager.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(WIN32)
    target_link_libraries(smartcut-gui-test PRIVATE winmm crypt32 dwmapi)
  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(MINGW)
    smartcut_deploy_build_runtime(smartcut-gui-test)
    smartcut_deploy_qt_runtime(smartcut-gui-test)
  endif()

  add_executable(smartcut-qt-tls-probe tests/qt_tls_probe.cpp)
  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(MINGW)
    smartcut_deploy_build_runtime(smartcut-qt-tls-probe)
    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)
target_link_libraries(smartcut-unit-tests PRIVATE smartcut-core)
if(MINGW)
  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)
  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-x64 COMMAND ${CMAKE_COMMAND}
    -DINPUT=$<TARGET_FILE:smartcut-cli>
    -P ${CMAKE_SOURCE_DIR}/cmake/assert-x64.cmake)
  add_test(NAME smartcut-worker-x64 COMMAND ${CMAKE_COMMAND}
    -DINPUT=$<TARGET_FILE:smartcut-worker>
    -P ${CMAKE_SOURCE_DIR}/cmake/assert-x64.cmake)
  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-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_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)
    set_tests_properties(smartcut-gui-navigation-stress PROPERTIES TIMEOUT 10)
    if(MINGW)
      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-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-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-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)
      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-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>
        -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)
      add_test(NAME smartcut-mpeg-program-stream-output COMMAND ${CMAKE_COMMAND}
        -DWORKER=$<TARGET_FILE:smartcut-worker-test>
        -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>
        -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-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-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>
        -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-media-joiner COMMAND ${CMAKE_COMMAND}
        -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)
      find_program(SMARTCUT_TEST_FFMPEG NAMES ffmpeg ffmpeg.exe PATHS "C:/ffmpeg_latest")
      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}")
        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}
          -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()
