# --- hosts core (no switch sources here) ---
add_library(dofs_hosts STATIC)

# Make both "hosts/…" and "core/…" resolvable from anywhere
target_include_directories(dofs_hosts
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
    $<INSTALL_INTERFACE:include>
)

target_link_libraries(dofs_hosts PUBLIC dofs_core dofs_network)

if(DOFS_GLOB_SOURCES)
  file(GLOB HOSTS_CC CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
  # Exclude switch/*.cc from this glob just in case
  list(FILTER HOSTS_CC EXCLUDE REGEX ".*/switch/.*")
  target_sources(dofs_hosts PRIVATE ${HOSTS_CC})
else()
  target_sources(dofs_hosts
    PUBLIC
      mgmt_msg.h
      policies.h
      publisher.h
      subscriber.h
    PRIVATE
      publisher.cc
      subscriber.cc
  )
endif()

add_library(dofs::hosts ALIAS dofs_hosts)

# --- Tooling stubs for headers in this folder only (not switch) ---
file(GLOB HOSTS_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
set(HOSTS_STUBS)
foreach(h ${HOSTS_HEADERS})
  get_filename_component(_base "${h}" NAME_WE)
  set(_stub "${CMAKE_CURRENT_BINARY_DIR}/${_base}.cpp")
  file(WRITE "${_stub}" "// tooling stub for ${_base}.h\n#include \"hosts/${_base}.h\"\n")
  list(APPEND HOSTS_STUBS "${_stub}")
endforeach()

add_library(dofs_hosts_headers_tooling STATIC ${HOSTS_STUBS})

# inherit include dirs/usage reqs from dofs_hosts
target_link_libraries(
    dofs_hosts_headers_tooling
  PRIVATE
    dofs_hosts
    dofs_core
    dofs_network)

# This ensures the same -I flags even if cmake-ide builds the stubs alone
target_include_directories(dofs_hosts_headers_tooling
  PRIVATE
    $<TARGET_PROPERTY:dofs_hosts,INTERFACE_INCLUDE_DIRECTORIES>
    $<TARGET_PROPERTY:dofs_hosts,INCLUDE_DIRECTORIES>
)
