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.

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