cmake_minimum_required(VERSION 3.25)
project(rexglue_diagnostic LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(rexglue CONFIG REQUIRED)
set(REXGLUE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../upstream/rexglue" CACHE PATH "Pinned patched SDK source")
function(rex_target_pch target header)
  target_precompile_headers(${target} PRIVATE "${header}")
endfunction()
function(rex_config_postfix target)
endfunction()
function(rexglue_add_version_resource target)
endfunction()
add_library(rexruntime ALIAS rex::runtime)
add_library(disasm ALIAS rex::disasm)
add_library(tomlplusplus ALIAS rex::tomlplusplus)
add_library(simde ALIAS rex::simde)
add_library(xxHash::xxhash ALIAS rex::xxhash)
add_compile_options(-fno-strict-aliasing -ffp-model=strict -fno-char8_t)
add_subdirectory(${REXGLUE_ROOT}/src/codegen codegen)
add_subdirectory(${REXGLUE_ROOT}/src/rexglue cli)
add_executable(gap_cleanup_test gap_cleanup_test.cpp)
target_link_libraries(gap_cleanup_test PRIVATE rexcodegen)
target_include_directories(gap_cleanup_test PRIVATE ${REXGLUE_ROOT}/src/codegen)
enable_testing()
add_test(NAME gap_cleanup_differential COMMAND gap_cleanup_test)
execute_process(COMMAND git show bd833a2ab69d305f99ddf57418fc38ffec8af93d:src/codegen/function_graph.cpp
  WORKING_DIRECTORY "${REXGLUE_ROOT}"
  OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/reference_function_graph.cpp"
  COMMAND_ERROR_IS_FATAL ANY)
foreach(variant indexed reference)
  add_executable(notification_${variant}_test notification_test.cpp)
  target_link_libraries(notification_${variant}_test PRIVATE rexcodegen)
  target_include_directories(notification_${variant}_test PRIVATE
    ${REXGLUE_ROOT}/src/codegen ${REXGLUE_ROOT}/thirdparty/disasm)
endforeach()
target_sources(notification_reference_test PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/reference_function_graph.cpp")
find_package(Python3 COMPONENTS Interpreter REQUIRED)
add_test(NAME notification_differential COMMAND ${Python3_EXECUTABLE}
  "${CMAKE_CURRENT_SOURCE_DIR}/compare_notifications.py"
  $<TARGET_FILE:notification_indexed_test> $<TARGET_FILE:notification_reference_test>)
