# [openmw-ja-port-module]
#
# Convenience CMake glue for the Japanese fork. Adds two custom targets:
#
#   * japort_audit            -> runs scripts/japort_audit.py once.
#                                Returns non-zero on any drift.
#   * japort_check_upstream   -> runs scripts/japort_check_upstream.py.
#                                Compares hook-target files against an
#                                upstream OpenMW checkout to flag the
#                                files most likely to merge-conflict.
#
# Neither target is part of ALL; both are opt-in so upstream builds are
# unaffected. Invoke with:
#
#   cmake --build . --target japort_audit
#   cmake --build . --target japort_check_upstream -- -DUPSTREAM_DIR=/path
#
# This file is intentionally tiny so future merges only have to keep
# `include(JapanesePortAudit)` near the bottom of the top-level
# CMakeLists.txt.

find_package(Python3 COMPONENTS Interpreter)

if (NOT Python3_FOUND)
    message(STATUS "[japort] Python3 not found - japort_* targets disabled")
    return()
endif()

set(_JAPORT_SCRIPT_DIR "${CMAKE_SOURCE_DIR}/scripts")

add_custom_target(japort_audit
    COMMAND "${Python3_EXECUTABLE}" "${_JAPORT_SCRIPT_DIR}/japort_audit.py"
            --root "${CMAKE_SOURCE_DIR}"
    WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
    COMMENT "[japort] Auditing Japanese-fork markers / manifest / deprecated keys"
    USES_TERMINAL
    VERBATIM
)

add_custom_target(japort_check_upstream
    COMMAND "${Python3_EXECUTABLE}" "${_JAPORT_SCRIPT_DIR}/japort_check_upstream.py"
            --root "${CMAKE_SOURCE_DIR}"
    WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
    COMMENT "[japort] Diffing JP-fork hook targets against upstream checkout"
    USES_TERMINAL
    VERBATIM
)

add_custom_target(japort_test
    COMMAND "${Python3_EXECUTABLE}" -m unittest discover -s
            "${_JAPORT_SCRIPT_DIR}/tests" -v
    WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
    COMMENT "[japort] Running manifest / source consistency tests"
    USES_TERMINAL
    VERBATIM
)
