project(demod)

if (ENABLE_CHANNELRX_DEMODINMARSAT AND INMARSATC_FOUND)
    add_subdirectory(demodinmarsat)
else()
    message(STATUS "Not building demodinmarsat (ENABLE_CHANNELRX_DEMODINMARSAT=${ENABLE_CHANNELRX_DEMODINMARSAT} INMARSATC_FOUND=${INMARSATC_FOUND})")
endif()

if (ENABLE_CHANNELRX_CHANNELPOWER)
    add_subdirectory(channelpower)
endif()

if (ENABLE_CHANNELRX_ENDOFTRAIN)
    add_subdirectory(demodendoftrain)
endif()

if (ENABLE_CHANNELRX_FREQSCANNER)
    add_subdirectory(freqscanner)
endif()

if (ENABLE_CHANNELRX_DEMODADSB AND Qt${QT_DEFAULT_MAJOR_VERSION}Quick_FOUND AND Qt${QT_DEFAULT_MAJOR_VERSION}QuickWidgets_FOUND AND Qt${QT_DEFAULT_MAJOR_VERSION}Positioning_FOUND AND Qt${QT_DEFAULT_MAJOR_VERSION}TextToSpeech_FOUND)
    add_subdirectory(demodadsb)
    # add_subdirectory(demodvormc)
else()
    message(STATUS "Not building demodadsb (ENABLE_CHANNELRX_DEMODADSB=${ENABLE_CHANNELRX_DEMODADSB} Qt${QT_DEFAULT_MAJOR_VERSION}Quick_FOUND=${Qt${QT_DEFAULT_MAJOR_VERSION}Quick_FOUND} Qt${QT_DEFAULT_MAJOR_VERSION}QuickWidgets_FOUND=${Qt${QT_DEFAULT_MAJOR_VERSION}QuickWidgets_FOUND} Qt${QT_DEFAULT_MAJOR_VERSION}Positioning_FOUND=${Qt${QT_DEFAULT_MAJOR_VERSION}Positioning_FOUND} Qt${QT_DEFAULT_MAJOR_VERSION}TextToSpeech_FOUND=${Qt${QT_DEFAULT_MAJOR_VERSION}TextToSpeech_FOUND})")
endif()

if (ENABLE_CHANNELRX_DEMODAM)
    add_subdirectory(demodam)
else()
    message(STATUS "Not building demodam (ENABLE_CHANNELRX_DEMODAM=${ENABLE_CHANNELRX_DEMODAM})")
endif()

if (ENABLE_CHANNELRX_DEMODBFM)
    add_subdirectory(demodbfm)
else()
    message(STATUS "Not building demodbfm (ENABLE_CHANNELRX_DEMODBFM=${ENABLE_CHANNELRX_DEMODBFM})")
endif()

if (ENABLE_CHANNELRX_DEMODNFM)
    add_subdirectory(demodnfm)
else()
    message(STATUS "Not building demodnfm (ENABLE_CHANNELRX_DEMODNFM=${ENABLE_CHANNELRX_DEMODNFM})")
endif()

if (ENABLE_CHANNELRX_DEMODSSB)
    add_subdirectory(demodssb)
else()
    message(STATUS "Not building demodssb (ENABLE_CHANNELRX_DEMODSSB=${ENABLE_CHANNELRX_DEMODSSB})")
endif()

if (ENABLE_CHANNELRX_UDPSINK)
    add_subdirectory(udpsink)
else()
    message(STATUS "Not building udpsink (ENABLE_CHANNELRX_UDPSINK=${ENABLE_CHANNELRX_UDPSINK})")
endif()

if (ENABLE_CHANNELRX_DEMODWFM)
    add_subdirectory(demodwfm)
else()
    message(STATUS "Not building demodwfm (ENABLE_CHANNELRX_DEMODWFM=${ENABLE_CHANNELRX_DEMODWFM})")
endif()

