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.

575 lines
19KB

  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)
  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 "${_dgl_library}-definitions")
  119. endif()
  120. dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP})
  121. target_link_libraries("${NAME}-dsp" PUBLIC "${NAME}")
  122. if(_dgl_library)
  123. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  124. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library})
  125. else()
  126. add_library("${NAME}-ui" INTERFACE)
  127. endif()
  128. ###
  129. foreach(_target ${_dpf_plugin_TARGETS})
  130. if(_target STREQUAL "jack")
  131. dpf__build_jack("${NAME}" "${_dgl_library}")
  132. elseif(_target STREQUAL "ladspa")
  133. dpf__build_ladspa("${NAME}")
  134. elseif(_target STREQUAL "dssi")
  135. dpf__build_dssi("${NAME}" "${_dgl_library}")
  136. elseif(_target STREQUAL "lv2")
  137. dpf__build_lv2("${NAME}" "${_dgl_library}" "${_dpf_plugin_MONOLITHIC}")
  138. elseif(_target STREQUAL "vst2")
  139. dpf__build_vst2("${NAME}" "${_dgl_library}")
  140. else()
  141. message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}")
  142. endif()
  143. endforeach()
  144. endfunction()
  145. # ------------------------------------------------------------------------------
  146. # DPF private functions (prefixed with `dpf__`)
  147. # ------------------------------------------------------------------------------
  148. # Note: The $<0:> trick is to prevent MSVC from appending the build type
  149. # to the output directory.
  150. #
  151. # dpf__build_jack
  152. # ------------------------------------------------------------------------------
  153. #
  154. # Add build rules for a JACK program.
  155. #
  156. function(dpf__build_jack NAME DGL_LIBRARY)
  157. find_package(PkgConfig)
  158. pkg_check_modules(JACK "jack")
  159. if(NOT JACK_FOUND)
  160. dpf__warn_once_only(missing_jack
  161. "JACK is not found, skipping the `jack` plugin targets")
  162. return()
  163. endif()
  164. dpf__create_dummy_source_list(_no_srcs)
  165. dpf__add_executable("${NAME}-jack" ${_no_srcs})
  166. dpf__add_plugin_main("${NAME}-jack" "jack")
  167. dpf__add_ui_main("${NAME}-jack" "jack" "${DGL_LIBRARY}")
  168. target_link_libraries("${NAME}-jack" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  169. set_target_properties("${NAME}-jack" PROPERTIES
  170. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  171. OUTPUT_NAME "${NAME}")
  172. target_include_directories("${NAME}-jack" PRIVATE ${JACK_INCLUDE_DIRS})
  173. target_link_directories("${NAME}-jack" PRIVATE ${JACK_LIBRARY_DIRS})
  174. target_link_libraries("${NAME}-jack" PRIVATE ${JACK_LIBRARIES})
  175. link_directories(${JACK_LIBRARY_DIRS})
  176. endfunction()
  177. # dpf__build_ladspa
  178. # ------------------------------------------------------------------------------
  179. #
  180. # Add build rules for a DSSI plugin.
  181. #
  182. function(dpf__build_ladspa NAME)
  183. dpf__create_dummy_source_list(_no_srcs)
  184. dpf__add_module("${NAME}-ladspa" ${_no_srcs})
  185. dpf__add_plugin_main("${NAME}-ladspa" "ladspa")
  186. target_link_libraries("${NAME}-ladspa" PRIVATE "${NAME}-dsp")
  187. set_target_properties("${NAME}-ladspa" PROPERTIES
  188. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  189. OUTPUT_NAME "${NAME}-ladspa"
  190. PREFIX "")
  191. endfunction()
  192. # dpf__build_dssi
  193. # ------------------------------------------------------------------------------
  194. #
  195. # Add build rules for a DSSI plugin.
  196. #
  197. function(dpf__build_dssi NAME DGL_LIBRARY)
  198. find_package(PkgConfig)
  199. pkg_check_modules(LIBLO "liblo")
  200. if(NOT LIBLO_FOUND)
  201. dpf__warn_once_only(missing_liblo
  202. "liblo is not found, skipping the `dssi` plugin targets")
  203. return()
  204. endif()
  205. dpf__create_dummy_source_list(_no_srcs)
  206. dpf__add_module("${NAME}-dssi" ${_no_srcs})
  207. dpf__add_plugin_main("${NAME}-dssi" "dssi")
  208. target_link_libraries("${NAME}-dssi" PRIVATE "${NAME}-dsp")
  209. set_target_properties("${NAME}-dssi" PROPERTIES
  210. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  211. OUTPUT_NAME "${NAME}-dssi"
  212. PREFIX "")
  213. if(DGL_LIBRARY)
  214. dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs})
  215. dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${DGL_LIBRARY}")
  216. target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui")
  217. set_target_properties("${NAME}-dssi-ui" PROPERTIES
  218. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>"
  219. OUTPUT_NAME "${NAME}_ui")
  220. target_include_directories("${NAME}-dssi-ui" PRIVATE ${LIBLO_INCLUDE_DIRS})
  221. target_link_directories("${NAME}-dssi-ui" PRIVATE ${LIBLO_LIBRARY_DIRS})
  222. target_link_libraries("${NAME}-dssi-ui" PRIVATE ${LIBLO_LIBRARIES})
  223. link_directories(${LIBLO_LIBRARY_DIRS})
  224. endif()
  225. endfunction()
  226. # dpf__build_lv2
  227. # ------------------------------------------------------------------------------
  228. #
  229. # Add build rules for a LV2 plugin.
  230. #
  231. function(dpf__build_lv2 NAME DGL_LIBRARY MONOLITHIC)
  232. dpf__create_dummy_source_list(_no_srcs)
  233. dpf__add_module("${NAME}-lv2" ${_no_srcs})
  234. dpf__add_plugin_main("${NAME}-lv2" "lv2")
  235. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-dsp")
  236. set_target_properties("${NAME}-lv2" PROPERTIES
  237. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  238. OUTPUT_NAME "${NAME}_dsp"
  239. PREFIX "")
  240. if(DGL_LIBRARY)
  241. if(MONOLITHIC)
  242. dpf__add_ui_main("${NAME}-lv2" "lv2" "${DGL_LIBRARY}")
  243. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui")
  244. set_target_properties("${NAME}-lv2" PROPERTIES
  245. OUTPUT_NAME "${NAME}")
  246. else()
  247. dpf__add_module("${NAME}-lv2-ui" ${_no_srcs})
  248. dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${DGL_LIBRARY}")
  249. target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui")
  250. set_target_properties("${NAME}-lv2-ui" PROPERTIES
  251. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  252. OUTPUT_NAME "${NAME}_ui"
  253. PREFIX "")
  254. endif()
  255. endif()
  256. dpf__add_lv2_ttl_generator()
  257. add_dependencies("${NAME}-lv2" lv2_ttl_generator)
  258. add_custom_command(TARGET "${NAME}-lv2" POST_BUILD
  259. COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
  260. "$<TARGET_FILE:lv2_ttl_generator>"
  261. "$<TARGET_FILE:${NAME}-lv2>"
  262. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2")
  263. endfunction()
  264. # dpf__build_vst2
  265. # ------------------------------------------------------------------------------
  266. #
  267. # Add build rules for a VST2 plugin.
  268. #
  269. function(dpf__build_vst2 NAME DGL_LIBRARY)
  270. dpf__create_dummy_source_list(_no_srcs)
  271. dpf__add_module("${NAME}-vst2" ${_no_srcs})
  272. dpf__add_plugin_main("${NAME}-vst2" "vst2")
  273. dpf__add_ui_main("${NAME}-vst2" "vst2" "${DGL_LIBRARY}")
  274. target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  275. set_target_properties("${NAME}-vst2" PROPERTIES
  276. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  277. OUTPUT_NAME "${NAME}-vst2"
  278. PREFIX "")
  279. endfunction()
  280. # dpf__add_dgl_cairo
  281. # ------------------------------------------------------------------------------
  282. #
  283. # Add the Cairo variant of DGL, if not already available.
  284. #
  285. function(dpf__add_dgl_cairo)
  286. if(TARGET dgl-cairo)
  287. return()
  288. endif()
  289. find_package(PkgConfig)
  290. pkg_check_modules(CAIRO "cairo" REQUIRED)
  291. dpf__add_static_library(dgl-cairo STATIC
  292. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  293. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  294. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  295. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  296. "${DPF_ROOT_DIR}/dgl/src/Resources.cpp"
  297. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  298. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp"
  299. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp")
  300. if(NOT APPLE)
  301. target_sources(dgl-cairo PRIVATE
  302. "${DPF_ROOT_DIR}/dgl/src/Window.cpp")
  303. else()
  304. target_sources(dgl-cairo PRIVATE
  305. "${DPF_ROOT_DIR}/dgl/src/Window.mm")
  306. endif()
  307. target_include_directories(dgl-cairo PUBLIC
  308. "${DPF_ROOT_DIR}/dgl")
  309. dpf__add_dgl_system_libs()
  310. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  311. add_library(dgl-cairo-definitions INTERFACE)
  312. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO")
  313. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  314. target_link_directories(dgl-cairo PRIVATE ${CAIRO_LIBRARY_DIRS})
  315. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions ${CAIRO_LIBRARIES})
  316. link_directories(${CAIRO_LIBRARY_DIRS})
  317. endfunction()
  318. # dpf__add_dgl_opengl
  319. # ------------------------------------------------------------------------------
  320. #
  321. # Add the OpenGL variant of DGL, if not already available.
  322. #
  323. function(dpf__add_dgl_opengl)
  324. if(TARGET dgl-opengl)
  325. return()
  326. endif()
  327. if(NOT OpenGL_GL_PREFERENCE)
  328. set(OpenGL_GL_PREFERENCE "LEGACY")
  329. endif()
  330. find_package(OpenGL REQUIRED)
  331. dpf__add_static_library(dgl-opengl STATIC
  332. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  333. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  334. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  335. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  336. "${DPF_ROOT_DIR}/dgl/src/Resources.cpp"
  337. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  338. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  339. "${DPF_ROOT_DIR}/dgl/src/Image.cpp"
  340. "${DPF_ROOT_DIR}/dgl/src/ImageWidgets.cpp"
  341. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp"
  342. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp")
  343. if(NOT APPLE)
  344. target_sources(dgl-opengl PRIVATE
  345. "${DPF_ROOT_DIR}/dgl/src/Window.cpp")
  346. else()
  347. target_sources(dgl-opengl PRIVATE
  348. "${DPF_ROOT_DIR}/dgl/src/Window.mm")
  349. endif()
  350. target_include_directories(dgl-opengl PUBLIC
  351. "${DPF_ROOT_DIR}/dgl")
  352. dpf__add_dgl_system_libs()
  353. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  354. add_library(dgl-opengl-definitions INTERFACE)
  355. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL")
  356. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  357. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  358. endfunction()
  359. # dpf__add_dgl_system_libs
  360. # ------------------------------------------------------------------------------
  361. #
  362. # Find system libraries required by DGL and add them as an interface target.
  363. #
  364. function(dpf__add_dgl_system_libs)
  365. if(TARGET dgl-system-libs)
  366. return()
  367. endif()
  368. add_library(dgl-system-libs INTERFACE)
  369. if(HAIKU)
  370. target_link_libraries(dgl-system-libs INTERFACE "be")
  371. elseif(WIN32)
  372. target_link_libraries(dgl-system-libs INTERFACE "gdi32" "comdlg32")
  373. elseif(APPLE)
  374. find_library(APPLE_COCOA_FRAMEWORK "Cocoa")
  375. target_link_libraries(dgl-system-libs INTERFACE "${APPLE_COCOA_FRAMEWORK}")
  376. else()
  377. find_package(X11 REQUIRED)
  378. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  379. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  380. endif()
  381. endfunction()
  382. # dpf__add_executable
  383. # ------------------------------------------------------------------------------
  384. #
  385. # Adds an executable target, and set some default properties on the target.
  386. #
  387. function(dpf__add_executable NAME)
  388. add_executable("${NAME}" ${ARGN})
  389. set_target_properties("${NAME}" PROPERTIES
  390. POSITION_INDEPENDENT_CODE TRUE
  391. C_VISIBILITY_PRESET "hidden"
  392. CXX_VISIBILITY_PRESET "hidden"
  393. VISIBILITY_INLINES_HIDDEN TRUE)
  394. endfunction()
  395. # dpf__add_module
  396. # ------------------------------------------------------------------------------
  397. #
  398. # Adds a module target, and set some default properties on the target.
  399. #
  400. function(dpf__add_module NAME)
  401. add_library("${NAME}" MODULE ${ARGN})
  402. set_target_properties("${NAME}" PROPERTIES
  403. POSITION_INDEPENDENT_CODE TRUE
  404. C_VISIBILITY_PRESET "hidden"
  405. CXX_VISIBILITY_PRESET "hidden"
  406. VISIBILITY_INLINES_HIDDEN TRUE)
  407. if ((NOT WIN32 AND NOT APPLE) OR MINGW)
  408. target_link_libraries("${NAME}" PRIVATE "-Wl,--no-undefined")
  409. endif()
  410. endfunction()
  411. # dpf__add_static_library
  412. # ------------------------------------------------------------------------------
  413. #
  414. # Adds a static library target, and set some default properties on the target.
  415. #
  416. function(dpf__add_static_library NAME)
  417. add_library("${NAME}" STATIC ${ARGN})
  418. set_target_properties("${NAME}" PROPERTIES
  419. POSITION_INDEPENDENT_CODE TRUE
  420. C_VISIBILITY_PRESET "hidden"
  421. CXX_VISIBILITY_PRESET "hidden"
  422. VISIBILITY_INLINES_HIDDEN TRUE)
  423. endfunction()
  424. # dpf__add_plugin_main
  425. # ------------------------------------------------------------------------------
  426. #
  427. # Adds plugin code to the given target.
  428. #
  429. function(dpf__add_plugin_main NAME TARGET)
  430. target_sources("${NAME}" PRIVATE
  431. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  432. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  433. endfunction()
  434. # dpf__add_ui_main
  435. # ------------------------------------------------------------------------------
  436. #
  437. # Adds UI code to the given target (only if the target has UI).
  438. #
  439. function(dpf__add_ui_main NAME TARGET HAS_UI)
  440. if(HAS_UI)
  441. target_sources("${NAME}" PRIVATE
  442. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  443. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  444. endif()
  445. endfunction()
  446. # dpf__add_plugin_target_definition
  447. # ------------------------------------------------------------------------------
  448. #
  449. # Adds the plugins target macro definition.
  450. # This selects which entry file is compiled according to the target type.
  451. #
  452. function(dpf__add_plugin_target_definition NAME TARGET)
  453. string(TOUPPER "${TARGET}" _upperTarget)
  454. # resolve the alias into the proper name
  455. # the name "vst2" is new, "vst" is legacy
  456. if(_upperTarget STREQUAL "VST2")
  457. set(_upperTarget "VST")
  458. endif()
  459. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  460. endfunction()
  461. # dpf__add_lv2_ttl_generator
  462. # ------------------------------------------------------------------------------
  463. #
  464. # Build the LV2 TTL generator.
  465. #
  466. function(dpf__add_lv2_ttl_generator)
  467. if(TARGET lv2_ttl_generator)
  468. return()
  469. endif()
  470. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  471. if(NOT WINDOWS AND NOT APPLE AND NOT HAIKU)
  472. target_link_libraries(lv2_ttl_generator "dl")
  473. endif()
  474. endfunction()
  475. # dpf__ensure_sources_non_empty
  476. # ------------------------------------------------------------------------------
  477. #
  478. # Ensure the given source list contains at least one file.
  479. # The function appends an empty source file to the list if necessary.
  480. # This is useful when CMake does not permit to add targets without sources.
  481. #
  482. function(dpf__ensure_sources_non_empty VAR)
  483. if(NOT "" STREQUAL "${${VAR}}")
  484. return()
  485. endif()
  486. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  487. if(NOT EXISTS "${_file}")
  488. file(WRITE "${_file}" "")
  489. endif()
  490. set("${VAR}" "${_file}" PARENT_SCOPE)
  491. endfunction()
  492. # dpf__create_dummy_source_list
  493. # ------------------------------------------------------------------------------
  494. #
  495. # Create a dummy source list which is equivalent to compiling nothing.
  496. # This is only for compatibility with older CMake versions, which refuse to add
  497. # targets without any sources.
  498. #
  499. macro(dpf__create_dummy_source_list VAR)
  500. set("${VAR}")
  501. if(CMAKE_VERSION VERSION_LESS "3.11")
  502. dpf__ensure_sources_non_empty("${VAR}")
  503. endif()
  504. endmacro()
  505. # dpf__warn_once
  506. # ------------------------------------------------------------------------------
  507. #
  508. # Prints a warning message once only.
  509. #
  510. function(dpf__warn_once_only TOKEN MESSAGE)
  511. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  512. if(NOT _warned)
  513. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  514. message(WARNING "${MESSAGE}")
  515. endif()
  516. endfunction()