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.

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