if (ENABLE_CHANNELRX_LOCALSINK)
    add_subdirectory(localsink)
else()
    message(STATUS "Not building localsink (ENABLE_CHANNELRX_LOCALSINK=${ENABLE_CHANNELRX_LOCALSINK})")
endif()

if (ENABLE_CHANNELRX_FILESINK)
    add_subdirectory(filesink)
else()
    message(STATUS "Not building filesink (ENABLE_CHANNELRX_FILESINK=${ENABLE_CHANNELRX_FILESINK})")
endif()

if (ENABLE_CHANNELRX_FREQTRACKER)
    add_subdirectory(freqtracker)
else()
    message(STATUS "Not building freqtracker (ENABLE_CHANNELRX_FREQTRACKER=${ENABLE_CHANNELRX_FREQTRACKER})")
endif()

if (ENABLE_CHANNELRX_DEMODCHIRPCHAT)
    add_subdirectory(demodchirpchat)
else()
    message(STATUS "Not building demodchirpchat (ENABLE_CHANNELRX_DEMODCHIRPCHAT=${ENABLE_CHANNELRX_DEMODCHIRPCHAT})")
endif()

if (ENABLE_CHANNELRX_DEMODMESHTASTIC)
    add_subdirectory(demodmeshtastic)
else()
    message(STATUS "Not building demodmeshtastic (ENABLE_CHANNELRX_DEMODMESHTASTIC=${ENABLE_CHANNELRX_DEMODMESHTASTIC})")
endif()

if (ENABLE_CHANNELRX_DEMODMESHCORE)
    add_subdirectory(demodmeshcore)
else()
    message(STATUS "Not building demodmeshcore (ENABLE_CHANNELRX_DEMODMESHCORE=${ENABLE_CHANNELRX_DEMODMESHCORE})")
endif()

if (ENABLE_CHANNELRX_DEMODVOR)
    add_subdirectory(demodvor)
else()
    message(STATUS "Not building demodvor (ENABLE_CHANNELRX_DEMODVOR=${ENABLE_CHANNELRX_DEMODVOR})")
endif()

if (ENABLE_CHANNELRX_DEMODPACKET)
    add_subdirectory(demodpacket)
else()
    message(STATUS "Not building demodpacket (ENABLE_CHANNELRX_DEMODPACKET=${ENABLE_CHANNELRX_DEMODPACKET})")
endif()

if (ENABLE_CHANNELRX_DEMODAIS)
    add_subdirectory(demodais)
else()
    message(STATUS "Not building demodais (ENABLE_CHANNELRX_DEMODAIS=${ENABLE_CHANNELRX_DEMODAIS})")
endif()

if (ENABLE_CHANNELRX_DEMODPAGER)
    add_subdirectory(demodpager)
else()
    message(STATUS "Not building demodpager (ENABLE_CHANNELRX_DEMODPAGER=${ENABLE_CHANNELRX_DEMODPAGER})")
endif()

if (ENABLE_CHANNELRX_RADIOCLOCK)
    add_subdirectory(radioclock)
else()
    message(STATUS "Not building radioclock (ENABLE_CHANNELRX_RADIOCLOCK=${ENABLE_CHANNELRX_RADIOCLOCK})")
endif()

if (ENABLE_CHANNELRX_RADIOASTRONOMY)
    add_subdirectory(radioastronomy)
else()
    message(STATUS "Not building radioastronomy (ENABLE_CHANNELRX_RADIOASTRONOMY=${ENABLE_CHANNELRX_RADIOASTRONOMY})")
endif()

if (ENABLE_CHANNELRX_DEMODRADIOSONDE)
    add_subdirectory(demodradiosonde)
else()
    message(STATUS "Not building demodradiosonde (ENABLE_CHANNELRX_DEMODRADIOSONDE=${ENABLE_CHANNELRX_DEMODRADIOSONDE})")
endif()

