DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

942 lines
33KB

  1. # DISTRHO Plugin Framework (DPF)
  2. # Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  3. # Copyright (C) 2022 Filipe Coelho <falktx@falktx.com>
  4. #
  5. # SPDX-License-Identifier: ISC
  6. # ------------------------------------------------------------------------------
  7. # CMake support module for the DISTRHO Plugin Framework
  8. #
  9. # The purpose of this module is to help building music plugins easily, when the
  10. # project uses CMake as its build system.
  11. #
  12. # In order to use the helpers provided by this module, a plugin author should
  13. # add DPF as a subproject, making the function `dpf_add_plugin` available.
  14. # The usage of this function is documented below in greater detail.
  15. #
  16. # Example project `CMakeLists.txt`:
  17. #
  18. # ```
  19. # cmake_minimum_required(VERSION 3.7)
  20. # project(MyPlugin)
  21. #
  22. # add_subdirectory(DPF)
  23. #
  24. # dpf_add_plugin(MyPlugin
  25. # TARGETS clap lv2 vst2 vst3
  26. # UI_TYPE opengl
  27. # FILES_DSP
  28. # src/MyPlugin.cpp
  29. # FILES_UI
  30. # src/MyUI.cpp)
  31. #
  32. # target_include_directories(MyPlugin
  33. # PUBLIC src)
  34. # ```
  35. #
  36. # Important: note that properties, such as include directories, definitions,
  37. # and linked libraries *must* be marked with `PUBLIC` so they take effect and
  38. # propagate into all the plugin targets.
  39. include(CMakeParseArguments)
  40. # ------------------------------------------------------------------------------
  41. # DPF public functions
  42. # ------------------------------------------------------------------------------
  43. # dpf_add_plugin(name <args...>)
  44. # ------------------------------------------------------------------------------
  45. #
  46. # Add a plugin built using the DISTRHO Plugin Framework.
  47. #
  48. # ------------------------------------------------------------------------------
  49. # Created targets:
  50. #
  51. # `<name>`
  52. # static library: the common part of the plugin
  53. # The public properties set on this target apply to both DSP and UI.
  54. #
  55. # `<name>-dsp`
  56. # static library: the DSP part of the plugin
  57. # The public properties set on this target apply to the DSP only.
  58. #
  59. # `<name>-ui`
  60. # static library: the UI part of the plugin
  61. # The public properties set on this target apply to the UI only.
  62. #
  63. # `<name>-<target>` for each target specified with the `TARGETS` argument.
  64. # This is target-dependent and not intended for public use.
  65. #
  66. # ------------------------------------------------------------------------------
  67. # Arguments:
  68. #
  69. # `TARGETS` <tgt1>...<tgtN>
  70. # a list of one of more of the following target types:
  71. # `jack`, `ladspa`, `dssi`, `lv2`, `vst2`, `vst3`, `clap`
  72. #
  73. # `UI_TYPE` <type>
  74. # the user interface type: `opengl` (default), `cairo`, `external`
  75. #
  76. # `FILES_COMMON` <file1>...<fileN>
  77. # list of sources which are part of both DSP and UI
  78. #
  79. # `FILES_DSP` <file1>...<fileN>
  80. # list of sources which are part of the DSP
  81. #
  82. # `FILES_UI` <file1>...<fileN>
  83. # list of sources which are part of the UI
  84. # empty indicates the plugin does not have UI
  85. #
  86. # `MODGUI_CLASS_NAME`
  87. # class name to use for modgui builds
  88. #
  89. # `MONOLITHIC`
  90. # build LV2 as a single binary for UI and DSP
  91. #
  92. # `NO_SHARED_RESOURCES`
  93. # do not build DPF shared resources (fonts, etc)
  94. #
  95. function(dpf_add_plugin NAME)
  96. set(options MONOLITHIC NO_SHARED_RESOURCES)
  97. set(oneValueArgs MODGUI_CLASS_NAME UI_TYPE)
  98. set(multiValueArgs FILES_COMMON FILES_DSP FILES_UI TARGETS)
  99. cmake_parse_arguments(_dpf_plugin "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  100. if("${_dpf_plugin_UI_TYPE}" STREQUAL "")
  101. set(_dpf_plugin_UI_TYPE "opengl")
  102. endif()
  103. set(_dgl_library)
  104. set(_dgl_external OFF)
  105. if(_dpf_plugin_FILES_UI)
  106. if(_dpf_plugin_UI_TYPE STREQUAL "cairo")
  107. dpf__add_dgl_cairo("${_dpf_plugin_NO_SHARED_RESOURCES}")
  108. set(_dgl_library dgl-cairo)
  109. elseif(_dpf_plugin_UI_TYPE STREQUAL "opengl")
  110. dpf__add_dgl_opengl("${_dpf_plugin_NO_SHARED_RESOURCES}")
  111. set(_dgl_library dgl-opengl)
  112. elseif(_dpf_plugin_UI_TYPE STREQUAL "external")
  113. set(_dgl_external ON)
  114. else()
  115. message(FATAL_ERROR "Unrecognized UI type for plugin: ${_dpf_plugin_UI_TYPE}")
  116. endif()
  117. endif()
  118. set(_dgl_has_ui OFF)
  119. if(_dgl_library OR _dgl_external)
  120. set(_dgl_has_ui ON)
  121. endif()
  122. ###
  123. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_COMMON)
  124. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_DSP)
  125. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_UI)
  126. ###
  127. dpf__add_static_library("${NAME}" ${_dpf_plugin_FILES_COMMON})
  128. target_include_directories("${NAME}" PUBLIC
  129. "${DPF_ROOT_DIR}/distrho")
  130. if(_dpf_plugin_MODGUI_CLASS_NAME)
  131. target_compile_definitions("${NAME}" PUBLIC "DISTRHO_PLUGIN_MODGUI_CLASS_NAME=\"${_dpf_plugin_MODGUI_CLASS_NAME}\"")
  132. endif()
  133. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  134. target_link_libraries("${NAME}" PRIVATE "dl")
  135. endif()
  136. if(_dgl_library AND NOT _dgl_external)
  137. # make sure that all code will see DGL_* definitions
  138. target_link_libraries("${NAME}" PUBLIC
  139. "${_dgl_library}-definitions"
  140. dgl-system-libs-definitions
  141. dgl-system-libs)
  142. endif()
  143. dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP})
  144. target_link_libraries("${NAME}-dsp" PUBLIC "${NAME}")
  145. if(_dgl_library AND NOT _dgl_external)
  146. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  147. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library})
  148. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  149. target_link_libraries("${NAME}-ui" PRIVATE "dl")
  150. endif()
  151. # add the files containing Objective-C classes
  152. dpf__add_plugin_specific_ui_sources("${NAME}-ui")
  153. elseif(_dgl_external)
  154. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  155. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}")
  156. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  157. target_link_libraries("${NAME}-ui" PRIVATE "dl")
  158. endif()
  159. # add the files containing Objective-C classes
  160. dpf__add_plugin_specific_ui_sources("${NAME}-ui")
  161. else()
  162. add_library("${NAME}-ui" INTERFACE)
  163. endif()
  164. ###
  165. foreach(_target ${_dpf_plugin_TARGETS})
  166. if(_target STREQUAL "jack")
  167. dpf__build_jack("${NAME}" "${_dgl_has_ui}")
  168. elseif(_target STREQUAL "ladspa")
  169. dpf__build_ladspa("${NAME}")
  170. elseif(_target STREQUAL "dssi")
  171. dpf__build_dssi("${NAME}" "${_dgl_has_ui}")
  172. elseif(_target STREQUAL "lv2")
  173. dpf__build_lv2("${NAME}" "${_dgl_has_ui}" "${_dpf_plugin_MONOLITHIC}")
  174. elseif(_target STREQUAL "vst2")
  175. dpf__build_vst2("${NAME}" "${_dgl_has_ui}")
  176. elseif(_target STREQUAL "vst3")
  177. dpf__build_vst3("${NAME}" "${_dgl_has_ui}")
  178. elseif(_target STREQUAL "clap")
  179. dpf__build_clap("${NAME}" "${_dgl_has_ui}")
  180. else()
  181. message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}")
  182. endif()
  183. endforeach()
  184. endfunction()
  185. # ------------------------------------------------------------------------------
  186. # DPF private functions (prefixed with `dpf__`)
  187. # ------------------------------------------------------------------------------
  188. # Note: The $<0:> trick is to prevent MSVC from appending the build type
  189. # to the output directory.
  190. #
  191. # dpf__build_jack
  192. # ------------------------------------------------------------------------------
  193. #
  194. # Add build rules for a JACK/Standalone program.
  195. #
  196. function(dpf__build_jack NAME HAS_UI)
  197. dpf__create_dummy_source_list(_no_srcs)
  198. dpf__add_executable("${NAME}-jack" ${_no_srcs})
  199. dpf__add_plugin_main("${NAME}-jack" "jack")
  200. dpf__add_ui_main("${NAME}-jack" "jack" "${HAS_UI}")
  201. target_link_libraries("${NAME}-jack" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  202. set_target_properties("${NAME}-jack" PROPERTIES
  203. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  204. OUTPUT_NAME "${NAME}")
  205. target_compile_definitions("${NAME}" PUBLIC "HAVE_JACK")
  206. target_compile_definitions("${NAME}-jack" PRIVATE "HAVE_GETTIMEOFDAY")
  207. find_package(PkgConfig)
  208. pkg_check_modules(SDL2 "sdl2")
  209. if(SDL2_FOUND)
  210. target_compile_definitions("${NAME}" PUBLIC "HAVE_SDL2")
  211. target_include_directories("${NAME}-jack" PRIVATE ${SDL2_STATIC_INCLUDE_DIRS})
  212. target_link_libraries("${NAME}-jack" PRIVATE ${SDL2_STATIC_LIBRARIES})
  213. dpf__target_link_directories("${NAME}-jack" ${SDL2_STATIC_LIBRARY_DIRS})
  214. endif()
  215. if(APPLE OR WIN32)
  216. target_compile_definitions("${NAME}" PUBLIC "HAVE_RTAUDIO")
  217. else()
  218. find_package(Threads)
  219. pkg_check_modules(ALSA "alsa")
  220. pkg_check_modules(PULSEAUDIO "libpulse-simple")
  221. if(ALSA_FOUND)
  222. target_compile_definitions("${NAME}" PUBLIC "HAVE_ALSA")
  223. target_include_directories("${NAME}-jack" PRIVATE ${ALSA_INCLUDE_DIRS})
  224. target_link_libraries("${NAME}-jack" PRIVATE ${ALSA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  225. dpf__target_link_directories("${NAME}-jack" ${ALSA_LIBRARY_DIRS})
  226. endif()
  227. if(PULSEAUDIO_FOUND)
  228. target_compile_definitions("${NAME}" PUBLIC "HAVE_PULSEAUDIO")
  229. target_include_directories("${NAME}-jack" PRIVATE ${PULSEAUDIO_INCLUDE_DIRS})
  230. target_link_libraries("${NAME}-jack" PRIVATE ${PULSEAUDIO_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  231. dpf__target_link_directories("${NAME}-jack" ${PULSEAUDIO_LIBRARY_DIRS})
  232. endif()
  233. if(ALSA_FOUND OR PULSEAUDIO_FOUND)
  234. target_compile_definitions("${NAME}" PUBLIC "HAVE_RTAUDIO")
  235. endif()
  236. endif()
  237. # for RtAudio native fallback
  238. if(APPLE)
  239. find_library(APPLE_COREAUDIO_FRAMEWORK "CoreAudio")
  240. find_library(APPLE_COREFOUNDATION_FRAMEWORK "CoreFoundation")
  241. find_library(APPLE_COREMIDI_FRAMEWORK "CoreMIDI")
  242. target_link_libraries("${NAME}-jack" PRIVATE
  243. "${APPLE_COREAUDIO_FRAMEWORK}"
  244. "${APPLE_COREFOUNDATION_FRAMEWORK}"
  245. "${APPLE_COREMIDI_FRAMEWORK}")
  246. elseif(WIN32)
  247. target_link_libraries("${NAME}-jack" PRIVATE "ksuser" "mfplat" "mfuuid" "ole32" "winmm" "wmcodecdspuuid")
  248. if(HAS_UI AND MINGW)
  249. set_target_properties("${NAME}-jack" PROPERTIES WIN32_EXECUTABLE TRUE)
  250. endif()
  251. endif()
  252. endfunction()
  253. # dpf__build_ladspa
  254. # ------------------------------------------------------------------------------
  255. #
  256. # Add build rules for a LADSPA plugin.
  257. #
  258. function(dpf__build_ladspa NAME)
  259. dpf__create_dummy_source_list(_no_srcs)
  260. dpf__add_module("${NAME}-ladspa" ${_no_srcs})
  261. dpf__add_plugin_main("${NAME}-ladspa" "ladspa")
  262. dpf__set_module_export_list("${NAME}-ladspa" "ladspa")
  263. target_link_libraries("${NAME}-ladspa" PRIVATE "${NAME}-dsp")
  264. set_target_properties("${NAME}-ladspa" PROPERTIES
  265. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  266. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/ladspa/$<0:>"
  267. OUTPUT_NAME "${NAME}-ladspa"
  268. PREFIX "")
  269. endfunction()
  270. # dpf__build_dssi
  271. # ------------------------------------------------------------------------------
  272. #
  273. # Add build rules for a DSSI plugin.
  274. #
  275. function(dpf__build_dssi NAME HAS_UI)
  276. find_package(PkgConfig)
  277. pkg_check_modules(LIBLO "liblo")
  278. if(NOT LIBLO_FOUND)
  279. dpf__warn_once_only(missing_liblo
  280. "liblo is not found, skipping the `dssi` plugin targets")
  281. return()
  282. endif()
  283. dpf__create_dummy_source_list(_no_srcs)
  284. dpf__add_module("${NAME}-dssi" ${_no_srcs})
  285. dpf__add_plugin_main("${NAME}-dssi" "dssi")
  286. dpf__set_module_export_list("${NAME}-dssi" "dssi")
  287. target_link_libraries("${NAME}-dssi" PRIVATE "${NAME}-dsp")
  288. set_target_properties("${NAME}-dssi" PROPERTIES
  289. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  290. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/dssi/$<0:>"
  291. OUTPUT_NAME "${NAME}-dssi"
  292. PREFIX "")
  293. if(HAS_UI)
  294. dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs})
  295. dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${HAS_UI}")
  296. target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui")
  297. set_target_properties("${NAME}-dssi-ui" PROPERTIES
  298. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>"
  299. OUTPUT_NAME "${NAME}_ui")
  300. target_compile_definitions("${NAME}" PUBLIC "HAVE_LIBLO")
  301. target_include_directories("${NAME}-dssi-ui" PRIVATE ${LIBLO_INCLUDE_DIRS})
  302. target_link_libraries("${NAME}-dssi-ui" PRIVATE ${LIBLO_LIBRARIES})
  303. dpf__target_link_directories("${NAME}-dssi-ui" ${LIBLO_LIBRARY_DIRS})
  304. endif()
  305. endfunction()
  306. # dpf__build_lv2
  307. # ------------------------------------------------------------------------------
  308. #
  309. # Add build rules for an LV2 plugin.
  310. #
  311. function(dpf__build_lv2 NAME HAS_UI MONOLITHIC)
  312. dpf__create_dummy_source_list(_no_srcs)
  313. dpf__add_module("${NAME}-lv2" ${_no_srcs})
  314. dpf__add_plugin_main("${NAME}-lv2" "lv2")
  315. if(HAS_UI AND MONOLITHIC)
  316. dpf__set_module_export_list("${NAME}-lv2" "lv2")
  317. else()
  318. dpf__set_module_export_list("${NAME}-lv2" "lv2-dsp")
  319. endif()
  320. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-dsp")
  321. set_target_properties("${NAME}-lv2" PROPERTIES
  322. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  323. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/lv2/$<0:>"
  324. OUTPUT_NAME "${NAME}_dsp"
  325. PREFIX "")
  326. if(HAS_UI)
  327. if(MONOLITHIC)
  328. dpf__add_ui_main("${NAME}-lv2" "lv2" "${HAS_UI}")
  329. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui")
  330. set_target_properties("${NAME}-lv2" PROPERTIES
  331. OUTPUT_NAME "${NAME}")
  332. else()
  333. dpf__add_module("${NAME}-lv2-ui" ${_no_srcs})
  334. dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${HAS_UI}")
  335. dpf__set_module_export_list("${NAME}-lv2-ui" "lv2-ui")
  336. target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui")
  337. set_target_properties("${NAME}-lv2-ui" PROPERTIES
  338. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  339. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/lv2/$<0:>"
  340. OUTPUT_NAME "${NAME}_ui"
  341. PREFIX "")
  342. endif()
  343. endif()
  344. dpf__add_lv2_ttl_generator()
  345. add_dependencies("${NAME}-lv2" lv2_ttl_generator)
  346. add_custom_command(TARGET "${NAME}-lv2" POST_BUILD
  347. COMMAND
  348. ${CMAKE_CROSSCOMPILING_EMULATOR}
  349. "$<TARGET_FILE:lv2_ttl_generator>"
  350. "$<TARGET_FILE:${NAME}-lv2>"
  351. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2"
  352. DEPENDS lv2_ttl_generator)
  353. endfunction()
  354. # dpf__build_vst2
  355. # ------------------------------------------------------------------------------
  356. #
  357. # Add build rules for a VST2 plugin.
  358. #
  359. function(dpf__build_vst2 NAME HAS_UI)
  360. dpf__create_dummy_source_list(_no_srcs)
  361. dpf__add_module("${NAME}-vst2" ${_no_srcs})
  362. dpf__add_plugin_main("${NAME}-vst2" "vst2")
  363. dpf__add_ui_main("${NAME}-vst2" "vst2" "${HAS_UI}")
  364. dpf__set_module_export_list("${NAME}-vst2" "vst2")
  365. target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  366. set_target_properties("${NAME}-vst2" PROPERTIES
  367. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  368. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst2/$<0:>"
  369. OUTPUT_NAME "${NAME}-vst2"
  370. PREFIX "")
  371. if(APPLE)
  372. set_target_properties("${NAME}-vst2" PROPERTIES
  373. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/MacOS/$<0:>"
  374. OUTPUT_NAME "${NAME}"
  375. SUFFIX "")
  376. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  377. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  378. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/Info.plist" @ONLY)
  379. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  380. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents")
  381. endif()
  382. endfunction()
  383. # dpf__determine_vst3_package_architecture
  384. # ------------------------------------------------------------------------------
  385. #
  386. # Determines the package architecture for a VST3 plugin target.
  387. #
  388. function(dpf__determine_vst3_package_architecture OUTPUT_VARIABLE)
  389. # if set by variable, override the detection
  390. if(DPF_VST3_ARCHITECTURE)
  391. set("${OUTPUT_VARIABLE}" "${DPF_VST3_ARCHITECTURE}" PARENT_SCOPE)
  392. return()
  393. endif()
  394. # not used on Apple, which supports universal binary
  395. if(APPLE)
  396. set("${OUTPUT_VARIABLE}" "universal" PARENT_SCOPE)
  397. return()
  398. endif()
  399. # identify the target processor (special case of MSVC, problematic sometimes)
  400. if(MSVC)
  401. set(vst3_system_arch "${MSVC_CXX_ARCHITECTURE_ID}")
  402. else()
  403. set(vst3_system_arch "${CMAKE_SYSTEM_PROCESSOR}")
  404. endif()
  405. # transform the processor name to a format that VST3 recognizes
  406. if(vst3_system_arch MATCHES "^(x86_64|amd64|AMD64|x64|X64)$")
  407. set(vst3_package_arch "x86_64")
  408. elseif(vst3_system_arch MATCHES "^(i.86|x86|X86)$")
  409. if(WIN32)
  410. set(vst3_package_arch "x86")
  411. else()
  412. set(vst3_package_arch "i386")
  413. endif()
  414. elseif(vst3_system_arch MATCHES "^(armv[3-8][a-z]*)$")
  415. set(vst3_package_arch "${vst3_system_arch}")
  416. elseif(vst3_system_arch MATCHES "^(aarch64)$")
  417. set(vst3_package_arch "aarch64")
  418. else()
  419. message(FATAL_ERROR "We don't know this architecture for VST3: ${vst3_system_arch}.")
  420. endif()
  421. # TODO: the detections for Windows arm/arm64 when supported
  422. set("${OUTPUT_VARIABLE}" "${vst3_package_arch}" PARENT_SCOPE)
  423. endfunction()
  424. # dpf__build_vst3
  425. # ------------------------------------------------------------------------------
  426. #
  427. # Add build rules for a VST3 plugin.
  428. #
  429. function(dpf__build_vst3 NAME HAS_UI)
  430. dpf__determine_vst3_package_architecture(vst3_arch)
  431. dpf__create_dummy_source_list(_no_srcs)
  432. dpf__add_module("${NAME}-vst3" ${_no_srcs})
  433. dpf__add_plugin_main("${NAME}-vst3" "vst3")
  434. dpf__add_ui_main("${NAME}-vst3" "vst3" "${HAS_UI}")
  435. dpf__set_module_export_list("${NAME}-vst3" "vst3")
  436. target_link_libraries("${NAME}-vst3" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  437. set_target_properties("${NAME}-vst3" PROPERTIES
  438. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst3/$<0:>"
  439. OUTPUT_NAME "${NAME}"
  440. PREFIX "")
  441. if(APPLE)
  442. set_target_properties("${NAME}-vst3" PROPERTIES
  443. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/MacOS/$<0:>"
  444. SUFFIX "")
  445. elseif(WIN32)
  446. set_target_properties("${NAME}-vst3" PROPERTIES
  447. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/${vst3_arch}-win/$<0:>" SUFFIX ".vst3")
  448. else()
  449. set_target_properties("${NAME}-vst3" PROPERTIES
  450. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/${vst3_arch}-linux/$<0:>")
  451. endif()
  452. if(APPLE)
  453. # Uses the same macOS bundle template as VST2
  454. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  455. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  456. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/Info.plist" @ONLY)
  457. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  458. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents")
  459. endif()
  460. endfunction()
  461. # dpf__build_clap
  462. # ------------------------------------------------------------------------------
  463. #
  464. # Add build rules for a VST2 plugin.
  465. #
  466. function(dpf__build_clap NAME HAS_UI)
  467. dpf__create_dummy_source_list(_no_srcs)
  468. dpf__add_module("${NAME}-clap" ${_no_srcs})
  469. dpf__add_plugin_main("${NAME}-clap" "clap")
  470. dpf__add_ui_main("${NAME}-clap" "clap" "${HAS_UI}")
  471. dpf__set_module_export_list("${NAME}-clap" "clap")
  472. target_link_libraries("${NAME}-clap" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  473. set_target_properties("${NAME}-clap" PROPERTIES
  474. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  475. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/clap/$<0:>"
  476. OUTPUT_NAME "${NAME}"
  477. PREFIX ""
  478. SUFFIX ".clap")
  479. if(APPLE)
  480. set_target_properties("${NAME}-clap" PROPERTIES
  481. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents/MacOS/$<0:>"
  482. OUTPUT_NAME "${NAME}"
  483. SUFFIX "")
  484. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  485. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  486. "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents/Info.plist" @ONLY)
  487. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  488. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents")
  489. endif()
  490. endfunction()
  491. # dpf__add_dgl_cairo
  492. # ------------------------------------------------------------------------------
  493. #
  494. # Add the Cairo variant of DGL, if not already available.
  495. #
  496. function(dpf__add_dgl_cairo NO_SHARED_RESOURCES)
  497. if(TARGET dgl-cairo)
  498. return()
  499. endif()
  500. find_package(PkgConfig)
  501. pkg_check_modules(CAIRO "cairo" REQUIRED)
  502. link_directories(${CAIRO_LIBRARY_DIRS})
  503. dpf__add_static_library(dgl-cairo STATIC
  504. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  505. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  506. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  507. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  508. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  509. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  510. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  511. "${DPF_ROOT_DIR}/dgl/src/Layout.cpp"
  512. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  513. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  514. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  515. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  516. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  517. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  518. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  519. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  520. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp")
  521. if(NO_SHARED_RESOURCES)
  522. target_compile_definitions(dgl-cairo PUBLIC "DGL_NO_SHARED_RESOURCES")
  523. else()
  524. target_sources(dgl-cairo PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  525. endif()
  526. if(NOT APPLE)
  527. target_sources(dgl-cairo PRIVATE
  528. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  529. else()
  530. target_sources(dgl-cairo PRIVATE
  531. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  532. endif()
  533. target_include_directories(dgl-cairo PUBLIC
  534. "${DPF_ROOT_DIR}/dgl")
  535. target_include_directories(dgl-cairo PUBLIC
  536. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  537. dpf__add_dgl_system_libs()
  538. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  539. add_library(dgl-cairo-definitions INTERFACE)
  540. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO" "HAVE_DGL")
  541. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  542. if(MINGW)
  543. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_STATIC_LIBRARIES})
  544. else()
  545. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_LIBRARIES})
  546. endif()
  547. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions)
  548. endfunction()
  549. # dpf__add_dgl_opengl
  550. # ------------------------------------------------------------------------------
  551. #
  552. # Add the OpenGL variant of DGL, if not already available.
  553. #
  554. function(dpf__add_dgl_opengl NO_SHARED_RESOURCES)
  555. if(TARGET dgl-opengl)
  556. return()
  557. endif()
  558. if(NOT OpenGL_GL_PREFERENCE)
  559. set(OpenGL_GL_PREFERENCE "LEGACY")
  560. endif()
  561. find_package(OpenGL REQUIRED)
  562. dpf__add_static_library(dgl-opengl STATIC
  563. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  564. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  565. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  566. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  567. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  568. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  569. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  570. "${DPF_ROOT_DIR}/dgl/src/Layout.cpp"
  571. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  572. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  573. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  574. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  575. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  576. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  577. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  578. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  579. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  580. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp")
  581. if(NO_SHARED_RESOURCES)
  582. target_compile_definitions(dgl-opengl PUBLIC "DGL_NO_SHARED_RESOURCES")
  583. else()
  584. target_sources(dgl-opengl PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  585. endif()
  586. if(NOT APPLE)
  587. target_sources(dgl-opengl PRIVATE
  588. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  589. else()
  590. target_sources(dgl-opengl PRIVATE
  591. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  592. endif()
  593. target_include_directories(dgl-opengl PUBLIC
  594. "${DPF_ROOT_DIR}/dgl")
  595. target_include_directories(dgl-opengl PUBLIC
  596. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  597. if(APPLE)
  598. target_compile_definitions(dgl-opengl PUBLIC "GL_SILENCE_DEPRECATION")
  599. endif()
  600. dpf__add_dgl_system_libs()
  601. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  602. add_library(dgl-opengl-definitions INTERFACE)
  603. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL" "HAVE_DGL")
  604. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  605. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  606. endfunction()
  607. # dpf__add_plugin_specific_ui_sources
  608. # ------------------------------------------------------------------------------
  609. #
  610. # Compile system specific files, for now it is just Objective-C code
  611. #
  612. function(dpf__add_plugin_specific_ui_sources NAME)
  613. if(APPLE)
  614. target_sources("${NAME}" PRIVATE
  615. "${DPF_ROOT_DIR}/distrho/DistrhoUI_macOS.mm")
  616. endif()
  617. endfunction()
  618. # dpf__add_dgl_system_libs
  619. # ------------------------------------------------------------------------------
  620. #
  621. # Find system libraries required by DGL and add them as an interface target.
  622. #
  623. function(dpf__add_dgl_system_libs)
  624. if(TARGET dgl-system-libs)
  625. return()
  626. endif()
  627. add_library(dgl-system-libs INTERFACE)
  628. add_library(dgl-system-libs-definitions INTERFACE)
  629. if(APPLE)
  630. find_library(APPLE_COCOA_FRAMEWORK "Cocoa")
  631. find_library(APPLE_COREVIDEO_FRAMEWORK "CoreVideo")
  632. target_link_libraries(dgl-system-libs INTERFACE "${APPLE_COCOA_FRAMEWORK}" "${APPLE_COREVIDEO_FRAMEWORK}")
  633. elseif(EMSCRIPTEN)
  634. elseif(HAIKU)
  635. target_link_libraries(dgl-system-libs INTERFACE "be")
  636. elseif(WIN32)
  637. target_link_libraries(dgl-system-libs INTERFACE "gdi32" "comdlg32")
  638. else()
  639. find_package(PkgConfig)
  640. pkg_check_modules(DBUS "dbus-1")
  641. if(DBUS_FOUND)
  642. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_DBUS")
  643. target_include_directories(dgl-system-libs INTERFACE "${DBUS_INCLUDE_DIRS}")
  644. target_link_libraries(dgl-system-libs INTERFACE "${DBUS_LIBRARIES}")
  645. endif()
  646. find_package(X11 REQUIRED)
  647. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_X11")
  648. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  649. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  650. if(X11_Xcursor_FOUND)
  651. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XCURSOR")
  652. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xcursor_LIB}")
  653. endif()
  654. if(X11_Xext_FOUND)
  655. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XEXT")
  656. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xext_LIB}")
  657. endif()
  658. if(X11_Xrandr_FOUND)
  659. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XRANDR")
  660. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xrandr_LIB}")
  661. endif()
  662. if(X11_XSync_FOUND)
  663. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XSYNC")
  664. target_link_libraries(dgl-system-libs INTERFACE "${X11_XSync_LIB}")
  665. endif()
  666. endif()
  667. if(MSVC)
  668. file(MAKE_DIRECTORY "${DPF_ROOT_DIR}/khronos/GL")
  669. foreach(_gl_header "glext.h")
  670. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}")
  671. file(DOWNLOAD "https://www.khronos.org/registry/OpenGL/api/GL/${_gl_header}" "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}" SHOW_PROGRESS)
  672. endif()
  673. endforeach()
  674. foreach(_khr_header "khrplatform.h")
  675. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}")
  676. file(DOWNLOAD "https://www.khronos.org/registry/EGL/api/KHR/${_khr_header}" "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}" SHOW_PROGRESS)
  677. endif()
  678. endforeach()
  679. target_include_directories(dgl-system-libs-definitions INTERFACE "${DPF_ROOT_DIR}/khronos")
  680. endif()
  681. target_link_libraries(dgl-system-libs INTERFACE dgl-system-libs-definitions)
  682. endfunction()
  683. # dpf__add_executable
  684. # ------------------------------------------------------------------------------
  685. #
  686. # Adds an executable target, and set some default properties on the target.
  687. #
  688. function(dpf__add_executable NAME)
  689. add_executable("${NAME}" ${ARGN})
  690. dpf__set_target_defaults("${NAME}")
  691. if(MINGW)
  692. target_link_libraries("${NAME}" PRIVATE "-static")
  693. endif()
  694. endfunction()
  695. # dpf__add_module
  696. # ------------------------------------------------------------------------------
  697. #
  698. # Adds a module target, and set some default properties on the target.
  699. #
  700. function(dpf__add_module NAME)
  701. add_library("${NAME}" MODULE ${ARGN})
  702. dpf__set_target_defaults("${NAME}")
  703. if(MINGW)
  704. target_link_libraries("${NAME}" PRIVATE "-static")
  705. endif()
  706. endfunction()
  707. # dpf__add_static_library
  708. # ------------------------------------------------------------------------------
  709. #
  710. # Adds a static library target, and set some default properties on the target.
  711. #
  712. function(dpf__add_static_library NAME)
  713. add_library("${NAME}" STATIC ${ARGN})
  714. dpf__set_target_defaults("${NAME}")
  715. endfunction()
  716. # dpf__set_module_export_list
  717. # ------------------------------------------------------------------------------
  718. #
  719. # Applies a list of exported symbols to the module target.
  720. #
  721. function(dpf__set_module_export_list NAME EXPORTS)
  722. if(WIN32)
  723. target_sources("${NAME}" PRIVATE "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.def")
  724. elseif(APPLE)
  725. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  726. "-Xlinker" "-exported_symbols_list"
  727. "-Xlinker" "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.exp")
  728. else()
  729. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  730. "-Xlinker" "--version-script=${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.version")
  731. endif()
  732. endfunction()
  733. # dpf__set_target_defaults
  734. # ------------------------------------------------------------------------------
  735. #
  736. # Set default properties which must apply to all DPF-defined targets.
  737. #
  738. function(dpf__set_target_defaults NAME)
  739. set_target_properties("${NAME}" PROPERTIES
  740. POSITION_INDEPENDENT_CODE TRUE
  741. C_VISIBILITY_PRESET "hidden"
  742. CXX_VISIBILITY_PRESET "hidden"
  743. VISIBILITY_INLINES_HIDDEN TRUE)
  744. if(WIN32)
  745. target_compile_definitions("${NAME}" PUBLIC "NOMINMAX")
  746. endif()
  747. if (MINGW)
  748. target_compile_options("${NAME}" PUBLIC "-mstackrealign")
  749. endif()
  750. if (MSVC)
  751. target_compile_options("${NAME}" PUBLIC "/UTF-8")
  752. target_compile_definitions("${NAME}" PUBLIC "_CRT_SECURE_NO_WARNINGS")
  753. endif()
  754. if (CMAKE_COMPILER_IS_GNUCXX)
  755. target_compile_options("${NAME}" PUBLIC "-fno-gnu-unique")
  756. endif()
  757. endfunction()
  758. # dpf__add_plugin_main
  759. # ------------------------------------------------------------------------------
  760. #
  761. # Adds plugin code to the given target.
  762. #
  763. function(dpf__add_plugin_main NAME TARGET)
  764. target_sources("${NAME}" PRIVATE
  765. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  766. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  767. endfunction()
  768. # dpf__add_ui_main
  769. # ------------------------------------------------------------------------------
  770. #
  771. # Adds UI code to the given target (only if the target has UI).
  772. #
  773. function(dpf__add_ui_main NAME TARGET HAS_UI)
  774. if(HAS_UI)
  775. target_sources("${NAME}" PRIVATE
  776. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  777. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  778. endif()
  779. endfunction()
  780. # dpf__add_plugin_target_definition
  781. # ------------------------------------------------------------------------------
  782. #
  783. # Adds the plugins target macro definition.
  784. # This selects which entry file is compiled according to the target type.
  785. #
  786. function(dpf__add_plugin_target_definition NAME TARGET)
  787. string(TOUPPER "${TARGET}" _upperTarget)
  788. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  789. endfunction()
  790. # dpf__add_lv2_ttl_generator
  791. # ------------------------------------------------------------------------------
  792. #
  793. # Build the LV2 TTL generator.
  794. #
  795. function(dpf__add_lv2_ttl_generator)
  796. if(TARGET lv2_ttl_generator)
  797. return()
  798. endif()
  799. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  800. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  801. target_link_libraries(lv2_ttl_generator PRIVATE "dl")
  802. endif()
  803. endfunction()
  804. # dpf__ensure_sources_non_empty
  805. # ------------------------------------------------------------------------------
  806. #
  807. # Ensure the given source list contains at least one file.
  808. # The function appends an empty source file to the list if necessary.
  809. # This is useful when CMake does not permit to add targets without sources.
  810. #
  811. function(dpf__ensure_sources_non_empty VAR)
  812. if(NOT "" STREQUAL "${${VAR}}")
  813. return()
  814. endif()
  815. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  816. if(NOT EXISTS "${_file}")
  817. file(WRITE "${_file}" "")
  818. endif()
  819. set("${VAR}" "${_file}" PARENT_SCOPE)
  820. endfunction()
  821. # dpf__create_dummy_source_list
  822. # ------------------------------------------------------------------------------
  823. #
  824. # Create a dummy source list which is equivalent to compiling nothing.
  825. # This is only for compatibility with older CMake versions, which refuse to add
  826. # targets without any sources.
  827. #
  828. macro(dpf__create_dummy_source_list VAR)
  829. set("${VAR}")
  830. if(CMAKE_VERSION VERSION_LESS "3.11")
  831. dpf__ensure_sources_non_empty("${VAR}")
  832. endif()
  833. endmacro()
  834. # dpf__target_link_directories
  835. # ------------------------------------------------------------------------------
  836. #
  837. # Call `target_link_directories` if cmake >= 3.13,
  838. # otherwise fallback to global `link_directories`.
  839. #
  840. macro(dpf__target_link_directories NAME DIRS)
  841. if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
  842. target_link_directories("${NAME}" PUBLIC ${DIRS})
  843. else()
  844. link_directories(${DIRS})
  845. endif()
  846. endmacro()
  847. # dpf__warn_once
  848. # ------------------------------------------------------------------------------
  849. #
  850. # Prints a warning message once only.
  851. #
  852. function(dpf__warn_once_only TOKEN MESSAGE)
  853. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  854. if(NOT _warned)
  855. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  856. message(WARNING "${MESSAGE}")
  857. endif()
  858. endfunction()