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.

974 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. separate_arguments(CMAKE_CROSSCOMPILING_EMULATOR)
  349. add_custom_command(TARGET "${NAME}-lv2" POST_BUILD
  350. COMMAND
  351. ${CMAKE_CROSSCOMPILING_EMULATOR}
  352. "$<TARGET_FILE:lv2_ttl_generator>"
  353. "$<TARGET_FILE:${NAME}-lv2>"
  354. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2"
  355. DEPENDS lv2_ttl_generator)
  356. endfunction()
  357. # dpf__build_vst2
  358. # ------------------------------------------------------------------------------
  359. #
  360. # Add build rules for a VST2 plugin.
  361. #
  362. function(dpf__build_vst2 NAME HAS_UI)
  363. dpf__create_dummy_source_list(_no_srcs)
  364. dpf__add_module("${NAME}-vst2" ${_no_srcs})
  365. dpf__add_plugin_main("${NAME}-vst2" "vst2")
  366. dpf__add_ui_main("${NAME}-vst2" "vst2" "${HAS_UI}")
  367. dpf__set_module_export_list("${NAME}-vst2" "vst2")
  368. target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  369. set_target_properties("${NAME}-vst2" PROPERTIES
  370. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  371. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst2/$<0:>"
  372. OUTPUT_NAME "${NAME}-vst2"
  373. PREFIX "")
  374. if(APPLE)
  375. set_target_properties("${NAME}-vst2" PROPERTIES
  376. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/MacOS/$<0:>"
  377. OUTPUT_NAME "${NAME}"
  378. SUFFIX "")
  379. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  380. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  381. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents/Info.plist" @ONLY)
  382. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  383. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst/Contents")
  384. endif()
  385. endfunction()
  386. # dpf__determine_vst3_package_architecture
  387. # ------------------------------------------------------------------------------
  388. #
  389. # Determines the package architecture for a VST3 plugin target.
  390. #
  391. function(dpf__determine_vst3_package_architecture OUTPUT_VARIABLE)
  392. # if set by variable, override the detection
  393. if(DPF_VST3_ARCHITECTURE)
  394. set("${OUTPUT_VARIABLE}" "${DPF_VST3_ARCHITECTURE}" PARENT_SCOPE)
  395. return()
  396. endif()
  397. # not used on Apple, which supports universal binary
  398. if(APPLE)
  399. set("${OUTPUT_VARIABLE}" "universal" PARENT_SCOPE)
  400. return()
  401. endif()
  402. # identify the target processor (special case of MSVC, problematic sometimes)
  403. if(MSVC)
  404. set(vst3_system_arch "${MSVC_CXX_ARCHITECTURE_ID}")
  405. else()
  406. set(vst3_system_arch "${CMAKE_SYSTEM_PROCESSOR}")
  407. endif()
  408. # transform the processor name to a format that VST3 recognizes
  409. if(vst3_system_arch MATCHES "^(x86_64|amd64|AMD64|x64|X64)$")
  410. set(vst3_package_arch "x86_64")
  411. elseif(vst3_system_arch MATCHES "^(i.86|x86|X86)$")
  412. if(WIN32)
  413. set(vst3_package_arch "x86")
  414. else()
  415. set(vst3_package_arch "i386")
  416. endif()
  417. elseif(vst3_system_arch MATCHES "^(armv[3-8][a-z]*)$")
  418. set(vst3_package_arch "${vst3_system_arch}")
  419. elseif(vst3_system_arch MATCHES "^(aarch64)$")
  420. set(vst3_package_arch "aarch64")
  421. else()
  422. message(FATAL_ERROR "We don't know this architecture for VST3: ${vst3_system_arch}.")
  423. endif()
  424. # TODO: the detections for Windows arm/arm64 when supported
  425. set("${OUTPUT_VARIABLE}" "${vst3_package_arch}" PARENT_SCOPE)
  426. endfunction()
  427. # dpf__build_vst3
  428. # ------------------------------------------------------------------------------
  429. #
  430. # Add build rules for a VST3 plugin.
  431. #
  432. function(dpf__build_vst3 NAME HAS_UI)
  433. dpf__determine_vst3_package_architecture(vst3_arch)
  434. dpf__create_dummy_source_list(_no_srcs)
  435. dpf__add_module("${NAME}-vst3" ${_no_srcs})
  436. dpf__add_plugin_main("${NAME}-vst3" "vst3")
  437. dpf__add_ui_main("${NAME}-vst3" "vst3" "${HAS_UI}")
  438. dpf__set_module_export_list("${NAME}-vst3" "vst3")
  439. target_link_libraries("${NAME}-vst3" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  440. set_target_properties("${NAME}-vst3" PROPERTIES
  441. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/vst3/$<0:>"
  442. OUTPUT_NAME "${NAME}"
  443. PREFIX "")
  444. if(APPLE)
  445. set_target_properties("${NAME}-vst3" PROPERTIES
  446. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/MacOS/$<0:>"
  447. SUFFIX "")
  448. elseif(WIN32)
  449. set_target_properties("${NAME}-vst3" PROPERTIES
  450. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/${vst3_arch}-win/$<0:>" SUFFIX ".vst3")
  451. else()
  452. set_target_properties("${NAME}-vst3" PROPERTIES
  453. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/${vst3_arch}-linux/$<0:>")
  454. endif()
  455. if(APPLE)
  456. # Uses the same macOS bundle template as VST2
  457. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  458. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  459. "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents/Info.plist" @ONLY)
  460. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  461. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.vst3/Contents")
  462. endif()
  463. endfunction()
  464. # dpf__build_clap
  465. # ------------------------------------------------------------------------------
  466. #
  467. # Add build rules for a CLAP plugin.
  468. #
  469. function(dpf__build_clap NAME HAS_UI)
  470. dpf__create_dummy_source_list(_no_srcs)
  471. dpf__add_module("${NAME}-clap" ${_no_srcs})
  472. dpf__add_plugin_main("${NAME}-clap" "clap")
  473. dpf__add_ui_main("${NAME}-clap" "clap" "${HAS_UI}")
  474. dpf__set_module_export_list("${NAME}-clap" "clap")
  475. target_link_libraries("${NAME}-clap" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  476. set_target_properties("${NAME}-clap" PROPERTIES
  477. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  478. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/obj/clap/$<0:>"
  479. OUTPUT_NAME "${NAME}"
  480. PREFIX ""
  481. SUFFIX ".clap")
  482. if(APPLE)
  483. set_target_properties("${NAME}-clap" PROPERTIES
  484. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents/MacOS/$<0:>"
  485. OUTPUT_NAME "${NAME}"
  486. SUFFIX "")
  487. set(INFO_PLIST_PROJECT_NAME "${NAME}")
  488. configure_file("${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/Info.plist"
  489. "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents/Info.plist" @ONLY)
  490. file(COPY "${DPF_ROOT_DIR}/utils/plugin.bundle/Contents/PkgInfo"
  491. DESTINATION "${PROJECT_BINARY_DIR}/bin/${NAME}.clap/Contents")
  492. endif()
  493. endfunction()
  494. # dpf__build_static
  495. # ------------------------------------------------------------------------------
  496. #
  497. # Add build rules for a static library.
  498. #
  499. function(dpf__build_static NAME HAS_UI)
  500. dpf__create_dummy_source_list(_no_srcs)
  501. dpf__add_module("${NAME}-static" ${_no_srcs} STATIC)
  502. dpf__add_plugin_main("${NAME}-static" "static")
  503. dpf__add_ui_main("${NAME}-static" "static" "${HAS_UI}")
  504. target_link_libraries("${NAME}-static" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  505. get_target_property(dsp_srcs "${NAME}-dsp" SOURCES)
  506. get_target_property(ui_srcs "${NAME}-ui" SOURCES)
  507. foreach(src ${dsp_srcs})
  508. target_sources("${NAME}-static" PRIVATE ${src})
  509. endforeach()
  510. foreach(src ${ui_srcs})
  511. target_sources("${NAME}-static" PRIVATE ${src})
  512. endforeach()
  513. set_target_properties("${NAME}-static" PROPERTIES
  514. ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  515. OUTPUT_NAME "${NAME}"
  516. PREFIX "")
  517. endfunction()
  518. # dpf__add_dgl_cairo
  519. # ------------------------------------------------------------------------------
  520. #
  521. # Add the Cairo variant of DGL, if not already available.
  522. #
  523. function(dpf__add_dgl_cairo NO_SHARED_RESOURCES)
  524. if(TARGET dgl-cairo)
  525. return()
  526. endif()
  527. find_package(PkgConfig)
  528. pkg_check_modules(CAIRO "cairo" REQUIRED)
  529. link_directories(${CAIRO_LIBRARY_DIRS})
  530. dpf__add_static_library(dgl-cairo STATIC
  531. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  532. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  533. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  534. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  535. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  536. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  537. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  538. "${DPF_ROOT_DIR}/dgl/src/Layout.cpp"
  539. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  540. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  541. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  542. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  543. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  544. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  545. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  546. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  547. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp")
  548. if(NO_SHARED_RESOURCES)
  549. target_compile_definitions(dgl-cairo PUBLIC "DGL_NO_SHARED_RESOURCES")
  550. else()
  551. target_sources(dgl-cairo PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  552. endif()
  553. if(NOT APPLE)
  554. target_sources(dgl-cairo PRIVATE
  555. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  556. else()
  557. target_sources(dgl-cairo PRIVATE
  558. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  559. endif()
  560. target_include_directories(dgl-cairo PUBLIC
  561. "${DPF_ROOT_DIR}/dgl")
  562. target_include_directories(dgl-cairo PUBLIC
  563. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  564. dpf__add_dgl_system_libs()
  565. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  566. add_library(dgl-cairo-definitions INTERFACE)
  567. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO" "HAVE_DGL")
  568. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  569. if(MINGW)
  570. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_STATIC_LIBRARIES})
  571. else()
  572. target_link_libraries(dgl-cairo PRIVATE ${CAIRO_LIBRARIES})
  573. endif()
  574. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions)
  575. endfunction()
  576. # dpf__add_dgl_opengl
  577. # ------------------------------------------------------------------------------
  578. #
  579. # Add the OpenGL variant of DGL, if not already available.
  580. #
  581. function(dpf__add_dgl_opengl NO_SHARED_RESOURCES)
  582. if(TARGET dgl-opengl)
  583. return()
  584. endif()
  585. if(NOT OpenGL_GL_PREFERENCE)
  586. set(OpenGL_GL_PREFERENCE "LEGACY")
  587. endif()
  588. find_package(OpenGL REQUIRED)
  589. dpf__add_static_library(dgl-opengl STATIC
  590. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  591. "${DPF_ROOT_DIR}/dgl/src/ApplicationPrivateData.cpp"
  592. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  593. "${DPF_ROOT_DIR}/dgl/src/EventHandlers.cpp"
  594. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  595. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  596. "${DPF_ROOT_DIR}/dgl/src/ImageBaseWidgets.cpp"
  597. "${DPF_ROOT_DIR}/dgl/src/Layout.cpp"
  598. "${DPF_ROOT_DIR}/dgl/src/SubWidget.cpp"
  599. "${DPF_ROOT_DIR}/dgl/src/SubWidgetPrivateData.cpp"
  600. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidget.cpp"
  601. "${DPF_ROOT_DIR}/dgl/src/TopLevelWidgetPrivateData.cpp"
  602. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  603. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp"
  604. "${DPF_ROOT_DIR}/dgl/src/Window.cpp"
  605. "${DPF_ROOT_DIR}/dgl/src/WindowPrivateData.cpp"
  606. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  607. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp")
  608. if(NO_SHARED_RESOURCES)
  609. target_compile_definitions(dgl-opengl PUBLIC "DGL_NO_SHARED_RESOURCES")
  610. else()
  611. target_sources(dgl-opengl PRIVATE "${DPF_ROOT_DIR}/dgl/src/Resources.cpp")
  612. endif()
  613. if(NOT APPLE)
  614. target_sources(dgl-opengl PRIVATE
  615. "${DPF_ROOT_DIR}/dgl/src/pugl.cpp")
  616. else()
  617. target_sources(dgl-opengl PRIVATE
  618. "${DPF_ROOT_DIR}/dgl/src/pugl.mm")
  619. endif()
  620. target_include_directories(dgl-opengl PUBLIC
  621. "${DPF_ROOT_DIR}/dgl")
  622. target_include_directories(dgl-opengl PUBLIC
  623. "${DPF_ROOT_DIR}/dgl/src/pugl-upstream/include")
  624. if(APPLE)
  625. target_compile_definitions(dgl-opengl PUBLIC "GL_SILENCE_DEPRECATION")
  626. endif()
  627. dpf__add_dgl_system_libs()
  628. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  629. add_library(dgl-opengl-definitions INTERFACE)
  630. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL" "HAVE_DGL")
  631. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  632. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  633. endfunction()
  634. # dpf__add_plugin_specific_ui_sources
  635. # ------------------------------------------------------------------------------
  636. #
  637. # Compile system specific files, for now it is just Objective-C code
  638. #
  639. function(dpf__add_plugin_specific_ui_sources NAME)
  640. if(APPLE)
  641. target_sources("${NAME}" PRIVATE
  642. "${DPF_ROOT_DIR}/distrho/DistrhoUI_macOS.mm")
  643. endif()
  644. endfunction()
  645. # dpf__add_dgl_system_libs
  646. # ------------------------------------------------------------------------------
  647. #
  648. # Find system libraries required by DGL and add them as an interface target.
  649. #
  650. function(dpf__add_dgl_system_libs)
  651. if(TARGET dgl-system-libs)
  652. return()
  653. endif()
  654. add_library(dgl-system-libs INTERFACE)
  655. add_library(dgl-system-libs-definitions INTERFACE)
  656. if(APPLE)
  657. find_library(APPLE_COCOA_FRAMEWORK "Cocoa")
  658. find_library(APPLE_COREVIDEO_FRAMEWORK "CoreVideo")
  659. target_link_libraries(dgl-system-libs INTERFACE "${APPLE_COCOA_FRAMEWORK}" "${APPLE_COREVIDEO_FRAMEWORK}")
  660. elseif(EMSCRIPTEN)
  661. elseif(HAIKU)
  662. target_link_libraries(dgl-system-libs INTERFACE "be")
  663. elseif(WIN32)
  664. target_link_libraries(dgl-system-libs INTERFACE "gdi32" "comdlg32")
  665. else()
  666. find_package(PkgConfig)
  667. pkg_check_modules(DBUS "dbus-1")
  668. if(DBUS_FOUND)
  669. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_DBUS")
  670. target_include_directories(dgl-system-libs INTERFACE "${DBUS_INCLUDE_DIRS}")
  671. target_link_libraries(dgl-system-libs INTERFACE "${DBUS_LIBRARIES}")
  672. endif()
  673. find_package(X11 REQUIRED)
  674. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_X11")
  675. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  676. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  677. if(X11_Xcursor_FOUND)
  678. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XCURSOR")
  679. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xcursor_LIB}")
  680. endif()
  681. if(X11_Xext_FOUND)
  682. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XEXT")
  683. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xext_LIB}")
  684. endif()
  685. if(X11_Xrandr_FOUND)
  686. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XRANDR")
  687. target_link_libraries(dgl-system-libs INTERFACE "${X11_Xrandr_LIB}")
  688. endif()
  689. if(X11_XSync_FOUND)
  690. target_compile_definitions(dgl-system-libs-definitions INTERFACE "HAVE_XSYNC")
  691. target_link_libraries(dgl-system-libs INTERFACE "${X11_XSync_LIB}")
  692. endif()
  693. endif()
  694. if(MSVC)
  695. file(MAKE_DIRECTORY "${DPF_ROOT_DIR}/khronos/GL")
  696. foreach(_gl_header "glext.h")
  697. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}")
  698. file(DOWNLOAD "https://www.khronos.org/registry/OpenGL/api/GL/${_gl_header}" "${DPF_ROOT_DIR}/khronos/GL/${_gl_header}" SHOW_PROGRESS)
  699. endif()
  700. endforeach()
  701. foreach(_khr_header "khrplatform.h")
  702. if(NOT EXISTS "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}")
  703. file(DOWNLOAD "https://www.khronos.org/registry/EGL/api/KHR/${_khr_header}" "${DPF_ROOT_DIR}/khronos/KHR/${_khr_header}" SHOW_PROGRESS)
  704. endif()
  705. endforeach()
  706. target_include_directories(dgl-system-libs-definitions INTERFACE "${DPF_ROOT_DIR}/khronos")
  707. endif()
  708. target_link_libraries(dgl-system-libs INTERFACE dgl-system-libs-definitions)
  709. endfunction()
  710. # dpf__add_executable
  711. # ------------------------------------------------------------------------------
  712. #
  713. # Adds an executable target, and set some default properties on the target.
  714. #
  715. function(dpf__add_executable NAME)
  716. add_executable("${NAME}" ${ARGN})
  717. dpf__set_target_defaults("${NAME}")
  718. if(MINGW)
  719. target_link_libraries("${NAME}" PRIVATE "-static")
  720. endif()
  721. endfunction()
  722. # dpf__add_module
  723. # ------------------------------------------------------------------------------
  724. #
  725. # Adds a module target, and set some default properties on the target.
  726. #
  727. function(dpf__add_module NAME)
  728. add_library("${NAME}" MODULE ${ARGN})
  729. dpf__set_target_defaults("${NAME}")
  730. if(MINGW)
  731. target_link_libraries("${NAME}" PRIVATE "-static")
  732. endif()
  733. endfunction()
  734. # dpf__add_static_library
  735. # ------------------------------------------------------------------------------
  736. #
  737. # Adds a static library target, and set some default properties on the target.
  738. #
  739. function(dpf__add_static_library NAME)
  740. add_library("${NAME}" STATIC ${ARGN})
  741. dpf__set_target_defaults("${NAME}")
  742. endfunction()
  743. # dpf__set_module_export_list
  744. # ------------------------------------------------------------------------------
  745. #
  746. # Applies a list of exported symbols to the module target.
  747. #
  748. function(dpf__set_module_export_list NAME EXPORTS)
  749. if(WIN32)
  750. target_sources("${NAME}" PRIVATE "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.def")
  751. elseif(APPLE)
  752. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  753. "-Xlinker" "-exported_symbols_list"
  754. "-Xlinker" "${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.exp")
  755. else()
  756. set_property(TARGET "${NAME}" APPEND PROPERTY LINK_OPTIONS
  757. "-Xlinker" "--version-script=${DPF_ROOT_DIR}/utils/symbols/${EXPORTS}.version")
  758. endif()
  759. endfunction()
  760. # dpf__set_target_defaults
  761. # ------------------------------------------------------------------------------
  762. #
  763. # Set default properties which must apply to all DPF-defined targets.
  764. #
  765. function(dpf__set_target_defaults NAME)
  766. set_target_properties("${NAME}" PROPERTIES
  767. POSITION_INDEPENDENT_CODE TRUE
  768. C_VISIBILITY_PRESET "hidden"
  769. CXX_VISIBILITY_PRESET "hidden"
  770. VISIBILITY_INLINES_HIDDEN TRUE)
  771. if(WIN32)
  772. target_compile_definitions("${NAME}" PUBLIC "NOMINMAX")
  773. endif()
  774. if (MINGW)
  775. target_compile_options("${NAME}" PUBLIC "-mstackrealign")
  776. endif()
  777. if (MSVC)
  778. target_compile_options("${NAME}" PUBLIC "/UTF-8")
  779. target_compile_definitions("${NAME}" PUBLIC "_CRT_SECURE_NO_WARNINGS")
  780. endif()
  781. if (CMAKE_COMPILER_IS_GNUCXX)
  782. target_compile_options("${NAME}" PUBLIC "-fno-gnu-unique")
  783. endif()
  784. endfunction()
  785. # dpf__add_plugin_main
  786. # ------------------------------------------------------------------------------
  787. #
  788. # Adds plugin code to the given target.
  789. #
  790. function(dpf__add_plugin_main NAME TARGET)
  791. target_sources("${NAME}" PRIVATE
  792. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  793. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  794. endfunction()
  795. # dpf__add_ui_main
  796. # ------------------------------------------------------------------------------
  797. #
  798. # Adds UI code to the given target (only if the target has UI).
  799. #
  800. function(dpf__add_ui_main NAME TARGET HAS_UI)
  801. if(HAS_UI)
  802. target_sources("${NAME}" PRIVATE
  803. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  804. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  805. endif()
  806. endfunction()
  807. # dpf__add_plugin_target_definition
  808. # ------------------------------------------------------------------------------
  809. #
  810. # Adds the plugins target macro definition.
  811. # This selects which entry file is compiled according to the target type.
  812. #
  813. function(dpf__add_plugin_target_definition NAME TARGET)
  814. string(TOUPPER "${TARGET}" _upperTarget)
  815. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  816. endfunction()
  817. # dpf__add_lv2_ttl_generator
  818. # ------------------------------------------------------------------------------
  819. #
  820. # Build the LV2 TTL generator.
  821. #
  822. function(dpf__add_lv2_ttl_generator)
  823. if(TARGET lv2_ttl_generator)
  824. return()
  825. endif()
  826. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  827. if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
  828. target_link_libraries(lv2_ttl_generator PRIVATE "dl")
  829. endif()
  830. endfunction()
  831. # dpf__ensure_sources_non_empty
  832. # ------------------------------------------------------------------------------
  833. #
  834. # Ensure the given source list contains at least one file.
  835. # The function appends an empty source file to the list if necessary.
  836. # This is useful when CMake does not permit to add targets without sources.
  837. #
  838. function(dpf__ensure_sources_non_empty VAR)
  839. if(NOT "" STREQUAL "${${VAR}}")
  840. return()
  841. endif()
  842. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  843. if(NOT EXISTS "${_file}")
  844. file(WRITE "${_file}" "")
  845. endif()
  846. set("${VAR}" "${_file}" PARENT_SCOPE)
  847. endfunction()
  848. # dpf__create_dummy_source_list
  849. # ------------------------------------------------------------------------------
  850. #
  851. # Create a dummy source list which is equivalent to compiling nothing.
  852. # This is only for compatibility with older CMake versions, which refuse to add
  853. # targets without any sources.
  854. #
  855. macro(dpf__create_dummy_source_list VAR)
  856. set("${VAR}")
  857. if(CMAKE_VERSION VERSION_LESS "3.11")
  858. dpf__ensure_sources_non_empty("${VAR}")
  859. endif()
  860. endmacro()
  861. # dpf__target_link_directories
  862. # ------------------------------------------------------------------------------
  863. #
  864. # Call `target_link_directories` if cmake >= 3.13,
  865. # otherwise fallback to global `link_directories`.
  866. #
  867. macro(dpf__target_link_directories NAME DIRS)
  868. if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
  869. target_link_directories("${NAME}" PUBLIC ${DIRS})
  870. else()
  871. link_directories(${DIRS})
  872. endif()
  873. endmacro()
  874. # dpf__warn_once
  875. # ------------------------------------------------------------------------------
  876. #
  877. # Prints a warning message once only.
  878. #
  879. function(dpf__warn_once_only TOKEN MESSAGE)
  880. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  881. if(NOT _warned)
  882. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  883. message(WARNING "${MESSAGE}")
  884. endif()
  885. endfunction()