set(GLDOZE_AUDIO_EDITOR_APP_DIR "${CMAKE_BINARY_DIR}/apps/audio-editor")
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/apps/audio-editor-sdk-preview")

add_library(gldoze_audio_editor MODULE audio_editor_preview_plugin.cpp)
target_link_libraries(gldoze_audio_editor PRIVATE gldoze_sdk)
set_target_properties(gldoze_audio_editor PROPERTIES
  LIBRARY_OUTPUT_DIRECTORY "${GLDOZE_AUDIO_EDITOR_APP_DIR}"
  PREFIX "lib"
  OUTPUT_NAME "gldoze_audio_editor"
  CXX_VISIBILITY_PRESET hidden
  VISIBILITY_INLINES_HIDDEN YES
)

file(MAKE_DIRECTORY "${GLDOZE_AUDIO_EDITOR_APP_DIR}")
configure_file(app.json.in "${GLDOZE_AUDIO_EDITOR_APP_DIR}/app.json" @ONLY)
configure_file("${GLDOZE_REPO_ROOT}/assets/desktop/icons/audio-editor.svg"
  "${GLDOZE_AUDIO_EDITOR_APP_DIR}/icon.svg" COPYONLY)

install(TARGETS gldoze_audio_editor
  LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/gldoze/apps/audio-editor"
  COMPONENT GLDozeDesktop)
install(FILES
  "${GLDOZE_AUDIO_EDITOR_APP_DIR}/app.json"
  "${GLDOZE_AUDIO_EDITOR_APP_DIR}/icon.svg"
  DESTINATION "${CMAKE_INSTALL_LIBDIR}/gldoze/apps/audio-editor"
  COMPONENT GLDozeDesktop)

if(BUILD_TESTING)
  add_executable(audio_editor_plugin_test audio_editor_preview_plugin_test.cpp)
  target_link_libraries(audio_editor_plugin_test PRIVATE gldoze_plugin_runtime)
  add_dependencies(audio_editor_plugin_test gldoze_audio_editor)
  add_test(NAME audio_editor_plugin
    COMMAND audio_editor_plugin_test "${GLDOZE_AUDIO_EDITOR_APP_DIR}/app.json")
endif()
