cmake_minimum_required(VERSION 3.24)
project(vtour_capture_recorder LANGUAGES CXX)
find_package(Threads REQUIRED)
if(APPLE)
  enable_language(OBJCXX)
  add_library(vtour_capture_recorder SHARED capture.cpp capture_mac.mm)
else()
  add_library(vtour_capture_recorder SHARED capture.cpp)
endif()
target_compile_features(vtour_capture_recorder PRIVATE cxx_std_17)
target_compile_definitions(vtour_capture_recorder PRIVATE CAPTURE_BUILD)
target_link_libraries(vtour_capture_recorder PRIVATE Threads::Threads)
set_target_properties(vtour_capture_recorder PROPERTIES PREFIX "" OUTPUT_NAME "screen-capture" CXX_VISIBILITY_PRESET hidden)
if(WIN32)
  target_compile_definitions(vtour_capture_recorder PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0602)
  target_link_libraries(vtour_capture_recorder PRIVATE mfplat mfreadwrite mfuuid ole32 windowscodecs user32 gdi32)
endif()
if(APPLE)
  # macOS backend: ScreenCaptureKit (screen frames), AVFoundation (H.264 MP4),
  # ImageIO (PNG). All are system frameworks.
  set_source_files_properties(capture_mac.mm PROPERTIES COMPILE_OPTIONS "-fobjc-arc")
  set_target_properties(vtour_capture_recorder PROPERTIES OBJCXX_STANDARD 17 OBJCXX_STANDARD_REQUIRED ON)
  target_link_libraries(vtour_capture_recorder PRIVATE
    "-framework ScreenCaptureKit" "-framework AVFoundation" "-framework CoreMedia"
    "-framework CoreVideo" "-framework CoreGraphics" "-framework ImageIO" "-framework Foundation")
endif()
