cmake_minimum_required(VERSION 3.22)

project(Gjalla VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(JUCE)

# GUI fonts, embedded into the binary. Both are licensed under the SIL OFL
# (see assets/fonts/OFL-*.txt, which must ship alongside any distribution).
juce_add_binary_data(GjallaAssets
    SOURCES
        assets/fonts/UnifrakturMaguntia.ttf
        assets/fonts/IMFellEnglish.ttf)

# PLUGIN_MANUFACTURER_CODE and PLUGIN_CODE must never change after the first
# public release, or saved DAW sessions will lose the plugin. Sgnv is shared
# with Galdr and Gala and is frozen; Gjla does not collide with Gldr or Gala.
juce_add_plugin(Gjalla
    COMPANY_NAME "Sognevo"
    BUNDLE_ID com.sognevo.gjalla
    IS_SYNTH FALSE
    NEEDS_MIDI_INPUT FALSE
    NEEDS_MIDI_OUTPUT FALSE
    IS_MIDI_EFFECT FALSE
    COPY_PLUGIN_AFTER_BUILD FALSE
    PLUGIN_MANUFACTURER_CODE Sgnv
    PLUGIN_CODE Gjla
    VST3_CATEGORIES Fx Distortion
    # The standalone build takes the guitar straight off the audio input.
    MICROPHONE_PERMISSION_ENABLED TRUE
    MICROPHONE_PERMISSION_TEXT "Gjalla processes the guitar or line input."
    FORMATS VST3 AU Standalone
    PRODUCT_NAME "Gjalla")

target_sources(Gjalla PRIVATE
    src/PluginProcessor.cpp
    src/PluginEditor.cpp)

target_compile_definitions(Gjalla PUBLIC
    JUCE_WEB_BROWSER=0
    JUCE_USE_CURL=0
    JUCE_VST3_CAN_REPLACE_VST2=0
    # Disabling the splash screen is permitted when JUCE is used under the (A)GPL.
    JUCE_DISPLAY_SPLASH_SCREEN=0)

target_link_libraries(Gjalla
    PRIVATE
        GjallaAssets
        juce::juce_audio_utils
        juce::juce_dsp
    PUBLIC
        juce::juce_recommended_config_flags
        juce::juce_recommended_lto_flags
        juce::juce_recommended_warning_flags)

# Headless DSP tests, run by CI on every platform. The siblings run the console
# app directly; CTest is registered on top of it so `ctest` drives the same
# binary, as the brief asks.
enable_testing()

juce_add_console_app(GjallaTests PRODUCT_NAME "GjallaTests")
target_sources(GjallaTests PRIVATE
    tests/Tests.cpp
    src/PluginProcessor.cpp
    src/PluginEditor.cpp)
target_compile_definitions(GjallaTests PRIVATE
    JUCE_WEB_BROWSER=0
    JUCE_USE_CURL=0
    JUCE_DISPLAY_SPLASH_SCREEN=0
    JucePlugin_Name="Gjalla")
target_link_libraries(GjallaTests PRIVATE
    GjallaAssets
    juce::juce_audio_utils
    juce::juce_dsp
    juce::juce_recommended_config_flags)

add_test(NAME GjallaTests COMMAND GjallaTests)

# CLAP export (MIT-licensed wrapper around the JUCE plugin target)
add_subdirectory(modules/clap-juce-extensions EXCLUDE_FROM_ALL)
clap_juce_extensions_plugin(TARGET Gjalla
    CLAP_ID "com.sognevo.gjalla"
    CLAP_FEATURES audio-effect distortion guitar)