if(ENABLE_CHANNELRX_DEMODDAB AND DAB_FOUND AND ZLIB_FOUND AND FAAD_FOUND)
    add_subdirectory(demoddab)
else()
    message(STATUS "Not building demoddab (ENABLE_CHANNELRX_DEMODDAB=${ENABLE_CHANNELRX_DEMODDAB} DAB_FOUND=${DAB_FOUND} ZLIB_FOUND=${ZLIB_FOUND} FAAD_FOUND=${FAAD_FOUND})")
endif()

if(ENABLE_CHANNELRX_DEMODAPT AND APT_FOUND AND SGP4_FOUND)
    add_subdirectory(demodapt)
else()
    message(STATUS "Not building demodapt (ENABLE_CHANNELRX_DEMODAPT=${ENABLE_CHANNELRX_DEMODAPT} APT_FOUND=${APT_FOUND} SGP4_FOUND=${SGP4_FOUND})")
endif()

if(ENABLE_CHANNELRX_DEMODDSD AND LIBDSDCC_FOUND AND LIBMBE_FOUND)
    add_subdirectory(demoddsd)
else()
    message(STATUS "Not building demoddsd (ENABLE_CHANNELRX_DEMODDSD=${ENABLE_CHANNELRX_DEMODDSD} LIBDSDCC_FOUND=${LIBDSDCC_FOUND} LIBMBE_FOUND=${LIBMBE_FOUND})")
endif()

if (ENABLE_CHANNELRX_REMOTESINK AND CM256CC_FOUND AND (HAS_SSE3 OR HAS_NEON))
    add_subdirectory(remotesink)
else()
    message(STATUS "Not building remotesink (ENABLE_CHANNELRX_REMOTESINK=${ENABLE_CHANNELRX_REMOTESINK} CM256CC_FOUND=${CM256CC_FOUND} HAS_SSE3=${HAS_SSE3} HAS_NEON=${HAS_NEON})")
endif()

if (ENABLE_CHANNELRX_REMOTETCPSINK)
    add_subdirectory(remotetcpsink)
else()
    message(STATUS "Not building remotetcpsink (ENABLE_CHANNELRX_REMOTETCPSINK=${ENABLE_CHANNELRX_REMOTETCPSINK})")
endif()

if (ENABLE_CHANNELRX_DEMODFREEDV AND CODEC2_FOUND)
    add_subdirectory(demodfreedv)
else()
    message(STATUS "Not building demodfreedv (ENABLE_CHANNELRX_DEMODFREEDV=${ENABLE_CHANNELRX_DEMODFREEDV} CODEC2_FOUND=${CODEC2_FOUND})")
endif()

if (ENABLE_CHANNELRX_DEMODM17 AND CODEC2_FOUND)
    add_subdirectory(demodm17)
else()
    message(STATUS "Not building demodm17 (ENABLE_CHANNELRX_DEMODFREEDV=${ENABLE_CHANNELRX_DEMODM17} CODEC2_FOUND=${CODEC2_FOUND})")
endif()

if (ENABLE_CHANNELRX_SIGMFFILESINK AND LIBSIGMF_FOUND)
    add_subdirectory(sigmffilesink)
else()
    message(STATUS "Not building sigmffilesink (ENABLE_CHANNELRX_SIGMFFILESINK=${ENABLE_CHANNELRX_SIGMFFILESINK} LIBSIGMF_FOUND=${LIBSIGMF_FOUND})")
endif()

if (ENABLE_CHANNELRX_NOISEFIGURE AND Boost_FOUND AND Boost_VERSION_STRING VERSION_GREATER_EQUAL "1.70.0")
    add_subdirectory(noisefigure)
else()
    message(STATUS "Not building noisefigure (ENABLE_CHANNELRX_NOISEFIGURE=${ENABLE_CHANNELRX_NOISEFIGURE} Boost_FOUND=${Boost_FOUND} Boost_VERSION_STRING=${Boost_VERSION_STRING})")
