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.

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