Collection of DPF-based plugins for packaging
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.

713 lines
25KB

  1. # DISTRHO Plugin Framework (DPF)
  2. # Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  3. #
  4. # SPDX-License-Identifier: ISC
  5. # ------------------------------------------------------------------------------
  6. # CMake support module for the DISTRHO Plugin Framework
  7. #
  8. # The purpose of this module is to help building music plugins easily, when the
  9. # project uses CMake as its build system.
  10. #
  11. # In order to use the helpers provided by this module, a plugin author should
  12. # add DPF as a subproject, making the function `dpf_add_plugin` available.
  13. # The usage of this function is documented below in greater detail.
  14. #
  15. # Example project `CMakeLists.txt`:
  16. #
  17. # ```
  18. # cmake_minimum_required(VERSION 3.7)
  19. # project(MyPlugin)
  20. #
  21. # add_subdirectory(DPF)
  22. #
  23. # dpf_add_plugin(MyPlugin
  24. # TARGETS lv2 vst2
  25. # UI_TYPE opengl
  26. # FILES_DSP
  27. # src/MyPlugin.cpp
  28. # FILES_UI
  29. # src/MyUI.cpp)
  30. #
  31. # target_include_directories(MyPlugin
  32. # PUBLIC src)
  33. # ```
  34. #
  35. # Important: note that properties, such as include directories, definitions,
  36. # and linked libraries *must* be marked with `PUBLIC` so they take effect and
  37. # propagate into all the plugin targets.
  38. include(CMakeParseArguments)
  39. # ------------------------------------------------------------------------------
  40. # DPF public functions
  41. # ------------------------------------------------------------------------------
  42. # dpf_add_plugin(name <args...>)
  43. # ------------------------------------------------------------------------------
  44. #
  45. # Add a plugin built using the DISTRHO Plugin Framework.
  46. #
  47. # ------------------------------------------------------------------------------
  48. # Created targets:
  49. #
  50. # `<name>`
  51. # static library: the common part of the plugin
  52. # The public properties set on this target apply to both DSP and UI.
  53. #
  54. # `<name>-dsp`
  55. # static library: the DSP part of the plugin
  56. # The public properties set on this target apply to the DSP only.
  57. #
  58. # `<name>-ui`
  59. # static library: the UI part of the plugin
  60. # The public properties set on this target apply to the UI only.
  61. #
  62. # `<name>-<target>` for each target specified with the `TARGETS` argument.
  63. # This is target-dependent and not intended for public use.
  64. #
  65. # ------------------------------------------------------------------------------
  66. # Arguments:
  67. #
  68. # `TARGETS` <tgt1>...<tgtN>
  69. # a list of one of more of the following target types:
  70. # `jack`, `ladspa`, `dssi`, `lv2`, `vst2`
  71. #
  72. # `UI_TYPE` <type>
  73. # the user interface type: `opengl` (default), `cairo`
  74. #
  75. # `MONOLITHIC`
  76. # build LV2 as a single binary for UI and DSP
  77. #
  78. # `FILES_DSP` <file1>...<fileN>
  79. # list of sources which are part of the DSP
  80. #
  81. # `FILES_UI` <file1>...<fileN>
  82. # list of sources which are part of the UI
  83. # empty indicates the plugin does not have UI
  84. #
  85. # `FILES_COMMON` <file1>...<fileN>
  86. # list of sources which are part of both DSP and UI
  87. #
  88. function(dpf_add_plugin NAME)
  89. set(options MONOLITHIC)
  90. set(oneValueArgs UI_TYPE)
  91. set(multiValueArgs TARGETS FILES_DSP FILES_UI FILES_COMMON)
  92. cmake_parse_arguments(_dpf_plugin "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  93. if("${_dpf_plugin_UI_TYPE}" STREQUAL "")
  94. set(_dpf_plugin_UI_TYPE "opengl")
  95. endif()
  96. set(_dgl_library)
  97. if(_dpf_plugin_FILES_UI)
  98. if(_dpf_plugin_UI_TYPE STREQUAL "cairo")
  99. dpf__add_dgl_cairo()
  100. set(_dgl_library dgl-cairo)
  101. elseif(_dpf_plugin_UI_TYPE STREQUAL "opengl")
  102. dpf__add_dgl_opengl()
  103. set(_dgl_library dgl-opengl)
  104. else()
  105. message(FATAL_ERROR "Unrecognized UI type for plugin: ${_dpf_plugin_UI_TYPE}")
  106. endif()
  107. endif()
  108. ###
  109. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_COMMON)
  110. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_DSP)
  111. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_UI)
  112. ###
  113. dpf__add_static_library("${NAME}" ${_dpf_plugin_FILES_COMMON})
  114. target_include_directories("${NAME}" PUBLIC
  115. "${DPF_ROOT_DIR}/distrho")
  116. if(_dgl_library)
  117. # make sure that all code will see DGL_* definitions
  118. target_link_libraries("${NAME}" PUBLIC
  119. "${_dgl_library}-definitions"
  120. dgl-system-libs-definitions)
  121. endif()
  122. dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP})
  123. target_link_libraries("${NAME}-dsp" PUBLIC "${NAME}")
  124. if(_dgl_library)
  125. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  126. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library})
  127. # add the files containing Objective-C classes, recompiled under namespace
  128. dpf__add_plugin_specific_ui_sources("${NAME}-ui")
  129. else()
  130. add_library("${NAME}-ui" INTERFACE)
  131. endif()
  132. ###
  133. foreach(_target ${_dpf_plugin_TARGETS})
  134. if(_target STREQUAL "jack")
  135. dpf__build_jack("${NAME}" "${_dgl_library}")
  136. elseif(_target STREQUAL "ladspa")
  137. dpf__build_ladspa("${NAME}")
  138. elseif(_target STREQUAL "dssi")
  139. dpf__build_dssi("${NAME}" "${_dgl_library}")
  140. elseif(_target STREQUAL "lv2")
  141. dpf__build_lv2("${NAME}" "${_dgl_library}" "${_dpf_plugin_MONOLITHIC}")
  142. elseif(_target STREQUAL "vst2")
  143. dpf__build_vst2("${NAME}" "${_dgl_library}")
  144. else()
  145. message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}")
  146. endif()
  147. endforeach()
  148. endfunction()
  149. # ------------------------------------------------------------------------------
  150. # DPF private functions (prefixed with `dpf__`)
  151. # ------------------------------------------------------------------------------
  152. # Note: The $<0:> trick is to prevent MSVC from appending the build type
  153. # to the output directory.
  154. #
  155. # dpf__build_jack
  156. # ------------------------------------------------------------------------------
  157. #
  158. # Add build rules for a JACK program.
  159. #
  160. function(dpf__build_jack NAME DGL_LIBRARY)
  161. dpf__create_dummy_source_list(_no_srcs)
  162. dpf__add_executable("${NAME}-jack" ${_no_srcs})
  163. dpf__add_plugin_main("${NAME}-jack" "jack")
  164. dpf__add_ui_main("${NAME}-jack" "jack" "${DGL_LIBRARY}")
  165. target_link_libraries("${NAME}-jack" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  166. set_target_properties("${NAME}-jack" PROPERTIES
  167. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  168. OUTPUT_NAME "${NAME}")
  169. # Note: libjack will be linked at runtime
  170. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  171. target_link_libraries("${NAME}-jack" PRIVATE "dl")
  172. endif()
  173. # for RtAudio native fallback
  174. if(APPLE)
  175. find_library(APPLE_COREAUDIO_FRAMEWORK "CoreAudio")
  176. find_library(APPLE_COREFOUNDATION_FRAMEWORK "CoreFoundation")
  177. target_link_libraries("${NAME}-jack" PRIVATE "${APPLE_COREAUDIO_FRAMEWORK}" "${APPLE_COREFOUNDATION_FRAMEWORK}")
  178. endif()
  179. endfunction()
  180. # dpf__build_ladspa
  181. # ------------------------------------------------------------------------------
  182. #
  183. # Add build rules for a DSSI plugin.
  184. #
  185. function(dpf__build_ladspa NAME)
  186. dpf__create_dummy_source_list(_no_srcs)
  187. dpf__add_module("${NAME}-ladspa" ${_no_srcs})
  188. dpf__add_plugin_main("${NAME}-ladspa" "ladspa")
  189. dpf__set_module_export_list("${NAME}-ladspa" "ladspa")
  190. target_link_libraries("${NAME}-ladspa" PRIVATE "${NAME}-dsp")
  191. set_target_properties("${NAME}-ladspa" PROPERTIES
  192. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  193. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/ladspa/$<0:>"
  194. OUTPUT_NAME "${NAME}-ladspa"
  195. PREFIX "")
  196. endfunction()
  197. # dpf__build_dssi
  198. # ------------------------------------------------------------------------------
  199. #
  200. # Add build rules for a DSSI plugin.
  201. #
  202. function(dpf__build_dssi NAME DGL_LIBRARY)
  203. find_package(PkgConfig)
  204. pkg_check_modules(LIBLO "liblo")
  205. if(NOT LIBLO_FOUND)
  206. dpf__warn_once_only(missing_liblo
  207. "liblo is not found, skipping the `dssi` plugin targets")
  208. return()
  209. endif()
  210. link_directories(${LIBLO_LIBRARY_DIRS})
  211. dpf__create_dummy_source_list(_no_srcs)
  212. dpf__add_module("${NAME}-dssi" ${_no_srcs})
  213. dpf__add_plugin_main("${NAME}-dssi" "dssi")
  214. dpf__set_module_export_list("${NAME}-dssi" "dssi")
  215. target_link_libraries("${NAME}-dssi" PRIVATE "${NAME}-dsp")
  216. set_target_properties("${NAME}-dssi" PROPERTIES
  217. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  218. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/dssi/$<0:>"
  219. OUTPUT_NAME "${NAME}-dssi"
  220. PREFIX "")
  221. if(DGL_LIBRARY)
  222. dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs})
  223. dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${DGL_LIBRARY}")
  224. target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui")
  225. set_target_properties("${NAME}-dssi-ui" PROPERTIES
  226. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>"
  227. OUTPUT_NAME "${NAME}_ui")
  228. target_include_directories("${NAME}-dssi-ui" PRIVATE ${LIBLO_INCLUDE_DIRS})
  229. target_link_libraries("${NAME}-dssi-ui" PRIVATE ${LIBLO_LIBRARIES})
  230. endif()
  231. endfunction()
  232. # dpf__build_lv2
  233. # ------------------------------------------------------------------------------
  234. #
  235. # Add build rules for a LV2 plugin.
  236. #
  237. function(dpf__build_lv2 NAME DGL_LIBRARY MONOLITHIC)
  238. dpf__create_dummy_source_list(_no_srcs)
  239. dpf__add_module("${NAME}-lv2" ${_no_srcs})
  240. dpf__add_plugin_main("${NAME}-lv2" "lv2")
  241. if(DGL_LIBRARY AND MONOLITHIC)
  242. dpf__set_module_export_list("${NAME}-lv2" "lv2")
  243. else()
  244. dpf__set_module_export_list("${NAME}-lv2" "lv2-dsp")
  245. endif()
  246. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-dsp")
  247. set_target_properties("${NAME}-lv2" PROPERTIES
  248. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  249. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/lv2/$<0:>"
  250. OUTPUT_NAME "${NAME}_dsp"
  251. PREFIX "")
  252. if(DGL_LIBRARY)
  253. if(MONOLITHIC)
  254. dpf__add_ui_main("${NAME}-lv2" "lv2" "${DGL_LIBRARY}")
  255. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui")
  256. set_target_properties("${NAME}-lv2" PROPERTIES
  257. OUTPUT_NAME "${NAME}")
  258. else()
  259. dpf__add_module("${NAME}-lv2-ui" ${_no_srcs})
  260. dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${DGL_LIBRARY}")
  261. dpf__set_module_export_list("${NAME}-lv2-ui" "lv2-ui")
  262. target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui")
  263. set_target_properties("${NAME}-lv2-ui" PROPERTIES
  264. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  265. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/lv2/$<0:>"
  266. OUTPUT_NAME "${NAME}_ui"
  267. PREFIX "")
  268. endif()
  269. endif()
  270. dpf__add_lv2_ttl_generator()
  271. add_dependencies("${NAME}-lv2" lv2_ttl_generator)
  272. add_custom_command(TARGET "${NAME}-lv2" POST_BUILD
  273. COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
  274. "$<TARGET_FILE:lv2_ttl_generator>"
  275. "$<TARGET_FILE:${NAME}-lv2>"
  276. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2"
  277. DEPENDS lv2_ttl_generator)
  278. endfunction()
  279. # dpf__build_vst2
  280. # ------------------------------------------------------------------------------
  281. #
  282. # Add build rules for a VST2 plugin.
  283. #
  284. function(dpf__build_vst2 NAME DGL_LIBRARY)
  285. dpf__create_dummy_source_list(_no_srcs)
  286. dpf__add_module("${NAME}-vst2" ${_no_srcs})
  287. dpf__add_plugin_main("${NAME}-vst2" "vst2")
  288. dpf__add_ui_main("${NAME}-vst2" "vst2" "${DGL_LIBRARY}")
  289. dpf__set_module_export_list("${NAME}-vst2" "vst2")
  290. target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  291. set_target_properties("${NAME}-vst2" PROPERTIES
  292. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  293. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst2/$<0:>"
  294. OUTPUT_NAME "${NAME}-vst2"
  295. PREFIX "")
  296. if(APPLE)
  297. set_target_properties("${NAME}-vst2" PROPERTIES
  298. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/MacOS/$<0:>"
  299. OUTPUT_NAME "${NAME}"
  300. SUFFIX "")
  301. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  302. configure_file("${DPF_ROOT_DIR}/utils/plugin.vst/Contents/Info.plist"
  303. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/Info.plist" @ONLY)
  304. file(COPY "${DPF_ROOT_DIR}/utils/plugin.vst/Contents/PkgInfo"
  305. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents")
  306. endif()
  307. endfunction()
  308. # dpf__add_dgl_cairo
  309. # ------------------------------------------------------------------------------
  310. #
  311. # Add the Cairo variant of DGL, if not already available.
  312. #
  313. function(dpf__add_dgl_cairo)
  314. if(TARGET dgl-cairo)
  315. return()
  316. endif()
  317. find_package(PkgConfig)
  318. pkg_check_modules(CAIRO "cairo" REQUIRED)
  319. link_directories(${CAIRO_LIBRARY_DIRS})
  320. dpf__add_static_library(dgl-cairo STATIC
  321. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  322. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  323. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  324. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  325. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  326. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  327. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  328. "${DPF_ROOT_DIR}/dgl/src/Resources.cpp"
  329. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  330. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  331. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  332. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  333. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  334. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  335. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  336. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  337. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp")
  338. if(NOT APPLE)
  339. target_sources(dgl-cairo PRIVATE
  340. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  341. else() # Note: macOS pugl will be built as part of DistrhoUI_macOS.mm
  342. #target_sources(dgl-opengl PRIVATE
  343. # "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  344. endif()
  345. target_include_directories(dgl-cairo PUBLIC
  346. "${DPF_ROOT_DIR}/dgl")
  347. target_include_directories(dgl-cairo PUBLIC
  348. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  349. dpf__add_dgl_system_libs()
  350. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  351. add_library(dgl-cairo-definitions INTERFACE)
  352. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO" "HAVE_DGL")
  353. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  354. if(MINGW)
  355. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_STATIC_LIBRARIES})
  356. else()
  357. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_LIBRARIES})
  358. endif()
  359. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions)
  360. endfunction()
  361. # dpf__add_dgl_opengl
  362. # ------------------------------------------------------------------------------
  363. #
  364. # Add the OpenGL variant of DGL, if not already available.
  365. #
  366. function(dpf__add_dgl_opengl)
  367. if(TARGET dgl-opengl)
  368. return()
  369. endif()
  370. if(NOT OpenGL_GL_PREFERENCE)
  371. set(OpenGL_GL_PREFERENCE "LEGACY")
  372. endif()
  373. find_package(OpenGL REQUIRED)
  374. dpf__add_static_library(dgl-opengl STATIC
  375. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  376. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  377. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  378. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  379. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  380. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  381. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  382. "${DPF_ROOT_DIR}/dgl/src/Resources.cpp"
  383. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  384. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  385. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  386. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  387. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  388. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  389. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  390. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  391. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  392. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp")
  393. if(NOT APPLE)
  394. target_sources(dgl-opengl PRIVATE
  395. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  396. else() # Note: macOS pugl will be built as part of DistrhoUI_macOS.mm
  397. #target_sources(dgl-opengl PRIVATE
  398. # "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  399. endif()
  400. target_include_directories(dgl-opengl PUBLIC
  401. "${DPF_ROOT_DIR}/dgl")
  402. target_include_directories(dgl-opengl PUBLIC
  403. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  404. if(APPLE)
  405. target_compile_definitions(dgl-opengl PUBLIC "GL_SILENCE_DEPRECATION")
  406. endif()
  407. dpf__add_dgl_system_libs()
  408. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  409. add_library(dgl-opengl-definitions INTERFACE)
  410. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL" "HAVE_DGL")
  411. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  412. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  413. endfunction()
  414. # dpf__add_plugin_specific_ui_sources
  415. # ------------------------------------------------------------------------------
  416. #
  417. # Compile plugin-specific UI sources into the target designated by the given
  418. # name. There are some special considerations here:
  419. # - On most platforms, sources can be compiled only once, as part of DGL;
  420. # - On macOS, for any sources which define Objective-C interfaces, these must
  421. # be recompiled for each plugin under a unique namespace. In this case, the
  422. # name must be a plugin-specific identifier, and it will be used for computing
  423. # the unique ID along with the project version.
  424. function(dpf__add_plugin_specific_ui_sources NAME)
  425. if(APPLE)
  426. target_sources("${NAME}" PRIVATE
  427. "${DPF_ROOT_DIR}/distrho/DistrhoUI_macOS.mm")
  428. string(SHA256 _hash "${NAME}:${PROJECT_VERSION}")
  429. target_compile_definitions("${NAME}" PUBLIC "PUGL_NAMESPACE=${_hash}")
  430. endif()
  431. endfunction()
  432. # dpf__add_dgl_system_libs
  433. # ------------------------------------------------------------------------------
  434. #
  435. # Find system libraries required by DGL and add them as an interface target.
  436. #
  437. function(dpf__add_dgl_system_libs)
  438. if(TARGET dgl-system-libs)
  439. return()
  440. endif()
  441. add_library(dgl-system-libs INTERFACE)
  442. add_library(dgl-system-libs-definitions INTERFACE)
  443. if(HAIKU)
  444. target_link_libraries(dgl-system-libs INTERFACE "be")
  445. elseif(WIN32)
  446. target_link_libraries(dgl-system-libs INTERFACE "gdi32" "comdlg32")
  447. elseif(APPLE)
  448. find_library(APPLE_COCOA_FRAMEWORK "Cocoa")
  449. find_library(APPLE_COREVIDEO_FRAMEWORK "CoreVideo")
  450. target_link_libraries(dgl-system-libs INTERFACE "${APPLE_COCOA_FRAMEWORK}" "${APPLE_COREVIDEO_FRAMEWORK}")
  451. else()
  452. find_package(X11 REQUIRED)
  453. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  454. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  455. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_X11")
  456. if(X11_Xext_FOUND)
  457. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xext_LIB}")
  458. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XEXT")
  459. endif()
  460. if(X11_XSync_FOUND)
  461. target_link_libraries(dgl-system-libs INTERFACE "${X11_XSync_LIB}")
  462. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XSYNC")
  463. endif()
  464. if(X11_Xrandr_FOUND)
  465. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xrandr_LIB}")
  466. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XRANDR")
  467. endif()
  468. #if(X11_Xcursor_FOUND)
  469. # target_link_libraries(dgl-system-libs INTERFACE "${X11_Xcursor_LIB}")
  470. # target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XCURSOR")
  471. #endif()
  472. endif()
  473. if(MSVC)
  474. file(MAKE_DIRECTORY "${DPF_ROOT_DIR}/khronos/GL")
  475. foreach(_gl_header "glext.h")
  476. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}")
  477. file(DOWNLOAD "https://www.khronos.org/registry/OpenGL/api/GL/${_gl_header}" "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}" SHOW_PROGRESS)
  478. endif()
  479. endforeach()
  480. foreach(_khr_header "khrplatform.h")
  481. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}")
  482. file(DOWNLOAD "https://www.khronos.org/registry/EGL/api/KHR/${_khr_header}" "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}" SHOW_PROGRESS)
  483. endif()
  484. endforeach()
  485. target_include_directories(dgl-system-libs-definitions INTERFACE "${DPF_ROOT_DIR}/khronos")
  486. endif()
  487. target_link_libraries(dgl-system-libs INTERFACE dgl-system-libs-definitions)
  488. endfunction()
  489. # dpf__add_executable
  490. # ------------------------------------------------------------------------------
  491. #
  492. # Adds an executable target, and set some default properties on the target.
  493. #
  494. function(dpf__add_executable NAME)
  495. add_executable("${NAME}" ${ARGN})
  496. dpf__set_target_defaults("${NAME}")
  497. if(MINGW)
  498. target_link_libraries("${NAME}" PRIVATE "-static")
  499. endif()
  500. endfunction()
  501. # dpf__add_module
  502. # ------------------------------------------------------------------------------
  503. #
  504. # Adds a module target, and set some default properties on the target.
  505. #
  506. function(dpf__add_module NAME)
  507. add_library("${NAME}" MODULE ${ARGN})
  508. dpf__set_target_defaults("${NAME}")
  509. if(MINGW)
  510. target_link_libraries("${NAME}" PRIVATE "-static")
  511. endif()
  512. endfunction()
  513. # dpf__add_static_library
  514. # ------------------------------------------------------------------------------
  515. #
  516. # Adds a static library target, and set some default properties on the target.
  517. #
  518. function(dpf__add_static_library NAME)
  519. add_library("${NAME}" STATIC ${ARGN})
  520. dpf__set_target_defaults("${NAME}")
  521. endfunction()
  522. # dpf__set_module_export_list
  523. # ------------------------------------------------------------------------------
  524. #
  525. # Applies a list of exported symbols to the module target.
  526. #
  527. function(dpf__set_module_export_list NAME EXPORTS)
  528. if(WIN32)
  529. target_sources("${NAME}" PRIVATE "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.def")
  530. elseif(APPLE)
  531. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  532. "-Xlinker" "-exported_symbols_list"
  533. "-Xlinker" "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.exp")
  534. else()
  535. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  536. "-Xlinker" "--version-script=${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.version")
  537. endif()
  538. endfunction()
  539. # dpf__set_target_defaults
  540. # ------------------------------------------------------------------------------
  541. #
  542. # Set default properties which must apply to all DPF-defined targets.
  543. #
  544. function(dpf__set_target_defaults NAME)
  545. set_target_properties("${NAME}" PROPERTIES
  546. POSITION_INDEPENDENT_CODE TRUE
  547. C_VISIBILITY_PRESET "hidden"
  548. CXX_VISIBILITY_PRESET "hidden"
  549. VISIBILITY_INLINES_HIDDEN TRUE)
  550. if(WIN32)
  551. target_compile_definitions("${NAME}" PUBLIC "NOMINMAX")
  552. endif()
  553. if (MINGW)
  554. target_compile_options("${NAME}" PUBLIC "-mstackrealign")
  555. endif()
  556. if (MSVC)
  557. target_compile_options("${NAME}" PUBLIC "/UTF-8")
  558. target_compile_definitions("${NAME}" PUBLIC "_CRT_SECURE_NO_WARNINGS")
  559. endif()
  560. endfunction()
  561. # dpf__add_plugin_main
  562. # ------------------------------------------------------------------------------
  563. #
  564. # Adds plugin code to the given target.
  565. #
  566. function(dpf__add_plugin_main NAME TARGET)
  567. target_sources("${NAME}" PRIVATE
  568. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  569. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  570. endfunction()
  571. # dpf__add_ui_main
  572. # ------------------------------------------------------------------------------
  573. #
  574. # Adds UI code to the given target (only if the target has UI).
  575. #
  576. function(dpf__add_ui_main NAME TARGET HAS_UI)
  577. if(HAS_UI)
  578. target_sources("${NAME}" PRIVATE
  579. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  580. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  581. endif()
  582. endfunction()
  583. # dpf__add_plugin_target_definition
  584. # ------------------------------------------------------------------------------
  585. #
  586. # Adds the plugins target macro definition.
  587. # This selects which entry file is compiled according to the target type.
  588. #
  589. function(dpf__add_plugin_target_definition NAME TARGET)
  590. string(TOUPPER "${TARGET}" _upperTarget)
  591. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  592. endfunction()
  593. # dpf__add_lv2_ttl_generator
  594. # ------------------------------------------------------------------------------
  595. #
  596. # Build the LV2 TTL generator.
  597. #
  598. function(dpf__add_lv2_ttl_generator)
  599. if(TARGET lv2_ttl_generator)
  600. return()
  601. endif()
  602. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  603. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  604. target_link_libraries(lv2_ttl_generator PRIVATE "dl")
  605. endif()
  606. endfunction()
  607. # dpf__ensure_sources_non_empty
  608. # ------------------------------------------------------------------------------
  609. #
  610. # Ensure the given source list contains at least one file.
  611. # The function appends an empty source file to the list if necessary.
  612. # This is useful when CMake does not permit to add targets without sources.
  613. #
  614. function(dpf__ensure_sources_non_empty VAR)
  615. if(NOT "" STREQUAL "${${VAR}}")
  616. return()
  617. endif()
  618. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  619. if(NOT EXISTS "${_file}")
  620. file(WRITE "${_file}" "")
  621. endif()
  622. set("${VAR}" "${_file}" PARENT_SCOPE)
  623. endfunction()
  624. # dpf__create_dummy_source_list
  625. # ------------------------------------------------------------------------------
  626. #
  627. # Create a dummy source list which is equivalent to compiling nothing.
  628. # This is only for compatibility with older CMake versions, which refuse to add
  629. # targets without any sources.
  630. #
  631. macro(dpf__create_dummy_source_list VAR)
  632. set("${VAR}")
  633. if(CMAKE_VERSION VERSION_LESS "3.11")
  634. dpf__ensure_sources_non_empty("${VAR}")
  635. endif()
  636. endmacro()
  637. # dpf__warn_once
  638. # ------------------------------------------------------------------------------
  639. #
  640. # Prints a warning message once only.
  641. #
  642. function(dpf__warn_once_only TOKEN MESSAGE)
  643. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  644. if(NOT _warned)
  645. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  646. message(WARNING "${MESSAGE}")
  647. endif()
  648. endfunction()