cmake_minimum_required(VERSION 3.16)
project(microReticulumTbeam LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# --------------------------------------------------------------------
# Portability shims
#
# microReticulum's CMake currently links against "msgpackc-cxx" and "MsgPack"
# as if they were system libraries, which breaks on machines that don't have
# those exact libs installed.
#
# Define shim targets so CMake treats them as targets (no "-l...").
# If/when you want a real msgpack-cxx dependency, replace the shim with
# FetchContent/find_package and link to that instead.
# --------------------------------------------------------------------
if(NOT TARGET msgpackc-cxx)
  add_library(msgpackc-cxx INTERFACE)
endif()

if(NOT TARGET MsgPack)
  add_library(MsgPack INTERFACE)
endif()


# Pull in the microReticulum submodule build
add_subdirectory(external/microReticulum)

# Provide DebugLog.h for microReticulum's MsgPack dependency
#set(DEBUGLOG_DIR ${CMAKE_SOURCE_DIR}/external/DebugLog)

#if(TARGET ReticulumShared)
#  target_include_directories(ReticulumShared PUBLIC ${DEBUGLOG_DIR})
#endif()

#if(TARGET ReticulumStatic)
#  target_include_directories(ReticulumStatic PUBLIC ${DEBUGLOG_DIR})
#endif()

set(DEBUGLOG_DIR     ${CMAKE_SOURCE_DIR}/external/DebugLog)
set(ARX_TYPETRAITS_DIR ${CMAKE_SOURCE_DIR}/external/ArxTypeTraits)
set(ARX_CONTAINER_DIR   ${CMAKE_SOURCE_DIR}/external/ArxContainer)

if(TARGET ReticulumShared)
  target_include_directories(ReticulumShared PUBLIC
    ${DEBUGLOG_DIR}
    ${ARX_TYPETRAITS_DIR}
    ${ARX_CONTAINER_DIR}
  )
endif()

if(TARGET ReticulumStatic)
  target_include_directories(ReticulumStatic PUBLIC
    ${DEBUGLOG_DIR}
    ${ARX_TYPETRAITS_DIR}
    ${ARX_CONTAINER_DIR}
  )
endif()

# We only need the static library for host-side tooling.
# The shared lib target requires system msgpack libs on some systems.
if(TARGET ReticulumShared)
  set_target_properties(ReticulumShared PROPERTIES EXCLUDE_FROM_ALL YES)
endif()

# Build our host-side tools
add_subdirectory(tools)
