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.

558 lines
18KB

  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 vst
  25. # UI_TYPE opengl
  26. # FILES_DSP
  27. # src/MyPlugin.cpp
  28. # FILES_UI
  29. # src/MyUI.cpp)
  30. # ```
  31. include(CMakeParseArguments)
  32. # ------------------------------------------------------------------------------
  33. # DPF public functions
  34. # ------------------------------------------------------------------------------
  35. # dpf_add_plugin(name <args...>)
  36. # ------------------------------------------------------------------------------
  37. #
  38. # Add a plugin built using the DISTRHO Plugin Framework.
  39. #
  40. # ------------------------------------------------------------------------------
  41. # Created targets:
  42. #
  43. # `<name>`
  44. # static library: the common part of the plugin
  45. # The public properties set on this target apply to both DSP and UI.
  46. #
  47. # `<name>-dsp`
  48. # static library: the DSP part of the plugin
  49. # The public properties set on this target apply to the DSP only.
  50. #
  51. # `<name>-ui`
  52. # static library: the UI part of the plugin
  53. # The public properties set on this target apply to the UI only.
  54. #
  55. # `<name>-<target>` for each target specified with the `TARGETS` argument.
  56. # This is target-dependent and not intended for public use.
  57. #
  58. # ------------------------------------------------------------------------------
  59. # Arguments:
  60. #
  61. # `TARGETS` <tgt1>...<tgtN>
  62. # a list of one of more of the following target types:
  63. # `jack`, `ladspa`, `dssi`, `lv2`, `vst`
  64. #
  65. # `UI_TYPE` <type>
  66. # the user interface type: `opengl` (default), `cairo`
  67. #
  68. # `MONOLITHIC`
  69. # build LV2 as a single binary for UI and DSP
  70. #
  71. # `FILES_DSP` <file1>...<fileN>
  72. # list of sources which are part of the DSP
  73. #
  74. # `FILES_UI` <file1>...<fileN>
  75. # list of sources which are part of the UI
  76. # empty indicates the plugin does not have UI
  77. #
  78. # `FILES_COMMON` <file1>...<fileN>
  79. # list of sources which are part of both DSP and UI
  80. #
  81. function(dpf_add_plugin NAME)
  82. set(options MONOLITHIC)
  83. set(oneValueArgs UI_TYPE)
  84. set(multiValueArgs TARGETS FILES_DSP FILES_UI)
  85. cmake_parse_arguments(_dpf_plugin "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  86. if("${_dpf_plugin_UI_TYPE}" STREQUAL "")
  87. set(_dpf_plugin_UI_TYPE "opengl")
  88. endif()
  89. set(_dgl_library)
  90. if(_dpf_plugin_FILES_UI)
  91. if(_dpf_plugin_UI_TYPE STREQUAL "cairo")
  92. dpf__add_dgl_cairo()
  93. set(_dgl_library dgl-cairo)
  94. elseif(_dpf_plugin_UI_TYPE STREQUAL "opengl")
  95. dpf__add_dgl_opengl()
  96. set(_dgl_library dgl-opengl)
  97. else()
  98. message(FATAL_ERROR "Unrecognized UI type for plugin: ${_dpf_plugin_UI_TYPE}")
  99. endif()
  100. endif()
  101. ###
  102. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_COMMON)
  103. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_DSP)
  104. dpf__ensure_sources_non_empty(_dpf_plugin_FILES_UI)
  105. ###
  106. dpf__add_static_library("${NAME}" ${_dpf_plugin_FILES_COMMON})
  107. target_include_directories("${NAME}" PUBLIC
  108. "${DPF_ROOT_DIR}/distrho")
  109. if(_dgl_library)
  110. # make sure that all code will see DGL_* definitions
  111. target_link_libraries("${NAME}" PUBLIC "${_dgl_library}-definitions")
  112. endif()
  113. dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP})
  114. target_link_libraries("${NAME}-dsp" PUBLIC "${NAME}")
  115. if(_dgl_library)
  116. dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
  117. target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library})
  118. else()
  119. add_library("${NAME}-ui" INTERFACE)
  120. endif()
  121. ###
  122. foreach(_target ${_dpf_plugin_TARGETS})
  123. if(_target STREQUAL "jack")
  124. dpf__build_jack("${NAME}" "${_dgl_library}")
  125. elseif(_target STREQUAL "ladspa")
  126. dpf__build_ladspa("${NAME}")
  127. elseif(_target STREQUAL "dssi")
  128. dpf__build_dssi("${NAME}" "${_dgl_library}")
  129. elseif(_target STREQUAL "lv2")
  130. dpf__build_lv2("${NAME}" "${_dgl_library}" "${_dpf_plugin_MONOLITHIC}")
  131. elseif(_target STREQUAL "vst")
  132. dpf__build_vst("${NAME}" "${_dgl_library}")
  133. else()
  134. message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}")
  135. endif()
  136. endforeach()
  137. endfunction()
  138. # ------------------------------------------------------------------------------
  139. # DPF private functions (prefixed with `dpf__`)
  140. # ------------------------------------------------------------------------------
  141. # Note: The $<0:> trick is to prevent MSVC from appending the build type
  142. # to the output directory.
  143. #
  144. # dpf__build_jack
  145. # ------------------------------------------------------------------------------
  146. #
  147. # Add build rules for a JACK program.
  148. #
  149. function(dpf__build_jack NAME DGL_LIBRARY)
  150. find_package(PkgConfig)
  151. pkg_check_modules(JACK "jack")
  152. if(NOT JACK_FOUND)
  153. dpf__warn_once_only(missing_jack
  154. "JACK is not found, skipping the `jack` plugin targets")
  155. return()
  156. endif()
  157. dpf__create_dummy_source_list(_no_srcs)
  158. dpf__add_executable("${NAME}-jack" ${_no_srcs})
  159. dpf__add_plugin_main("${NAME}-jack" "jack")
  160. dpf__add_ui_main("${NAME}-jack" "jack" "${DGL_LIBRARY}")
  161. target_link_libraries("${NAME}-jack" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  162. set_target_properties("${NAME}-jack" PROPERTIES
  163. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  164. OUTPUT_NAME "${NAME}")
  165. target_include_directories("${NAME}-jack" PRIVATE ${JACK_INCLUDE_DIRS})
  166. target_link_libraries("${NAME}-jack" PRIVATE ${JACK_LIBRARIES})
  167. link_directories(${JACK_LIBRARY_DIRS})
  168. endfunction()
  169. # dpf__build_ladspa
  170. # ------------------------------------------------------------------------------
  171. #
  172. # Add build rules for a DSSI plugin.
  173. #
  174. function(dpf__build_ladspa NAME)
  175. dpf__create_dummy_source_list(_no_srcs)
  176. dpf__add_module("${NAME}-ladspa" ${_no_srcs})
  177. dpf__add_plugin_main("${NAME}-ladspa" "ladspa")
  178. target_link_libraries("${NAME}-ladspa" PRIVATE "${NAME}-dsp")
  179. set_target_properties("${NAME}-ladspa" PROPERTIES
  180. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  181. OUTPUT_NAME "${NAME}-ladspa"
  182. PREFIX "")
  183. endfunction()
  184. # dpf__build_dssi
  185. # ------------------------------------------------------------------------------
  186. #
  187. # Add build rules for a DSSI plugin.
  188. #
  189. function(dpf__build_dssi NAME DGL_LIBRARY)
  190. find_package(PkgConfig)
  191. pkg_check_modules(LIBLO "liblo")
  192. if(NOT LIBLO_FOUND)
  193. dpf__warn_once_only(missing_liblo
  194. "liblo is not found, skipping the `dssi` plugin targets")
  195. return()
  196. endif()
  197. dpf__create_dummy_source_list(_no_srcs)
  198. dpf__add_module("${NAME}-dssi" ${_no_srcs})
  199. dpf__add_plugin_main("${NAME}-dssi" "dssi")
  200. target_link_libraries("${NAME}-dssi" PRIVATE "${NAME}-dsp")
  201. set_target_properties("${NAME}-dssi" PROPERTIES
  202. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  203. OUTPUT_NAME "${NAME}-dssi"
  204. PREFIX "")
  205. if(DGL_LIBRARY)
  206. dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs})
  207. dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${DGL_LIBRARY}")
  208. target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui")
  209. set_target_properties("${NAME}-dssi-ui" PROPERTIES
  210. RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>"
  211. OUTPUT_NAME "${NAME}_ui")
  212. target_include_directories("${NAME}-dssi-ui" PRIVATE ${LIBLO_INCLUDE_DIRS})
  213. target_link_libraries("${NAME}-dssi-ui" PRIVATE ${LIBLO_LIBRARIES})
  214. link_directories(${LIBLO_LIBRARY_DIRS})
  215. endif()
  216. endfunction()
  217. # dpf__build_lv2
  218. # ------------------------------------------------------------------------------
  219. #
  220. # Add build rules for a LV2 plugin.
  221. #
  222. function(dpf__build_lv2 NAME DGL_LIBRARY MONOLITHIC)
  223. dpf__create_dummy_source_list(_no_srcs)
  224. dpf__add_module("${NAME}-lv2" ${_no_srcs})
  225. dpf__add_plugin_main("${NAME}-lv2" "lv2")
  226. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-dsp")
  227. set_target_properties("${NAME}-lv2" PROPERTIES
  228. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  229. OUTPUT_NAME "${NAME}_dsp"
  230. PREFIX "")
  231. if(DGL_LIBRARY)
  232. if(MONOLITHIC)
  233. dpf__add_ui_main("${NAME}-lv2" "lv2" "${DGL_LIBRARY}")
  234. target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui")
  235. set_target_properties("${NAME}-lv2" PROPERTIES
  236. OUTPUT_NAME "${NAME}")
  237. else()
  238. dpf__add_module("${NAME}-lv2-ui" ${_no_srcs})
  239. dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${DGL_LIBRARY}")
  240. target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui")
  241. set_target_properties("${NAME}-lv2-ui" PROPERTIES
  242. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2/$<0:>"
  243. OUTPUT_NAME "${NAME}_ui"
  244. PREFIX "")
  245. endif()
  246. endif()
  247. dpf__add_lv2_ttl_generator()
  248. add_dependencies("${NAME}-lv2" lv2_ttl_generator)
  249. add_custom_command(TARGET "${NAME}-lv2" POST_BUILD
  250. COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR}
  251. "$<TARGET_FILE:lv2_ttl_generator>"
  252. "$<TARGET_FILE:${NAME}-lv2>"
  253. WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}.lv2")
  254. endfunction()
  255. # dpf__build_vst
  256. # ------------------------------------------------------------------------------
  257. #
  258. # Add build rules for a VST plugin.
  259. #
  260. function(dpf__build_vst NAME DGL_LIBRARY)
  261. dpf__create_dummy_source_list(_no_srcs)
  262. dpf__add_module("${NAME}-vst" ${_no_srcs})
  263. dpf__add_plugin_main("${NAME}-vst" "vst")
  264. dpf__add_ui_main("${NAME}-vst" "vst" "${DGL_LIBRARY}")
  265. target_link_libraries("${NAME}-vst" PRIVATE "${NAME}-dsp" "${NAME}-ui")
  266. set_target_properties("${NAME}-vst" PROPERTIES
  267. LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
  268. OUTPUT_NAME "${NAME}-vst"
  269. PREFIX "")
  270. endfunction()
  271. # dpf__add_dgl_cairo
  272. # ------------------------------------------------------------------------------
  273. #
  274. # Add the Cairo variant of DGL, if not already available.
  275. #
  276. function(dpf__add_dgl_cairo)
  277. if(TARGET dgl-cairo)
  278. return()
  279. endif()
  280. find_package(PkgConfig)
  281. pkg_check_modules(CAIRO "cairo" REQUIRED)
  282. dpf__add_static_library(dgl-cairo STATIC
  283. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  284. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  285. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  286. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  287. "${DPF_ROOT_DIR}/dgl/src/Resources.cpp"
  288. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  289. "${DPF_ROOT_DIR}/dgl/src/Cairo.cpp"
  290. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp")
  291. if(NOT APPLE)
  292. target_sources(dgl-cairo PRIVATE
  293. "${DPF_ROOT_DIR}/dgl/src/Window.cpp")
  294. else()
  295. target_sources(dgl-cairo PRIVATE
  296. "${DPF_ROOT_DIR}/dgl/src/Window.mm")
  297. endif()
  298. target_include_directories(dgl-cairo PUBLIC
  299. "${DPF_ROOT_DIR}/dgl")
  300. dpf__add_dgl_system_libs()
  301. target_link_libraries(dgl-cairo PRIVATE dgl-system-libs)
  302. add_library(dgl-cairo-definitions INTERFACE)
  303. target_compile_definitions(dgl-cairo-definitions INTERFACE "DGL_CAIRO" "HAVE_CAIRO")
  304. target_include_directories(dgl-cairo PUBLIC ${CAIRO_INCLUDE_DIRS})
  305. target_link_libraries(dgl-cairo PRIVATE dgl-cairo-definitions ${CAIRO_LIBRARIES})
  306. link_directories(${CAIRO_LIBRARY_DIRS})
  307. endfunction()
  308. # dpf__add_dgl_opengl
  309. # ------------------------------------------------------------------------------
  310. #
  311. # Add the OpenGL variant of DGL, if not already available.
  312. #
  313. function(dpf__add_dgl_opengl)
  314. if(TARGET dgl-opengl)
  315. return()
  316. endif()
  317. if(NOT OpenGL_GL_PREFERENCE)
  318. set(OpenGL_GL_PREFERENCE "LEGACY")
  319. endif()
  320. find_package(OpenGL REQUIRED)
  321. dpf__add_static_library(dgl-opengl STATIC
  322. "${DPF_ROOT_DIR}/dgl/src/Application.cpp"
  323. "${DPF_ROOT_DIR}/dgl/src/Color.cpp"
  324. "${DPF_ROOT_DIR}/dgl/src/Geometry.cpp"
  325. "${DPF_ROOT_DIR}/dgl/src/ImageBase.cpp"
  326. "${DPF_ROOT_DIR}/dgl/src/Resources.cpp"
  327. "${DPF_ROOT_DIR}/dgl/src/Widget.cpp"
  328. "${DPF_ROOT_DIR}/dgl/src/OpenGL.cpp"
  329. "${DPF_ROOT_DIR}/dgl/src/Image.cpp"
  330. "${DPF_ROOT_DIR}/dgl/src/ImageWidgets.cpp"
  331. "${DPF_ROOT_DIR}/dgl/src/NanoVG.cpp"
  332. "${DPF_ROOT_DIR}/dgl/src/WidgetPrivateData.cpp")
  333. if(NOT APPLE)
  334. target_sources(dgl-opengl PRIVATE
  335. "${DPF_ROOT_DIR}/dgl/src/Window.cpp")
  336. else()
  337. target_sources(dgl-opengl PRIVATE
  338. "${DPF_ROOT_DIR}/dgl/src/Window.mm")
  339. endif()
  340. target_include_directories(dgl-opengl PUBLIC
  341. "${DPF_ROOT_DIR}/dgl")
  342. dpf__add_dgl_system_libs()
  343. target_link_libraries(dgl-opengl PRIVATE dgl-system-libs)
  344. add_library(dgl-opengl-definitions INTERFACE)
  345. target_compile_definitions(dgl-opengl-definitions INTERFACE "DGL_OPENGL" "HAVE_OPENGL")
  346. target_include_directories(dgl-opengl PUBLIC "${OPENGL_INCLUDE_DIR}")
  347. target_link_libraries(dgl-opengl PRIVATE dgl-opengl-definitions "${OPENGL_gl_LIBRARY}")
  348. endfunction()
  349. # dpf__add_dgl_system_libs
  350. # ------------------------------------------------------------------------------
  351. #
  352. # Find system libraries required by DGL and add them as an interface target.
  353. #
  354. function(dpf__add_dgl_system_libs)
  355. if(TARGET dgl-system-libs)
  356. return()
  357. endif()
  358. add_library(dgl-system-libs INTERFACE)
  359. if(HAIKU)
  360. target_link_libraries(dgl-system-libs INTERFACE "be")
  361. elseif(WIN32)
  362. target_link_libraries(dgl-system-libs INTERFACE "gdi32" "comdlg32")
  363. elseif(APPLE)
  364. find_library(APPLE_COCOA_FRAMEWORK "Cocoa")
  365. target_link_libraries(dgl-system-libs INTERFACE "${APPLE_COCOA_FRAMEWORK}")
  366. else()
  367. find_package(X11 REQUIRED)
  368. target_include_directories(dgl-system-libs INTERFACE "${X11_INCLUDE_DIR}")
  369. target_link_libraries(dgl-system-libs INTERFACE "${X11_X11_LIB}")
  370. endif()
  371. endfunction()
  372. # dpf__add_executable
  373. # ------------------------------------------------------------------------------
  374. #
  375. # Adds an executable target, and set some default properties on the target.
  376. #
  377. function(dpf__add_executable NAME)
  378. add_executable("${NAME}" ${ARGN})
  379. set_target_properties("${NAME}" PROPERTIES
  380. POSITION_INDEPENDENT_CODE TRUE
  381. C_VISIBILITY_PRESET "hidden"
  382. CXX_VISIBILITY_PRESET "hidden"
  383. VISIBILITY_INLINES_HIDDEN TRUE)
  384. endfunction()
  385. # dpf__add_module
  386. # ------------------------------------------------------------------------------
  387. #
  388. # Adds a module target, and set some default properties on the target.
  389. #
  390. function(dpf__add_module NAME)
  391. add_library("${NAME}" MODULE ${ARGN})
  392. set_target_properties("${NAME}" PROPERTIES
  393. POSITION_INDEPENDENT_CODE TRUE
  394. C_VISIBILITY_PRESET "hidden"
  395. CXX_VISIBILITY_PRESET "hidden"
  396. VISIBILITY_INLINES_HIDDEN TRUE)
  397. if ((NOT WIN32 AND NOT APPLE) OR MINGW)
  398. target_link_libraries("${NAME}" PRIVATE "-Wl,--no-undefined")
  399. endif()
  400. endfunction()
  401. # dpf__add_static_library
  402. # ------------------------------------------------------------------------------
  403. #
  404. # Adds a static library target, and set some default properties on the target.
  405. #
  406. function(dpf__add_static_library NAME)
  407. add_library("${NAME}" STATIC ${ARGN})
  408. set_target_properties("${NAME}" PROPERTIES
  409. POSITION_INDEPENDENT_CODE TRUE
  410. C_VISIBILITY_PRESET "hidden"
  411. CXX_VISIBILITY_PRESET "hidden"
  412. VISIBILITY_INLINES_HIDDEN TRUE)
  413. endfunction()
  414. # dpf__add_plugin_main
  415. # ------------------------------------------------------------------------------
  416. #
  417. # Adds plugin code to the given target.
  418. #
  419. function(dpf__add_plugin_main NAME TARGET)
  420. target_sources("${NAME}" PRIVATE
  421. "${DPF_ROOT_DIR}/distrho/DistrhoPluginMain.cpp")
  422. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  423. endfunction()
  424. # dpf__add_ui_main
  425. # ------------------------------------------------------------------------------
  426. #
  427. # Adds UI code to the given target (only if the target has UI).
  428. #
  429. function(dpf__add_ui_main NAME TARGET HAS_UI)
  430. if(HAS_UI)
  431. target_sources("${NAME}" PRIVATE
  432. "${DPF_ROOT_DIR}/distrho/DistrhoUIMain.cpp")
  433. dpf__add_plugin_target_definition("${NAME}" "${TARGET}")
  434. endif()
  435. endfunction()
  436. # dpf__add_plugin_target_definition
  437. # ------------------------------------------------------------------------------
  438. #
  439. # Adds the plugins target macro definition.
  440. # This selects which entry file is compiled according to the target type.
  441. #
  442. function(dpf__add_plugin_target_definition NAME TARGET)
  443. string(TOUPPER "${TARGET}" _upperTarget)
  444. target_compile_definitions("${NAME}" PRIVATE "DISTRHO_PLUGIN_TARGET_${_upperTarget}")
  445. endfunction()
  446. # dpf__add_lv2_ttl_generator
  447. # ------------------------------------------------------------------------------
  448. #
  449. # Build the LV2 TTL generator.
  450. #
  451. function(dpf__add_lv2_ttl_generator)
  452. if(TARGET lv2_ttl_generator)
  453. return()
  454. endif()
  455. add_executable(lv2_ttl_generator "${DPF_ROOT_DIR}/utils/lv2-ttl-generator/lv2_ttl_generator.c")
  456. if(NOT WINDOWS AND NOT APPLE AND NOT HAIKU)
  457. target_link_libraries(lv2_ttl_generator "dl")
  458. endif()
  459. endfunction()
  460. # dpf__ensure_sources_non_empty
  461. # ------------------------------------------------------------------------------
  462. #
  463. # Ensure the given source list contains at least one file.
  464. # The function appends an empty source file to the list if necessary.
  465. # This is useful when CMake does not permit to add targets without sources.
  466. #
  467. function(dpf__ensure_sources_non_empty VAR)
  468. if(NOT "" STREQUAL "${${VAR}}")
  469. return()
  470. endif()
  471. set(_file "${CMAKE_CURRENT_BINARY_DIR}/_dpf_empty.c")
  472. if(NOT EXISTS "${_file}")
  473. file(WRITE "${_file}" "")
  474. endif()
  475. set("${VAR}" "${_file}" PARENT_SCOPE)
  476. endfunction()
  477. # dpf__create_dummy_source_list
  478. # ------------------------------------------------------------------------------
  479. #
  480. # Create a dummy source list which is equivalent to compiling nothing.
  481. # This is only for compatibility with older CMake versions, which refuse to add
  482. # targets without any sources.
  483. #
  484. macro(dpf__create_dummy_source_list VAR)
  485. set("${VAR}")
  486. if(CMAKE_VERSION VERSION_LESS "3.11")
  487. dpf__ensure_sources_non_empty("${VAR}")
  488. endif()
  489. endmacro()
  490. # dpf__warn_once
  491. # ------------------------------------------------------------------------------
  492. #
  493. # Prints a warning message once only.
  494. #
  495. function(dpf__warn_once_only TOKEN MESSAGE)
  496. get_property(_warned GLOBAL PROPERTY "dpf__have_warned_${TOKEN}")
  497. if(NOT _warned)
  498. set_property(GLOBAL PROPERTY "dpf__have_warned_${TOKEN}" TRUE)
  499. message(WARNING "${MESSAGE}")
  500. endif()
  501. endfunction()