cmake_minimum_required(VERSION 3.20)
project(network_stamp_config LANGUAGES C CXX)
enable_testing()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
get_filename_component(REPO "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
execute_process(COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/generate.py" "${REPO}" "${CMAKE_CURRENT_BINARY_DIR}"
    COMMAND_ERROR_IS_FATAL ANY)
include("${CMAKE_CURRENT_BINARY_DIR}/sources.cmake")
add_library(network_stamp_codec OBJECT ${CONFIG_CODEC_SOURCES})
add_executable(network_stamp_config main.cpp $<TARGET_OBJECTS:network_stamp_codec>)
add_executable(network_stamp_records_compat "${REPO}/apps/linux_lvgl/tests/reticulum_network_records_test.cpp" $<TARGET_OBJECTS:network_stamp_codec>)
add_executable(network_stamp_esp_records "${REPO}/tests/reticulum_gateway/test_access_config.cpp" $<TARGET_OBJECTS:network_stamp_codec>)
add_executable(network_stamp_full_document "${REPO}/apps/linux_lvgl/tests/linux_tms_document_test.cpp"
    ${CONFIG_DOCUMENT_SOURCES} $<TARGET_OBJECTS:network_stamp_codec>)
foreach(target IN ITEMS network_stamp_codec network_stamp_config network_stamp_records_compat network_stamp_esp_records network_stamp_full_document)
    target_compile_features(${target} PRIVATE cxx_std_17)
    target_compile_definitions(${target} PRIVATE TRAIL_MATE_LORA_TX_POWER_MAX_DBM=22)
    target_include_directories(${target} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}" "${REPO}/modules/core_sys/include"
        "${REPO}/modules/core_chat/include" "${REPO}/modules/core_gps/include" "${REPO}/modules/core_phone/include"
        "${REPO}/platform/linux/common/include" "${REPO}/modules/core_chat/generated" "${REPO}/modules/core_chat/third_party/nanopb")
    target_compile_options(${target} PRIVATE -UNDEBUG -ffunction-sections -fdata-sections -fsanitize=address,undefined -fno-omit-frame-pointer)
    if(NOT target STREQUAL "network_stamp_codec")
        target_link_options(${target} PRIVATE -Wl,--gc-sections -fsanitize=address,undefined)
    endif()
endforeach()
foreach(target IN ITEMS network_stamp_config network_stamp_records_compat network_stamp_esp_records network_stamp_full_document)
    add_test(NAME ${target} COMMAND ${target})
endforeach()
