find_package(ZLIB REQUIRED)
add_executable(arc arc.cpp)
target_link_libraries(arc PRIVATE ZLIB::ZLIB)

# lifttest: differential lifter tests against Unicorn (optional; needs unicorn
# and a tests.c generated by `x2recomp <game.exe> build/lifttest/tests.c`).
find_package(PkgConfig)
if(PkgConfig_FOUND)
  pkg_check_modules(UNICORN IMPORTED_TARGET unicorn)
endif()
set(X2_LIFTTEST_C ${CMAKE_BINARY_DIR}/lifttest/tests.c)
if(UNICORN_FOUND AND EXISTS ${X2_LIFTTEST_C})
  add_executable(lifttest lifttest.cpp ${X2_LIFTTEST_C})
  target_include_directories(lifttest PRIVATE ${CMAKE_SOURCE_DIR}/runtime/include)
  target_link_libraries(lifttest PRIVATE PkgConfig::UNICORN)
  set_source_files_properties(${X2_LIFTTEST_C} PROPERTIES COMPILE_OPTIONS "-w;-O1;-fwrapv")
endif()

add_executable(kofarc kofarc.cpp ${CMAKE_SOURCE_DIR}/runtime/src/txac.c)
# fxdump: list compiled D3DX effects (fx_2_0), e.g. the ones embedded in a game.exe
add_executable(fxdump fxdump.c ${CMAKE_SOURCE_DIR}/runtime/src/gfx/fx.c)
# offline shader translation over shaders saved with X2_SHADER_DUMP
add_executable(shadertest shadertest.c ${CMAKE_SOURCE_DIR}/runtime/src/gfx/sm3_glsl.c ${CMAKE_SOURCE_DIR}/runtime/src/gfx/hlsl_glsl.c
  ${CMAKE_SOURCE_DIR}/runtime/src/gfx/d3dasm.c)
target_link_libraries(shadertest PRIVATE m)
if(APPLE) # msl: compiled by the Metal compiler
  enable_language(OBJC)
  target_sources(shadertest PRIVATE shadertest_metal.m)
  target_link_libraries(shadertest PRIVATE "-framework Metal" "-framework Foundation")
endif()
target_link_libraries(fxdump PRIVATE m)

# retro_host: minimal libretro frontend for testing the core (desktop, needs SDL3)
find_package(SDL3 CONFIG QUIET)
if(SDL3_FOUND AND NOT WIN32) # dlopen: Linux and macOS
  add_executable(retro_host retro_host.c)
  target_link_libraries(retro_host PRIVATE SDL3::SDL3 ZLIB::ZLIB ${CMAKE_DL_LIBS})
  if(APPLE)
    target_link_libraries(retro_host PRIVATE "-framework OpenGL")
  endif()
endif()
