cmake_minimum_required(VERSION 3.21)

# Builds AL-Arcade MC Launcher and the libraries it links against.
#
# Game backends:
#   android - macOS/Linux. Downloads the Android build from Google Play and runs it
#             with the mcpelauncher engine (engine/, a separate CMake project that
#             scripts/build-macos.sh builds alongside this one).
#   windows - Windows. Starts the official Minecraft for Windows; no engine needed.

file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" ALARCADE_VERSION LIMIT_COUNT 1)
project(alarcade-mc-launcher-suite VERSION ${ALARCADE_VERSION} LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Several pinned upstream libraries still declare very old minimum versions.
set(CMAKE_POLICY_VERSION_MINIMUM 3.5 CACHE STRING "" FORCE)

if(APPLE)
    enable_language(OBJCXX)
endif()

if(WIN32)
    set(ALARCADE_BACKEND_DEFAULT windows)
else()
    set(ALARCADE_BACKEND_DEFAULT android)
endif()
set(ALARCADE_BACKEND ${ALARCADE_BACKEND_DEFAULT} CACHE STRING "Game backend: android or windows")
set_property(CACHE ALARCADE_BACKEND PROPERTY STRINGS android windows)

file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/launcher/LAUNCHER_VERSION_COMPAT" LAUNCHER_VERSION_COMPATS)
list(GET LAUNCHER_VERSION_COMPATS 0 LAUNCHER_VERSION_COMPAT)
set(LAUNCHER_VERSION_COMPAT ${LAUNCHER_VERSION_COMPAT} CACHE STRING "" FORCE)

if(ALARCADE_BACKEND STREQUAL "android")
    add_subdirectory(deps/file-util)
    add_subdirectory(deps/axml-parser)
    add_subdirectory(deps/mcpelauncher-apkinfo)
    add_subdirectory(deps/mcpelauncher-common)
    add_subdirectory(deps/mcpelauncher-extract)
    add_subdirectory(deps/google-play-api)
    if(NOT APPLE)
        # macOS signs in through the native WebKit sheet in launcher/macos instead.
        add_subdirectory(deps/playdl-signin-ui-qt)
    endif()
endif()

add_subdirectory(launcher)

if(ALARCADE_BACKEND STREQUAL "android")
    set(GAME_LAUNCHER_PATH "." CACHE STRING "Paths, relative to the application directory, searched for mcpelauncher-client.")
    if(GAME_LAUNCHER_PATH)
        target_compile_definitions(alarcade-mc-launcher PRIVATE -DGAME_LAUNCHER_PATH="${GAME_LAUNCHER_PATH}")
    endif()
endif()
