cmake_minimum_required(VERSION 3.12)
project(sdrplay_sdr_support)

if(APPLE)
    include_directories("/usr/local/include")
    set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/lib)
endif()

message("Building with SDRPlay support")
file(GLOB_RECURSE sdrplay_sdr_support_CPPS *.cpp)
add_library(sdrplay_sdr_support SHARED ${sdrplay_sdr_support_CPPS})
target_include_directories(sdrplay_sdr_support PUBLIC src src/sdrplay)
target_link_libraries(sdrplay_sdr_support PUBLIC satdump_core)

if(MSVC)
    target_compile_definitions(sdrplay_sdr_support PUBLIC SDRPLAY_LIB_PATH="sdrplay_api.dll")
    install(TARGETS sdrplay_sdr_support DESTINATION ${CMAKE_INSTALL_LIBDIR}/satdump/plugins RUNTIME_DEPENDENCY_SET satdump_deps)
elseif(APPLE AND BUNDLING_MODE)
    target_compile_definitions(sdrplay_sdr_support PUBLIC SDRPLAY_LIB_PATH="../libs/libsdrplay_api.dylib")
    install(TARGETS sdrplay_sdr_support DESTINATION ${CMAKE_INSTALL_LIBDIR}/satdump/plugins)
else()
    if(SDRPLAY_LIBRARY)
        target_compile_definitions(sdrplay_sdr_support PUBLIC SDRPLAY_LIB_PATH="${SDRPLAY_LIBRARY}")
    else()
        target_compile_definitions(sdrplay_sdr_support PUBLIC SDRPLAY_LIB_PATH="libsdrplay_api.so")
    endif()
    install(TARGETS sdrplay_sdr_support DESTINATION ${CMAKE_INSTALL_LIBDIR}/satdump/plugins)
endif()
