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.

1027 lines
36KB

  1. # DISTRHO Plugin Framework (DPF)
  2. # Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  3. # Copyright (C) 2022-2024 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_AUDIOUNIT_FRAMEWORK "AudioUnit")
  511. find_library(APPLE_COREFOUNDATION_FRAMEWORK "CoreFoundation")
  512. target_compile_options("${NAME}-au" PRIVATE "-ObjC++")
  513. target_link_libraries("${NAME}-au" PRIVATE
  514. "${NAME}-dsp"
  515. "${NAME}-ui"
  516. "${APPLE_AUDIOTOOLBOX_FRAMEWORK}"
  517. "${APPLE_AUDIOUNIT_FRAMEWORK}"
  518. "${APPLE_COREFOUNDATION_FRAMEWORK}")
  519. set_target_properties("${NAME}-au" PROPERTIES
  520. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.component/Contents/MacOS/$<0:>"
  521. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/au/$<0:>"
  522. OUTPUT_NAME "${NAME}"
  523. PREFIX ""
  524. SUFFIX "")
  525. dpf__add_executable("${NAME}-export" ${_no_srcs})
  526. dpf__add_plugin_main("${NAME}-export" "export")
  527. dpf__add_ui_main("${NAME}-export" "export" "${HAS_UI}")
  528. target_link_libraries("${NAME}-export" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  529. separate_arguments(CMAKE_CROSSCOMPILING_EMULATOR)
  530. add_custom_command(TARGET "${NAME}-au" POST_BUILD
  531. COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:${NAME}-export>" "${NAME}"
  532. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.component/Contents"
  533. DEPENDS "${NAME}-export")
  534. add_dependencies("${NAME}-au" "${NAME}-export")
  535. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  536. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.component/Contents")
  537. endfunction()
  538. # dpf__build_static
  539. # ------------------------------------------------------------------------------
  540. #
  541. # Add build rules for a static library.
  542. #
  543. function(dpf__build_static NAME HAS_UI)
  544. dpf__create_dummy_source_list(_no_srcs)
  545. dpf__add_module("${NAME}-static" ${_no_srcs} STATIC)
  546. dpf__add_plugin_main("${NAME}-static" "static")
  547. dpf__add_ui_main("${NAME}-static" "static" "${HAS_UI}")
  548. target_link_libraries("${NAME}-static" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  549. get_target_property(dsp_srcs "${NAME}-dsp" SOURCES)
  550. get_target_property(ui_srcs "${NAME}-ui" SOURCES)
  551. foreach(src ${dsp_srcs})
  552. target_sources("${NAME}-static" PRIVATE ${src})
  553. endforeach()
  554. foreach(src ${ui_srcs})
  555. target_sources("${NAME}-static" PRIVATE ${src})
  556. endforeach()
  557. set_target_properties("${NAME}-static" PROPERTIES
  558. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  559. OUTPUT_NAME "${NAME}"
  560. PREFIX "")
  561. endfunction()
  562. # dpf__add_dgl_cairo
  563. # ------------------------------------------------------------------------------
  564. #
  565. # Add the Cairo variant of DGL, if not already available.
  566. #
  567. function(dpf__add_dgl_cairo NO_SHARED_RESOURCES)
  568. if(TARGET dgl-cairo)
  569. return()
  570. endif()
  571. find_package(PkgConfig)
  572. pkg_check_modules(CAIRO "cairo" REQUIRED)
  573. link_directories(${CAIRO_LIBRARY_DIRS})
  574. dpf__add_static_library(dgl-cairo STATIC
  575. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  576. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  577. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  578. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  579. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  580. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  581. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  582. "${DPF_ROOT_DIR}/dgl/src/Layout.cpp"
  583. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  584. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  585. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  586. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  587. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  588. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  589. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  590. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  591. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp")
  592. if(NO_SHARED_RESOURCES)
  593. target_compile_definitions(dgl-cairo PUBLIC "DGL_NO_SHARED_RESOURCES")
  594. else()
  595. target_sources(dgl-cairo PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  596. endif()
  597. if(APPLE)
  598. target_sources(dgl-cairo PRIVATE
  599. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  600. else()
  601. target_sources(dgl-cairo PRIVATE
  602. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  603. endif()
  604. target_include_directories(dgl-cairo PUBLIC
  605. "${DPF_ROOT_DIR}/dgl")
  606. target_include_directories(dgl-cairo PUBLIC
  607. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  608. dpf__add_dgl_system_libs()
  609. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  610. add_library(dgl-cairo-definitions INTERFACE)
  611. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO" "HAVE_DGL")
  612. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  613. if(MINGW)
  614. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_STATIC_LIBRARIES})
  615. else()
  616. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_LIBRARIES})
  617. endif()
  618. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions)
  619. endfunction()
  620. # dpf__add_dgl_opengl
  621. # ------------------------------------------------------------------------------
  622. #
  623. # Add the OpenGL variant of DGL, if not already available.
  624. #
  625. function(dpf__add_dgl_opengl NO_SHARED_RESOURCES)
  626. if(TARGET dgl-opengl)
  627. return()
  628. endif()
  629. if(NOT OpenGL_GL_PREFERENCE)
  630. set(OpenGL_GL_PREFERENCE "LEGACY")
  631. endif()
  632. find_package(OpenGL REQUIRED)
  633. dpf__add_static_library(dgl-opengl STATIC
  634. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  635. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  636. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  637. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  638. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  639. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  640. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  641. "${DPF_ROOT_DIR}/dgl/src/Layout.cpp"
  642. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  643. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  644. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  645. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  646. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  647. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  648. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  649. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  650. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  651. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp")
  652. if(NO_SHARED_RESOURCES)
  653. target_compile_definitions(dgl-opengl PUBLIC "DGL_NO_SHARED_RESOURCES")
  654. else()
  655. target_sources(dgl-opengl PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  656. endif()
  657. if(APPLE)
  658. target_sources(dgl-opengl PRIVATE
  659. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  660. else()
  661. target_sources(dgl-opengl PRIVATE
  662. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  663. endif()
  664. target_include_directories(dgl-opengl PUBLIC
  665. "${DPF_ROOT_DIR}/dgl")
  666. target_include_directories(dgl-opengl PUBLIC
  667. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  668. if(APPLE)
  669. target_compile_definitions(dgl-opengl PUBLIC "GL_SILENCE_DEPRECATION")
  670. endif()
  671. dpf__add_dgl_system_libs()
  672. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  673. add_library(dgl-opengl-definitions INTERFACE)
  674. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL" "HAVE_DGL")
  675. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  676. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  677. endfunction()
  678. # dpf__add_plugin_specific_ui_sources
  679. # ------------------------------------------------------------------------------
  680. #
  681. # Compile system specific files, for now it is just Objective-C code
  682. #
  683. function(dpf__add_plugin_specific_ui_sources NAME)
  684. if(APPLE)
  685. target_sources("${NAME}" PRIVATE
  686. "${DPF_ROOT_DIR}/distrho/DistrhoUI_macOS.mm")
  687. endif()
  688. endfunction()
  689. # dpf__add_dgl_system_libs
  690. # ------------------------------------------------------------------------------
  691. #
  692. # Find system libraries required by DGL and add them as an interface target.
  693. #
  694. function(dpf__add_dgl_system_libs)
  695. if(TARGET dgl-system-libs)
  696. return()
  697. endif()
  698. add_library(dgl-system-libs INTERFACE)
  699. add_library(dgl-system-libs-definitions INTERFACE)
  700. if(APPLE)
  701. find_library(APPLE_COCOA_FRAMEWORK "Cocoa")
  702. find_library(APPLE_COREVIDEO_FRAMEWORK "CoreVideo")
  703. target_link_libraries(dgl-system-libs INTERFACE "${APPLE_COCOA_FRAMEWORK}" "${APPLE_COREVIDEO_FRAMEWORK}")
  704. elseif(EMSCRIPTEN)
  705. elseif(HAIKU)
  706. target_link_libraries(dgl-system-libs INTERFACE "be")
  707. elseif(WIN32)
  708. target_link_libraries(dgl-system-libs INTERFACE "comdlg32" "dwmapi" "gdi32")
  709. else()
  710. find_package(PkgConfig)
  711. pkg_check_modules(DBUS "dbus-1")
  712. if(DBUS_FOUND)
  713. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_DBUS")
  714. target_include_directories(dgl-system-libs INTERFACE "${DBUS_INCLUDE_DIRS}")
  715. target_link_libraries(dgl-system-libs INTERFACE "${DBUS_LIBRARIES}")
  716. endif()
  717. find_package(X11 REQUIRED)
  718. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_X11")
  719. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  720. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  721. if(X11_Xcursor_FOUND)
  722. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XCURSOR")
  723. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xcursor_LIB}")
  724. endif()
  725. if(X11_Xext_FOUND)
  726. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XEXT")
  727. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xext_LIB}")
  728. endif()
  729. if(X11_Xrandr_FOUND)
  730. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XRANDR")
  731. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xrandr_LIB}")
  732. endif()
  733. if(X11_XSync_FOUND)
  734. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XSYNC")
  735. target_link_libraries(dgl-system-libs INTERFACE "${X11_XSync_LIB}")
  736. endif()
  737. endif()
  738. if(MSVC)
  739. file(MAKE_DIRECTORY "${DPF_ROOT_DIR}/khronos/GL")
  740. foreach(_gl_header "glext.h")
  741. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}")
  742. file(DOWNLOAD "https://www.khronos.org/registry/OpenGL/api/GL/${_gl_header}" "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}" SHOW_PROGRESS)
  743. endif()
  744. endforeach()
  745. foreach(_khr_header "khrplatform.h")
  746. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}")
  747. file(DOWNLOAD "https://www.khronos.org/registry/EGL/api/KHR/${_khr_header}" "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}" SHOW_PROGRESS)
  748. endif()
  749. endforeach()
  750. target_include_directories(dgl-system-libs-definitions INTERFACE "${DPF_ROOT_DIR}/khronos")
  751. endif()
  752. target_link_libraries(dgl-system-libs INTERFACE dgl-system-libs-definitions)
  753. endfunction()
  754. # dpf__add_executable
  755. # ------------------------------------------------------------------------------
  756. #
  757. # Adds an executable target, and set some default properties on the target.
  758. #
  759. function(dpf__add_executable NAME)
  760. add_executable("${NAME}" ${ARGN})
  761. dpf__set_target_defaults("${NAME}")
  762. if(MINGW)
  763. target_link_libraries("${NAME}" PRIVATE "-static")
  764. endif()
  765. endfunction()
  766. # dpf__add_module
  767. # ------------------------------------------------------------------------------
  768. #
  769. # Adds a module target, and set some default properties on the target.
  770. #
  771. function(dpf__add_module NAME)
  772. add_library("${NAME}" MODULE ${ARGN})
  773. dpf__set_target_defaults("${NAME}")
  774. if(APPLE)
  775. set_target_properties("${NAME}" PROPERTIES SUFFIX ".dylib")
  776. elseif(MINGW)
  777. target_link_libraries("${NAME}" PRIVATE "-static")
  778. endif()
  779. endfunction()
  780. # dpf__add_static_library
  781. # ------------------------------------------------------------------------------
  782. #
  783. # Adds a static library target, and set some default properties on the target.
  784. #
  785. function(dpf__add_static_library NAME)
  786. add_library("${NAME}" STATIC ${ARGN})
  787. dpf__set_target_defaults("${NAME}")
  788. endfunction()
  789. # dpf__set_module_export_list
  790. # ------------------------------------------------------------------------------
  791. #
  792. # Applies a list of exported symbols to the module target.
  793. #
  794. function(dpf__set_module_export_list NAME EXPORTS)
  795. if(WIN32)
  796. target_sources("${NAME}" PRIVATE "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.def")
  797. elseif(APPLE)
  798. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  799. "-Xlinker" "-exported_symbols_list"
  800. "-Xlinker" "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.exp")
  801. else()
  802. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  803. "-Xlinker" "--version-script=${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.version")
  804. endif()
  805. endfunction()
  806. # dpf__set_target_defaults
  807. # ------------------------------------------------------------------------------
  808. #
  809. # Set default properties which must apply to all DPF-defined targets.
  810. #
  811. function(dpf__set_target_defaults NAME)
  812. set_target_properties("${NAME}" PROPERTIES
  813. POSITION_INDEPENDENT_CODE TRUE
  814. C_VISIBILITY_PRESET "hidden"
  815. CXX_VISIBILITY_PRESET "hidden"
  816. VISIBILITY_INLINES_HIDDEN TRUE)
  817. if(WIN32)
  818. target_compile_definitions("${NAME}" PUBLIC "NOMINMAX")
  819. endif()
  820. if (MINGW)
  821. target_compile_options("${NAME}" PUBLIC "-mstackrealign")
  822. endif()
  823. if (MSVC)
  824. target_compile_options("${NAME}" PUBLIC "/UTF-8")
  825. target_compile_definitions("${NAME}" PUBLIC "_CRT_SECURE_NO_WARNINGS")
  826. endif()
  827. if (CMAKE_COMPILER_IS_GNUCXX)
  828. target_compile_options("${NAME}" PUBLIC "-fno-gnu-unique")
  829. endif()
  830. endfunction()
  831. # dpf__add_plugin_main
  832. # ------------------------------------------------------------------------------
  833. #
  834. # Adds plugin code to the given target.
  835. #
  836. function(dpf__add_plugin_main NAME TARGET)
  837. target_sources("${NAME}" PRIVATE
  838. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  839. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  840. endfunction()
  841. # dpf__add_ui_main
  842. # ------------------------------------------------------------------------------
  843. #
  844. # Adds UI code to the given target (only if the target has UI).
  845. #
  846. function(dpf__add_ui_main NAME TARGET HAS_UI)
  847. if(HAS_UI)
  848. target_sources("${NAME}" PRIVATE
  849. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  850. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  851. endif()
  852. endfunction()
  853. # dpf__add_plugin_target_definition
  854. # ------------------------------------------------------------------------------
  855. #
  856. # Adds the plugins target macro definition.
  857. # This selects which entry file is compiled according to the target type.
  858. #
  859. function(dpf__add_plugin_target_definition NAME TARGET)
  860. string(TOUPPER "${TARGET}" _upperTarget)
  861. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  862. endfunction()
  863. # dpf__add_lv2_ttl_generator
  864. # ------------------------------------------------------------------------------
  865. #
  866. # Build the LV2 TTL generator.
  867. #
  868. function(dpf__add_lv2_ttl_generator)
  869. if(TARGET lv2_ttl_generator)
  870. return()
  871. endif()
  872. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  873. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  874. target_link_libraries(lv2_ttl_generator PRIVATE "dl")
  875. endif()
  876. endfunction()
  877. # dpf__ensure_sources_non_empty
  878. # ------------------------------------------------------------------------------
  879. #
  880. # Ensure the given source list contains at least one file.
  881. # The function appends an empty source file to the list if necessary.
  882. # This is useful when CMake does not permit to add targets without sources.
  883. #
  884. function(dpf__ensure_sources_non_empty VAR)
  885. if(NOT "" STREQUAL "${${VAR}}")
  886. return()
  887. endif()
  888. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  889. if(NOT EXISTS "${_file}")
  890. file(WRITE "${_file}" "")
  891. endif()
  892. set("${VAR}" "${_file}" PARENT_SCOPE)
  893. endfunction()
  894. # dpf__create_dummy_source_list
  895. # ------------------------------------------------------------------------------
  896. #
  897. # Create a dummy source list which is equivalent to compiling nothing.
  898. # This is only for compatibility with older CMake versions, which refuse to add
  899. # targets without any sources.
  900. #
  901. macro(dpf__create_dummy_source_list VAR)
  902. set("${VAR}")
  903. if(CMAKE_VERSION VERSION_LESS "3.11")
  904. dpf__ensure_sources_non_empty("${VAR}")
  905. endif()
  906. endmacro()
  907. # dpf__target_link_directories
  908. # ------------------------------------------------------------------------------
  909. #
  910. # Call `target_link_directories` if cmake >= 3.13,
  911. # otherwise fallback to global `link_directories`.
  912. #
  913. macro(dpf__target_link_directories NAME DIRS)
  914. if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
  915. target_link_directories("${NAME}" PUBLIC ${DIRS})
  916. else()
  917. link_directories(${DIRS})
  918. endif()
  919. endmacro()
  920. # dpf__warn_once
  921. # ------------------------------------------------------------------------------
  922. #
  923. # Prints a warning message once only.
  924. #
  925. function(dpf__warn_once_only TOKEN MESSAGE)
  926. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  927. if(NOT _warned)
  928. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  929. message(WARNING "${MESSAGE}")
  930. endif()
  931. endfunction()