cmake_minimum_required(VERSION 3.20)
project(gow_port CXX C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(MSVC)
  add_compile_options(/W4 /utf-8)
  add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)
endif()

# --- building something other people can download ---------------------
# GOW_VERSION is what the launcher prints in its corner: a local build stays "-dev" (no update
# checks); the release workflow passes the git tag with its "gow-v" prefix stripped.
set(GOW_VERSION "0.1.0-dev" CACHE STRING "Version string shown by the launcher")
set(GOW_UPDATE_OWNER "samioan" CACHE STRING "GitHub owner to check for updates")
set(GOW_UPDATE_REPO "gow-betrayal-remastered" CACHE STRING "GitHub repo to check for updates")
set(GOW_UPDATE_TAG_PREFIX "gow-v" CACHE STRING "Release tag prefix identifying a God of War: Betrayal build")
# The shipping build: only the launcher and the game.
option(GOW_DIST "Build only the shipped executables (launcher + game)" OFF)
# Static CRT so "unzip and play" needs no Visual C++ redistributable.
if(MSVC)
  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

add_library(stb_image STATIC third_party/stb/stb_image_impl.cpp)
target_include_directories(stb_image PUBLIC third_party/stb)
add_library(puff STATIC third_party/puff/puff.c)
target_include_directories(puff PUBLIC third_party/puff)
if(MSVC)
  target_compile_options(stb_image PRIVATE /W3)
  target_compile_options(puff PRIVATE /W3)
endif()

# The runtime (Java shims, software renderer, resource banks, the hand-ported Engine and Scene) plus
# the game classes generated by tools/java2cpp.py into src/gen/ (regenerate with `python tools/java2cpp.py`).
file(GLOB GEN_SRC CONFIGURE_DEPENDS src/gen/*.cpp)
add_library(gow_core STATIC src/engine.cpp src/scene.cpp src/gfx.cpp src/jrt.cpp src/platform.cpp ${GEN_SRC})
target_include_directories(gow_core PUBLIC src)
target_link_libraries(gow_core PUBLIC stb_image dbghelp winmm shell32)

# The game: a software-rendered raw Win32 shell (no SDL/D3D/GL dependency) around the translated game.
add_executable(gow_port WIN32 src/main.cpp src/input.cpp src/display.cpp)
target_link_libraries(gow_port PRIVATE gow_core shell32 winmm dbghelp xinput)

# --- the launcher -------------------------------------------------------
# What a downloaded zip opens: picks and unpacks the user's own .jar, runs the game, and updates itself
# from GitHub releases. See src/launcher/. Artwork (assets/banner.png, gow.ico) is generated from
# assets/banner_source.png by tools/make_banner.py and tools/make_icon.py.
configure_file(src/launcher/version.h.in "${CMAKE_BINARY_DIR}/generated/launcher/version.h" @ONLY)
add_executable(gow_launcher WIN32
  src/launcher/launcher_main.cpp
  src/launcher/banner.cpp
  src/launcher/install.cpp
  src/launcher/launcher_config.cpp
  src/launcher/update_check.cpp
  src/launcher/updater.cpp
  src/launcher/zip_reader.cpp
  src/platform/win32/exe_dir.cpp
  src/launcher/launcher.rc
)
set_target_properties(gow_launcher PROPERTIES OUTPUT_NAME "GodOfWar")
target_include_directories(gow_launcher PRIVATE src "${CMAKE_BINARY_DIR}/generated")
target_link_libraries(gow_launcher PRIVATE stb_image puff comctl32 ole32 winhttp)
target_compile_definitions(gow_launcher PRIVATE UNICODE _UNICODE)
if(MSVC)
  target_link_options(gow_launcher PRIVATE /MANIFEST:NO)
endif()