endif()

if (ENABLE_CHANNELRX_DEMODFT8 AND FT8_SUPPORT)
    add_subdirectory(demodft8)
else()
    message(STATUS "Not building demodft8 (ENABLE_CHANNELRX_DEMODFT8=${ENABLE_CHANNELRX_DEMODFT8} FT8_SUPPORT=${FT8_SUPPORT})")
endif()

if (ENABLE_CHANNELRX_DEMODNAVTEX)
    add_subdirectory(demodnavtex)
else()
    message(STATUS "Not building demodnavtex (ENABLE_CHANNELRX_DEMODNAVTEX=${ENABLE_CHANNELRX_DEMODNAVTEX})")
endif()

if (ENABLE_CHANNELRX_DEMODRTTY)
    add_subdirectory(demodrtty)
else()
    message(STATUS "Not building demodrtty (ENABLE_CHANNELRX_DEMODRTTY=${ENABLE_CHANNELRX_DEMODRTTY})")
endif()

if (ENABLE_CHANNELRX_DEMODILS)
    add_subdirectory(demodils)
else()
    message(STATUS "Not building demodils (ENABLE_CHANNELRX_DEMODILS=${ENABLE_CHANNELRX_DEMODILS})")
endif()

if (ENABLE_CHANNELRX_DEMODDSC)
    add_subdirectory(demoddsc)
else()
    message(STATUS "Not building demoddsc (ENABLE_CHANNELRX_DEMODDSC=${ENABLE_CHANNELRX_DEMODDSC})")
endif()

if (ENABLE_CHANNELRX_WDSPRX AND WDSP_SUPPORT)
    add_subdirectory(wdsprx)
else()
    message(STATUS "Not building wdsprx (ENABLE_CHANNELRX_WDSPRX=${ENABLE_CHANNELRX_WDSPRX} WDSP_SUPPORT=${WDSP_SUPPORT})")
endif()

# need ffmpeg 3.1 that correstonds to
# libavutil 55.27.100
# libavcodec 57.48.101
# libavformat 57.40.101
find_package(FFmpeg COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE)

if (ENABLE_CHANNELRX_DEMODDATV AND FFMPEG_FOUND)
    if(WIN32)
    add_subdirectory(demoddatv)
    else()
    if(((AVUTIL_VERSION VERSION_GREATER "55.27.99") AND (AVCODEC_VERSION VERSION_GREATER "57.48.101")) OR FFMPEG_EXTERNAL OR FFMPEG_SKIP_CHECK)
        message(STATUS "Include demoddatv")
        add_subdirectory(demoddatv)
    else()
        message(STATUS "FFmpeg too old to compile demoddatv; needs at least avutil: 55.27.100, avcodec/avformat: 57.48.101")
    endif()
    endif()
else()
    message(STATUS "Not building demoddatv (ENABLE_CHANNELRX_DEMODDATV=${ENABLE_CHANNELRX_DEMODDATV} FFMPEG_FOUND=${FFMPEG_FOUND})")
endif()

if(NOT SERVER_MODE)
    if (ENABLE_CHANNELRX_HEATMAP)
        add_subdirectory(heatmap)
    else()
        message(STATUS "Not building heatmap (ENABLE_CHANNELRX_HEATMAP=${ENABLE_CHANNELRX_HEATMAP})")
    endif()

    if (ENABLE_CHANNELRX_CHANALYZER)
        add_subdirectory(chanalyzer)
    else()
        message(STATUS "Not building chanalyzer (ENABLE_CHANNELRX_CHANALYZER=${ENABLE_CHANNELRX_CHANALYZER})")
    endif()

    if (ENABLE_CHANNELRX_DEMODATV)
        add_subdirectory(demodatv)
    else()
        message(STATUS "Not building demodatv (ENABLE_CHANNELRX_DEMODATV=${ENABLE_CHANNELRX_DEMODATV})")
    endif()
endif()
