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.

930 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. elseif(_dgl_external)
  142. target_link_libraries("${NAME}" PUBLIC
  143. dgl-system-libs-definitions)
  144. endif()
  145. dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP})
  146. target_link_libraries("${NAME}-dsp" PUBLIC "${NAME}")
  147. if(_dgl_library AND NOT _dgl_external)
  148. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  149. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library})
  150. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  151. target_link_libraries("${NAME}-ui" PRIVATE "dl")
  152. endif()
  153. # add the files containing Objective-C classes
  154. dpf__add_plugin_specific_ui_sources("${NAME}-ui")
  155. elseif(_dgl_external)
  156. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  157. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}")
  158. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  159. target_link_libraries("${NAME}-ui" PRIVATE "dl")
  160. endif()
  161. # add the files containing Objective-C classes
  162. dpf__add_plugin_specific_ui_sources("${NAME}-ui")
  163. else()
  164. add_library("${NAME}-ui" INTERFACE)
  165. endif()
  166. ###
  167. foreach(_target ${_dpf_plugin_TARGETS})
  168. if(_target STREQUAL "jack")
  169. dpf__build_jack("${NAME}" "${_dgl_has_ui}")
  170. elseif(_target STREQUAL "ladspa")
  171. dpf__build_ladspa("${NAME}")
  172. elseif(_target STREQUAL "dssi")
  173. dpf__build_dssi("${NAME}" "${_dgl_has_ui}")
  174. elseif(_target STREQUAL "lv2")
  175. dpf__build_lv2("${NAME}" "${_dgl_has_ui}" "${_dpf_plugin_MONOLITHIC}")
  176. elseif(_target STREQUAL "vst2")
  177. dpf__build_vst2("${NAME}" "${_dgl_has_ui}")
  178. elseif(_target STREQUAL "vst3")
  179. dpf__build_vst3("${NAME}" "${_dgl_has_ui}")
  180. elseif(_target STREQUAL "clap")
  181. dpf__build_clap("${NAME}" "${_dgl_has_ui}")
  182. else()
  183. message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}")
  184. endif()
  185. endforeach()
  186. endfunction()
  187. # ------------------------------------------------------------------------------
  188. # DPF private functions (prefixed with `dpf__`)
  189. # ------------------------------------------------------------------------------
  190. # Note: The $<0:> trick is to prevent MSVC from appending the build type
  191. # to the output directory.
  192. #
  193. # dpf__build_jack
  194. # ------------------------------------------------------------------------------
  195. #
  196. # Add build rules for a JACK/Standalone program.
  197. #
  198. function(dpf__build_jack NAME HAS_UI)
  199. dpf__create_dummy_source_list(_no_srcs)
  200. dpf__add_executable("${NAME}-jack" ${_no_srcs})
  201. dpf__add_plugin_main("${NAME}-jack" "jack")
  202. dpf__add_ui_main("${NAME}-jack" "jack" "${HAS_UI}")
  203. target_link_libraries("${NAME}-jack" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  204. set_target_properties("${NAME}-jack" PROPERTIES
  205. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  206. OUTPUT_NAME "${NAME}")
  207. target_compile_definitions("${NAME}" PUBLIC "HAVE_JACK")
  208. find_package(PkgConfig)
  209. pkg_check_modules(SDL2 "sdl2")
  210. if(SDL2_FOUND)
  211. target_compile_definitions("${NAME}" PUBLIC "HAVE_SDL2")
  212. target_include_directories("${NAME}-jack" PRIVATE ${SDL2_INCLUDE_DIRS})
  213. target_link_libraries("${NAME}-jack" PRIVATE ${SDL2_LIBRARIES})
  214. dpf__target_link_directories("${NAME}-jack" ${SDL2_LIBRARY_DIRS})
  215. endif()
  216. if(APPLE OR WIN32)
  217. target_compile_definitions("${NAME}" PUBLIC "HAVE_RTAUDIO")
  218. else()
  219. find_package(Threads)
  220. pkg_check_modules(ALSA "alsa")
  221. pkg_check_modules(PULSEAUDIO "libpulse-simple")
  222. if(ALSA_FOUND)
  223. target_compile_definitions("${NAME}" PUBLIC "HAVE_ALSA")
  224. target_include_directories("${NAME}-jack" PRIVATE ${ALSA_INCLUDE_DIRS})
  225. target_link_libraries("${NAME}-jack" PRIVATE ${ALSA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  226. dpf__target_link_directories("${NAME}-jack" ${ALSA_LIBRARY_DIRS})
  227. endif()
  228. if(PULSEAUDIO_FOUND)
  229. target_compile_definitions("${NAME}" PUBLIC "HAVE_PULSEAUDIO")
  230. target_include_directories("${NAME}-jack" PRIVATE ${PULSEAUDIO_INCLUDE_DIRS})
  231. target_link_libraries("${NAME}-jack" PRIVATE ${PULSEAUDIO_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  232. dpf__target_link_directories("${NAME}-jack" ${PULSEAUDIO_LIBRARY_DIRS})
  233. endif()
  234. if(ALSA_FOUND OR PULSEAUDIO_FOUND)
  235. target_compile_definitions("${NAME}" PUBLIC "HAVE_RTAUDIO")
  236. endif()
  237. endif()
  238. # for RtAudio native fallback
  239. if(APPLE)
  240. find_library(APPLE_COREAUDIO_FRAMEWORK "CoreAudio")
  241. find_library(APPLE_COREFOUNDATION_FRAMEWORK "CoreFoundation")
  242. find_library(APPLE_COREMIDI_FRAMEWORK "CoreMIDI")
  243. target_link_libraries("${NAME}-jack" PRIVATE
  244. "${APPLE_COREAUDIO_FRAMEWORK}"
  245. "${APPLE_COREFOUNDATION_FRAMEWORK}"
  246. "${APPLE_COREMIDI_FRAMEWORK}")
  247. elseif(WIN32)
  248. target_link_libraries("${NAME}-jack" PRIVATE "dsound" "ole32" "winmm")
  249. endif()
  250. endfunction()
  251. # dpf__build_ladspa
  252. # ------------------------------------------------------------------------------
  253. #
  254. # Add build rules for a LADSPA plugin.
  255. #
  256. function(dpf__build_ladspa NAME)
  257. dpf__create_dummy_source_list(_no_srcs)
  258. dpf__add_module("${NAME}-ladspa" ${_no_srcs})
  259. dpf__add_plugin_main("${NAME}-ladspa" "ladspa")
  260. dpf__set_module_export_list("${NAME}-ladspa" "ladspa")
  261. target_link_libraries("${NAME}-ladspa" PRIVATE "${NAME}-dsp")
  262. set_target_properties("${NAME}-ladspa" PROPERTIES
  263. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  264. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/ladspa/$<0:>"
  265. OUTPUT_NAME "${NAME}-ladspa"
  266. PREFIX "")
  267. endfunction()
  268. # dpf__build_dssi
  269. # ------------------------------------------------------------------------------
  270. #
  271. # Add build rules for a DSSI plugin.
  272. #
  273. function(dpf__build_dssi NAME HAS_UI)
  274. find_package(PkgConfig)
  275. pkg_check_modules(LIBLO "liblo")
  276. if(NOT LIBLO_FOUND)
  277. dpf__warn_once_only(missing_liblo
  278. "liblo is not found, skipping the `dssi` plugin targets")
  279. return()
  280. endif()
  281. dpf__create_dummy_source_list(_no_srcs)
  282. dpf__add_module("${NAME}-dssi" ${_no_srcs})
  283. dpf__add_plugin_main("${NAME}-dssi" "dssi")
  284. dpf__set_module_export_list("${NAME}-dssi" "dssi")
  285. target_link_libraries("${NAME}-dssi" PRIVATE "${NAME}-dsp")
  286. set_target_properties("${NAME}-dssi" PROPERTIES
  287. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  288. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/dssi/$<0:>"
  289. OUTPUT_NAME "${NAME}-dssi"
  290. PREFIX "")
  291. if(HAS_UI)
  292. dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs})
  293. dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${HAS_UI}")
  294. target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui")
  295. set_target_properties("${NAME}-dssi-ui" PROPERTIES
  296. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>"
  297. OUTPUT_NAME "${NAME}_ui")
  298. target_compile_definitions("${NAME}" PUBLIC "HAVE_LIBLO")
  299. target_include_directories("${NAME}-dssi-ui" PRIVATE ${LIBLO_INCLUDE_DIRS})
  300. target_link_libraries("${NAME}-dssi-ui" PRIVATE ${LIBLO_LIBRARIES})
  301. dpf__target_link_directories("${NAME}-dssi-ui" ${LIBLO_LIBRARY_DIRS})
  302. endif()
  303. endfunction()
  304. # dpf__build_lv2
  305. # ------------------------------------------------------------------------------
  306. #
  307. # Add build rules for an LV2 plugin.
  308. #
  309. function(dpf__build_lv2 NAME HAS_UI MONOLITHIC)
  310. dpf__create_dummy_source_list(_no_srcs)
  311. dpf__add_module("${NAME}-lv2" ${_no_srcs})
  312. dpf__add_plugin_main("${NAME}-lv2" "lv2")
  313. if(HAS_UI AND MONOLITHIC)
  314. dpf__set_module_export_list("${NAME}-lv2" "lv2")
  315. else()
  316. dpf__set_module_export_list("${NAME}-lv2" "lv2-dsp")
  317. endif()
  318. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-dsp")
  319. set_target_properties("${NAME}-lv2" PROPERTIES
  320. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  321. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/lv2/$<0:>"
  322. OUTPUT_NAME "${NAME}_dsp"
  323. PREFIX "")
  324. if(HAS_UI)
  325. if(MONOLITHIC)
  326. dpf__add_ui_main("${NAME}-lv2" "lv2" "${HAS_UI}")
  327. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui")
  328. set_target_properties("${NAME}-lv2" PROPERTIES
  329. OUTPUT_NAME "${NAME}")
  330. else()
  331. dpf__add_module("${NAME}-lv2-ui" ${_no_srcs})
  332. dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${HAS_UI}")
  333. dpf__set_module_export_list("${NAME}-lv2-ui" "lv2-ui")
  334. target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui")
  335. set_target_properties("${NAME}-lv2-ui" PROPERTIES
  336. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  337. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/lv2/$<0:>"
  338. OUTPUT_NAME "${NAME}_ui"
  339. PREFIX "")
  340. endif()
  341. endif()
  342. dpf__add_lv2_ttl_generator()
  343. add_dependencies("${NAME}-lv2" lv2_ttl_generator)
  344. add_custom_command(TARGET "${NAME}-lv2" POST_BUILD
  345. COMMAND
  346. ${CMAKE_CROSSCOMPILING_EMULATOR}
  347. "$<TARGET_FILE:lv2_ttl_generator>"
  348. "$<TARGET_FILE:${NAME}-lv2>"
  349. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2"
  350. DEPENDS lv2_ttl_generator)
  351. endfunction()
  352. # dpf__build_vst2
  353. # ------------------------------------------------------------------------------
  354. #
  355. # Add build rules for a VST2 plugin.
  356. #
  357. function(dpf__build_vst2 NAME HAS_UI)
  358. dpf__create_dummy_source_list(_no_srcs)
  359. dpf__add_module("${NAME}-vst2" ${_no_srcs})
  360. dpf__add_plugin_main("${NAME}-vst2" "vst2")
  361. dpf__add_ui_main("${NAME}-vst2" "vst2" "${HAS_UI}")
  362. dpf__set_module_export_list("${NAME}-vst2" "vst2")
  363. target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  364. set_target_properties("${NAME}-vst2" PROPERTIES
  365. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  366. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst2/$<0:>"
  367. OUTPUT_NAME "${NAME}-vst2"
  368. PREFIX "")
  369. if(APPLE)
  370. set_target_properties("${NAME}-vst2" PROPERTIES
  371. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/MacOS/$<0:>"
  372. OUTPUT_NAME "${NAME}"
  373. SUFFIX "")
  374. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  375. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  376. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/Info.plist" @ONLY)
  377. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  378. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents")
  379. endif()
  380. endfunction()
  381. # dpf__determine_vst3_package_architecture
  382. # ------------------------------------------------------------------------------
  383. #
  384. # Determines the package architecture for a VST3 plugin target.
  385. #
  386. function(dpf__determine_vst3_package_architecture OUTPUT_VARIABLE)
  387. # if set by variable, override the detection
  388. if(DPF_VST3_ARCHITECTURE)
  389. set("${OUTPUT_VARIABLE}" "${DPF_VST3_ARCHITECTURE}" PARENT_SCOPE)
  390. return()
  391. endif()
  392. # not used on Apple, which supports universal binary
  393. if(APPLE)
  394. set("${OUTPUT_VARIABLE}" "universal" PARENT_SCOPE)
  395. return()
  396. endif()
  397. # identify the target processor (special case of MSVC, problematic sometimes)
  398. if(MSVC)
  399. set(vst3_system_arch "${MSVC_CXX_ARCHITECTURE_ID}")
  400. else()
  401. set(vst3_system_arch "${CMAKE_SYSTEM_PROCESSOR}")
  402. endif()
  403. # transform the processor name to a format that VST3 recognizes
  404. if(vst3_system_arch MATCHES "^(x86_64|amd64|AMD64|x64|X64)$")
  405. set(vst3_package_arch "x86_64")
  406. elseif(vst3_system_arch MATCHES "^(i.86|x86|X86)$")
  407. if(WIN32)
  408. set(vst3_package_arch "x86")
  409. else()
  410. set(vst3_package_arch "i386")
  411. endif()
  412. elseif(vst3_system_arch MATCHES "^(armv[3-8][a-z]*)$")
  413. set(vst3_package_arch "${vst3_system_arch}")
  414. elseif(vst3_system_arch MATCHES "^(aarch64)$")
  415. set(vst3_package_arch "aarch64")
  416. else()
  417. message(FATAL_ERROR "We don't know this architecture for VST3: ${vst3_system_arch}.")
  418. endif()
  419. # TODO: the detections for Windows arm/arm64 when supported
  420. set("${OUTPUT_VARIABLE}" "${vst3_package_arch}" PARENT_SCOPE)
  421. endfunction()
  422. # dpf__build_vst3
  423. # ------------------------------------------------------------------------------
  424. #
  425. # Add build rules for a VST3 plugin.
  426. #
  427. function(dpf__build_vst3 NAME HAS_UI)
  428. dpf__determine_vst3_package_architecture(vst3_arch)
  429. dpf__create_dummy_source_list(_no_srcs)
  430. dpf__add_module("${NAME}-vst3" ${_no_srcs})
  431. dpf__add_plugin_main("${NAME}-vst3" "vst3")
  432. dpf__add_ui_main("${NAME}-vst3" "vst3" "${HAS_UI}")
  433. dpf__set_module_export_list("${NAME}-vst3" "vst3")
  434. target_link_libraries("${NAME}-vst3" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  435. set_target_properties("${NAME}-vst3" PROPERTIES
  436. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst3/$<0:>"
  437. OUTPUT_NAME "${NAME}"
  438. PREFIX "")
  439. if(APPLE)
  440. set_target_properties("${NAME}-vst3" PROPERTIES
  441. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/MacOS/$<0:>"
  442. SUFFIX "")
  443. elseif(WIN32)
  444. set_target_properties("${NAME}-vst3" PROPERTIES
  445. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/${vst3_arch}-win/$<0:>" SUFFIX ".vst3")
  446. else()
  447. set_target_properties("${NAME}-vst3" PROPERTIES
  448. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/${vst3_arch}-linux/$<0:>")
  449. endif()
  450. if(APPLE)
  451. # Uses the same macOS bundle template as VST2
  452. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  453. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  454. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/Info.plist" @ONLY)
  455. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  456. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents")
  457. endif()
  458. endfunction()
  459. # dpf__build_clap
  460. # ------------------------------------------------------------------------------
  461. #
  462. # Add build rules for a VST2 plugin.
  463. #
  464. function(dpf__build_clap NAME HAS_UI)
  465. dpf__create_dummy_source_list(_no_srcs)
  466. dpf__add_module("${NAME}-clap" ${_no_srcs})
  467. dpf__add_plugin_main("${NAME}-clap" "clap")
  468. dpf__add_ui_main("${NAME}-clap" "clap" "${HAS_UI}")
  469. dpf__set_module_export_list("${NAME}-clap" "clap")
  470. target_link_libraries("${NAME}-clap" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  471. set_target_properties("${NAME}-clap" PROPERTIES
  472. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  473. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/clap/$<0:>"
  474. OUTPUT_NAME "${NAME}"
  475. PREFIX ""
  476. SUFFIX ".clap")
  477. if(APPLE)
  478. set_target_properties("${NAME}-clap" PROPERTIES
  479. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents/MacOS/$<0:>"
  480. OUTPUT_NAME "${NAME}"
  481. SUFFIX "")
  482. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  483. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  484. "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents/Info.plist" @ONLY)
  485. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  486. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents")
  487. endif()
  488. endfunction()
  489. # dpf__add_dgl_cairo
  490. # ------------------------------------------------------------------------------
  491. #
  492. # Add the Cairo variant of DGL, if not already available.
  493. #
  494. function(dpf__add_dgl_cairo NO_SHARED_RESOURCES)
  495. if(TARGET dgl-cairo)
  496. return()
  497. endif()
  498. find_package(PkgConfig)
  499. pkg_check_modules(CAIRO "cairo" REQUIRED)
  500. link_directories(${CAIRO_LIBRARY_DIRS})
  501. dpf__add_static_library(dgl-cairo STATIC
  502. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  503. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  504. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  505. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  506. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  507. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  508. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  509. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  510. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  511. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  512. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  513. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  514. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  515. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  516. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  517. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp")
  518. if(NO_SHARED_RESOURCES)
  519. target_compile_definitions(dgl-cairo PUBLIC "DGL_NO_SHARED_RESOURCES")
  520. else()
  521. target_sources(dgl-cairo PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  522. endif()
  523. if(NOT APPLE)
  524. target_sources(dgl-cairo PRIVATE
  525. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  526. else()
  527. target_sources(dgl-cairo PRIVATE
  528. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  529. endif()
  530. target_include_directories(dgl-cairo PUBLIC
  531. "${DPF_ROOT_DIR}/dgl")
  532. target_include_directories(dgl-cairo PUBLIC
  533. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  534. dpf__add_dgl_system_libs()
  535. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  536. add_library(dgl-cairo-definitions INTERFACE)
  537. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO" "HAVE_DGL")
  538. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  539. if(MINGW)
  540. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_STATIC_LIBRARIES})
  541. else()
  542. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_LIBRARIES})
  543. endif()
  544. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions)
  545. endfunction()
  546. # dpf__add_dgl_opengl
  547. # ------------------------------------------------------------------------------
  548. #
  549. # Add the OpenGL variant of DGL, if not already available.
  550. #
  551. function(dpf__add_dgl_opengl NO_SHARED_RESOURCES)
  552. if(TARGET dgl-opengl)
  553. return()
  554. endif()
  555. if(NOT OpenGL_GL_PREFERENCE)
  556. set(OpenGL_GL_PREFERENCE "LEGACY")
  557. endif()
  558. find_package(OpenGL REQUIRED)
  559. dpf__add_static_library(dgl-opengl STATIC
  560. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  561. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  562. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  563. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  564. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  565. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  566. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  567. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  568. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  569. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  570. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  571. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  572. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  573. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  574. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  575. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  576. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp")
  577. if(NO_SHARED_RESOURCES)
  578. target_compile_definitions(dgl-opengl PUBLIC "DGL_NO_SHARED_RESOURCES")
  579. else()
  580. target_sources(dgl-opengl PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  581. endif()
  582. if(NOT APPLE)
  583. target_sources(dgl-opengl PRIVATE
  584. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  585. else()
  586. target_sources(dgl-opengl PRIVATE
  587. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  588. endif()
  589. target_include_directories(dgl-opengl PUBLIC
  590. "${DPF_ROOT_DIR}/dgl")
  591. target_include_directories(dgl-opengl PUBLIC
  592. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  593. if(APPLE)
  594. target_compile_definitions(dgl-opengl PUBLIC "GL_SILENCE_DEPRECATION")
  595. endif()
  596. dpf__add_dgl_system_libs()
  597. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  598. add_library(dgl-opengl-definitions INTERFACE)
  599. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL" "HAVE_DGL")
  600. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  601. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  602. endfunction()
  603. # dpf__add_plugin_specific_ui_sources
  604. # ------------------------------------------------------------------------------
  605. #
  606. # Compile system specific files, for now it is just Objective-C code
  607. #
  608. function(dpf__add_plugin_specific_ui_sources NAME)
  609. if(APPLE)
  610. target_sources("${NAME}" PRIVATE
  611. "${DPF_ROOT_DIR}/distrho/DistrhoUI_macOS.mm")
  612. endif()
  613. endfunction()
  614. # dpf__add_dgl_system_libs
  615. # ------------------------------------------------------------------------------
  616. #
  617. # Find system libraries required by DGL and add them as an interface target.
  618. #
  619. function(dpf__add_dgl_system_libs)
  620. if(TARGET dgl-system-libs)
  621. return()
  622. endif()
  623. add_library(dgl-system-libs INTERFACE)
  624. add_library(dgl-system-libs-definitions INTERFACE)
  625. if(HAIKU)
  626. target_link_libraries(dgl-system-libs INTERFACE "be")
  627. elseif(WIN32)
  628. target_link_libraries(dgl-system-libs INTERFACE "gdi32" "comdlg32")
  629. elseif(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. else()
  634. find_package(X11 REQUIRED)
  635. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  636. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  637. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_X11")
  638. if(X11_Xcursor_FOUND)
  639. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xcursor_LIB}")
  640. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XCURSOR")
  641. endif()
  642. if(X11_Xext_FOUND)
  643. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xext_LIB}")
  644. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XEXT")
  645. endif()
  646. if(X11_Xrandr_FOUND)
  647. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xrandr_LIB}")
  648. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XRANDR")
  649. endif()
  650. if(X11_XSync_FOUND)
  651. target_link_libraries(dgl-system-libs INTERFACE "${X11_XSync_LIB}")
  652. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XSYNC")
  653. endif()
  654. endif()
  655. if(MSVC)
  656. file(MAKE_DIRECTORY "${DPF_ROOT_DIR}/khronos/GL")
  657. foreach(_gl_header "glext.h")
  658. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}")
  659. file(DOWNLOAD "https://www.khronos.org/registry/OpenGL/api/GL/${_gl_header}" "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}" SHOW_PROGRESS)
  660. endif()
  661. endforeach()
  662. foreach(_khr_header "khrplatform.h")
  663. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}")
  664. file(DOWNLOAD "https://www.khronos.org/registry/EGL/api/KHR/${_khr_header}" "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}" SHOW_PROGRESS)
  665. endif()
  666. endforeach()
  667. target_include_directories(dgl-system-libs-definitions INTERFACE "${DPF_ROOT_DIR}/khronos")
  668. endif()
  669. target_link_libraries(dgl-system-libs INTERFACE dgl-system-libs-definitions)
  670. endfunction()
  671. # dpf__add_executable
  672. # ------------------------------------------------------------------------------
  673. #
  674. # Adds an executable target, and set some default properties on the target.
  675. #
  676. function(dpf__add_executable NAME)
  677. add_executable("${NAME}" ${ARGN})
  678. dpf__set_target_defaults("${NAME}")
  679. if(MINGW)
  680. target_link_libraries("${NAME}" PRIVATE "-static")
  681. endif()
  682. endfunction()
  683. # dpf__add_module
  684. # ------------------------------------------------------------------------------
  685. #
  686. # Adds a module target, and set some default properties on the target.
  687. #
  688. function(dpf__add_module NAME)
  689. add_library("${NAME}" MODULE ${ARGN})
  690. dpf__set_target_defaults("${NAME}")
  691. if(MINGW)
  692. target_link_libraries("${NAME}" PRIVATE "-static")
  693. endif()
  694. endfunction()
  695. # dpf__add_static_library
  696. # ------------------------------------------------------------------------------
  697. #
  698. # Adds a static library target, and set some default properties on the target.
  699. #
  700. function(dpf__add_static_library NAME)
  701. add_library("${NAME}" STATIC ${ARGN})
  702. dpf__set_target_defaults("${NAME}")
  703. endfunction()
  704. # dpf__set_module_export_list
  705. # ------------------------------------------------------------------------------
  706. #
  707. # Applies a list of exported symbols to the module target.
  708. #
  709. function(dpf__set_module_export_list NAME EXPORTS)
  710. if(WIN32)
  711. target_sources("${NAME}" PRIVATE "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.def")
  712. elseif(APPLE)
  713. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  714. "-Xlinker" "-exported_symbols_list"
  715. "-Xlinker" "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.exp")
  716. else()
  717. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  718. "-Xlinker" "--version-script=${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.version")
  719. endif()
  720. endfunction()
  721. # dpf__set_target_defaults
  722. # ------------------------------------------------------------------------------
  723. #
  724. # Set default properties which must apply to all DPF-defined targets.
  725. #
  726. function(dpf__set_target_defaults NAME)
  727. set_target_properties("${NAME}" PROPERTIES
  728. POSITION_INDEPENDENT_CODE TRUE
  729. C_VISIBILITY_PRESET "hidden"
  730. CXX_VISIBILITY_PRESET "hidden"
  731. VISIBILITY_INLINES_HIDDEN TRUE)
  732. if(WIN32)
  733. target_compile_definitions("${NAME}" PUBLIC "NOMINMAX")
  734. endif()
  735. if (MINGW)
  736. target_compile_options("${NAME}" PUBLIC "-mstackrealign")
  737. endif()
  738. if (MSVC)
  739. target_compile_options("${NAME}" PUBLIC "/UTF-8")
  740. target_compile_definitions("${NAME}" PUBLIC "_CRT_SECURE_NO_WARNINGS")
  741. endif()
  742. if (CMAKE_COMPILER_IS_GNUCXX)
  743. target_compile_options("${NAME}" PUBLIC "-fno-gnu-unique")
  744. endif()
  745. endfunction()
  746. # dpf__add_plugin_main
  747. # ------------------------------------------------------------------------------
  748. #
  749. # Adds plugin code to the given target.
  750. #
  751. function(dpf__add_plugin_main NAME TARGET)
  752. target_sources("${NAME}" PRIVATE
  753. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  754. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  755. endfunction()
  756. # dpf__add_ui_main
  757. # ------------------------------------------------------------------------------
  758. #
  759. # Adds UI code to the given target (only if the target has UI).
  760. #
  761. function(dpf__add_ui_main NAME TARGET HAS_UI)
  762. if(HAS_UI)
  763. target_sources("${NAME}" PRIVATE
  764. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  765. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  766. endif()
  767. endfunction()
  768. # dpf__add_plugin_target_definition
  769. # ------------------------------------------------------------------------------
  770. #
  771. # Adds the plugins target macro definition.
  772. # This selects which entry file is compiled according to the target type.
  773. #
  774. function(dpf__add_plugin_target_definition NAME TARGET)
  775. string(TOUPPER "${TARGET}" _upperTarget)
  776. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  777. endfunction()
  778. # dpf__add_lv2_ttl_generator
  779. # ------------------------------------------------------------------------------
  780. #
  781. # Build the LV2 TTL generator.
  782. #
  783. function(dpf__add_lv2_ttl_generator)
  784. if(TARGET lv2_ttl_generator)
  785. return()
  786. endif()
  787. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  788. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  789. target_link_libraries(lv2_ttl_generator PRIVATE "dl")
  790. endif()
  791. endfunction()
  792. # dpf__ensure_sources_non_empty
  793. # ------------------------------------------------------------------------------
  794. #
  795. # Ensure the given source list contains at least one file.
  796. # The function appends an empty source file to the list if necessary.
  797. # This is useful when CMake does not permit to add targets without sources.
  798. #
  799. function(dpf__ensure_sources_non_empty VAR)
  800. if(NOT "" STREQUAL "${${VAR}}")
  801. return()
  802. endif()
  803. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  804. if(NOT EXISTS "${_file}")
  805. file(WRITE "${_file}" "")
  806. endif()
  807. set("${VAR}" "${_file}" PARENT_SCOPE)
  808. endfunction()
  809. # dpf__create_dummy_source_list
  810. # ------------------------------------------------------------------------------
  811. #
  812. # Create a dummy source list which is equivalent to compiling nothing.
  813. # This is only for compatibility with older CMake versions, which refuse to add
  814. # targets without any sources.
  815. #
  816. macro(dpf__create_dummy_source_list VAR)
  817. set("${VAR}")
  818. if(CMAKE_VERSION VERSION_LESS "3.11")
  819. dpf__ensure_sources_non_empty("${VAR}")
  820. endif()
  821. endmacro()
  822. # dpf__target_link_directories
  823. # ------------------------------------------------------------------------------
  824. #
  825. # Call `target_link_directories` if cmake >= 3.13,
  826. # otherwise fallback to global `link_directories`.
  827. #
  828. macro(dpf__target_link_directories NAME DIRS)
  829. if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
  830. target_link_directories("${NAME}" PUBLIC ${DIRS})
  831. else()
  832. link_directories(${DIRS})
  833. endif()
  834. endmacro()
  835. # dpf__warn_once
  836. # ------------------------------------------------------------------------------
  837. #
  838. # Prints a warning message once only.
  839. #
  840. function(dpf__warn_once_only TOKEN MESSAGE)
  841. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  842. if(NOT _warned)
  843. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  844. message(WARNING "${MESSAGE}")
  845. endif()
  846. endfunction()