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.

799 lines
28KB

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