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.

972 lines
34KB

  1. # DISTRHO Plugin Framework (DPF)
  2. # Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  3. # Copyright (C) 2022 Filipe Coelho <falktx@falktx.com>
  4. #
  5. # SPDX-License-Identifier: ISC
  6. # ------------------------------------------------------------------------------
  7. # CMake support module for the DISTRHO Plugin Framework
  8. #
  9. # The purpose of this module is to help building music plugins easily, when the
  10. # project uses CMake as its build system.
  11. #
  12. # In order to use the helpers provided by this module, a plugin author should
  13. # add DPF as a subproject, making the function `dpf_add_plugin` available.
  14. # The usage of this function is documented below in greater detail.
  15. #
  16. # Example project `CMakeLists.txt`:
  17. #
  18. # ```
  19. # cmake_minimum_required(VERSION 3.7)
  20. # project(MyPlugin)
  21. #
  22. # add_subdirectory(DPF)
  23. #
  24. # dpf_add_plugin(MyPlugin
  25. # TARGETS clap lv2 vst2 vst3
  26. # UI_TYPE opengl
  27. # FILES_DSP
  28. # src/MyPlugin.cpp
  29. # FILES_UI
  30. # src/MyUI.cpp)
  31. #
  32. # target_include_directories(MyPlugin
  33. # PUBLIC src)
  34. # ```
  35. #
  36. # Important: note that properties, such as include directories, definitions,
  37. # and linked libraries *must* be marked with `PUBLIC` so they take effect and
  38. # propagate into all the plugin targets.
  39. include(CMakeParseArguments)
  40. # ------------------------------------------------------------------------------
  41. # DPF public functions
  42. # ------------------------------------------------------------------------------
  43. # dpf_add_plugin(name <args...>)
  44. # ------------------------------------------------------------------------------
  45. #
  46. # Add a plugin built using the DISTRHO Plugin Framework.
  47. #
  48. # ------------------------------------------------------------------------------
  49. # Created targets:
  50. #
  51. # `<name>`
  52. # static library: the common part of the plugin
  53. # The public properties set on this target apply to both DSP and UI.
  54. #
  55. # `<name>-dsp`
  56. # static library: the DSP part of the plugin
  57. # The public properties set on this target apply to the DSP only.
  58. #
  59. # `<name>-ui`
  60. # static library: the UI part of the plugin
  61. # The public properties set on this target apply to the UI only.
  62. #
  63. # `<name>-<target>` for each target specified with the `TARGETS` argument.
  64. # This is target-dependent and not intended for public use.
  65. #
  66. # ------------------------------------------------------------------------------
  67. # Arguments:
  68. #
  69. # `TARGETS` <tgt1>...<tgtN>
  70. # a list of one of more of the following target types:
  71. # `jack`, `ladspa`, `dssi`, `lv2`, `vst2`, `vst3`, `clap`
  72. #
  73. # `UI_TYPE` <type>
  74. # the user interface type: `opengl` (default), `cairo`, `external`
  75. #
  76. # `FILES_COMMON` <file1>...<fileN>
  77. # list of sources which are part of both DSP and UI
  78. #
  79. # `FILES_DSP` <file1>...<fileN>
  80. # list of sources which are part of the DSP
  81. #
  82. # `FILES_UI` <file1>...<fileN>
  83. # list of sources which are part of the UI
  84. # empty indicates the plugin does not have UI
  85. #
  86. # `MODGUI_CLASS_NAME`
  87. # class name to use for modgui builds
  88. #
  89. # `MONOLITHIC`
  90. # build LV2 as a single binary for UI and DSP
  91. #
  92. # `NO_SHARED_RESOURCES`
  93. # do not build DPF shared resources (fonts, etc)
  94. #
  95. function(dpf_add_plugin NAME)
  96. set(options MONOLITHIC NO_SHARED_RESOURCES)
  97. set(oneValueArgs MODGUI_CLASS_NAME UI_TYPE)
  98. set(multiValueArgs FILES_COMMON FILES_DSP FILES_UI TARGETS)
  99. cmake_parse_arguments(_dpf_plugin "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  100. if("${_dpf_plugin_UI_TYPE}" STREQUAL "")
  101. set(_dpf_plugin_UI_TYPE "opengl")
  102. endif()
  103. set(_dgl_library)
  104. set(_dgl_external OFF)
  105. if(_dpf_plugin_FILES_UI)
  106. if(_dpf_plugin_UI_TYPE STREQUAL "cairo")
  107. dpf__add_dgl_cairo("${_dpf_plugin_NO_SHARED_RESOURCES}")
  108. set(_dgl_library dgl-cairo)
  109. elseif(_dpf_plugin_UI_TYPE STREQUAL "opengl")
  110. dpf__add_dgl_opengl("${_dpf_plugin_NO_SHARED_RESOURCES}")
  111. set(_dgl_library dgl-opengl)
  112. elseif(_dpf_plugin_UI_TYPE STREQUAL "external")
  113. set(_dgl_external ON)
  114. else()
  115. message(FATAL_ERROR "Unrecognized UI type for plugin: ${_dpf_plugin_UI_TYPE}")
  116. endif()
  117. endif()
  118. set(_dgl_has_ui OFF)
  119. if(_dgl_library OR _dgl_external)
  120. set(_dgl_has_ui ON)
  121. endif()
  122. ###
  123. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_COMMON)
  124. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_DSP)
  125. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_UI)
  126. ###
  127. dpf__add_static_library("${NAME}" ${_dpf_plugin_FILES_COMMON})
  128. target_include_directories("${NAME}" PUBLIC
  129. "${DPF_ROOT_DIR}/distrho")
  130. if(_dpf_plugin_MODGUI_CLASS_NAME)
  131. target_compile_definitions("${NAME}" PUBLIC "DISTRHO_PLUGIN_MODGUI_CLASS_NAME=\"${_dpf_plugin_MODGUI_CLASS_NAME}\"")
  132. endif()
  133. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  134. target_link_libraries("${NAME}" PRIVATE "dl")
  135. endif()
  136. if(_dgl_library AND NOT _dgl_external)
  137. # make sure that all code will see DGL_* definitions
  138. target_link_libraries("${NAME}" PUBLIC
  139. "${_dgl_library}-definitions"
  140. dgl-system-libs-definitions
  141. dgl-system-libs)
  142. endif()
  143. dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP})
  144. target_link_libraries("${NAME}-dsp" PUBLIC "${NAME}")
  145. if(_dgl_library AND NOT _dgl_external)
  146. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  147. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library})
  148. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  149. target_link_libraries("${NAME}-ui" PRIVATE "dl")
  150. endif()
  151. # add the files containing Objective-C classes
  152. dpf__add_plugin_specific_ui_sources("${NAME}-ui")
  153. elseif(_dgl_external)
  154. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  155. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}")
  156. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  157. target_link_libraries("${NAME}-ui" PRIVATE "dl")
  158. endif()
  159. # add the files containing Objective-C classes
  160. dpf__add_plugin_specific_ui_sources("${NAME}-ui")
  161. else()
  162. add_library("${NAME}-ui" INTERFACE)
  163. endif()
  164. ###
  165. foreach(_target ${_dpf_plugin_TARGETS})
  166. if(_target STREQUAL "jack")
  167. dpf__build_jack("${NAME}" "${_dgl_has_ui}")
  168. elseif(_target STREQUAL "ladspa")
  169. dpf__build_ladspa("${NAME}")
  170. elseif(_target STREQUAL "dssi")
  171. dpf__build_dssi("${NAME}" "${_dgl_has_ui}")
  172. elseif(_target STREQUAL "lv2")
  173. dpf__build_lv2("${NAME}" "${_dgl_has_ui}" "${_dpf_plugin_MONOLITHIC}")
  174. elseif(_target STREQUAL "vst2")
  175. dpf__build_vst2("${NAME}" "${_dgl_has_ui}")
  176. elseif(_target STREQUAL "vst3")
  177. dpf__build_vst3("${NAME}" "${_dgl_has_ui}")
  178. elseif(_target STREQUAL "clap")
  179. dpf__build_clap("${NAME}" "${_dgl_has_ui}")
  180. elseif(_target STREQUAL "static")
  181. dpf__build_static("${NAME}" "${_dgl_has_ui}")
  182. else()
  183. message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}")
  184. endif()
  185. endforeach()
  186. endfunction()
  187. # ------------------------------------------------------------------------------
  188. # DPF private functions (prefixed with `dpf__`)
  189. # ------------------------------------------------------------------------------
  190. # Note: The $<0:> trick is to prevent MSVC from appending the build type
  191. # to the output directory.
  192. #
  193. # dpf__build_jack
  194. # ------------------------------------------------------------------------------
  195. #
  196. # Add build rules for a JACK/Standalone program.
  197. #
  198. function(dpf__build_jack NAME HAS_UI)
  199. dpf__create_dummy_source_list(_no_srcs)
  200. dpf__add_executable("${NAME}-jack" ${_no_srcs})
  201. dpf__add_plugin_main("${NAME}-jack" "jack")
  202. dpf__add_ui_main("${NAME}-jack" "jack" "${HAS_UI}")
  203. target_link_libraries("${NAME}-jack" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  204. set_target_properties("${NAME}-jack" PROPERTIES
  205. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  206. OUTPUT_NAME "${NAME}")
  207. target_compile_definitions("${NAME}" PUBLIC "HAVE_JACK")
  208. target_compile_definitions("${NAME}-jack" PRIVATE "HAVE_GETTIMEOFDAY")
  209. find_package(PkgConfig)
  210. pkg_check_modules(SDL2 "sdl2")
  211. if(SDL2_FOUND)
  212. target_compile_definitions("${NAME}" PUBLIC "HAVE_SDL2")
  213. target_include_directories("${NAME}-jack" PRIVATE ${SDL2_STATIC_INCLUDE_DIRS})
  214. target_link_libraries("${NAME}-jack" PRIVATE ${SDL2_STATIC_LIBRARIES})
  215. dpf__target_link_directories("${NAME}-jack" "${SDL2_STATIC_LIBRARY_DIRS}")
  216. endif()
  217. if(APPLE OR WIN32)
  218. target_compile_definitions("${NAME}" PUBLIC "HAVE_RTAUDIO")
  219. else()
  220. find_package(Threads)
  221. pkg_check_modules(ALSA "alsa")
  222. pkg_check_modules(PULSEAUDIO "libpulse-simple")
  223. if(ALSA_FOUND)
  224. target_compile_definitions("${NAME}" PUBLIC "HAVE_ALSA")
  225. target_include_directories("${NAME}-jack" PRIVATE ${ALSA_INCLUDE_DIRS})
  226. target_link_libraries("${NAME}-jack" PRIVATE ${ALSA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  227. dpf__target_link_directories("${NAME}-jack" "${ALSA_LIBRARY_DIRS}")
  228. endif()
  229. if(PULSEAUDIO_FOUND)
  230. target_compile_definitions("${NAME}" PUBLIC "HAVE_PULSEAUDIO")
  231. target_include_directories("${NAME}-jack" PRIVATE ${PULSEAUDIO_INCLUDE_DIRS})
  232. target_link_libraries("${NAME}-jack" PRIVATE ${PULSEAUDIO_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
  233. dpf__target_link_directories("${NAME}-jack" "${PULSEAUDIO_LIBRARY_DIRS}")
  234. endif()
  235. if(ALSA_FOUND OR PULSEAUDIO_FOUND)
  236. target_compile_definitions("${NAME}" PUBLIC "HAVE_RTAUDIO")
  237. endif()
  238. endif()
  239. # for RtAudio native fallback
  240. if(APPLE)
  241. find_library(APPLE_COREAUDIO_FRAMEWORK "CoreAudio")
  242. find_library(APPLE_COREFOUNDATION_FRAMEWORK "CoreFoundation")
  243. find_library(APPLE_COREMIDI_FRAMEWORK "CoreMIDI")
  244. target_link_libraries("${NAME}-jack" PRIVATE
  245. "${APPLE_COREAUDIO_FRAMEWORK}"
  246. "${APPLE_COREFOUNDATION_FRAMEWORK}"
  247. "${APPLE_COREMIDI_FRAMEWORK}")
  248. elseif(WIN32)
  249. target_link_libraries("${NAME}-jack" PRIVATE "ksuser" "mfplat" "mfuuid" "ole32" "winmm" "wmcodecdspuuid")
  250. if(HAS_UI AND MINGW)
  251. set_target_properties("${NAME}-jack" PROPERTIES WIN32_EXECUTABLE TRUE)
  252. endif()
  253. endif()
  254. endfunction()
  255. # dpf__build_ladspa
  256. # ------------------------------------------------------------------------------
  257. #
  258. # Add build rules for a LADSPA plugin.
  259. #
  260. function(dpf__build_ladspa NAME)
  261. dpf__create_dummy_source_list(_no_srcs)
  262. dpf__add_module("${NAME}-ladspa" ${_no_srcs})
  263. dpf__add_plugin_main("${NAME}-ladspa" "ladspa")
  264. dpf__set_module_export_list("${NAME}-ladspa" "ladspa")
  265. target_link_libraries("${NAME}-ladspa" PRIVATE "${NAME}-dsp")
  266. set_target_properties("${NAME}-ladspa" PROPERTIES
  267. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  268. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/ladspa/$<0:>"
  269. OUTPUT_NAME "${NAME}-ladspa"
  270. PREFIX "")
  271. endfunction()
  272. # dpf__build_dssi
  273. # ------------------------------------------------------------------------------
  274. #
  275. # Add build rules for a DSSI plugin.
  276. #
  277. function(dpf__build_dssi NAME HAS_UI)
  278. find_package(PkgConfig)
  279. pkg_check_modules(LIBLO "liblo")
  280. if(NOT LIBLO_FOUND)
  281. dpf__warn_once_only(missing_liblo
  282. "liblo is not found, skipping the `dssi` plugin targets")
  283. return()
  284. endif()
  285. dpf__create_dummy_source_list(_no_srcs)
  286. dpf__add_module("${NAME}-dssi" ${_no_srcs})
  287. dpf__add_plugin_main("${NAME}-dssi" "dssi")
  288. dpf__set_module_export_list("${NAME}-dssi" "dssi")
  289. target_link_libraries("${NAME}-dssi" PRIVATE "${NAME}-dsp")
  290. set_target_properties("${NAME}-dssi" PROPERTIES
  291. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  292. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/dssi/$<0:>"
  293. OUTPUT_NAME "${NAME}-dssi"
  294. PREFIX "")
  295. if(HAS_UI)
  296. dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs})
  297. dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${HAS_UI}")
  298. target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui")
  299. set_target_properties("${NAME}-dssi-ui" PROPERTIES
  300. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>"
  301. OUTPUT_NAME "${NAME}_ui")
  302. target_compile_definitions("${NAME}" PUBLIC "HAVE_LIBLO")
  303. target_include_directories("${NAME}-dssi-ui" PRIVATE ${LIBLO_INCLUDE_DIRS})
  304. target_link_libraries("${NAME}-dssi-ui" PRIVATE ${LIBLO_LIBRARIES})
  305. dpf__target_link_directories("${NAME}-dssi-ui" "${LIBLO_LIBRARY_DIRS}")
  306. endif()
  307. endfunction()
  308. # dpf__build_lv2
  309. # ------------------------------------------------------------------------------
  310. #
  311. # Add build rules for an LV2 plugin.
  312. #
  313. function(dpf__build_lv2 NAME HAS_UI MONOLITHIC)
  314. dpf__create_dummy_source_list(_no_srcs)
  315. dpf__add_module("${NAME}-lv2" ${_no_srcs})
  316. dpf__add_plugin_main("${NAME}-lv2" "lv2")
  317. if(HAS_UI AND MONOLITHIC)
  318. dpf__set_module_export_list("${NAME}-lv2" "lv2")
  319. else()
  320. dpf__set_module_export_list("${NAME}-lv2" "lv2-dsp")
  321. endif()
  322. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-dsp")
  323. set_target_properties("${NAME}-lv2" PROPERTIES
  324. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  325. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/lv2/$<0:>"
  326. OUTPUT_NAME "${NAME}_dsp"
  327. PREFIX "")
  328. if(HAS_UI)
  329. if(MONOLITHIC)
  330. dpf__add_ui_main("${NAME}-lv2" "lv2" "${HAS_UI}")
  331. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui")
  332. set_target_properties("${NAME}-lv2" PROPERTIES
  333. OUTPUT_NAME "${NAME}")
  334. else()
  335. dpf__add_module("${NAME}-lv2-ui" ${_no_srcs})
  336. dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${HAS_UI}")
  337. dpf__set_module_export_list("${NAME}-lv2-ui" "lv2-ui")
  338. target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui")
  339. set_target_properties("${NAME}-lv2-ui" PROPERTIES
  340. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  341. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/lv2/$<0:>"
  342. OUTPUT_NAME "${NAME}_ui"
  343. PREFIX "")
  344. endif()
  345. endif()
  346. dpf__add_lv2_ttl_generator()
  347. add_dependencies("${NAME}-lv2" lv2_ttl_generator)
  348. add_custom_command(TARGET "${NAME}-lv2" POST_BUILD
  349. COMMAND
  350. ${CMAKE_CROSSCOMPILING_EMULATOR}
  351. "$<TARGET_FILE:lv2_ttl_generator>"
  352. "$<TARGET_FILE:${NAME}-lv2>"
  353. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2"
  354. DEPENDS lv2_ttl_generator)
  355. endfunction()
  356. # dpf__build_vst2
  357. # ------------------------------------------------------------------------------
  358. #
  359. # Add build rules for a VST2 plugin.
  360. #
  361. function(dpf__build_vst2 NAME HAS_UI)
  362. dpf__create_dummy_source_list(_no_srcs)
  363. dpf__add_module("${NAME}-vst2" ${_no_srcs})
  364. dpf__add_plugin_main("${NAME}-vst2" "vst2")
  365. dpf__add_ui_main("${NAME}-vst2" "vst2" "${HAS_UI}")
  366. dpf__set_module_export_list("${NAME}-vst2" "vst2")
  367. target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  368. set_target_properties("${NAME}-vst2" PROPERTIES
  369. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  370. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst2/$<0:>"
  371. OUTPUT_NAME "${NAME}-vst2"
  372. PREFIX "")
  373. if(APPLE)
  374. set_target_properties("${NAME}-vst2" PROPERTIES
  375. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/MacOS/$<0:>"
  376. OUTPUT_NAME "${NAME}"
  377. SUFFIX "")
  378. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  379. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  380. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/Info.plist" @ONLY)
  381. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  382. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents")
  383. endif()
  384. endfunction()
  385. # dpf__determine_vst3_package_architecture
  386. # ------------------------------------------------------------------------------
  387. #
  388. # Determines the package architecture for a VST3 plugin target.
  389. #
  390. function(dpf__determine_vst3_package_architecture OUTPUT_VARIABLE)
  391. # if set by variable, override the detection
  392. if(DPF_VST3_ARCHITECTURE)
  393. set("${OUTPUT_VARIABLE}" "${DPF_VST3_ARCHITECTURE}" PARENT_SCOPE)
  394. return()
  395. endif()
  396. # not used on Apple, which supports universal binary
  397. if(APPLE)
  398. set("${OUTPUT_VARIABLE}" "universal" PARENT_SCOPE)
  399. return()
  400. endif()
  401. # identify the target processor (special case of MSVC, problematic sometimes)
  402. if(MSVC)
  403. set(vst3_system_arch "${MSVC_CXX_ARCHITECTURE_ID}")
  404. else()
  405. set(vst3_system_arch "${CMAKE_SYSTEM_PROCESSOR}")
  406. endif()
  407. # transform the processor name to a format that VST3 recognizes
  408. if(vst3_system_arch MATCHES "^(x86_64|amd64|AMD64|x64|X64)$")
  409. set(vst3_package_arch "x86_64")
  410. elseif(vst3_system_arch MATCHES "^(i.86|x86|X86)$")
  411. if(WIN32)
  412. set(vst3_package_arch "x86")
  413. else()
  414. set(vst3_package_arch "i386")
  415. endif()
  416. elseif(vst3_system_arch MATCHES "^(armv[3-8][a-z]*)$")
  417. set(vst3_package_arch "${vst3_system_arch}")
  418. elseif(vst3_system_arch MATCHES "^(aarch64)$")
  419. set(vst3_package_arch "aarch64")
  420. else()
  421. message(FATAL_ERROR "We don't know this architecture for VST3: ${vst3_system_arch}.")
  422. endif()
  423. # TODO: the detections for Windows arm/arm64 when supported
  424. set("${OUTPUT_VARIABLE}" "${vst3_package_arch}" PARENT_SCOPE)
  425. endfunction()
  426. # dpf__build_vst3
  427. # ------------------------------------------------------------------------------
  428. #
  429. # Add build rules for a VST3 plugin.
  430. #
  431. function(dpf__build_vst3 NAME HAS_UI)
  432. dpf__determine_vst3_package_architecture(vst3_arch)
  433. dpf__create_dummy_source_list(_no_srcs)
  434. dpf__add_module("${NAME}-vst3" ${_no_srcs})
  435. dpf__add_plugin_main("${NAME}-vst3" "vst3")
  436. dpf__add_ui_main("${NAME}-vst3" "vst3" "${HAS_UI}")
  437. dpf__set_module_export_list("${NAME}-vst3" "vst3")
  438. target_link_libraries("${NAME}-vst3" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  439. set_target_properties("${NAME}-vst3" PROPERTIES
  440. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst3/$<0:>"
  441. OUTPUT_NAME "${NAME}"
  442. PREFIX "")
  443. if(APPLE)
  444. set_target_properties("${NAME}-vst3" PROPERTIES
  445. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/MacOS/$<0:>"
  446. SUFFIX "")
  447. elseif(WIN32)
  448. set_target_properties("${NAME}-vst3" PROPERTIES
  449. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/${vst3_arch}-win/$<0:>" SUFFIX ".vst3")
  450. else()
  451. set_target_properties("${NAME}-vst3" PROPERTIES
  452. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/${vst3_arch}-linux/$<0:>")
  453. endif()
  454. if(APPLE)
  455. # Uses the same macOS bundle template as VST2
  456. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  457. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  458. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/Info.plist" @ONLY)
  459. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  460. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents")
  461. endif()
  462. endfunction()
  463. # dpf__build_clap
  464. # ------------------------------------------------------------------------------
  465. #
  466. # Add build rules for a CLAP plugin.
  467. #
  468. function(dpf__build_clap NAME HAS_UI)
  469. dpf__create_dummy_source_list(_no_srcs)
  470. dpf__add_module("${NAME}-clap" ${_no_srcs})
  471. dpf__add_plugin_main("${NAME}-clap" "clap")
  472. dpf__add_ui_main("${NAME}-clap" "clap" "${HAS_UI}")
  473. dpf__set_module_export_list("${NAME}-clap" "clap")
  474. target_link_libraries("${NAME}-clap" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  475. set_target_properties("${NAME}-clap" PROPERTIES
  476. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  477. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/clap/$<0:>"
  478. OUTPUT_NAME "${NAME}"
  479. PREFIX ""
  480. SUFFIX ".clap")
  481. if(APPLE)
  482. set_target_properties("${NAME}-clap" PROPERTIES
  483. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents/MacOS/$<0:>"
  484. OUTPUT_NAME "${NAME}"
  485. SUFFIX "")
  486. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  487. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  488. "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents/Info.plist" @ONLY)
  489. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  490. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents")
  491. endif()
  492. endfunction()
  493. # dpf__build_static
  494. # ------------------------------------------------------------------------------
  495. #
  496. # Add build rules for a static library.
  497. #
  498. function(dpf__build_static NAME HAS_UI)
  499. dpf__create_dummy_source_list(_no_srcs)
  500. dpf__add_module("${NAME}-static" ${_no_srcs} STATIC)
  501. dpf__add_plugin_main("${NAME}-static" "static")
  502. dpf__add_ui_main("${NAME}-static" "static" "${HAS_UI}")
  503. target_link_libraries("${NAME}-static" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  504. get_target_property(dsp_srcs "${NAME}-dsp" SOURCES)
  505. get_target_property(ui_srcs "${NAME}-ui" SOURCES)
  506. foreach(src ${dsp_srcs})
  507. target_sources("${NAME}-static" PRIVATE ${src})
  508. endforeach()
  509. foreach(src ${ui_srcs})
  510. target_sources("${NAME}-static" PRIVATE ${src})
  511. endforeach()
  512. set_target_properties("${NAME}-static" PROPERTIES
  513. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  514. OUTPUT_NAME "${NAME}"
  515. PREFIX "")
  516. endfunction()
  517. # dpf__add_dgl_cairo
  518. # ------------------------------------------------------------------------------
  519. #
  520. # Add the Cairo variant of DGL, if not already available.
  521. #
  522. function(dpf__add_dgl_cairo NO_SHARED_RESOURCES)
  523. if(TARGET dgl-cairo)
  524. return()
  525. endif()
  526. find_package(PkgConfig)
  527. pkg_check_modules(CAIRO "cairo" REQUIRED)
  528. link_directories(${CAIRO_LIBRARY_DIRS})
  529. dpf__add_static_library(dgl-cairo STATIC
  530. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  531. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  532. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  533. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  534. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  535. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  536. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  537. "${DPF_ROOT_DIR}/dgl/src/Layout.cpp"
  538. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  539. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  540. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  541. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  542. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  543. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  544. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  545. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  546. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp")
  547. if(NO_SHARED_RESOURCES)
  548. target_compile_definitions(dgl-cairo PUBLIC "DGL_NO_SHARED_RESOURCES")
  549. else()
  550. target_sources(dgl-cairo PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  551. endif()
  552. if(NOT APPLE)
  553. target_sources(dgl-cairo PRIVATE
  554. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  555. else()
  556. target_sources(dgl-cairo PRIVATE
  557. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  558. endif()
  559. target_include_directories(dgl-cairo PUBLIC
  560. "${DPF_ROOT_DIR}/dgl")
  561. target_include_directories(dgl-cairo PUBLIC
  562. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  563. dpf__add_dgl_system_libs()
  564. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  565. add_library(dgl-cairo-definitions INTERFACE)
  566. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO" "HAVE_DGL")
  567. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  568. if(MINGW)
  569. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_STATIC_LIBRARIES})
  570. else()
  571. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_LIBRARIES})
  572. endif()
  573. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions)
  574. endfunction()
  575. # dpf__add_dgl_opengl
  576. # ------------------------------------------------------------------------------
  577. #
  578. # Add the OpenGL variant of DGL, if not already available.
  579. #
  580. function(dpf__add_dgl_opengl NO_SHARED_RESOURCES)
  581. if(TARGET dgl-opengl)
  582. return()
  583. endif()
  584. if(NOT OpenGL_GL_PREFERENCE)
  585. set(OpenGL_GL_PREFERENCE "LEGACY")
  586. endif()
  587. find_package(OpenGL REQUIRED)
  588. dpf__add_static_library(dgl-opengl STATIC
  589. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  590. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  591. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  592. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  593. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  594. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  595. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  596. "${DPF_ROOT_DIR}/dgl/src/Layout.cpp"
  597. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  598. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  599. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  600. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  601. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  602. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  603. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  604. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  605. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  606. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp")
  607. if(NO_SHARED_RESOURCES)
  608. target_compile_definitions(dgl-opengl PUBLIC "DGL_NO_SHARED_RESOURCES")
  609. else()
  610. target_sources(dgl-opengl PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  611. endif()
  612. if(NOT APPLE)
  613. target_sources(dgl-opengl PRIVATE
  614. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  615. else()
  616. target_sources(dgl-opengl PRIVATE
  617. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  618. endif()
  619. target_include_directories(dgl-opengl PUBLIC
  620. "${DPF_ROOT_DIR}/dgl")
  621. target_include_directories(dgl-opengl PUBLIC
  622. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  623. if(APPLE)
  624. target_compile_definitions(dgl-opengl PUBLIC "GL_SILENCE_DEPRECATION")
  625. endif()
  626. dpf__add_dgl_system_libs()
  627. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  628. add_library(dgl-opengl-definitions INTERFACE)
  629. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL" "HAVE_DGL")
  630. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  631. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  632. endfunction()
  633. # dpf__add_plugin_specific_ui_sources
  634. # ------------------------------------------------------------------------------
  635. #
  636. # Compile system specific files, for now it is just Objective-C code
  637. #
  638. function(dpf__add_plugin_specific_ui_sources NAME)
  639. if(APPLE)
  640. target_sources("${NAME}" PRIVATE
  641. "${DPF_ROOT_DIR}/distrho/DistrhoUI_macOS.mm")
  642. endif()
  643. endfunction()
  644. # dpf__add_dgl_system_libs
  645. # ------------------------------------------------------------------------------
  646. #
  647. # Find system libraries required by DGL and add them as an interface target.
  648. #
  649. function(dpf__add_dgl_system_libs)
  650. if(TARGET dgl-system-libs)
  651. return()
  652. endif()
  653. add_library(dgl-system-libs INTERFACE)
  654. add_library(dgl-system-libs-definitions INTERFACE)
  655. if(APPLE)
  656. find_library(APPLE_COCOA_FRAMEWORK "Cocoa")
  657. find_library(APPLE_COREVIDEO_FRAMEWORK "CoreVideo")
  658. target_link_libraries(dgl-system-libs INTERFACE "${APPLE_COCOA_FRAMEWORK}" "${APPLE_COREVIDEO_FRAMEWORK}")
  659. elseif(EMSCRIPTEN)
  660. elseif(HAIKU)
  661. target_link_libraries(dgl-system-libs INTERFACE "be")
  662. elseif(WIN32)
  663. target_link_libraries(dgl-system-libs INTERFACE "gdi32" "comdlg32")
  664. else()
  665. find_package(PkgConfig)
  666. pkg_check_modules(DBUS "dbus-1")
  667. if(DBUS_FOUND)
  668. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_DBUS")
  669. target_include_directories(dgl-system-libs INTERFACE "${DBUS_INCLUDE_DIRS}")
  670. target_link_libraries(dgl-system-libs INTERFACE "${DBUS_LIBRARIES}")
  671. endif()
  672. find_package(X11 REQUIRED)
  673. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_X11")
  674. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  675. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  676. if(X11_Xcursor_FOUND)
  677. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XCURSOR")
  678. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xcursor_LIB}")
  679. endif()
  680. if(X11_Xext_FOUND)
  681. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XEXT")
  682. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xext_LIB}")
  683. endif()
  684. if(X11_Xrandr_FOUND)
  685. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XRANDR")
  686. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xrandr_LIB}")
  687. endif()
  688. if(X11_XSync_FOUND)
  689. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XSYNC")
  690. target_link_libraries(dgl-system-libs INTERFACE "${X11_XSync_LIB}")
  691. endif()
  692. endif()
  693. if(MSVC)
  694. file(MAKE_DIRECTORY "${DPF_ROOT_DIR}/khronos/GL")
  695. foreach(_gl_header "glext.h")
  696. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}")
  697. file(DOWNLOAD "https://www.khronos.org/registry/OpenGL/api/GL/${_gl_header}" "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}" SHOW_PROGRESS)
  698. endif()
  699. endforeach()
  700. foreach(_khr_header "khrplatform.h")
  701. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}")
  702. file(DOWNLOAD "https://www.khronos.org/registry/EGL/api/KHR/${_khr_header}" "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}" SHOW_PROGRESS)
  703. endif()
  704. endforeach()
  705. target_include_directories(dgl-system-libs-definitions INTERFACE "${DPF_ROOT_DIR}/khronos")
  706. endif()
  707. target_link_libraries(dgl-system-libs INTERFACE dgl-system-libs-definitions)
  708. endfunction()
  709. # dpf__add_executable
  710. # ------------------------------------------------------------------------------
  711. #
  712. # Adds an executable target, and set some default properties on the target.
  713. #
  714. function(dpf__add_executable NAME)
  715. add_executable("${NAME}" ${ARGN})
  716. dpf__set_target_defaults("${NAME}")
  717. if(MINGW)
  718. target_link_libraries("${NAME}" PRIVATE "-static")
  719. endif()
  720. endfunction()
  721. # dpf__add_module
  722. # ------------------------------------------------------------------------------
  723. #
  724. # Adds a module target, and set some default properties on the target.
  725. #
  726. function(dpf__add_module NAME)
  727. add_library("${NAME}" MODULE ${ARGN})
  728. dpf__set_target_defaults("${NAME}")
  729. if(MINGW)
  730. target_link_libraries("${NAME}" PRIVATE "-static")
  731. endif()
  732. endfunction()
  733. # dpf__add_static_library
  734. # ------------------------------------------------------------------------------
  735. #
  736. # Adds a static library target, and set some default properties on the target.
  737. #
  738. function(dpf__add_static_library NAME)
  739. add_library("${NAME}" STATIC ${ARGN})
  740. dpf__set_target_defaults("${NAME}")
  741. endfunction()
  742. # dpf__set_module_export_list
  743. # ------------------------------------------------------------------------------
  744. #
  745. # Applies a list of exported symbols to the module target.
  746. #
  747. function(dpf__set_module_export_list NAME EXPORTS)
  748. if(WIN32)
  749. target_sources("${NAME}" PRIVATE "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.def")
  750. elseif(APPLE)
  751. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  752. "-Xlinker" "-exported_symbols_list"
  753. "-Xlinker" "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.exp")
  754. else()
  755. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  756. "-Xlinker" "--version-script=${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.version")
  757. endif()
  758. endfunction()
  759. # dpf__set_target_defaults
  760. # ------------------------------------------------------------------------------
  761. #
  762. # Set default properties which must apply to all DPF-defined targets.
  763. #
  764. function(dpf__set_target_defaults NAME)
  765. set_target_properties("${NAME}" PROPERTIES
  766. POSITION_INDEPENDENT_CODE TRUE
  767. C_VISIBILITY_PRESET "hidden"
  768. CXX_VISIBILITY_PRESET "hidden"
  769. VISIBILITY_INLINES_HIDDEN TRUE)
  770. if(WIN32)
  771. target_compile_definitions("${NAME}" PUBLIC "NOMINMAX")
  772. endif()
  773. if (MINGW)
  774. target_compile_options("${NAME}" PUBLIC "-mstackrealign")
  775. endif()
  776. if (MSVC)
  777. target_compile_options("${NAME}" PUBLIC "/UTF-8")
  778. target_compile_definitions("${NAME}" PUBLIC "_CRT_SECURE_NO_WARNINGS")
  779. endif()
  780. if (CMAKE_COMPILER_IS_GNUCXX)
  781. target_compile_options("${NAME}" PUBLIC "-fno-gnu-unique")
  782. endif()
  783. endfunction()
  784. # dpf__add_plugin_main
  785. # ------------------------------------------------------------------------------
  786. #
  787. # Adds plugin code to the given target.
  788. #
  789. function(dpf__add_plugin_main NAME TARGET)
  790. target_sources("${NAME}" PRIVATE
  791. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  792. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  793. endfunction()
  794. # dpf__add_ui_main
  795. # ------------------------------------------------------------------------------
  796. #
  797. # Adds UI code to the given target (only if the target has UI).
  798. #
  799. function(dpf__add_ui_main NAME TARGET HAS_UI)
  800. if(HAS_UI)
  801. target_sources("${NAME}" PRIVATE
  802. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  803. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  804. endif()
  805. endfunction()
  806. # dpf__add_plugin_target_definition
  807. # ------------------------------------------------------------------------------
  808. #
  809. # Adds the plugins target macro definition.
  810. # This selects which entry file is compiled according to the target type.
  811. #
  812. function(dpf__add_plugin_target_definition NAME TARGET)
  813. string(TOUPPER "${TARGET}" _upperTarget)
  814. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  815. endfunction()
  816. # dpf__add_lv2_ttl_generator
  817. # ------------------------------------------------------------------------------
  818. #
  819. # Build the LV2 TTL generator.
  820. #
  821. function(dpf__add_lv2_ttl_generator)
  822. if(TARGET lv2_ttl_generator)
  823. return()
  824. endif()
  825. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  826. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  827. target_link_libraries(lv2_ttl_generator PRIVATE "dl")
  828. endif()
  829. endfunction()
  830. # dpf__ensure_sources_non_empty
  831. # ------------------------------------------------------------------------------
  832. #
  833. # Ensure the given source list contains at least one file.
  834. # The function appends an empty source file to the list if necessary.
  835. # This is useful when CMake does not permit to add targets without sources.
  836. #
  837. function(dpf__ensure_sources_non_empty VAR)
  838. if(NOT "" STREQUAL "${${VAR}}")
  839. return()
  840. endif()
  841. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  842. if(NOT EXISTS "${_file}")
  843. file(WRITE "${_file}" "")
  844. endif()
  845. set("${VAR}" "${_file}" PARENT_SCOPE)
  846. endfunction()
  847. # dpf__create_dummy_source_list
  848. # ------------------------------------------------------------------------------
  849. #
  850. # Create a dummy source list which is equivalent to compiling nothing.
  851. # This is only for compatibility with older CMake versions, which refuse to add
  852. # targets without any sources.
  853. #
  854. macro(dpf__create_dummy_source_list VAR)
  855. set("${VAR}")
  856. if(CMAKE_VERSION VERSION_LESS "3.11")
  857. dpf__ensure_sources_non_empty("${VAR}")
  858. endif()
  859. endmacro()
  860. # dpf__target_link_directories
  861. # ------------------------------------------------------------------------------
  862. #
  863. # Call `target_link_directories` if cmake >= 3.13,
  864. # otherwise fallback to global `link_directories`.
  865. #
  866. macro(dpf__target_link_directories NAME DIRS)
  867. if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
  868. target_link_directories("${NAME}" PUBLIC ${DIRS})
  869. else()
  870. link_directories(${DIRS})
  871. endif()
  872. endmacro()
  873. # dpf__warn_once
  874. # ------------------------------------------------------------------------------
  875. #
  876. # Prints a warning message once only.
  877. #
  878. function(dpf__warn_once_only TOKEN MESSAGE)
  879. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  880. if(NOT _warned)
  881. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  882. message(WARNING "${MESSAGE}")
  883. endif()
  884. endfunction()