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.

923 lines
32KB

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