cmake_minimum_required(VERSION 3.8)
project(detectssb CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()

# SoapySDR is the only dependency: the detector reaches the Amarisoft card
# through the support module, never through libsdr directly.
find_package(SoapySDR "0.7" REQUIRED)

add_executable(detectssb detectssb.cpp)

target_link_libraries(detectssb PRIVATE SoapySDR)

# The correlator is the hot path, so let the compiler vectorise it.
target_compile_options(detectssb PRIVATE -Wall -Wextra -O3)

# Tune for this CPU.  install.sh always builds on the machine that runs the
# program, so the binary never meets a different processor, and the wider
# vectors are worth about 30%: an SDR100 runs this at 15.36 Msps, twice the
# SDR50 rate.  Skipped where the compiler does not know the flag.
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-march=native HAVE_MARCH_NATIVE)
if(HAVE_MARCH_NATIVE)
    target_compile_options(detectssb PRIVATE -march=native)
endif()

install(TARGETS detectssb RUNTIME DESTINATION bin)
