# -*- cmake -*-
# Copyright 2021 Jean Pierre Cimalando
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

include(FetchContent)

if(YSFX_PLUGIN_USE_SYSTEM_JUCE)
    find_package(JUCE REQUIRED)
else()
    FetchContent_Declare(juce
        URL "https://github.com/juce-framework/JUCE/archive/refs/tags/7.0.0.tar.gz"
        URL_HASH "SHA512=0347380fce37eae58a2cfd2d14cf3d8025b37e8de87104656cc0699a8de914762199d4e6a214d24afd99cee548ec6aec198a7a04d804a97d0f4ceed49bf9a969")

    FetchContent_GetProperties(juce)
    if(NOT juce_POPULATED)
        FetchContent_Populate(juce)
        add_subdirectory("${juce_SOURCE_DIR}" "${juce_BINARY_DIR}" EXCLUDE_FROM_ALL)
    endif()
endif()

if(YSFX_PLUGIN_VST3_SDK_PATH)
    juce_set_vst3_sdk_path("${YSFX_PLUGIN_VST3_SDK_PATH}")
endif()

juce_add_plugin(ysfx_plugin
  PLUGIN_CODE "ysfx"
  PLUGIN_MANUFACTURER_CODE "Jpci"
  PRODUCT_NAME "ysfx"
  COMPANY_NAME "Jean Pierre Cimalando"
  FORMATS VST3 AU
  NEEDS_MIDI_INPUT TRUE
  NEEDS_MIDI_OUTPUT TRUE
  NEEDS_CURL FALSE
  NEEDS_WEB_BROWSER FALSE
  VST3_CATEGORIES "Fx"
  AU_MAIN_TYPE "kAudioUnitType_Effect"
  COPY_PLUGIN_AFTER_BUILD "${YSFX_PLUGIN_COPY}")

target_sources(ysfx_plugin
    PRIVATE
        "plugin/processor.cpp"
        "plugin/processor.h"
        "plugin/editor.cpp"
        "plugin/editor.h"
        "plugin/lookandfeel.cpp"
        "plugin/lookandfeel.h"
        "plugin/parameter.cpp"
        "plugin/parameter.h"
        "plugin/info.cpp"
        "plugin/info.h"
        "plugin/components/parameters_panel.cpp"
        "plugin/components/parameters_panel.h"
        "plugin/components/graphics_view.cpp"
        "plugin/components/graphics_view.h"
        "plugin/components/ide_view.cpp"
        "plugin/components/ide_view.h"
        "plugin/utility/audio_processor_suspender.h"
        "plugin/utility/functional_timer.h"
        "plugin/utility/async_updater.cpp"
        "plugin/utility/async_updater.h"
        "plugin/utility/rt_semaphore.cpp"
        "plugin/utility/rt_semaphore.h"
        "plugin/utility/sync_bitset.hpp")

target_compile_definitions(ysfx_plugin
  PUBLIC
      "JUCE_WEB_BROWSER=0"
      "JUCE_USE_CURL=0"
      "JUCE_VST3_CAN_REPLACE_VST2=0"
      "JUCE_DISPLAY_SPLASH_SCREEN=0")

target_include_directories(ysfx_plugin
    PRIVATE
        "plugin")

target_link_libraries(ysfx_plugin
  PRIVATE
      ysfx::ysfx
      juce::juce_audio_processors
      juce::juce_gui_basics
      juce::juce_gui_extra
      juce::juce_opengl
      juce::juce_recommended_config_flags
      juce::juce_recommended_warning_flags)

if(YSFX_PLUGIN_LTO)
    target_link_libraries(ysfx_plugin PRIVATE juce::juce_recommended_lto_flags)
endif()

if(YSFX_PLUGIN_FORCE_DEBUG)
    target_compile_definitions(ysfx_plugin PRIVATE "JUCE_FORCE_DEBUG=1")
endif()
