cmake_minimum_required(VERSION 3.22)

project(SerumAlt VERSION 1.0.0 LANGUAGES CXX)

# ---------------------------------------------------------------------------
# C++ standard
# ---------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# ---------------------------------------------------------------------------
# JUCE
# ---------------------------------------------------------------------------
if(NOT DEFINED JUCE_ROOT)
    set(JUCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/JUCE")
endif()
add_subdirectory("${JUCE_ROOT}")

# ---------------------------------------------------------------------------
# Plugin target
# ---------------------------------------------------------------------------
# JUCE 7.0.12 builds its VST3 manifest helper (juce_vst3_helper) with the same
# toolchain as the plugin itself. When cross-compiling, that produces a Windows
# .exe which cannot run on the Linux build host, so we disable the automatic
# manifest step and inject a platform-independent moduleinfo.json afterwards
# (see build_windows.sh). Native builds keep the automatic step.
set(SERUMALT_VST3_AUTO_MANIFEST TRUE)
if(CMAKE_CROSSCOMPILING)
    set(SERUMALT_VST3_AUTO_MANIFEST FALSE)
endif()

juce_add_plugin(SerumAlt
    VERSION 1.0.0
    COMPANY_NAME "SerumAlt Audio"
    IS_SYNTH TRUE
    NEEDS_MIDI_INPUT TRUE
    NEEDS_MIDI_OUTPUT FALSE
    IS_MIDI_EFFECT FALSE
    EDITOR_WANTS_KEYBOARD_FOCUS FALSE
    PLUGIN_MANUFACTURER_CODE Salt
    PLUGIN_CODE Sera
    BUNDLE_ID com.serumalt.SerumAlt
    FORMATS VST3 AU Standalone
    PRODUCT_NAME "SerumAlt"
    VST3_AUTO_MANIFEST ${SERUMALT_VST3_AUTO_MANIFEST})

juce_generate_juce_header(SerumAlt)

set(SERUMALT_SOURCES
    Source/PluginProcessor.cpp
    Source/PluginEditor.cpp
    Source/Params.cpp
    Source/Wavetable.cpp
    Source/Oscillator.cpp
    Source/SubOscillator.cpp
    Source/NoiseOscillator.cpp
    Source/Filter.cpp
    Source/FilterBank.cpp
    Source/Envelope.cpp
    Source/LFO.cpp
    Source/ModulationMatrix.cpp
    Source/FXProcessor.cpp
    Source/MacroControls.cpp
    Source/RAVEButton.cpp
    Source/SynthVoice.cpp
    Source/Engine.cpp
    Source/Resources.cpp
    Source/EffectUnits/Hyper.cpp
    Source/EffectUnits/Chorus.cpp
    Source/EffectUnits/Flanger.cpp
    Source/EffectUnits/Phaser.cpp
    Source/EffectUnits/Distortion.cpp
    Source/EffectUnits/EQ.cpp
    Source/EffectUnits/Compressor.cpp
    Source/EffectUnits/Delay.cpp
    Source/EffectUnits/Reverb.cpp
    Source/GUI/Knob.cpp
    Source/GUI/Slider.cpp
    Source/GUI/ToggleButton.cpp
    Source/GUI/Display.cpp
    Source/GUI/WaveformDisplay.cpp
    Source/GUI/FilterDisplay.cpp
    Source/GUI/EnvelopeDisplay.cpp
    Source/GUI/LFODisplay.cpp
    Source/GUI/Panel.cpp
    Source/Presets/FactoryPresets.cpp)

target_sources(SerumAlt PRIVATE ${SERUMALT_SOURCES})

target_compile_definitions(SerumAlt
    PUBLIC
        JUCE_WEB_BROWSER=0
        JUCE_USE_CURL=0
        JUCE_VST3_CAN_REPLACE_VST2=0)

target_link_libraries(SerumAlt
    PRIVATE
        juce::juce_audio_utils
        juce::juce_dsp
    PUBLIC
        juce::juce_recommended_config_flags
        juce::juce_recommended_warning_flags)

# ---------------------------------------------------------------------------
# Headless QA harness (console app that drives the processor and checks output)
# ---------------------------------------------------------------------------
option(SERUMALT_BUILD_TESTS "Build the headless QA harness" ON)

if(SERUMALT_BUILD_TESTS)
    juce_add_console_app(SerumAltTest)
    juce_generate_juce_header(SerumAltTest)
    target_sources(SerumAltTest PRIVATE ${SERUMALT_SOURCES} Source/Tests/TestMain.cpp)
    target_compile_definitions(SerumAltTest
        PUBLIC
            JUCE_WEB_BROWSER=0
            JUCE_USE_CURL=0)
    target_link_libraries(SerumAltTest
        PRIVATE
            juce::juce_audio_utils
            juce::juce_dsp
        PUBLIC
            juce::juce_recommended_config_flags
            juce::juce_recommended_warning_flags)
endif()

if(MSVC)
    target_compile_options(SerumAlt PRIVATE /W4)
else()
    target_compile_options(SerumAlt PRIVATE -Wall -Wextra)
endif()
