# Copyright 2011,2012,2016,2018,2019 Free Software Foundation, Inc.
#
# This file was generated by gr_modtool, a tool from the GNU Radio framework
# This file is a part of gr-op25_repeater
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.

########################################################################
# Setup library
########################################################################
include(GNUInstallDirs)

list(APPEND op25_repeater_sources
    ambe_encoder_sb_impl.cc
    dmr_bs_tx_bb_impl.cc
    ysf_tx_sb_impl.cc
    dstar_tx_sb_impl.cc
    vocoder_impl.cc
    gardner_cc_impl.cc
    costas_loop_cc_impl.cc
    p25_frame_assembler_impl.cc
    frame_assembler_impl.cc
    analog_udp_impl.cc
    rmsagc_ff_impl.cc
    fsk4_slicer_fb_impl.cc
    iqfile_source_impl.cc
    bch.cc
    rs.cc
    p25_framer.cc
    p25p1_fdma.cc
    op25_crypt_algs.cc
    op25_crypt_adp.cc
    op25_crypt_des.cc
    op25_crypt_aes.cc
    p25p1_voice_encode.cc
    p25p1_voice_decode.cc
    p25p2_framer.cc
    p25p2_isch.cc
    p25p2_duid.cc
    p25p2_sync.cc
    p25p2_tdma.cc
    p25p2_vf.cc
    imbe_decoder.cc
    software_imbe_decoder.cc
    ambe.c
    mbelib.c
    ambe_encoder.cc
    rx_sync.cc
    rx_smartnet.cc
    rx_subchannel.cc
    hamming.cc
    golay2087.cc
    bptc19696.cc
    trellis.cc
    dmr_cai.cc
    dmr_slot.cc
    op25_audio.cc
    op25_timer.cc
    CCITTChecksumReverse.cpp
)

add_subdirectory(imbe_vocoder)

option(P25_ONLY "Restrict decode to P25 frames only" OFF)
if (P25_ONLY)
  message(STATUS "Decode P25 frame types only")
  add_definitions(-DP25_FRAME_TYPES_ONLY)
else()
  message(STATUS "Decode all frame types")
endif()

option(AMBE_TONES "Enable AMBE tone synthesis" ON)
if (AMBE_TONES)
  message(STATUS "AMBE Tone Synthesis Enabled")
else()
  message(STATUS "AMBE Tone Synthesis Disabled")
  add_definitions(-DDISABLE_AMBE_TONES)
  target_link_libraries(gnuradio-op25_repeater ${Boost_LIBRARIES} gnuradio::gnuradio-runtime gnuradio-blocks ${GR_FILTER_LIBRARIES} imbe_vocoder)
endif()
unset(AMBE_TONES CACHE)

option(NID_PARITY_CHECK "Enable NID Parity Check" OFF)
if (NID_PARITY_CHECK)
  message(STATUS "NID Parity Check Enabled")
else()
  message(STATUS "NID Parity Check Disabled")
  add_definitions(-DDISABLE_NID_PARITY_CHECK)
endif()
unset(NID_PARITY_CHECK CACHE)

add_definitions(-DEZPWD_NO_EXCEPTS)


set(op25_repeater_sources "${op25_repeater_sources}" PARENT_SCOPE)
if(NOT op25_repeater_sources)
    MESSAGE(STATUS "No C++ sources... skipping lib/")
    return()
endif(NOT op25_repeater_sources)

add_library(gnuradio-op25_repeater SHARED ${op25_repeater_sources})
target_link_libraries(gnuradio-op25_repeater PRIVATE imbe_vocoder gnuradio::gnuradio-runtime gnuradio::gnuradio-filter)
target_include_directories(gnuradio-op25_repeater
    PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
    PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../lib>
    PUBLIC $<INSTALL_INTERFACE:include>
  )
set_target_properties(gnuradio-op25_repeater PROPERTIES DEFINE_SYMBOL "gnuradio_op25_repeater_EXPORTS")

if(APPLE)
    set_target_properties(gnuradio-op25_repeater PROPERTIES
        INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
    )
endif(APPLE)

########################################################################
# Install built library files
########################################################################
include(GrMiscUtils)
GR_LIBRARY_FOO(gnuradio-op25_repeater)

########################################################################
# Print summary
########################################################################
message(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Building for version: ${VERSION} / ${LIBVER}")

########################################################################
# Build and register unit test
########################################################################
include(GrTest)

include_directories(${CPPUNIT_INCLUDE_DIRS})

# If your unit tests require special include paths, add them here
#include_directories()
# List all files that contain Boost.UTF unit tests here
list(APPEND test_op25_repeater_sources

)
# Anything we need to link to for the unit tests go here
list(APPEND GR_TEST_TARGET_DEPS gnuradio-op25_repeater)

if(NOT test_op25_repeater_sources)
    MESSAGE(STATUS "No C++ unit tests... skipping")
    return()
endif(NOT test_op25_repeater_sources)

target_link_libraries(
  ${GNURADIO_RUNTIME_LIBRARIES}
  ${CPPUNIT_LIBRARIES}
  gnuradio-op25_repeater
)

foreach(qa_file ${test_op25_repeater_sources})
    GR_ADD_CPP_TEST("op25_repeater_${qa_file}"
        ${CMAKE_CURRENT_SOURCE_DIR}/${qa_file}
    )
endforeach(qa_file)

###################################add_executable(test-op25_repeater ${test_op25_repeater_sources})
#####################################
# d2460
########################################################################
list(APPEND d2460_sources
    ${CMAKE_CURRENT_SOURCE_DIR}/d2460.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/ambe.c
    ${CMAKE_CURRENT_SOURCE_DIR}/mbelib.c
    ${CMAKE_CURRENT_SOURCE_DIR}/ambe_encoder.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/software_imbe_decoder.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/imbe_decoder.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/p25p2_vf.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/rs.cc
)

add_executable(op25-d2460 ${d2460_sources})
target_link_libraries(op25-d2460 imbe_vocoder)

add_subdirectory(imbe_vocoder)

########################################################################
# Utilities
########################################################################
list(APPEND scan4sync_sources
    ${CMAKE_CURRENT_SOURCE_DIR}/scan4sync.cc
)

list(APPEND BER_sources
    ${CMAKE_CURRENT_SOURCE_DIR}/BER.cc
)

add_executable(scan4sync ${scan4sync_sources})
add_executable(BER ${BER_sources})
target_link_libraries(scan4sync)
target_link_libraries(BER)
