cmake_minimum_required(VERSION 3.18)
project(ntsc_encoder LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
find_package(OpenCV REQUIRED)

# NOTE: wrapper.cpp currently includes encoder.cpp, so encoder.cpp must NOT be
# compiled as a separate translation unit (otherwise you get duplicate symbols).
pybind11_add_module(ntsc_encoder src/wrapper.cpp)

target_link_libraries(ntsc_encoder PRIVATE ${OpenCV_LIBS})

# scikit-build-core builds wheels from CMake install() output.
# The extension must be installed into the Python platlib directory.
# (SKBUILD_PLATLIB_DIR is provided by scikit-build-core during builds.)
if (DEFINED SKBUILD_PLATLIB_DIR)
  set(_PY_PLATLIB_DIR "${SKBUILD_PLATLIB_DIR}")
else()
  # Fallback for manual CMake builds.
  set(_PY_PLATLIB_DIR ".")
endif()

install(TARGETS ntsc_encoder
  LIBRARY DESTINATION "${_PY_PLATLIB_DIR}"
  RUNTIME DESTINATION "${_PY_PLATLIB_DIR}"
)
