cmake_minimum_required(VERSION 3.21)
project(GoW2Recomp VERSION 0.1.1 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ---------------------------------------------------------------------------
# Build stages
#   GOW2_BUILD_INSTALLER  - gow2-setup (no game data needed)
#   GOW2_BUILD_GAME       - the recompiled game. Needs <install>/generated,
#                           which only exists after the user ran gow2-setup
#                           against their own ISO and then ps2_recomp.
# ---------------------------------------------------------------------------
option(GOW2_BUILD_INSTALLER "Build the BYOI installer" ON)
option(GOW2_BUILD_GAME "Build the recompiled game executable" OFF)
set(GOW2_GENERATED_DIR "${CMAKE_SOURCE_DIR}/generated" CACHE PATH
    "ps2_recomp output directory (created from the user's ISO, never committed)")

add_library(gow2_common STATIC
    common/src/iso9660.cpp
    common/src/settings.cpp
    common/src/sha256.cpp
)
target_include_directories(gow2_common PUBLIC common/include)

if(GOW2_BUILD_INSTALLER)
    add_executable(gow2-setup installer/src/main.cpp)
    target_link_libraries(gow2-setup PRIVATE gow2_common)
    # The recompiler config templates travel with the installer.
    add_custom_target(gow2-setup-config ALL
        COMMAND "${CMAKE_COMMAND}" -E copy_directory
                "${CMAKE_SOURCE_DIR}/config" "$<TARGET_FILE_DIR:gow2-setup>/config"
        VERBATIM)
    add_dependencies(gow2-setup gow2-setup-config)
endif()

if(GOW2_BUILD_GAME)
    add_subdirectory(port)
endif()
