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.

1023 lines
36KB

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