cmake_minimum_required(VERSION 3.22)
# Apple Silicon only (no Intel builds); ignored on other platforms.
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Target architecture on macOS")
project(EThomsenPlugins VERSION 1.0.0 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(APPLE)
    set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum macOS version")
endif()

# JUCE is fetched once for all plugins (needs network on the first configure).
include(FetchContent)
FetchContent_Declare(JUCE
    GIT_REPOSITORY https://github.com/juce-framework/JUCE.git
    GIT_TAG        8.0.9
    GIT_SHALLOW    TRUE)
FetchContent_MakeAvailable(JUCE)

if(APPLE)
    set(ET_FORMATS AU)                 # Logic
else()
    set(ET_FORMATS VST3 Standalone)    # compile checks and GUI screenshots only
endif()

option(ET_BUILD_TESTS "Build the headless DSP tests" OFF)

# Shared binary data (Common/UI/Widgets.h): the company mark drawn in every header (ui::LogoMark), the
# knob cap, the surface grain and the Inter ET typeface (ui::Style). Built from their sources by
# Common/UI/assets/tools/make_assets.py.
set(ET_ASSETS ${CMAKE_CURRENT_SOURCE_DIR}/Common/UI/assets)
juce_add_binary_data(et_common_assets
    HEADER_NAME EtCommonAssets.h
    NAMESPACE   EtAssets
    SOURCES     ${ET_ASSETS}/logo-mark.png
                ${ET_ASSETS}/knob-256.png
                ${ET_ASSETS}/knob-128.png
                ${ET_ASSETS}/texture-512.jpg
                ${ET_ASSETS}/fonts/InterET-Regular.ttf
                ${ET_ASSETS}/fonts/InterET-Medium.ttf
                ${ET_ASSETS}/fonts/InterET-SemiBold.ttf)

# Common settings for every plugin target
function(et_configure_plugin target)
    target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source ${CMAKE_SOURCE_DIR}/Common ${CMAKE_SOURCE_DIR}/Common/DSP)
    target_compile_definitions(${target} PUBLIC
        JUCE_WEB_BROWSER=0
        JUCE_USE_CURL=0
        JUCE_VST3_CAN_REPLACE_VST2=0
        JUCE_DISPLAY_SPLASH_SCREEN=0)
    target_link_libraries(${target}
        PRIVATE juce::juce_audio_utils juce::juce_dsp et_common_assets
        PUBLIC  juce::juce_recommended_config_flags juce::juce_recommended_warning_flags)
    if(APPLE)
        target_link_libraries(${target} PUBLIC juce::juce_recommended_lto_flags)   # LTO only for the real builds
    endif()
endfunction()

# Window renders for the screenshots (<Plugin>/tests/render_view.cpp, test_<plugin>_view; only with
# ET_BUILD_TESTS): linked against the plugin's SharedCode library like the golden tools, so the
# processor and editor are the object code that goes into the VST3/AU. tools/screenshots/ViewHarness.h
# runs them; the signals come from Strip/tests/Signals.h and VocalChain/tests/Singer.h.
function(et_add_view_harness plugin target)
    if(ET_BUILD_TESTS AND TARGET ${plugin})
        add_executable(${target} ${ARGN})
        target_include_directories(${target} PRIVATE $<TARGET_PROPERTY:${plugin},INCLUDE_DIRECTORIES>
            ${CMAKE_SOURCE_DIR}/tools/screenshots ${CMAKE_SOURCE_DIR}/Strip/tests ${CMAKE_SOURCE_DIR}/VocalChain/tests)
        target_link_libraries(${target} PRIVATE ${plugin})
    endif()
endfunction()

add_subdirectory(VocalChain)
add_subdirectory(KickTune)
add_subdirectory(KickBassCheck)
add_subdirectory(VocalRider)
add_subdirectory(BusBalance)
add_subdirectory(HeadroomCheck)
add_subdirectory(NotePan)
add_subdirectory(Pump)
add_subdirectory(Punch)
add_subdirectory(Colour)
add_subdirectory(Loud)
add_subdirectory(Reference)
add_subdirectory(KickSynth)
add_subdirectory(SubBass)
add_subdirectory(VocalPocket)
add_subdirectory(Harmony)
add_subdirectory(EQ)
add_subdirectory(DrumWidener)
add_subdirectory(Strip)
add_subdirectory(Wings)

# The shared engines (Common/DSP/Engines) on their own, against the plugins that carry them
if(ET_BUILD_TESTS)
    add_executable(test_engines Common/tests/test_engines.cpp)
    target_include_directories(test_engines PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/Common/DSP)
endif()

# Golden renders (tools/golden): every plugin's processor through fixed signals and parameter sets,
# output, latency, state and editor written raw, to prove an internal change leaves them identical.
option(ET_BUILD_GOLDEN "Build the golden render tools (tools/golden)" OFF)
if(ET_BUILD_GOLDEN)
    add_subdirectory(tools/golden)
endif()

