cmake_minimum_required(VERSION 3.24)
project(veyra_remoteplay_core_probe LANGUAGES CXX)
include(CTest)
find_package(Threads REQUIRED)
get_filename_component(VEYRA_ROOT "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
option(VEYRA_RP_SANITIZERS "Enable AddressSanitizer and UndefinedBehaviorSanitizer" OFF)
option(VEYRA_RP_BUILD_NATIVE "Build the REAL pinned Chiaki adapter (requires dependencies)" OFF)
if(VEYRA_RP_BUILD_NATIVE)
    include("${VEYRA_ROOT}/cmake/VeyraRemotePlay.cmake")
else()
add_library(veyra_remoteplay_core STATIC
    "${VEYRA_ROOT}/src/remoteplay/Validation.cpp"
    "${VEYRA_ROOT}/src/remoteplay/AnnexB.cpp"
    "${VEYRA_ROOT}/src/remoteplay/Timeline.cpp"
    "${VEYRA_ROOT}/src/remoteplay/VideoIngress.cpp"
    "${VEYRA_ROOT}/src/remoteplay/SessionInbox.cpp")
target_include_directories(veyra_remoteplay_core PUBLIC "${VEYRA_ROOT}/include")
target_compile_features(veyra_remoteplay_core PUBLIC cxx_std_20)
set_target_properties(veyra_remoteplay_core PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(veyra_remoteplay_core PUBLIC Threads::Threads)
endif()
if(MSVC)
    target_compile_options(veyra_remoteplay_core PUBLIC /utf-8 /W4 /WX /permissive-)
else()
    target_compile_options(veyra_remoteplay_core PUBLIC -Wall -Wextra -Wpedantic -Wconversion -Wshadow -Werror)
    if(VEYRA_RP_SANITIZERS)
        target_compile_options(veyra_remoteplay_core PUBLIC -fsanitize=address,undefined -fno-omit-frame-pointer)
        target_link_options(veyra_remoteplay_core PUBLIC -fsanitize=address,undefined)
    endif()
endif()
add_executable(veyra_remoteplay_core_tests "${VEYRA_ROOT}/tests/remoteplay/CoreTests.cpp")
target_link_libraries(veyra_remoteplay_core_tests PRIVATE veyra_remoteplay_core)
# Deliberately no NVIDIA/FFmpeg/Win32 dependency in these tests. A pass here does
# NOT establish native Chiaki compilation, video decoding, PS5 connection or latency.
file(STRINGS "${VEYRA_ROOT}/tests/remoteplay/CoreTests.cpp" TEST_DECLS REGEX "^TEST\\([A-Za-z0-9_]+\\)")
foreach(DECL IN LISTS TEST_DECLS)
    string(REGEX MATCH "^TEST\\(([A-Za-z0-9_]+)\\)" _match "${DECL}")
    set(NAME "${CMAKE_MATCH_1}")
    add_test(NAME "rp.${NAME}" COMMAND veyra_remoteplay_core_tests --case "${NAME}")
    set_tests_properties("rp.${NAME}" PROPERTIES TIMEOUT 30 LABELS "offline-core")
endforeach()
if(VEYRA_RP_BUILD_NATIVE)
    include("${CMAKE_CURRENT_LIST_DIR}/NativeChiaki.cmake")
endif()
