LynxPlugins.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # LYNX's own plugins as VST3 / CLAP (round 180b, docs/PLUGIN_EXPORT.md; LV2 on Linux behind LYNX_PLUGINS_LV2, round 190ov). Included from CMakeLists.txt only with
  2. # -DLYNX_BUILD_PLUGINS=ON. One static library holds JUCE and the app's sources (compiled once); each VST3 adds JUCE's wrapper
  3. # for its catalog entry, and one CLAP module holds every entry.
  4. add_library(lynx_plugin_runtime STATIC src/plugin/ExportProcessor.cpp ${LYNX_APP_SOURCES})
  5. set(LYNX_PLUGIN_DEFINES
  6. JUCE_WEB_BROWSER=0 JUCE_USE_CURL=0 JUCE_PLUGINHOST_VST3=1 JUCE_USE_MP3AUDIOFORMAT=0
  7. JUCE_STANDALONE_APPLICATION=0 JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1
  8. JUCE_APPLICATION_NAME_STRING="LYNX" JUCE_APPLICATION_VERSION_STRING="${PROJECT_VERSION}"
  9. LYNX_EXPORT_VERSION="${PROJECT_VERSION}")
  10. foreach(m juce_core juce_data_structures juce_events juce_graphics juce_gui_basics juce_gui_extra juce_audio_basics
  11. juce_audio_devices juce_audio_formats juce_audio_processors juce_audio_utils juce_dsp juce_opengl)
  12. list(APPEND LYNX_PLUGIN_DEFINES JUCE_MODULE_AVAILABLE_${m}=1)
  13. endforeach()
  14. if(WIN32)
  15. list(APPEND LYNX_PLUGIN_DEFINES JUCE_ASIO=1)
  16. target_include_directories(lynx_plugin_runtime PRIVATE third_party/asiosdk/common)
  17. target_link_libraries(lynx_plugin_runtime PRIVATE winhttp ws2_32 iphlpapi) # (iphlpapi, ws2_32: Ableton Link, round 190gl)
  18. target_link_libraries(lynx_plugin_runtime PRIVATE mfplat mfreadwrite mfuuid) # (Media Foundation: video decoding, M4A export)
  19. elseif(APPLE)
  20. list(APPEND LYNX_PLUGIN_DEFINES JUCE_PLUGINHOST_AU=1)
  21. # the system's video decoder, as in the app (ui/VideoMediaMac.mm; manual retain / release)
  22. target_sources(lynx_plugin_runtime PRIVATE src/ui/VideoMediaMac.mm)
  23. set_source_files_properties(src/ui/VideoMediaMac.mm PROPERTIES COMPILE_OPTIONS "-fno-objc-arc")
  24. target_link_libraries(lynx_plugin_runtime PRIVATE "-framework AVFoundation" "-framework CoreMedia" "-framework CoreVideo"
  25. "-framework AudioToolbox" "-framework CoreFoundation" ${CMAKE_DL_LIBS}) # (AudioToolbox: M4A export)
  26. # the moving marks' backend, as in the app: ui/MotionOverlay.cpp (in LYNX_APP_SOURCES) calls it (round 190nk)
  27. target_sources(lynx_plugin_runtime PRIVATE src/ui/MotionOverlayMac.mm)
  28. set_source_files_properties(src/ui/MotionOverlayMac.mm PROPERTIES COMPILE_OPTIONS "-fno-objc-arc")
  29. target_link_libraries(lynx_plugin_runtime PRIVATE "-framework QuartzCore")
  30. else()
  31. list(APPEND LYNX_PLUGIN_DEFINES JUCE_ALSA=1 JUCE_JACK=1 JUCE_PLUGINHOST_LV2=1)
  32. target_include_directories(lynx_plugin_runtime SYSTEM PRIVATE third_party/pipewire/include/pipewire-0.3 third_party/pipewire/include/spa-0.2)
  33. target_link_libraries(lynx_plugin_runtime PRIVATE ${CMAKE_DL_LIBS})
  34. # the moving marks' X11 backend, as in the app: ui/MotionOverlay.cpp (in LYNX_APP_SOURCES) calls it (round 190nk; the
  35. # 0.1.30 release run's Linux plugin link failed without it)
  36. target_sources(lynx_plugin_runtime PRIVATE src/ui/MotionOverlayX11.cpp)
  37. endif()
  38. target_compile_definitions(lynx_plugin_runtime PUBLIC ${LYNX_PLUGIN_DEFINES})
  39. target_include_directories(lynx_plugin_runtime
  40. PUBLIC src third_party/clap/include "${juce_SOURCE_DIR}/modules" "${juce_SOURCE_DIR}/modules/juce_audio_processors/format_types/VST3_SDK"
  41. PRIVATE third_party/onnxruntime ${CMAKE_CURRENT_BINARY_DIR}/lynx_build)
  42. target_link_libraries(lynx_plugin_runtime
  43. PUBLIC lynx_core
  44. PRIVATE juce::juce_audio_utils juce::juce_audio_processors juce::juce_dsp juce::juce_opengl)
  45. set_target_properties(lynx_plugin_runtime PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON)
  46. # the host's symbols are never taken for ours, and only the entry points are visible
  47. function(lynx_finish_plugin target)
  48. set_target_properties(${target} PROPERTIES PREFIX "" CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON)
  49. target_link_libraries(${target} PRIVATE lynx_plugin_runtime)
  50. if(WIN32)
  51. target_sources(${target} PRIVATE resources/LynxPlugin.rc)
  52. endif()
  53. if(APPLE)
  54. target_link_options(${target} PRIVATE -Wl,-dead_strip)
  55. endif()
  56. if(UNIX AND NOT APPLE)
  57. target_link_options(${target} PRIVATE -static-libstdc++ -static-libgcc -Wl,--gc-sections -Wl,--exclude-libs,ALL -Wl,-z,defs)
  58. target_compile_options(${target} PRIVATE -ffunction-sections -fdata-sections)
  59. endif()
  60. endfunction()
  61. if(WIN32)
  62. set(LYNX_VST3_ARCH x86_64-win)
  63. elseif(APPLE)
  64. set(LYNX_VST3_ARCH MacOS)
  65. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64")
  66. set(LYNX_VST3_ARCH aarch64-linux)
  67. else()
  68. set(LYNX_VST3_ARCH x86_64-linux)
  69. endif()
  70. set(LYNX_PLUGIN_OUT "${CMAKE_BINARY_DIR}/plugins")
  71. # round 190ov: the VST3 short list also as LV2 bundles on Linux (JUCE's LV2 wrapper, plugin/Lv2Entry.cpp). On since round
  72. # 190pk (0.1.31), which fixed what made JUCE's LV2 host fail on them (cmake/LynxPatchJuce.cmake, fix 50)
  73. option(LYNX_PLUGINS_LV2 "Linux: build the VST3 short list as LV2 bundles too" ON)
  74. # every built entry of the one table, src/plugin/plugins.def; the index counts the built entries (plugin/ExportCatalog.h).
  75. # built = 2: a VST3 of its own as well (built = 1: in the CLAP only)
  76. file(STRINGS src/plugin/plugins.def LYNX_PLUGIN_LINES REGEX "^LYNX_PLUGIN .*, [12][)]$")
  77. # (round 190pq: an edit of the table re-runs CMake, so a newly built entry gets its targets in an existing build folder)
  78. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/plugins.def")
  79. set(index 0)
  80. set(LYNX_PLUGIN_TARGETS lynx_clap)
  81. foreach(line IN LISTS LYNX_PLUGIN_LINES)
  82. # (round 190ov: the LV2 URI comes from the clap id, read first: a REGEX REPLACE resets CMAKE_MATCH_<n>)
  83. string(REGEX REPLACE "^LYNX_PLUGIN [(]\"[^\"]+\", [01], [^,]+, [^,]+, \"com[.]ka1-s[.]lynx[.]([^\"]+)\", .*$" "\\1" lv2_id "${line}")
  84. if(NOT line MATCHES "^LYNX_PLUGIN [(]\"([^\"]+)\", ([01]), [^,]+, [^,]+, \"[^\"]+\", (0x[0-9a-f]+), \"([^\"]+)\", ([12])[)]$")
  85. message(FATAL_ERROR "src/plugin/plugins.def: can't read: ${line}")
  86. endif()
  87. if(CMAKE_MATCH_5 STREQUAL "2")
  88. set(name "${CMAKE_MATCH_1}")
  89. set(target "lynx_vst3_${index}")
  90. add_library(${target} MODULE src/plugin/Vst3Entry.cpp)
  91. target_compile_definitions(${target} PRIVATE LYNX_EXPORT_INDEX=${index} JucePlugin_Name="${name}" JucePlugin_IsSynth=${CMAKE_MATCH_2}
  92. JucePlugin_PluginCode=${CMAKE_MATCH_3} JucePlugin_Vst3Category="${CMAKE_MATCH_4}")
  93. lynx_finish_plugin(${target})
  94. if(APPLE)
  95. # a bundle: <name>.vst3/Contents/{Info.plist, MacOS/<name>}
  96. set_source_files_properties(src/plugin/Vst3Entry.cpp PROPERTIES COMPILE_OPTIONS "-xobjective-c++")
  97. string(REGEX REPLACE "[^A-Za-z0-9]" "-" bundle_id "${name}")
  98. set_target_properties(${target} PROPERTIES BUNDLE TRUE BUNDLE_EXTENSION vst3 OUTPUT_NAME "${name}"
  99. LIBRARY_OUTPUT_DIRECTORY "${LYNX_PLUGIN_OUT}"
  100. MACOSX_BUNDLE_GUI_IDENTIFIER "com.ka1-s.lynx.vst3.${bundle_id}"
  101. MACOSX_BUNDLE_BUNDLE_NAME "${name}"
  102. MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
  103. MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
  104. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/resources/plugin/Info.plist.in")
  105. else()
  106. set_target_properties(${target} PROPERTIES
  107. OUTPUT_NAME "${name}"
  108. LIBRARY_OUTPUT_DIRECTORY "${LYNX_PLUGIN_OUT}/${name}.vst3/Contents/${LYNX_VST3_ARCH}")
  109. endif()
  110. if(WIN32)
  111. set_target_properties(${target} PROPERTIES SUFFIX ".vst3")
  112. endif()
  113. list(APPEND LYNX_PLUGIN_TARGETS ${target})
  114. # round 190ov: on Linux the same short list as LV2 bundles (JUCE's LV2 wrapper, plugin/Lv2Entry.cpp):
  115. # <name with dashes>.lv2/{<name>.so, manifest.ttl, dsp.ttl, ui.ttl}, the .ttl files written by JUCE's juce_lv2_helper
  116. if(UNIX AND NOT APPLE AND LYNX_PLUGINS_LV2)
  117. set(lv2_defs LYNX_EXPORT_INDEX=${index} JucePlugin_Name="${name}" JucePlugin_IsSynth=${CMAKE_MATCH_2}
  118. JucePlugin_PluginCode=${CMAKE_MATCH_3} JucePlugin_Vst3Category="${CMAKE_MATCH_4}"
  119. JucePlugin_LV2URI="https://lynx-share.com/plugins/lv2/${lv2_id}")
  120. # (round 190pk: an effect's LV2 class from its VST3 category, so LV2 hosts file it; JUCE wrote lv2:Plugin)
  121. set(lv2_class "")
  122. set(lv2_category "${CMAKE_MATCH_4}") # (copied: the MATCHES below resets CMAKE_MATCH_<n>)
  123. if(CMAKE_MATCH_2 STREQUAL "0")
  124. foreach(pair "EQ=EQPlugin" "Dynamics=DynamicsPlugin" "Reverb=ReverbPlugin" "Delay=DelayPlugin" "Pitch=PitchPlugin")
  125. string(REPLACE "=" ";" pair "${pair}")
  126. list(GET pair 0 word)
  127. list(GET pair 1 cls)
  128. if(lv2_class STREQUAL "" AND lv2_category MATCHES "(^|[|])${word}")
  129. set(lv2_class "lv2:${cls}")
  130. endif()
  131. endforeach()
  132. endif()
  133. if(NOT lv2_class STREQUAL "")
  134. list(APPEND lv2_defs JucePlugin_LV2Class="${lv2_class}")
  135. endif()
  136. string(REGEX REPLACE "[^A-Za-z0-9]" "-" lv2_name "${name}")
  137. set(lv2_target "lynx_lv2_${index}")
  138. add_library(${lv2_target} MODULE src/plugin/Lv2Entry.cpp)
  139. target_compile_definitions(${lv2_target} PRIVATE ${lv2_defs})
  140. target_include_directories(${lv2_target} PRIVATE src/plugin/lv2)
  141. target_link_libraries(${lv2_target} PRIVATE juce_lilv_headers)
  142. lynx_finish_plugin(${lv2_target})
  143. set_target_properties(${lv2_target} PROPERTIES OUTPUT_NAME "${lv2_name}" LIBRARY_OUTPUT_DIRECTORY "${LYNX_PLUGIN_OUT}/${lv2_name}.lv2")
  144. if(NOT TARGET lynx_lv2_helper)
  145. add_executable(lynx_lv2_helper "${juce_SOURCE_DIR}/modules/juce_audio_plugin_client/LV2/juce_LV2ManifestHelper.cpp")
  146. target_compile_features(lynx_lv2_helper PRIVATE cxx_std_17)
  147. target_link_libraries(lynx_lv2_helper PRIVATE ${CMAKE_DL_LIBS})
  148. endif()
  149. add_custom_command(TARGET ${lv2_target} POST_BUILD COMMAND lynx_lv2_helper "$<TARGET_FILE:${lv2_target}>" VERBATIM)
  150. list(APPEND LYNX_PLUGIN_TARGETS ${lv2_target})
  151. endif()
  152. endif()
  153. math(EXPR index "${index} + 1")
  154. endforeach()
  155. add_library(lynx_clap MODULE src/plugin/ClapEntry.cpp)
  156. lynx_finish_plugin(lynx_clap)
  157. if(APPLE)
  158. # a bundle: LYNX Plugins.clap/Contents/{Info.plist, MacOS/LYNX Plugins}
  159. set_target_properties(lynx_clap PROPERTIES BUNDLE TRUE BUNDLE_EXTENSION clap OUTPUT_NAME "LYNX Plugins"
  160. LIBRARY_OUTPUT_DIRECTORY "${LYNX_PLUGIN_OUT}"
  161. MACOSX_BUNDLE_GUI_IDENTIFIER "com.ka1-s.lynx.clap"
  162. MACOSX_BUNDLE_BUNDLE_NAME "LYNX Plugins"
  163. MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
  164. MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
  165. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/resources/plugin/Info.plist.in")
  166. else()
  167. set_target_properties(lynx_clap PROPERTIES OUTPUT_NAME "LYNX Plugins" SUFFIX ".clap" LIBRARY_OUTPUT_DIRECTORY "${LYNX_PLUGIN_OUT}")
  168. endif()
  169. # the check: loads the built plugins as a host does (docs/PLUGIN_EXPORT.md)
  170. add_executable(plugexporttest tools/plugexporttest.cpp)
  171. target_link_libraries(plugexporttest PRIVATE lynx_plugin_runtime)
  172. # every plugin of the table: cmake --build <dir> --target lynx_plugins (scripts/package-plugins.sh packs them)
  173. add_custom_target(lynx_plugins DEPENDS ${LYNX_PLUGIN_TARGETS} plugexporttest)