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.

670 lines
23KB

  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. target_link_libraries("${NAME}-ladspa" PRIVATE "${NAME}-dsp")
  190. set_target_properties("${NAME}-ladspa" PROPERTIES
  191. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  192. OUTPUT_NAME "${NAME}-ladspa"
  193. PREFIX "")
  194. endfunction()
  195. # dpf__build_dssi
  196. # ------------------------------------------------------------------------------
  197. #
  198. # Add build rules for a DSSI plugin.
  199. #
  200. function(dpf__build_dssi NAME DGL_LIBRARY)
  201. find_package(PkgConfig)
  202. pkg_check_modules(LIBLO "liblo")
  203. if(NOT LIBLO_FOUND)
  204. dpf__warn_once_only(missing_liblo
  205. "liblo is not found, skipping the `dssi` plugin targets")
  206. return()
  207. endif()
  208. link_directories(${LIBLO_LIBRARY_DIRS})
  209. dpf__create_dummy_source_list(_no_srcs)
  210. dpf__add_module("${NAME}-dssi" ${_no_srcs})
  211. dpf__add_plugin_main("${NAME}-dssi" "dssi")
  212. target_link_libraries("${NAME}-dssi" PRIVATE "${NAME}-dsp")
  213. set_target_properties("${NAME}-dssi" PROPERTIES
  214. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  215. OUTPUT_NAME "${NAME}-dssi"
  216. PREFIX "")
  217. if(DGL_LIBRARY)
  218. dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs})
  219. dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${DGL_LIBRARY}")
  220. target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui")
  221. set_target_properties("${NAME}-dssi-ui" PROPERTIES
  222. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>"
  223. OUTPUT_NAME "${NAME}_ui")
  224. target_include_directories("${NAME}-dssi-ui" PRIVATE ${LIBLO_INCLUDE_DIRS})
  225. target_link_libraries("${NAME}-dssi-ui" PRIVATE ${LIBLO_LIBRARIES})
  226. endif()
  227. endfunction()
  228. # dpf__build_lv2
  229. # ------------------------------------------------------------------------------
  230. #
  231. # Add build rules for a LV2 plugin.
  232. #
  233. function(dpf__build_lv2 NAME DGL_LIBRARY MONOLITHIC)
  234. dpf__create_dummy_source_list(_no_srcs)
  235. dpf__add_module("${NAME}-lv2" ${_no_srcs})
  236. dpf__add_plugin_main("${NAME}-lv2" "lv2")
  237. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-dsp")
  238. set_target_properties("${NAME}-lv2" PROPERTIES
  239. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  240. OUTPUT_NAME "${NAME}_dsp"
  241. PREFIX "")
  242. if(DGL_LIBRARY)
  243. if(MONOLITHIC)
  244. dpf__add_ui_main("${NAME}-lv2" "lv2" "${DGL_LIBRARY}")
  245. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui")
  246. set_target_properties("${NAME}-lv2" PROPERTIES
  247. OUTPUT_NAME "${NAME}")
  248. else()
  249. dpf__add_module("${NAME}-lv2-ui" ${_no_srcs})
  250. dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${DGL_LIBRARY}")
  251. target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui")
  252. set_target_properties("${NAME}-lv2-ui" PROPERTIES
  253. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  254. OUTPUT_NAME "${NAME}_ui"
  255. PREFIX "")
  256. endif()
  257. endif()
  258. dpf__add_lv2_ttl_generator()
  259. add_dependencies("${NAME}-lv2" lv2_ttl_generator)
  260. add_custom_command(TARGET "${NAME}-lv2" POST_BUILD
  261. COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
  262. "$<TARGET_FILE:lv2_ttl_generator>"
  263. "$<TARGET_FILE:${NAME}-lv2>"
  264. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2"
  265. DEPENDS lv2_ttl_generator)
  266. endfunction()
  267. # dpf__build_vst2
  268. # ------------------------------------------------------------------------------
  269. #
  270. # Add build rules for a VST2 plugin.
  271. #
  272. function(dpf__build_vst2 NAME DGL_LIBRARY)
  273. dpf__create_dummy_source_list(_no_srcs)
  274. dpf__add_module("${NAME}-vst2" ${_no_srcs})
  275. dpf__add_plugin_main("${NAME}-vst2" "vst2")
  276. dpf__add_ui_main("${NAME}-vst2" "vst2" "${DGL_LIBRARY}")
  277. target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  278. set_target_properties("${NAME}-vst2" PROPERTIES
  279. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  280. OUTPUT_NAME "${NAME}-vst2"
  281. PREFIX "")
  282. endfunction()
  283. # dpf__add_dgl_cairo
  284. # ------------------------------------------------------------------------------
  285. #
  286. # Add the Cairo variant of DGL, if not already available.
  287. #
  288. function(dpf__add_dgl_cairo)
  289. if(TARGET dgl-cairo)
  290. return()
  291. endif()
  292. find_package(PkgConfig)
  293. pkg_check_modules(CAIRO "cairo" REQUIRED)
  294. link_directories(${CAIRO_LIBRARY_DIRS})
  295. dpf__add_static_library(dgl-cairo STATIC
  296. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  297. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  298. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  299. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  300. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  301. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  302. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  303. "${DPF_ROOT_DIR}/dgl/src/Resources.cpp"
  304. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  305. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  306. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  307. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  308. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  309. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  310. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  311. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  312. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp")
  313. if(NOT APPLE)
  314. target_sources(dgl-cairo PRIVATE
  315. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  316. else() # Note: macOS pugl will be built as part of DistrhoUI_macOS.mm
  317. #target_sources(dgl-opengl PRIVATE
  318. # "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  319. endif()
  320. target_include_directories(dgl-cairo PUBLIC
  321. "${DPF_ROOT_DIR}/dgl")
  322. target_include_directories(dgl-cairo PUBLIC
  323. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  324. dpf__add_dgl_system_libs()
  325. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  326. add_library(dgl-cairo-definitions INTERFACE)
  327. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO" "HAVE_DGL")
  328. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  329. if(MINGW)
  330. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_STATIC_LIBRARIES})
  331. else()
  332. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_LIBRARIES})
  333. endif()
  334. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions)
  335. endfunction()
  336. # dpf__add_dgl_opengl
  337. # ------------------------------------------------------------------------------
  338. #
  339. # Add the OpenGL variant of DGL, if not already available.
  340. #
  341. function(dpf__add_dgl_opengl)
  342. if(TARGET dgl-opengl)
  343. return()
  344. endif()
  345. if(NOT OpenGL_GL_PREFERENCE)
  346. set(OpenGL_GL_PREFERENCE "LEGACY")
  347. endif()
  348. find_package(OpenGL REQUIRED)
  349. dpf__add_static_library(dgl-opengl STATIC
  350. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  351. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  352. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  353. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  354. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  355. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  356. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  357. "${DPF_ROOT_DIR}/dgl/src/Resources.cpp"
  358. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  359. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  360. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  361. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  362. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  363. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  364. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  365. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  366. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  367. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp")
  368. if(NOT APPLE)
  369. target_sources(dgl-opengl PRIVATE
  370. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  371. else() # Note: macOS pugl will be built as part of DistrhoUI_macOS.mm
  372. #target_sources(dgl-opengl PRIVATE
  373. # "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  374. endif()
  375. target_include_directories(dgl-opengl PUBLIC
  376. "${DPF_ROOT_DIR}/dgl")
  377. target_include_directories(dgl-opengl PUBLIC
  378. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  379. if(APPLE)
  380. target_compile_definitions(dgl-opengl PUBLIC "GL_SILENCE_DEPRECATION")
  381. endif()
  382. dpf__add_dgl_system_libs()
  383. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  384. add_library(dgl-opengl-definitions INTERFACE)
  385. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL" "HAVE_DGL")
  386. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  387. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  388. endfunction()
  389. # dpf__add_plugin_specific_ui_sources
  390. # ------------------------------------------------------------------------------
  391. #
  392. # Compile plugin-specific UI sources into the target designated by the given
  393. # name. There are some special considerations here:
  394. # - On most platforms, sources can be compiled only once, as part of DGL;
  395. # - On macOS, for any sources which define Objective-C interfaces, these must
  396. # be recompiled for each plugin under a unique namespace. In this case, the
  397. # name must be a plugin-specific identifier, and it will be used for computing
  398. # the unique ID along with the project version.
  399. function(dpf__add_plugin_specific_ui_sources NAME)
  400. if(APPLE)
  401. target_sources("${NAME}" PRIVATE
  402. "${DPF_ROOT_DIR}/distrho/DistrhoUI_macOS.mm")
  403. string(SHA256 _hash "${NAME}:${PROJECT_VERSION}")
  404. target_compile_definitions("${NAME}" PUBLIC "PUGL_NAMESPACE=${_hash}")
  405. endif()
  406. endfunction()
  407. # dpf__add_dgl_system_libs
  408. # ------------------------------------------------------------------------------
  409. #
  410. # Find system libraries required by DGL and add them as an interface target.
  411. #
  412. function(dpf__add_dgl_system_libs)
  413. if(TARGET dgl-system-libs)
  414. return()
  415. endif()
  416. add_library(dgl-system-libs INTERFACE)
  417. add_library(dgl-system-libs-definitions INTERFACE)
  418. if(HAIKU)
  419. target_link_libraries(dgl-system-libs INTERFACE "be")
  420. elseif(WIN32)
  421. target_link_libraries(dgl-system-libs INTERFACE "gdi32" "comdlg32")
  422. elseif(APPLE)
  423. find_library(APPLE_COCOA_FRAMEWORK "Cocoa")
  424. find_library(APPLE_COREVIDEO_FRAMEWORK "CoreVideo")
  425. target_link_libraries(dgl-system-libs INTERFACE "${APPLE_COCOA_FRAMEWORK}" "${APPLE_COREVIDEO_FRAMEWORK}")
  426. else()
  427. find_package(X11 REQUIRED)
  428. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  429. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  430. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_X11")
  431. if(X11_Xext_FOUND)
  432. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xext_LIB}")
  433. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XEXT")
  434. endif()
  435. if(X11_XSync_FOUND)
  436. target_link_libraries(dgl-system-libs INTERFACE "${X11_XSync_LIB}")
  437. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XSYNC")
  438. endif()
  439. if(X11_Xrandr_FOUND)
  440. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xrandr_LIB}")
  441. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XRANDR")
  442. endif()
  443. #if(X11_Xcursor_FOUND)
  444. # target_link_libraries(dgl-system-libs INTERFACE "${X11_Xcursor_LIB}")
  445. # target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XCURSOR")
  446. #endif()
  447. endif()
  448. if(MSVC)
  449. file(MAKE_DIRECTORY "${DPF_ROOT_DIR}/khronos/GL")
  450. foreach(_gl_header "glext.h")
  451. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}")
  452. file(DOWNLOAD "https://www.khronos.org/registry/OpenGL/api/GL/${_gl_header}" "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}" SHOW_PROGRESS)
  453. endif()
  454. endforeach()
  455. foreach(_khr_header "khrplatform.h")
  456. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}")
  457. file(DOWNLOAD "https://www.khronos.org/registry/EGL/api/KHR/${_khr_header}" "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}" SHOW_PROGRESS)
  458. endif()
  459. endforeach()
  460. target_include_directories(dgl-system-libs-definitions INTERFACE "${DPF_ROOT_DIR}/khronos")
  461. endif()
  462. target_link_libraries(dgl-system-libs INTERFACE dgl-system-libs-definitions)
  463. endfunction()
  464. # dpf__add_executable
  465. # ------------------------------------------------------------------------------
  466. #
  467. # Adds an executable target, and set some default properties on the target.
  468. #
  469. function(dpf__add_executable NAME)
  470. add_executable("${NAME}" ${ARGN})
  471. dpf__set_target_defaults("${NAME}")
  472. if(MINGW)
  473. target_link_libraries("${NAME}" PRIVATE "-static")
  474. endif()
  475. endfunction()
  476. # dpf__add_module
  477. # ------------------------------------------------------------------------------
  478. #
  479. # Adds a module target, and set some default properties on the target.
  480. #
  481. function(dpf__add_module NAME)
  482. add_library("${NAME}" MODULE ${ARGN})
  483. dpf__set_target_defaults("${NAME}")
  484. if(MINGW)
  485. target_link_libraries("${NAME}" PRIVATE "-static")
  486. endif()
  487. endfunction()
  488. # dpf__add_static_library
  489. # ------------------------------------------------------------------------------
  490. #
  491. # Adds a static library target, and set some default properties on the target.
  492. #
  493. function(dpf__add_static_library NAME)
  494. add_library("${NAME}" STATIC ${ARGN})
  495. dpf__set_target_defaults("${NAME}")
  496. endfunction()
  497. # dpf__set_target_defaults
  498. # ------------------------------------------------------------------------------
  499. #
  500. # Set default properties which must apply to all DPF-defined targets.
  501. #
  502. function(dpf__set_target_defaults NAME)
  503. set_target_properties("${NAME}" PROPERTIES
  504. POSITION_INDEPENDENT_CODE TRUE
  505. C_VISIBILITY_PRESET "hidden"
  506. CXX_VISIBILITY_PRESET "hidden"
  507. VISIBILITY_INLINES_HIDDEN TRUE)
  508. if(WIN32)
  509. target_compile_definitions("${NAME}" PUBLIC "NOMINMAX")
  510. endif()
  511. if (MINGW)
  512. target_compile_options("${NAME}" PUBLIC "-mstackrealign")
  513. endif()
  514. if (MSVC)
  515. target_compile_options("${NAME}" PUBLIC "/UTF-8")
  516. target_compile_definitions("${NAME}" PUBLIC "_CRT_SECURE_NO_WARNINGS")
  517. endif()
  518. endfunction()
  519. # dpf__add_plugin_main
  520. # ------------------------------------------------------------------------------
  521. #
  522. # Adds plugin code to the given target.
  523. #
  524. function(dpf__add_plugin_main NAME TARGET)
  525. target_sources("${NAME}" PRIVATE
  526. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  527. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  528. endfunction()
  529. # dpf__add_ui_main
  530. # ------------------------------------------------------------------------------
  531. #
  532. # Adds UI code to the given target (only if the target has UI).
  533. #
  534. function(dpf__add_ui_main NAME TARGET HAS_UI)
  535. if(HAS_UI)
  536. target_sources("${NAME}" PRIVATE
  537. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  538. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  539. endif()
  540. endfunction()
  541. # dpf__add_plugin_target_definition
  542. # ------------------------------------------------------------------------------
  543. #
  544. # Adds the plugins target macro definition.
  545. # This selects which entry file is compiled according to the target type.
  546. #
  547. function(dpf__add_plugin_target_definition NAME TARGET)
  548. string(TOUPPER "${TARGET}" _upperTarget)
  549. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  550. endfunction()
  551. # dpf__add_lv2_ttl_generator
  552. # ------------------------------------------------------------------------------
  553. #
  554. # Build the LV2 TTL generator.
  555. #
  556. function(dpf__add_lv2_ttl_generator)
  557. if(TARGET lv2_ttl_generator)
  558. return()
  559. endif()
  560. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  561. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  562. target_link_libraries(lv2_ttl_generator PRIVATE "dl")
  563. endif()
  564. endfunction()
  565. # dpf__ensure_sources_non_empty
  566. # ------------------------------------------------------------------------------
  567. #
  568. # Ensure the given source list contains at least one file.
  569. # The function appends an empty source file to the list if necessary.
  570. # This is useful when CMake does not permit to add targets without sources.
  571. #
  572. function(dpf__ensure_sources_non_empty VAR)
  573. if(NOT "" STREQUAL "${${VAR}}")
  574. return()
  575. endif()
  576. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  577. if(NOT EXISTS "${_file}")
  578. file(WRITE "${_file}" "")
  579. endif()
  580. set("${VAR}" "${_file}" PARENT_SCOPE)
  581. endfunction()
  582. # dpf__create_dummy_source_list
  583. # ------------------------------------------------------------------------------
  584. #
  585. # Create a dummy source list which is equivalent to compiling nothing.
  586. # This is only for compatibility with older CMake versions, which refuse to add
  587. # targets without any sources.
  588. #
  589. macro(dpf__create_dummy_source_list VAR)
  590. set("${VAR}")
  591. if(CMAKE_VERSION VERSION_LESS "3.11")
  592. dpf__ensure_sources_non_empty("${VAR}")
  593. endif()
  594. endmacro()
  595. # dpf__warn_once
  596. # ------------------------------------------------------------------------------
  597. #
  598. # Prints a warning message once only.
  599. #
  600. function(dpf__warn_once_only TOKEN MESSAGE)
  601. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  602. if(NOT _warned)
  603. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  604. message(WARNING "${MESSAGE}")
  605. endif()
  606. endfunction()