
# =========================================================================
#  ReMoM — windowed Master of Magic.
# =========================================================================

add_executable(ReMoM ReMoM.c ReMoM_Init.c Automation_Driver.c)

add_custom_target(run_pre_build_task
    COMMAND ${CMAKE_COMMAND} -E echo "Running pre-build task..."
    COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/timestamp.txt"
    COMMENT "Updating timestamp file in binary directory"
    VERBATIM
)
add_dependencies(ReMoM run_pre_build_task)

set_target_properties(ReMoM PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Export dynamic symbols so STU_BRAK's POSIX backtrace prints function names
# instead of raw hex.  On GCC/Clang this is `-rdynamic`; on MSVC it is a no-op
# (dbghelp resolves symbols via the .pdb).  See doc/@Devel/Devel-Crash-Reports.md.
set_target_properties(ReMoM PROPERTIES ENABLE_EXPORTS ON)

if(USE_WIN32)
    target_compile_definitions(ReMoM PUBLIC _STU_WIN)
elseif(USE_SDL3)
    target_compile_definitions(ReMoM PUBLIC USE_SDL3)
endif()

if(USE_WIN32)
    set(_sdl_main_lib "")
elseif(USE_SDL3)
    set(_sdl_main_lib SDL3::SDL3)
else()
    set(_sdl_main_lib SDL2::SDL2)
endif()

target_link_libraries(ReMoM PUBLIC
    momlib
    MOX
    STU
    Platform
    ${_sdl_main_lib}
)

target_include_directories(ReMoM PUBLIC
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_SOURCE_DIR}/src
)

set_target_properties(ReMoM PROPERTIES
    VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:ReMoM>"
)
# Asset staging is handled once at the project level (see top-level CMakeLists.txt).



# =========================================================================
#  DeMoM — Driven Master of Magic (windowless).
#  Always built, always windowless.  Links Platform_Windowless directly so it
#  is not affected by which windowed backend the preset chose for ReMoM.
# =========================================================================

add_executable(DeMoM DeMoM.c ReMoM_Init.c Automation_Driver.c Game_Save_Dump.c)

set_target_properties(DeMoM PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Export dynamic symbols so STU_BRAK's POSIX backtrace prints function names
# instead of raw hex.  See ReMoM above and doc/@Devel/Devel-Crash-Reports.md.
set_target_properties(DeMoM PROPERTIES ENABLE_EXPORTS ON)

target_link_libraries(DeMoM PUBLIC
    momlib
    MOX
    STU
    Platform_Windowless
)

target_include_directories(DeMoM PUBLIC
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_SOURCE_DIR}/src
)

set_target_properties(DeMoM PROPERTIES
    VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:DeMoM>"
)
# Asset staging is handled once at the project level (see top-level CMakeLists.txt).
