cmake_minimum_required(VERSION 3.16)
project(cactoz_gameserver CXX C)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)

FetchContent_Declare(
  uwebsockets
  GIT_REPOSITORY https://github.com/uNetworking/uWebSockets.git
  GIT_TAG v20.79.0
)
FetchContent_MakeAvailable(uwebsockets)

# uWebSockets pulls uSockets in via a git submodule, which plain FetchContent
# does not check out. Fetch the exact commit uWebSockets v20.79.0 pins instead.
FetchContent_Declare(
  usockets_src
  GIT_REPOSITORY https://github.com/uNetworking/uSockets.git
  GIT_TAG 86097c490263ab662d62e8e7b541390bdec7d149
)
FetchContent_MakeAvailable(usockets_src)

FetchContent_Declare(
  json
  GIT_REPOSITORY https://github.com/nlohmann/json.git
  GIT_TAG v3.12.0
)
FetchContent_MakeAvailable(json)

file(GLOB USOCKETS_SOURCES
  ${usockets_src_SOURCE_DIR}/src/*.c
  ${usockets_src_SOURCE_DIR}/src/eventing/*.c
)
add_library(usockets STATIC ${USOCKETS_SOURCES})
target_include_directories(usockets PUBLIC ${usockets_src_SOURCE_DIR}/src)
target_compile_definitions(usockets PUBLIC LIBUS_NO_SSL LIBUS_USE_EPOLL)

add_executable(gameserver
  src/main.cpp
  src/Lobby.cpp
)
target_include_directories(gameserver PRIVATE
  ${uwebsockets_SOURCE_DIR}/src
  src
)
target_link_libraries(gameserver PRIVATE usockets nlohmann_json::nlohmann_json pthread z)
