# gh6 - ReXGlue Recompiled Project
# Generated by: rexglue init
#
# This file is SDK-managed. Running 'rexglue migrate' will overwrite it.

cmake_minimum_required(VERSION 3.25)
project(gh6 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find ReXGlue SDK
# REXSDK env var takes precedence, otherwise search system paths
set(REXSDK_DIR "" CACHE PATH "Path to rexglue-sdk source tree")
if(REXSDK_DIR)
    add_subdirectory("${REXSDK_DIR}" rexglue-sdk)
else()
    # Check REXSDK env var for installed SDK path
    if(DEFINED ENV{REXSDK})
        list(PREPEND CMAKE_PREFIX_PATH $ENV{REXSDK})
    endif()
    find_package(rexglue QUIET CONFIG)
    if(NOT rexglue_FOUND)
        message(FATAL_ERROR
            "ReXGlue SDK not found. Either:\n"
            "  - Set REXSDK_DIR to the rexglue-sdk source tree (e.g. thirdparty/rexglue-sdk)\n"
            "  - Set the REXSDK environment variable to the installed SDK path\n"
            "  - Install the SDK package and ensure it is on CMAKE_PREFIX_PATH")
    endif()
endif()

# User source files
file( GLOB_RECURSE GH6_SOURCES src/*.cpp src/*.c)

# Include generated code if codegen has been run
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/generated/sources.cmake")
    include(generated/sources.cmake)
    list(APPEND GH6_SOURCES ${GENERATED_SOURCES})
endif()

if(WIN32)
    add_executable(gh6 WIN32 ${GH6_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/gh6.rc)
else()
    add_executable(gh6 ${GH6_SOURCES})
endif()

target_include_directories(gh6 PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/generated
)

target_link_libraries(gh6 PRIVATE
    rex::core
    rex::system
    rex::kernel
    rex::graphics
    rex::ui
)

target_compile_options(gh6 PRIVATE -msse2)

# Platform entry point, ReXApp source, and platform-specific settings
rexglue_configure_target(gh6)

# Codegen target - run 'cmake --build . --target gh6_codegen'
add_custom_target(gh6_codegen
    COMMAND $<TARGET_FILE:rex::rexglue> codegen ${CMAKE_CURRENT_SOURCE_DIR}/gh6_config.toml
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Generating recompiled code for gh6"
    VERBATIM
)