project(bladerf)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(LibUSB)

add_definitions(-DBLADERF_OS_LINUX)

set(bladerf_SOURCES
    ${LIBBLADERFCOMMONSRC}/src/sha256.c
    ${LIBBLADERFCOMMONSRC}/src/dc_calibration.c
    ${LIBBLADERFCOMMONSRC}/src/parse.c
    ${LIBBLADERFCOMMONSRC}/src/devcfg.c
    ${LIBBLADERFCOMMONSRC}/src/conversions.c
    ${LIBBLADERFCOMMONSRC}/src/log.c
    ${LIBBLADERFCOMMONSRC}/src/str_queue.c
    ${LIBBLADERFSRC}/host/misc/dev/lms_freqsel/freqsel.c
    ${LIBBLADERFSRC}/fpga_common/src/lms.c
    ${LIBBLADERFSRC}/fpga_common/src/band_select.c
    ${LIBBLADERFLIBSRC}/src/helpers/interleave.c
    ${LIBBLADERFLIBSRC}/src/helpers/timeout.c
    ${LIBBLADERFLIBSRC}/src/helpers/wallclock.c
    ${LIBBLADERFLIBSRC}/src/helpers/configfile.c
    ${LIBBLADERFLIBSRC}/src/helpers/file.c
    ${LIBBLADERFLIBSRC}/src/helpers/version.c
    ${LIBBLADERFLIBSRC}/src/driver/fpga_trigger.c
    ${LIBBLADERFLIBSRC}/src/driver/si5338.c
    ${LIBBLADERFLIBSRC}/src/driver/dac161s055.c
    ${LIBBLADERFLIBSRC}/src/driver/fx3_fw.c
    ${LIBBLADERFLIBSRC}/src/driver/smb_clock.c
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/dac_core.c
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/ad9361.c
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/util.c
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/platform.c
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/ad9361_api.c
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/adc_core.c
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/ad9361_conv.c
    ${LIBBLADERFLIBSRC}/src/driver/spi_flash.c
    ${LIBBLADERFLIBSRC}/src/driver/ina219.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf2/compatibility.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf2/capabilities.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf2/params.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf2/bladerf2.c
    ${LIBBLADERFLIBSRC}/src/board/board.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/flash.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/bladerf1.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/image.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/compatibility.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/calibration.c
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/capabilities.c
    ${LIBBLADERFLIBSRC}/src/expansion/xb100.c
    ${LIBBLADERFLIBSRC}/src/expansion/xb200.c
    ${LIBBLADERFLIBSRC}/src/expansion/xb300.c
    ${LIBBLADERFLIBSRC}/src/streaming/async.c
    ${LIBBLADERFLIBSRC}/src/streaming/sync_worker.c
    ${LIBBLADERFLIBSRC}/src/streaming/sync.c
    ${LIBBLADERFLIBSRC}/src/bladerf.c
    ${LIBBLADERFLIBSRC}/src/init_fini.c
    ${LIBBLADERFLIBSRC}/src/backend/dummy/dummy.c
    ${LIBBLADERFLIBSRC}/src/backend/backend.c
    ${LIBBLADERFLIBSRC}/src/backend/usb/usb.c
    ${LIBBLADERFLIBSRC}/src/backend/usb/libusb.c
    ${LIBBLADERFLIBSRC}/src/backend/usb/nios_access.c
    ${LIBBLADERFLIBSRC}/src/backend/usb/nios_legacy_access.c
    ${LIBBLADERFLIBSRC}/src/devinfo.c
)

