cmake_minimum_required(VERSION 3.16)
project(ConsoleClient CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Emit build/compile_commands.json so clangd (Zed, VS Code, etc.) picks up the include roots and defines.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Release by default: a Debug build of the API takes about 500 MB of disk space.
# Multi-config generators (Visual Studio, Xcode) pick the configuration at build time instead.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()

# --- SFS3 client API, built from source as a subproject -------------------
# The API folder sits next to the demo folders. Building it here, in the same pass,
# gives the right library names, system libraries and configuration on every platform.
# Override the location with -DSFS3_DIR=/path/to/SFS3_API_Cpp if it moves.
set(SFS3_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../SFS3_API_Cpp"
    CACHE PATH "SFS3 C++ API root")
get_filename_component(SFS3_DIR "${SFS3_DIR}" ABSOLUTE)

if(NOT EXISTS "${SFS3_DIR}/src/CMakeLists.txt")
  message(FATAL_ERROR
    "SFS3 C++ API not found in ${SFS3_DIR}. Place it next to this folder, or set -DSFS3_DIR=...")
endif()

# A development checkout also contains the API's test harness: never build it here
set(SFS_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory("${SFS3_DIR}/src" "${CMAKE_BINARY_DIR}/sfs3")

# --- The example app ------------------------------------------------------
# CONFIGURE_DEPENDS re-checks the glob at build time, so new *.cpp files are picked up
# without a manual reconfigure. Headers are listed for IDE/clangd visibility only.
file(GLOB CONSOLE_CLIENT_SOURCES CONFIGURE_DEPENDS
  "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
  "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
add_executable(ConsoleClient ${CONSOLE_CLIENT_SOURCES})
target_link_libraries(ConsoleClient PRIVATE sfs_client)

# Same output folder for every configuration, so multi-config generators don't add bin/Debug etc.
set_target_properties(ConsoleClient PROPERTIES
  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin"
  RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/bin"
  RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/bin"
  RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/bin"
  RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/bin")
