cmake_minimum_required(VERSION 3.20)
project(iggy-shim LANGUAGES CXX)

# Path to the neoLegacy checkout (for the public Iggy headers we implement).
set(NEOLEGACY_DIR "$ENV{HOME}/neoLegacy" CACHE PATH "neoLegacy source tree")
set(IGGY_INCLUDE "${NEOLEGACY_DIR}/Minecraft.Client/Windows64/Iggy/include")
set(RMLUI_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/RmlUi")
set(FREETYPE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/freetype")

# Built as a DLL with __RADINDLL__ so RADEXPFUNC resolves to dllexport —
# the exact linking model the original iggy_w64.dll used. The game links our
# import lib (iggy_shim_w64.lib) instead of RAD's. UI is rendered by RmlUi
# (a standard HTML/CSS game-UI library) driven through the game's GDraw D3D11
# backend, with FreeType + the game's own Mojangles.ttf for text.
add_library(iggy_shim SHARED
    src/iggy_api_core.cpp
    src/iggy_api_values.cpp
    src/scene_registry.cpp
    src/ui_renderer.cpp
    src/text_renderer.cpp
    src/raw_d3d.cpp
    src/rml_render.cpp
    src/rml_backend.cpp
)

target_include_directories(iggy_shim PRIVATE "${IGGY_INCLUDE}" src "${RMLUI_DIR}/Include")
target_compile_features(iggy_shim PRIVATE cxx_std_17)
target_compile_definitions(iggy_shim PRIVATE __RADINDLL__ RMLUI_STATIC_LIB)

if(MSVC OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    target_compile_options(iggy_shim PRIVATE /MT /EHsc /W3)
endif()

target_link_libraries(iggy_shim PRIVATE
    "${RMLUI_DIR}/build-w64/rmlui.lib"
    "${FREETYPE_DIR}/build-w64/freetype.lib"
)

set_target_properties(iggy_shim PROPERTIES OUTPUT_NAME "iggy_shim_w64" PREFIX "")
