# SPDX-License-Identifier: MIT
# Copyright (c) 2025 aetherd Contributors

cmake_minimum_required(VERSION 3.20.0)

# Make aetherd headers available globally (for modules)
zephyr_include_directories(include)

# Build aetherd library
zephyr_library()

zephyr_library_sources(
  src/aetherd/aetherd.c
  src/aetherd/aetherd_groups.c
  # /usr subsystem: core aetherd.c depends on it (contrib ownership,
  # CGA handle lookup) independent of the presentation layers
  src/aetherd/aetherd_usr.c
  src/aetherd/aetherd_usr_fs.c
)

zephyr_library_sources_ifdef(CONFIG_AETHERD_CHAT
  src/aetherd/aetherd_chat.c
)

zephyr_library_sources_ifdef(CONFIG_AETHERD_GFX
  src/aetherd/aetherd_gfx.c
  # The world map artwork: 42KB of 1-bit line art, generated from the
  # PNG by tools/mkworld.py. Uncompressed on purpose — it costs no
  # decompressor, no scratch RAM, and renders the same on a colour
  # client as on 1-bit ePaper.
  src/aetherd/gfx_world_data.c
)

# Gopher/finger presentation layers (protocol cores; transports are
# provided by the application). CMake dedupes aetherd_usr.c if both are on.
zephyr_library_sources_ifdef(CONFIG_AETHERD_GOPHER
  src/aetherd/aetherd_gopher.c
  src/aetherd/aetherd_usr.c
  src/aetherd/aetherd_usr_fs.c
)

zephyr_library_sources_ifdef(CONFIG_AETHERD_FINGER
  src/aetherd/aetherd_finger.c
  src/aetherd/aetherd_usr.c
)

# On-device TCP listeners for gopher/finger (Zephyr transport). One file
# serves both, each half #ifdef'd on its NET option; build it if either is on.
if(CONFIG_AETHERD_GOPHER_NET OR CONFIG_AETHERD_FINGER_NET)
  zephyr_library_sources(src/aetherd/aetherd_gopher_net.c)
endif()

zephyr_library_sources_ifdef(CONFIG_AETHERD_GAMES
  src/aetherd/aetherd_nehemiah.c
)

zephyr_library_sources_ifdef(CONFIG_AETHERD_GAMES
  src/aetherd/aetherd_games.c
)

zephyr_library_sources_ifdef(CONFIG_AETHERD_FTN
  src/aetherd/aetherd_ftn.c
)

zephyr_library_sources_ifdef(CONFIG_AETHERD_NET
  src/aetherd/aetherd_net.c
)
