11# DISTRHO Plugin Framework (DPF)
22# Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
3+ # Copyright (C) 2022 Filipe Coelho <falktx@falktx.com>
34#
45# SPDX-License-Identifier: ISC
56
2223# add_subdirectory(DPF)
2324#
2425# dpf_add_plugin(MyPlugin
25- # TARGETS lv2 vst2 vst3
26+ # TARGETS clap lv2 vst2 vst3
2627# UI_TYPE opengl
2728# FILES_DSP
2829# src/MyPlugin.cpp
@@ -71,7 +72,7 @@ include(CMakeParseArguments)
7172#
7273# `TARGETS` <tgt1>...<tgtN>
7374# a list of one of more of the following target types:
74- # `jack`, `ladspa`, `dssi`, `lv2`, `vst2`, `vst3`
75+ # `jack`, `ladspa`, `dssi`, `lv2`, `vst2`, `vst3`, `clap`
7576#
7677# `UI_TYPE` <type>
7778# the user interface type: `opengl` (default), `cairo`
@@ -90,7 +91,7 @@ include(CMakeParseArguments)
9091# list of sources which are part of both DSP and UI
9192#
9293function (dpf_add_plugin NAME )
93- set (options MONOLITHIC)
94+ set (options MONOLITHIC NO_SHARED_RESOURCES )
9495 set (oneValueArgs UI_TYPE)
9596 set (multiValueArgs TARGETS FILES_DSP FILES_UI FILES_COMMON)
9697 cmake_parse_arguments (_dpf_plugin "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
@@ -102,10 +103,10 @@ function(dpf_add_plugin NAME)
102103 set (_dgl_library)
103104 if (_dpf_plugin_FILES_UI)
104105 if (_dpf_plugin_UI_TYPE STREQUAL "cairo" )
105- dpf__add_dgl_cairo ()
106+ dpf__add_dgl_cairo (" ${_dpf_plugin_NO_SHARED_RESOURCES} " )
106107 set (_dgl_library dgl-cairo)
107108 elseif (_dpf_plugin_UI_TYPE STREQUAL "opengl" )
108- dpf__add_dgl_opengl ()
109+ dpf__add_dgl_opengl (" ${_dpf_plugin_NO_SHARED_RESOURCES} " )
109110 set (_dgl_library dgl-opengl)
110111 else ()
111112 message (FATAL_ERROR "Unrecognized UI type for plugin: ${_dpf_plugin_UI_TYPE} " )
@@ -162,6 +163,8 @@ function(dpf_add_plugin NAME)
162163 dpf__build_vst2 ("${NAME} " "${_dgl_library} " )
163164 elseif (_target STREQUAL "vst3" )
164165 dpf__build_vst3 ("${NAME} " "${_dgl_library} " )
166+ elseif (_target STREQUAL "clap" )
167+ dpf__build_clap ("${NAME} " "${_dgl_library} " )
165168 else ()
166169 message (FATAL_ERROR "Unrecognized target type for plugin: ${_target} " )
167170 endif ()
@@ -179,7 +182,7 @@ endfunction()
179182# dpf__build_jack
180183# ------------------------------------------------------------------------------
181184#
182- # Add build rules for a JACK program.
185+ # Add build rules for a JACK/Standalone program.
183186#
184187function (dpf__build_jack NAME DGL_LIBRARY )
185188 dpf__create_dummy_source_list (_no_srcs )
@@ -192,11 +195,51 @@ function(dpf__build_jack NAME DGL_LIBRARY)
192195 RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR } /bin/$<0:>"
193196 OUTPUT_NAME "${NAME} " )
194197
198+ target_compile_definitions ("${NAME} " PUBLIC "HAVE_JACK" )
199+
200+ find_package (PkgConfig )
201+ pkg_check_modules (SDL2 "sdl2" )
202+ if (SDL2_FOUND)
203+ target_compile_definitions ("${NAME} " PUBLIC "HAVE_SDL2" )
204+ target_include_directories ("${NAME} -jack" PRIVATE ${SDL2_INCLUDE_DIRS} )
205+ target_link_libraries ("${NAME} -jack" PRIVATE ${SDL2_LIBRARIES} )
206+ dpf__target_link_directories ("${NAME} -jack" ${SDL2_LIBRARY_DIRS} )
207+ endif ()
208+
209+ if (APPLE OR WIN32 )
210+ target_compile_definitions ("${NAME} " PUBLIC "HAVE_RTAUDIO" )
211+ else ()
212+ find_package (Threads )
213+ pkg_check_modules (ALSA "alsa" )
214+ pkg_check_modules (PULSEAUDIO "libpulse-simple" )
215+ if (ALSA_FOUND)
216+ target_compile_definitions ("${NAME} " PUBLIC "HAVE_ALSA" )
217+ target_include_directories ("${NAME} -jack" PRIVATE ${ALSA_INCLUDE_DIRS} )
218+ target_link_libraries ("${NAME} -jack" PRIVATE ${ALSA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
219+ dpf__target_link_directories ("${NAME} -jack" ${ALSA_LIBRARY_DIRS} )
220+ endif ()
221+ if (PULSEAUDIO_FOUND)
222+ target_compile_definitions ("${NAME} " PUBLIC "HAVE_PULSEAUDIO" )
223+ target_include_directories ("${NAME} -jack" PRIVATE ${PULSEAUDIO_INCLUDE_DIRS} )
224+ target_link_libraries ("${NAME} -jack" PRIVATE ${PULSEAUDIO_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
225+ dpf__target_link_directories ("${NAME} -jack" ${PULSEAUDIO_LIBRARY_DIRS} )
226+ endif ()
227+ if (ALSA_FOUND OR PULSEAUDIO_FOUND)
228+ target_compile_definitions ("${NAME} " PUBLIC "HAVE_RTAUDIO" )
229+ endif ()
230+ endif ()
231+
195232 # for RtAudio native fallback
196233 if (APPLE )
197234 find_library (APPLE_COREAUDIO_FRAMEWORK "CoreAudio" )
198235 find_library (APPLE_COREFOUNDATION_FRAMEWORK "CoreFoundation" )
199- target_link_libraries ("${NAME} -jack" PRIVATE "${APPLE_COREAUDIO_FRAMEWORK} " "${APPLE_COREFOUNDATION_FRAMEWORK} " )
236+ find_library (APPLE_COREMIDI_FRAMEWORK "CoreMIDI" )
237+ target_link_libraries ("${NAME} -jack" PRIVATE
238+ "${APPLE_COREAUDIO_FRAMEWORK} "
239+ "${APPLE_COREFOUNDATION_FRAMEWORK} "
240+ "${APPLE_COREMIDI_FRAMEWORK} " )
241+ elseif (WIN32 )
242+ target_link_libraries ("${NAME} -jack" PRIVATE "dsound" "ole32" "winmm" )
200243 endif ()
201244endfunction ()
202245
@@ -233,8 +276,6 @@ function(dpf__build_dssi NAME DGL_LIBRARY)
233276 return ()
234277 endif ()
235278
236- link_directories (${LIBLO_LIBRARY_DIRS} )
237-
238279 dpf__create_dummy_source_list (_no_srcs )
239280
240281 dpf__add_module ("${NAME} -dssi" ${_no_srcs} )
@@ -255,8 +296,10 @@ function(dpf__build_dssi NAME DGL_LIBRARY)
255296 RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR } /bin/${NAME} -dssi/$<0:>"
256297 OUTPUT_NAME "${NAME} _ui" )
257298
299+ target_compile_definitions ("${NAME} " PUBLIC "HAVE_LIBLO" )
258300 target_include_directories ("${NAME} -dssi-ui" PRIVATE ${LIBLO_INCLUDE_DIRS} )
259301 target_link_libraries ("${NAME} -dssi-ui" PRIVATE ${LIBLO_LIBRARIES} )
302+ dpf__target_link_directories ("${NAME} -dssi-ui" ${LIBLO_LIBRARY_DIRS} )
260303 endif ()
261304endfunction ()
262305
@@ -306,6 +349,7 @@ function(dpf__build_lv2 NAME DGL_LIBRARY MONOLITHIC)
306349
307350 add_custom_command (TARGET "${NAME} -lv2" POST_BUILD
308351 COMMAND
352+ ${CMAKE_CROSSCOMPILING_EMULATOR}
309353 "$<TARGET_FILE :lv2_ttl_generator >"
310354 "$<TARGET_FILE :${NAME} -lv2 >"
311355 WORKING_DIRECTORY "${PROJECT_BINARY_DIR } /bin/${NAME} .lv2"
@@ -432,12 +476,45 @@ function(dpf__build_vst3 NAME DGL_LIBRARY)
432476 endif ()
433477endfunction ()
434478
479+ # dpf__build_clap
480+ # ------------------------------------------------------------------------------
481+ #
482+ # Add build rules for a VST2 plugin.
483+ #
484+ function (dpf__build_clap NAME DGL_LIBRARY )
485+ dpf__create_dummy_source_list (_no_srcs )
486+
487+ dpf__add_module ("${NAME} -clap" ${_no_srcs} )
488+ dpf__add_plugin_main ("${NAME} -clap" "clap" )
489+ dpf__add_ui_main ("${NAME} -clap" "clap" "${DGL_LIBRARY} " )
490+ dpf__set_module_export_list ("${NAME} -clap" "clap" )
491+ target_link_libraries ("${NAME} -clap" PRIVATE "${NAME} -dsp" "${NAME} -ui" )
492+ set_target_properties ("${NAME} -clap" PROPERTIES
493+ LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR } /bin/$<0:>"
494+ ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR } /obj/clap/$<0:>"
495+ OUTPUT_NAME "${NAME} "
496+ PREFIX ""
497+ SUFFIX ".clap" )
498+
499+ if (APPLE )
500+ set_target_properties ("${NAME} -clap" PROPERTIES
501+ LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR } /bin/${NAME} .clap/Contents/MacOS/$<0:>"
502+ OUTPUT_NAME "${NAME} "
503+ SUFFIX "" )
504+ set (INFO_PLIST_PROJECT_NAME "${NAME} " )
505+ configure_file ("${DPF_ROOT_DIR} /utils/plugin.bundle/Contents/Info.plist"
506+ "${PROJECT_BINARY_DIR } /bin/${NAME} .clap/Contents/Info.plist" @ONLY )
507+ file (COPY "${DPF_ROOT_DIR} /utils/plugin.bundle/Contents/PkgInfo"
508+ DESTINATION "${PROJECT_BINARY_DIR } /bin/${NAME} .clap/Contents" )
509+ endif ()
510+ endfunction ()
511+
435512# dpf__add_dgl_cairo
436513# ------------------------------------------------------------------------------
437514#
438515# Add the Cairo variant of DGL, if not already available.
439516#
440- function (dpf__add_dgl_cairo )
517+ function (dpf__add_dgl_cairo NO_SHARED_RESOURCES )
441518 if (TARGET dgl-cairo)
442519 return ()
443520 endif ()
@@ -455,7 +532,6 @@ function(dpf__add_dgl_cairo)
455532 "${DPF_ROOT_DIR} /dgl/src/Geometry.cpp"
456533 "${DPF_ROOT_DIR} /dgl/src/ImageBase.cpp"
457534 "${DPF_ROOT_DIR} /dgl/src/ImageBaseWidgets.cpp"
458- "${DPF_ROOT_DIR} /dgl/src/Resources.cpp"
459535 "${DPF_ROOT_DIR} /dgl/src/SubWidget.cpp"
460536 "${DPF_ROOT_DIR} /dgl/src/SubWidgetPrivateData.cpp"
461537 "${DPF_ROOT_DIR} /dgl/src/TopLevelWidget.cpp"
@@ -465,11 +541,16 @@ function(dpf__add_dgl_cairo)
465541 "${DPF_ROOT_DIR} /dgl/src/Window.cpp"
466542 "${DPF_ROOT_DIR} /dgl/src/WindowPrivateData.cpp"
467543 "${DPF_ROOT_DIR} /dgl/src/Cairo.cpp" )
544+ if (NO_SHARED_RESOURCES)
545+ target_compile_definitions (dgl-cairo PUBLIC "DGL_NO_SHARED_RESOURCES" )
546+ else ()
547+ target_sources (dgl-cairo PRIVATE "${DPF_ROOT_DIR} /dgl/src/Resources.cpp" )
548+ endif ()
468549 if (NOT APPLE )
469550 target_sources (dgl-cairo PRIVATE
470551 "${DPF_ROOT_DIR} /dgl/src/pugl.cpp" )
471552 else ()
472- target_sources (dgl-opengl PRIVATE
553+ target_sources (dgl-cairo PRIVATE
473554 "${DPF_ROOT_DIR} /dgl/src/pugl.mm" )
474555 endif ()
475556 target_include_directories (dgl-cairo PUBLIC
@@ -497,7 +578,7 @@ endfunction()
497578#
498579# Add the OpenGL variant of DGL, if not already available.
499580#
500- function (dpf__add_dgl_opengl )
581+ function (dpf__add_dgl_opengl NO_SHARED_RESOURCES )
501582 if (TARGET dgl-opengl)
502583 return ()
503584 endif ()
@@ -516,7 +597,6 @@ function(dpf__add_dgl_opengl)
516597 "${DPF_ROOT_DIR} /dgl/src/Geometry.cpp"
517598 "${DPF_ROOT_DIR} /dgl/src/ImageBase.cpp"
518599 "${DPF_ROOT_DIR} /dgl/src/ImageBaseWidgets.cpp"
519- "${DPF_ROOT_DIR} /dgl/src/Resources.cpp"
520600 "${DPF_ROOT_DIR} /dgl/src/SubWidget.cpp"
521601 "${DPF_ROOT_DIR} /dgl/src/SubWidgetPrivateData.cpp"
522602 "${DPF_ROOT_DIR} /dgl/src/TopLevelWidget.cpp"
@@ -527,6 +607,11 @@ function(dpf__add_dgl_opengl)
527607 "${DPF_ROOT_DIR} /dgl/src/WindowPrivateData.cpp"
528608 "${DPF_ROOT_DIR} /dgl/src/OpenGL.cpp"
529609 "${DPF_ROOT_DIR} /dgl/src/NanoVG.cpp" )
610+ if (NO_SHARED_RESOURCES)
611+ target_compile_definitions (dgl-opengl PUBLIC "DGL_NO_SHARED_RESOURCES" )
612+ else ()
613+ target_sources (dgl-opengl PRIVATE "${DPF_ROOT_DIR} /dgl/src/Resources.cpp" )
614+ endif ()
530615 if (NOT APPLE )
531616 target_sources (dgl-opengl PRIVATE
532617 "${DPF_ROOT_DIR} /dgl/src/pugl.cpp" )
@@ -700,6 +785,9 @@ function(dpf__set_target_defaults NAME)
700785 target_compile_options ("${NAME} " PUBLIC "/UTF-8" )
701786 target_compile_definitions ("${NAME} " PUBLIC "_CRT_SECURE_NO_WARNINGS" )
702787 endif ()
788+ if (CMAKE_COMPILER_IS_GNUCXX)
789+ target_compile_options ("${NAME} " PUBLIC "-fno-gnu-unique" )
790+ endif ()
703791endfunction ()
704792
705793# dpf__add_plugin_main
@@ -784,6 +872,20 @@ macro(dpf__create_dummy_source_list VAR)
784872 endif ()
785873endmacro ()
786874
875+ # dpf__target_link_directories
876+ # ------------------------------------------------------------------------------
877+ #
878+ # Call `target_link_directories` if cmake >= 3.13,
879+ # otherwise fallback to global `link_directories`.
880+ #
881+ macro (dpf__target_link_directories NAME DIRS )
882+ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13" )
883+ target_link_directories ("${NAME} " PUBLIC ${DIRS} )
884+ else ()
885+ link_directories (${DIRS} )
886+ endif ()
887+ endmacro ()
888+
787889# dpf__warn_once
788890# ------------------------------------------------------------------------------
789891#
0 commit comments