juce_add_plugin(BusBalance
    VERSION                     1.0.1
    PRODUCT_NAME                "Bus Balance"
    COMPANY_NAME                "e-thomsen"
    BUNDLE_ID                   "dk.e-thomsen.busbalance"
    PLUGIN_MANUFACTURER_CODE    Etho
    PLUGIN_CODE                 Bbal
    FORMATS                     ${ET_FORMATS}
    AU_MAIN_TYPE                kAudioUnitType_Effect
    IS_SYNTH FALSE NEEDS_MIDI_INPUT FALSE NEEDS_MIDI_OUTPUT FALSE IS_MIDI_EFFECT FALSE
    EDITOR_WANTS_KEYBOARD_FOCUS FALSE
    COPY_PLUGIN_AFTER_BUILD     TRUE)
target_sources(BusBalance PRIVATE Source/PluginProcessor.cpp Source/PluginEditor.cpp)
et_configure_plugin(BusBalance)

if(ET_BUILD_TESTS)
    add_executable(test_busbalance tests/test_balance.cpp)
    target_include_directories(test_busbalance PRIVATE Source/DSP ${CMAKE_SOURCE_DIR}/Common/DSP)
endif()

if(ET_BUILD_TESTS)
    # 17 processors in one process: the one without a registry slot passes audio untouched and says so
    juce_add_console_app(test_busbalance_overflow PRODUCT_NAME "test_busbalance_overflow")
    target_sources(test_busbalance_overflow PRIVATE tests/test_overflow.cpp Source/PluginProcessor.cpp Source/PluginEditor.cpp)
    target_include_directories(test_busbalance_overflow PRIVATE Source ${CMAKE_SOURCE_DIR}/Common ${CMAKE_SOURCE_DIR}/Common/DSP)
    target_compile_definitions(test_busbalance_overflow PRIVATE JUCE_WEB_BROWSER=0 JUCE_USE_CURL=0 JUCE_MODAL_LOOPS_PERMITTED=1
                               "JucePlugin_Name=\"Bus Balance\"")
    target_link_libraries(test_busbalance_overflow PRIVATE juce::juce_audio_utils et_common_assets juce::juce_dsp juce::juce_recommended_config_flags)
endif()

if(ET_BUILD_TESTS)
    # band publication between two threads (also built by hand with -fsanitize=thread, see README)
    find_package(Threads REQUIRED)
    add_executable(test_busbalance_race tests/test_registry_race.cpp)
    target_include_directories(test_busbalance_race PRIVATE Source/DSP ${CMAKE_SOURCE_DIR}/Common/DSP)
    target_link_libraries(test_busbalance_race PRIVATE Threads::Threads)

    # six processors with synthetic buses; renders the vocals window in both views
    juce_add_console_app(test_busbalance_masking PRODUCT_NAME "test_busbalance_masking")
    target_sources(test_busbalance_masking PRIVATE tests/test_masking_view.cpp Source/PluginProcessor.cpp Source/PluginEditor.cpp)
    target_include_directories(test_busbalance_masking PRIVATE Source ${CMAKE_SOURCE_DIR}/Common ${CMAKE_SOURCE_DIR}/Common/DSP)
    target_compile_definitions(test_busbalance_masking PRIVATE JUCE_WEB_BROWSER=0 JUCE_USE_CURL=0 JUCE_MODAL_LOOPS_PERMITTED=1
                               "JucePlugin_Name=\"Bus Balance\"")
    target_link_libraries(test_busbalance_masking PRIVATE juce::juce_audio_utils et_common_assets juce::juce_dsp juce::juce_recommended_config_flags)
endif()
