cmake_minimum_required(VERSION 3.22)

project(SerumAlt VERSION 1.0.0 LANGUAGES CXX)

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()

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/Plugin/PluginProcessor.cpp
    Source/GUI/PluginEditor.cpp
    Source/Params/Params.cpp
    Source/Synth/Wavetable.cpp
    Source/Synth/Oscillator.cpp
    Source/Synth/SubOscillator.cpp
    Source/Synth/NoiseOscillator.cpp
    Source/Synth/Filter.cpp
    Source/Synth/FilterBank.cpp
    Source/Synth/Envelope.cpp
    Source/Synth/LFO.cpp
    Source/Modulation/ModulationMatrix.cpp
    Source/EffectUnits/FXProcessor.cpp
    Source/Modulation/MacroControls.cpp
    Source/Modulation/RAVEButton.cpp
    Source/Synth/SynthVoice.cpp
    Source/Engine/Engine.cpp
    Source/Resources/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/KnobLookAndFeel.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)

# One include directory per module, so a source names a header without a path
# prefix. No two headers in this tree share a basename.
set(SERUMALT_INCLUDE_DIRS
    Source
    Source/EffectUnits
    Source/Engine
    Source/GUI
    Source/Modulation
    Source/Params
    Source/Plugin
    Source/Presets
    Source/Resources
    Source/Synth
    Source/Tests)

function(serumalt_configure_target target)
    juce_generate_juce_header(${target})
    target_sources(${target} PRIVATE ${SERUMALT_SOURCES})
    target_include_directories(${target} PRIVATE ${SERUMALT_INCLUDE_DIRS})
    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()
