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)

option(SERUMALT_BUILD_PLUGIN "Build production plugin and standalone formats" ON)
option(SERUMALT_BUILD_TESTS "Build the headless QA harness" OFF)

if(NOT SERUMALT_BUILD_PLUGIN AND NOT SERUMALT_BUILD_TESTS)
    message(FATAL_ERROR "Enable SERUMALT_BUILD_PLUGIN or SERUMALT_BUILD_TESTS")
endif()

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

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)

function(serumalt_configure_target target)
    juce_generate_juce_header(${target})
    target_sources(${target} PRIVATE ${SERUMALT_SOURCES})
    target_compile_definitions(${target}
        PUBLIC
            JUCE_WEB_BROWSER=0
            JUCE_USE_CURL=0
            JUCE_VST3_CAN_REPLACE_VST2=0)
    target_link_libraries(${target}
        PRIVATE
            juce::juce_audio_utils
            juce::juce_dsp
        PUBLIC
            juce::juce_recommended_config_flags
            juce::juce_recommended_warning_flags)
    if(MSVC)
        target_compile_options(${target} PRIVATE /W4)
    else()
        target_compile_options(${target} PRIVATE -Wall -Wextra)
    endif()
endfunction()

if(SERUMALT_BUILD_PLUGIN)
    include(cmake/Plugin.cmake)
endif()

if(SERUMALT_BUILD_TESTS)
    enable_testing()
    include(cmake/Harness.cmake)
endif()
