cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(relay_zephyr)

# Logged at boot (see main.c) so a serial capture says which app commit -
# dirty tree or not - is actually running, independent of the Zephyr
# kernel's own "Booting Zephyr OS build ..." line, which only identifies
# the vendored zephyr tree, not this app's source.
execute_process(
	COMMAND git -C ${CMAKE_CURRENT_SOURCE_DIR} describe --always --dirty --long
	OUTPUT_VARIABLE APP_BUILD_ID
	OUTPUT_STRIP_TRAILING_WHITESPACE
	ERROR_QUIET
)
if(NOT APP_BUILD_ID)
	set(APP_BUILD_ID "unknown")
endif()

# CONFIG_DISABLE_MAC_VERIFY/CONFIG_DISABLE_PUBKEY_VERIFY (see Kconfig)
# short-circuit the two real auth checks to always pass - bench/test
# builds only, never meant to reach a fielded unit. CONFIG_* is already
# available here: find_package(Zephyr ...) above has already run
# Kconfig by this point. Flagging it in the build tag means a UART/
# syslog capture alone proves whether auth was live, without having to
# also know or trust the build's Kconfig fragment.
if(CONFIG_DISABLE_MAC_VERIFY OR CONFIG_DISABLE_PUBKEY_VERIFY)
	set(APP_BUILD_ID "${APP_BUILD_ID}-NOAUTH")
endif()

target_compile_definitions(app PRIVATE APP_BUILD_ID="${APP_BUILD_ID}")

# Headers are included by their path relative to src (e.g.
# "frame/frame.h"), so only src itself needs to be on the include path -
# no per-module directory, and no risk of a same-named header in two
# modules shadowing each other.
target_include_directories(app PRIVATE
	src
)

target_sources(app PRIVATE
	src/main.c
	src/beacon/beacon_ctx.c
	src/beacon/beacon_rx.c
	src/beacon/beacon_work.c
	src/frame/beacon_frame.c
	src/frame/frame.c
	src/frame/msg_frame.c
	src/frame/pkt_log.c
	src/frame/rx_dedup.c
	src/relay/cad_rx.c
	src/relay/cbf.c
	src/relay/relay_work.c
	src/relay/tx_queue.c
	src/rx/discovery_rx.c
	src/rx/payload_rx.c
	src/rx/payload_work.c
	src/net/peer_stats.c
	src/net/time_ctx.c
	src/crypto/base_ident_pubkey.c
	src/crypto/group_key.c
	src/crypto/group_mac.c
	src/crypto/ident.c
	src/crypto/ident_privkey.c
	src/crypto/ident_stub.c
	src/crypto/pubkey_table.c
)

# Base-station-only networking (WiFi connect) - every other node shares
# the frame/CBF/topology code above unconditionally and skips this.
target_sources_ifdef(CONFIG_APP_BASE_STATION app PRIVATE src/net/net_base.c)
