cmake_minimum_required(VERSION 3.20)
project(ISS2000 VERSION 0.7.1 LANGUAGES C CXX)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(ISS2000_N64RECOMP_SOURCE "" CACHE PATH "Pinned N64Recomp source checkout")
set(ISS2000_GENERATED "${CMAKE_SOURCE_DIR}/.local/boot/functions" CACHE PATH "Private generated original boot source")
if(NOT EXISTS "${ISS2000_N64RECOMP_SOURCE}/include/recomp.h")
  message(FATAL_ERROR "Set ISS2000_N64RECOMP_SOURCE to the pinned checkout")
endif()
if(NOT EXISTS "${ISS2000_GENERATED}/funcs_0.c")
  message(FATAL_ERROR "Generate the original boot diagnostic with python3 -m tools.recompile first")
endif()
add_executable(iss2000-diagnostic src/diagnostic.cpp "${ISS2000_GENERATED}/funcs_0.c")
target_include_directories(iss2000-diagnostic PRIVATE
  "${ISS2000_N64RECOMP_SOURCE}/include" "${ISS2000_GENERATED}")
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
  set_source_files_properties("${ISS2000_GENERATED}/funcs_0.c" PROPERTIES COMPILE_OPTIONS "-fexceptions")
endif()
enable_testing()
add_test(NAME original_entry_diagnostic COMMAND iss2000-diagnostic)
add_test(NAME rejects_unknown_continuation COMMAND iss2000-diagnostic --reject-continuation)
set_tests_properties(rejects_unknown_continuation PROPERTIES WILL_FAIL TRUE)

option(ISS2000_BUILD_GAME "Build the native development game launcher" OFF)
if(ISS2000_BUILD_GAME)
  include(cmake/game.cmake)
endif()
