# --- Library: dofs_network ---
add_library(dofs_network STATIC)

# Expose src/ so "network/..." and "core/..." resolve from anywhere
target_include_directories(dofs_network
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
    $<INSTALL_INTERFACE:include>
)

target_link_libraries(dofs_network PUBLIC dofs_core)

# Sources
if(DOFS_GLOB_SOURCES)
  file(GLOB NETWORK_CC CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
  target_sources(dofs_network PRIVATE ${NETWORK_CC})
else()
  target_sources(dofs_network
    PUBLIC
      packet.h
      link.h
      network_node.h
      network_switch.h
      network_nic.h
    PRIVATE
      packet.cc
      link.cc
      network_node.cc
      network_switch.cc
      network_nic.cc
  )
endif()

# Alias
add_library(dofs::network ALIAS dofs_network)

# --- Tooling: per-header stubs for "network/*.h" ---
file(GLOB NETWORK_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")

set(NETWORK_STUBS)
foreach(h ${NETWORK_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 \"network/${_base}.h\"\n")
  list(APPEND NETWORK_STUBS "${_stub}")
endforeach()

add_library(dofs_network_headers_tooling STATIC ${NETWORK_STUBS})
# Make stubs see the same include roots as the real target
target_include_directories(dofs_network_headers_tooling
  PRIVATE
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
)
target_link_libraries(dofs_network_headers_tooling PRIVATE dofs_network dofs_core)

# --- Subdir: switch ---
add_subdirectory(switch)
add_subdirectory(nic)
