# setup
find_package(lv2-plugin REQUIRED)
include_directories(include ../newt_core/include)
include_directories( ${LV2-PLUGIN_INCLUDE_DIRS} )

# generate manifest & PEG file
if (INCLUDE_EXT_INPUTS)
  set(CM_SCRIPT_ARG "true")
endif()
add_custom_command(
  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/bundle/newt_lv2_instr.ttl
  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/newt_lv2_instr.peg
  COMMAND "bash" ${CMAKE_SOURCE_DIR}/scripts/create_manifest.sh ${CMAKE_SOURCE_DIR} ${CM_SCRIPT_ARG}
  COMMAND ${PEG_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/bundle/newt_lv2_instr.ttl ${CMAKE_CURRENT_SOURCE_DIR}/include/newt_lv2_instr.peg
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bundle/newt_lv2_instr_begin.ttl
    ${CMAKE_CURRENT_SOURCE_DIR}/bundle/newt_lv2_instr_end.ttl
	${CMAKE_CURRENT_SOURCE_DIR}/bundle/newt_lv2_instr_extinputs.ttl
  )
set_source_files_properties(
  ${CMAKE_CURRENT_SOURCE_DIR}/include/newt_lv2_instr.peg PROPERTIES
  GENERATED 1
  CPLUSPLUS ON
  )

# build lib
add_library(newt_lv2_instr SHARED
  newt_lv2_instr.cpp
  newt_lv2_voice.cpp
  include/config.h
  include/newt_lv2_instr.h
  include/newt_lv2_voice.h
  include/newt_lv2_instr.peg
)
set_target_properties(newt_lv2_instr PROPERTIES PREFIX "")
if (DEBUG)
  set_target_properties(newt_lv2_instr PROPERTIES COMPILE_FLAGS "-g")
endif()
target_link_libraries(newt_lv2_instr newt_core ${LV2-PLUGIN_LIBRARIES} stk )

# install lv2 bundle
install(TARGETS newt_lv2_instr
  LIBRARY
  DESTINATION ${LV2_INSTALL_DIR}/newtonator.lv2
  NAMELINK_SKIP
  )
install(FILES bundle/manifest.ttl bundle/newt_lv2_instr.ttl
  DESTINATION ${LV2_INSTALL_DIR}/newtonator.lv2
  )
