cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
IF(DEFINED ENV{OPENAIR_DIR})
  message("...using oai source files in $ENV{OPENAIR_DIR}")
ELSE()
  message("OPENAIR_DIR is not defined.  You must run \"source oaienv\" from the oai root dir")
  # exit early 
  return()
ENDIF()



set(OPENAIR_DIR $ENV{OPENAIR_DIR})
set(APPROOT ${OPENAIR_DIR}/common/utils/telnetsrv )
set(OPENAIR_BUILD_DIR $ENV{OPENAIR_DIR}/cmake_targets)
set(OPENAIR1_DIR $ENV{OPENAIR1_DIR})
set(OPENAIR2_DIR $ENV{OPENAIR2_DIR})
set(OPENAIR3_DIR $ENV{OPENAIR3_DIR})
set(OPENAIR_PHY_DIR $ENV{OPENAIR1_DIR}/PHY)
set(OPENAIR_TARGET_DIR $ENV{OPENAIR_DIR}/targets)
set(OPENAIR_COMMONUTILS_DIR $ENV{OPENAIR_DIR}/common/utils)
set(OPENAIR2_COMMON_DIR $ENV{OPENAIR_DIR}/openair2/COMMON)
set(OPENAIR_ASN1INC  ${OPENAIR_BUILD_DIR}/lte_build_oai/build/CMakeFiles/Rel14)
set(OPENAIR_NFAPIINC $ENV{NFAPI_DIR} )

set(CMAKE_INSTALL_PREFIX $ENV{OPENAIR_TARGETS})

add_definitions (-DRel14  -DCMAKER -DENABLE_FXP -DENABLE_ITTI -DENABLE_NAS_UE_LOGGING -DENABLE_SECURITY  -DENABLE_USE_CPU_EXECUTION_TIME  -DENABLE_USE_MME -DENABLE_VCD -DENB_AGENT -DENB_MODE -DETHERNET=1  -DEXMIMO_IOT -DJUMBO_FRAME  -DLINK_ENB_PDCP_TO_GTPV1U -DLOG_NO_THREAD -DMAC_CONTEXT -DMAX_NUM_CCs=1  -DNAS_BUILT_IN_UE -DNAS_UE  -DNB_ANTENNAS_RX=2 -DNB_ANTENNAS_TX=2 -DNB_ANTENNAS_TXRX=2 -DNEW_FFT -DNO_RRM -DNone=1 -DOAI_NW_DRIVER_USE_NETLINK  -DOPENAIR1 -DOPENAIR2  -DOPENAIR_LTE -DPC_DSP -DPC_TARGET -DPHYSIM  -DPHY_CONTEXT -DPUCCH -DRel10=1  -DS1AP_VERSION=R10   -DTRACE_RLC_MUTEX -DUSER_MODE -DX2AP_VERSION=R11 -DXFORMS -mavx2 -msse4.1 -mssse3)
add_compile_options( -fPIC -march=native -Ofast)

include_directories( ./ ${OPENAIR_COMMON_DIR} ${OPENAIR_DIR} ${OPENAIR1_DIR} ${OPENAIR2_DIR} ${OPENAIR2_COMMON_DIR} ${OPENAIR2_DIR}/UTIL/LOG 
                    ${OPENAIR_COMMONUTILS_DIR}/msc ${OPENAIR_COMMONUTILS_DIR}/itti ${OPENAIR_COMMONUTILS_DIR}/hashtable ${OPENAIR_COMMONUTILS_DIR} ${OPENAIR_ASN1INC}
		    ${OPENAIR2_DIR}/LAYER2/RLC/AM_v9.3.0  ${OPENAIR_COMMONUTILS_DIR}/msc ${OPENAIR_COMMONUTILS_DIR}/itti ${OPENAIR_COMMONUTILS_DIR}/hashtable ${OPENAIR_COMMONUTILS_DIR} ${OPENAIR_ASN1INC}
		    ${OPENAIR2_DIR}/LAYER2/RLC  ${OPENAIR2_DIR}/UTIL/LISTS   ${OPENAIR2_DIR}/UTIL/MEM  ${OPENAIR2_DIR}/LAYER2/RLC/UM_v9.3.0 
		    ${OPENAIR2_DIR}/LAYER2/RLC/TM_v9.3.0 ${OPENAIR2_DIR}/RRC/LITE ${OPENAIR_TARGET_DIR}/COMMON  ${OPENAIR_TARGET_DIR}/ARCH/COMMON
		    ${OPENAIR3_DIR}/NAS/COMMON/API/NETWORK ${OPENAIR3_DIR}/NAS/COMMON/EMM/MSG/ ${OPENAIR3_DIR}/NAS/COMMON/IES/ ${OPENAIR3_DIR}/NAS/COMMON/UTIL 
		    ${OPENAIR3_DIR}/NAS/COMMON/ESM/MSG/  ${OPENAIR3_DIR}/GTPV1-U  ${OPENAIR3_DIR}/GTPV1-U/nw-gtpv1u/shared ${OPENAIR3_DIR}/GTPV1-U/nw-gtpv1u/include
		    ${OPENAIR3_DIR}/UTILS ${OPENAIR_NFAPIINC})

set(TELNETSRV_SOURCE
    ${APPROOT}/telnetsrv.c
    ${APPROOT}/telnetsrv_phycmd.c
    ${APPROOT}/telnetsrv_proccmd.c
    )

#set(TELNETSRV_ETHDEVCMD_SOURCE
#    ${APPROOT}/telnetsrv/telnetsrv_ethdevcmd.c
#    )



add_library(telnetsrv MODULE ${TELNETSRV_SOURCE} )
#add_library(telnetsrv_ethdevcmd MODULE ${TELNETSRV_ETHDEVCMD_SOURCE} )


install(TARGETS telnetsrv DESTINATION bin)

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