set(bladerf_HEADERS
    ./common/include/host_config.h
    ./libraries/libbladeRF/src/version.h
    ./libraries/libbladeRF/src/backend/backend_config.h    
    ${LIBBLADERFCOMMONSRC}/include/thread.h
    ${LIBBLADERFCOMMONSRC}/include/parse.h
    ${LIBBLADERFCOMMONSRC}/include/minmax.h
    ${LIBBLADERFCOMMONSRC}/include/rel_assert.h
    ${LIBBLADERFCOMMONSRC}/include/devcfg.h
    ${LIBBLADERFCOMMONSRC}/include/str_queue.h
    ${LIBBLADERFCOMMONSRC}/include/log.h
    ${LIBBLADERFCOMMONSRC}/include/dc_calibration.h
    ${LIBBLADERFCOMMONSRC}/include/sha256.h
    ${LIBBLADERFCOMMONSRC}/include/conversions.h
    ${LIBBLADERFSRC}/fpga_common/include/lms.h
    ${LIBBLADERFSRC}/fpga_common/include/band_select.h
    ${LIBBLADERFLIBSRC}/src/helpers/interleave.h
    ${LIBBLADERFLIBSRC}/src/helpers/wallclock.h
    ${LIBBLADERFLIBSRC}/src/helpers/timeout.h
    ${LIBBLADERFLIBSRC}/src/helpers/version.h
    ${LIBBLADERFLIBSRC}/src/helpers/configfile.h
    ${LIBBLADERFLIBSRC}/src/helpers/file.h
    ${LIBBLADERFLIBSRC}/src/driver/dac161s055.h
    ${LIBBLADERFLIBSRC}/src/driver/fpga_trigger.h
    ${LIBBLADERFLIBSRC}/src/driver/si5338.h
    ${LIBBLADERFLIBSRC}/src/driver/ina219.h
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/platform.h
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/util.h
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/dac_core.h
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/config.h
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/adc_core.h
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/common.h
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/ad9361.h
    ${LIBBLADERFLIBSRC}/src/driver/thirdparty/adi/ad9361_api.h
    ${LIBBLADERFLIBSRC}/src/driver/spi_flash.h
    ${LIBBLADERFLIBSRC}/src/driver/fx3_fw.h
    ${LIBBLADERFLIBSRC}/src/driver/smb_clock.h
    ${LIBBLADERFLIBSRC}/src/board/bladerf2/capabilities.h
    ${LIBBLADERFLIBSRC}/src/board/bladerf2/compatibility.h
    ${LIBBLADERFLIBSRC}/src/board/board.h
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/calibration.h
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/capabilities.h
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/compatibility.h
    ${LIBBLADERFLIBSRC}/src/board/bladerf1/flash.h
    ${LIBBLADERFLIBSRC}/src/expansion/xb300.h
    ${LIBBLADERFLIBSRC}/src/expansion/xb100.h
    ${LIBBLADERFLIBSRC}/src/expansion/xb200.h
    ${LIBBLADERFLIBSRC}/src/streaming/sync.h
    ${LIBBLADERFLIBSRC}/src/streaming/sync_worker.h
    ${LIBBLADERFLIBSRC}/src/streaming/metadata.h
    ${LIBBLADERFLIBSRC}/src/streaming/format.h
    ${LIBBLADERFLIBSRC}/src/streaming/async.h
    ${LIBBLADERFLIBSRC}/src/backend/backend.h
    ${LIBBLADERFLIBSRC}/src/backend/dummy/dummy.h
    ${LIBBLADERFLIBSRC}/src/backend/usb/nios_legacy_access.h
    ${LIBBLADERFLIBSRC}/src/backend/usb/nios_access.h
    ${LIBBLADERFLIBSRC}/src/backend/usb/usb.h
    ${LIBBLADERFLIBSRC}/src/devinfo.h
    ${LIBBLADERFLIBSRC}/include/bladeRF2.h
    ${LIBBLADERFLIBSRC}/include/libbladeRF.h
    ${LIBBLADERFLIBSRC}/include/bladeRF1.h
)

include_directories(
    .
    ${CMAKE_CURRENT_BINARY_DIR}
    ${LIBUSB_INCLUDE_DIR}
    ${LIBBLADERFLIBSRC}/include
    ${LIBBLADERFLIBSRC}/src
    ${LIBBLADERFSRC}/firmware_common
    ${LIBBLADERFSRC}/fpga_common/include
    ${LIBBLADERFCOMMONSRC}/include
    ${LIBBLADERFCOMMONSRC}/include/windows
    ./include
    ./common/include
    ./libraries/libbladeRF/src
    ./libraries/libbladeRF/src/backend
)

add_definitions(-DQT_SHARED)

add_library(bladerf SHARED
    ${bladerf_SOURCES}
)

target_link_libraries(bladerf
    ${LIBUSB_LIBRARIES}
)

install(TARGETS bladerf DESTINATION lib)

