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

target_include_directories(dofs_nic
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>          # "network/...", "core/..."
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src/network>  # ** enables "nic/..." **
    $<INSTALL_INTERFACE:include>
)

# Sources
if(DOFS_GLOB_SOURCES)
  file(GLOB NIC_CC CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
  target_sources(dofs_nic PRIVATE ${NIC_CC})
else()
  target_sources(dofs_nic
    PUBLIC
	nic_telemetry.h
	congestion_control.h
      	load_balance.h
    PRIVATE
	congestion_control.cc
      	load_balance.cc
  )
endif()

target_link_libraries(dofs_nic PUBLIC dofs_network dofs_core)
add_library(dofs::nic ALIAS dofs_nic)

# --- Tooling stubs for nic headers ---
file(GLOB NIC_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")

set(NIC_STUBS)
foreach(h ${NIC_HEADERS})
  get_filename_component(_base "${h}" NAME_WE)
  set(_stub "${CMAKE_CURRENT_BINARY_DIR}/nic_${_base}.cpp")
  file(WRITE "${_stub}" "// stub nic/${_base}.h\n#include \"nic/${_base}.h\"\n")
  list(APPEND NIC_STUBS "${_stub}")
endforeach()

add_library(dofs_nic_headers_tooling STATIC ${NIC_STUBS})

# Make sure stubs see the SAME include roots
target_include_directories(dofs_nic_headers_tooling
  PRIVATE
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src/network>  # ** not src/network/nic **
)

target_link_libraries(dofs_nic_headers_tooling PRIVATE dofs_nic dofs_network dofs_core)
