cmake_minimum_required(VERSION 3.16)
project(ssb_multi_receiver LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(fmt 9 REQUIRED)

# GNU Radio and gr-osmosdr both ship pkg-config (.pc) files on Debian/Ubuntu.
# We use those rather than GNU Radio's CMake package config because the
# exact CMake target/component names have shifted across GNU Radio 3.8 /
# 3.9 / 3.10, whereas the pkg-config module names below have stayed stable.
pkg_check_modules(GR_RUNTIME REQUIRED IMPORTED_TARGET gnuradio-runtime)
pkg_check_modules(GR_BLOCKS  REQUIRED IMPORTED_TARGET gnuradio-blocks)
pkg_check_modules(GR_FILTER  REQUIRED IMPORTED_TARGET gnuradio-filter)
pkg_check_modules(GR_ANALOG  REQUIRED IMPORTED_TARGET gnuradio-analog)
pkg_check_modules(OSMOSDR    REQUIRED IMPORTED_TARGET gnuradio-osmosdr)

add_executable(ssb_multi_receiver
  src/main.cpp
  src/Config.cpp
  src/UnixSocketSink.cpp
  src/ChannelBuilder.cpp
  src/ReceiverFlowgraph.cpp
)

target_include_directories(ssb_multi_receiver PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(ssb_multi_receiver PRIVATE fmt::fmt
  PkgConfig::GR_RUNTIME
  PkgConfig::GR_BLOCKS
  PkgConfig::GR_FILTER
  PkgConfig::GR_ANALOG
  PkgConfig::OSMOSDR
  nlohmann_json::nlohmann_json
  Threads::Threads
)

target_compile_options(ssb_multi_receiver PRIVATE -Wall -Wextra -Wpedantic)
