set(TELNETROOT ${OPENAIR_DIR}/common/utils/telnetsrv )

set(TELNETSRV_SOURCE
    ${TELNETROOT}/telnetsrv.c
    ${TELNETROOT}/telnetsrv_proccmd.c
    ${TELNETROOT}/telnetsrv_loader.c
    ${TELNETROOT}/telnetsrv_measurements.c
    )
    
add_library(telnetsrv MODULE ${TELNETSRV_SOURCE} )
target_link_libraries(telnetsrv PRIVATE history ncurses form )

foreach(TELNETLIB enb gnb 4Gue 5Gue)
    set(TELNETLIB_SRCS "")
    foreach(TELNETLIB_ASRC measurements phycmd)
       set(TELNETLIB_SRC ${OPENAIR_DIR}/common/utils/telnetsrv/telnetsrv_${TELNETLIB}_${TELNETLIB_ASRC}.c)
       if (EXISTS ${TELNETLIB_SRC})
          set( TELNETLIB_SRCS "${TELNETLIB_SRC};${TELNETLIB_SRCS}")
       endif()
    endforeach()
    if(NOT "${TELNETLIB_SRCS}" STREQUAL "")
       message("Add ${TELNETLIB} specific telnet functions in libtelnetsrv_${TELNETLIB}.so")
       add_library(telnetsrv_${TELNETLIB} MODULE ${TELNETLIB_SRCS} )
       add_dependencies(telnetsrv telnetsrv_${TELNETLIB})
       install(TARGETS  telnetsrv_${TELNETLIB} DESTINATION bin)
    else()
       message("No specific telnet functions for ${TELNETLIB}")
    endif()  
endforeach()

install(TARGETS telnetsrv DESTINATION bin)

if (EXISTS "${OPENAIR_BUILD_DIR}/ran_build/build" AND IS_DIRECTORY "${OPENAIR_BUILD_DIR}/ran_build/build")
     install(TARGETS telnetsrv DESTINATION ${OPENAIR_BUILD_DIR}/ran_build/build)
endif (EXISTS "${OPENAIR_BUILD_DIR}/ran_build/build" AND IS_DIRECTORY "${OPENAIR_BUILD_DIR}/ran_build/build")
