# Copyright 2011,2012,2016 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# 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.

########################################################################
# Find library
########################################################################
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
find_package(KCSDR REQUIRED)
if (NOT KCSDR_FOUND)
    message(FATAL_ERROR "Can not find package: kcsdr_lib")
endif(NOT KCSDR_FOUND)
########################################################################
# Setup library
########################################################################
include(GrPlatform) #define LIB_SUFFIX

include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})

include_directories(/usr/local/include/kcsdr)

list(APPEND kc_sdr_sources
    source_impl.cc
    transmitter_impl.cc
)

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

add_library(gnuradio-kc_sdr SHARED ${kc_sdr_sources})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
message(STATUS "add library ==> ${KCSDR_LIBRARIES}")
message(STATUS "add library path to ld path --> ${KCSDR_LIBRARY_PATH}")
file(WRITE ./libkcsdr.conf "${KCSDR_LIBRARY_PATH}")

target_link_libraries(gnuradio-kc_sdr ${Boost_LIBRARIES} ${GNURADIO_ALL_LIBRARIES}
                     ${KCSDR_LIBRARIES})
set_target_properties(gnuradio-kc_sdr PROPERTIES DEFINE_SYMBOL "gnuradio_kc_sdr_EXPORTS")

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

########################################################################
# Install built library files
########################################################################
include(GrMiscUtils)
GR_LIBRARY_FOO(gnuradio-kc_sdr RUNTIME_COMPONENT "kc_sdr_runtime" DEVEL_COMPONENT "kc_sdr_devel")

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

include_directories(${CPPUNIT_INCLUDE_DIRS})

list(APPEND test_kc_sdr_sources
    ${CMAKE_CURRENT_SOURCE_DIR}/test_kc_sdr.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/qa_kc_sdr.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/qa_transmitter.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/qa_source.cc
)

add_executable(test-kc_sdr ${test_kc_sdr_sources})

target_link_libraries(
  test-kc_sdr
  ${GNURADIO_RUNTIME_LIBRARIES}
  ${Boost_LIBRARIES}
  ${CPPUNIT_LIBRARIES}
  gnuradio-kc_sdr
)

GR_ADD_TEST(test_kc_sdr test-kc_sdr)

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

