From a338aa6559c8d8d79d0e062f6a2963f511c667c0 Mon Sep 17 00:00:00 2001 From: AnClark Liu Date: Wed, 28 Dec 2022 12:20:05 +0000 Subject: [PATCH] CMake: Add external UI support Squashed commit of the following: commit d1a682345862ae6cc1cf83524febdb5076aa4827 Author: AnClark Date: Thu Dec 15 09:03:18 2022 +0800 Refactor CMake var _dgl_library -> _dgl_has_ui in plugin build functions Plugin build functions (dpf__build_) invokes dpf__add_ui_main() which has a parameter HAS_UI. This parameter acts like a switch, controlling if DistrhoPluginMain.cpp shall be compiled. Before this patch, value of _dgl_library is passed into HAS_UI. However, this will make it ambiguous. Variable _dgl_library should only be served as a flag of DGL UI type, and should not be a switch of whether to build DistrhoPluginMain.cpp or not. What's more, since DPF's CMake build system starts to support external UI, which is not limited to DGL, simply checking _dgl_library for dgl__add_ui_main() is no longer relevant. So, instead, I use variable _dgl_has_ui which keeps to the point. It will be set to ON if _dgl_library is non-empty or _dgl_external is ON. commit 2d162a16b6894879a941b131553aded7d451eebe Author: AnClark Liu Date: Tue Dec 13 23:13:49 2022 +0800 Build ExternalUI and EmbedExternalUI example plugins with cmake Note: Build CLAP versions as well. commit 2cf060910e8d7589f9b21842f6b0ae802bc89d0a Author: AnClark Liu Date: Tue Dec 13 23:07:40 2022 +0800 Add external UI support for cmake Signed-off-by: falkTX --- CMakeLists.txt | 3 +- cmake/DPF-plugin.cmake | 69 +++++++++++++------- examples/EmbedExternalUI/CMakeLists.txt | 13 ++++ examples/EmbedExternalUI/DistrhoPluginInfo.h | 1 + examples/ExternalUI/CMakeLists.txt | 13 ++++ examples/ExternalUI/DistrhoPluginInfo.h | 1 + 6 files changed, 74 insertions(+), 26 deletions(-) create mode 100644 examples/EmbedExternalUI/CMakeLists.txt create mode 100644 examples/ExternalUI/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index f77596233..ff50b7686 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,8 @@ if(DPF_EXAMPLES) add_subdirectory("examples/CairoUI") endif() endif() - #add_subdirectory("examples/ExternalUI") + add_subdirectory("examples/ExternalUI") + add_subdirectory("examples/EmbedExternalUI") add_subdirectory("examples/FileHandling") add_subdirectory("examples/Info") add_subdirectory("examples/Latency") diff --git a/cmake/DPF-plugin.cmake b/cmake/DPF-plugin.cmake index 81552770c..1d31daf99 100644 --- a/cmake/DPF-plugin.cmake +++ b/cmake/DPF-plugin.cmake @@ -75,7 +75,7 @@ include(CMakeParseArguments) # `jack`, `ladspa`, `dssi`, `lv2`, `vst2`, `vst3`, `clap` # # `UI_TYPE` -# the user interface type: `opengl` (default), `cairo` +# the user interface type: `opengl` (default), `cairo`, `external` # # `MONOLITHIC` # build LV2 as a single binary for UI and DSP @@ -101,6 +101,7 @@ function(dpf_add_plugin NAME) endif() set(_dgl_library) + set(_dgl_external OFF) if(_dpf_plugin_FILES_UI) if(_dpf_plugin_UI_TYPE STREQUAL "cairo") dpf__add_dgl_cairo("${_dpf_plugin_NO_SHARED_RESOURCES}") @@ -108,11 +109,18 @@ function(dpf_add_plugin NAME) elseif(_dpf_plugin_UI_TYPE STREQUAL "opengl") dpf__add_dgl_opengl("${_dpf_plugin_NO_SHARED_RESOURCES}") set(_dgl_library dgl-opengl) + elseif(_dpf_plugin_UI_TYPE STREQUAL "external") + set(_dgl_external ON) else() message(FATAL_ERROR "Unrecognized UI type for plugin: ${_dpf_plugin_UI_TYPE}") endif() endif() + set(_dgl_has_ui OFF) + if(_dgl_library OR _dgl_external) + set(_dgl_has_ui ON) + endif() + ### dpf__ensure_sources_non_empty(_dpf_plugin_FILES_COMMON) dpf__ensure_sources_non_empty(_dpf_plugin_FILES_DSP) @@ -127,17 +135,20 @@ function(dpf_add_plugin NAME) target_link_libraries("${NAME}" PRIVATE "dl") endif() - if(_dgl_library) + if(_dgl_library AND NOT _dgl_external) # make sure that all code will see DGL_* definitions target_link_libraries("${NAME}" PUBLIC "${_dgl_library}-definitions" dgl-system-libs-definitions) + elseif(_dgl_external) + target_link_libraries("${NAME}" PUBLIC + dgl-system-libs-definitions) endif() dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP}) target_link_libraries("${NAME}-dsp" PUBLIC "${NAME}") - if(_dgl_library) + if(_dgl_library AND NOT _dgl_external) dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI}) target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library}) if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU)) @@ -145,6 +156,14 @@ function(dpf_add_plugin NAME) endif() # add the files containing Objective-C classes dpf__add_plugin_specific_ui_sources("${NAME}-ui") + elseif(_dgl_external) + dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI}) + target_link_libraries("${NAME}-ui" PUBLIC "${NAME}") + if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU)) + target_link_libraries("${NAME}-ui" PRIVATE "dl") + endif() + # add the files containing Objective-C classes + dpf__add_plugin_specific_ui_sources("${NAME}-ui") else() add_library("${NAME}-ui" INTERFACE) endif() @@ -152,19 +171,19 @@ function(dpf_add_plugin NAME) ### foreach(_target ${_dpf_plugin_TARGETS}) if(_target STREQUAL "jack") - dpf__build_jack("${NAME}" "${_dgl_library}") + dpf__build_jack("${NAME}" "${_dgl_has_ui}") elseif(_target STREQUAL "ladspa") dpf__build_ladspa("${NAME}") elseif(_target STREQUAL "dssi") - dpf__build_dssi("${NAME}" "${_dgl_library}") + dpf__build_dssi("${NAME}" "${_dgl_has_ui}") elseif(_target STREQUAL "lv2") - dpf__build_lv2("${NAME}" "${_dgl_library}" "${_dpf_plugin_MONOLITHIC}") + dpf__build_lv2("${NAME}" "${_dgl_has_ui}" "${_dpf_plugin_MONOLITHIC}") elseif(_target STREQUAL "vst2") - dpf__build_vst2("${NAME}" "${_dgl_library}") + dpf__build_vst2("${NAME}" "${_dgl_has_ui}") elseif(_target STREQUAL "vst3") - dpf__build_vst3("${NAME}" "${_dgl_library}") + dpf__build_vst3("${NAME}" "${_dgl_has_ui}") elseif(_target STREQUAL "clap") - dpf__build_clap("${NAME}" "${_dgl_library}") + dpf__build_clap("${NAME}" "${_dgl_has_ui}") else() message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}") endif() @@ -184,12 +203,12 @@ endfunction() # # Add build rules for a JACK/Standalone program. # -function(dpf__build_jack NAME DGL_LIBRARY) +function(dpf__build_jack NAME HAS_UI) dpf__create_dummy_source_list(_no_srcs) dpf__add_executable("${NAME}-jack" ${_no_srcs}) dpf__add_plugin_main("${NAME}-jack" "jack") - dpf__add_ui_main("${NAME}-jack" "jack" "${DGL_LIBRARY}") + dpf__add_ui_main("${NAME}-jack" "jack" "${HAS_UI}") target_link_libraries("${NAME}-jack" PRIVATE "${NAME}-dsp" "${NAME}-ui") set_target_properties("${NAME}-jack" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>" @@ -267,7 +286,7 @@ endfunction() # # Add build rules for a DSSI plugin. # -function(dpf__build_dssi NAME DGL_LIBRARY) +function(dpf__build_dssi NAME HAS_UI) find_package(PkgConfig) pkg_check_modules(LIBLO "liblo") if(NOT LIBLO_FOUND) @@ -288,9 +307,9 @@ function(dpf__build_dssi NAME DGL_LIBRARY) OUTPUT_NAME "${NAME}-dssi" PREFIX "") - if(DGL_LIBRARY) + if(HAS_UI) dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs}) - dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${DGL_LIBRARY}") + dpf__add_ui_main("${NAME}-dssi-ui" "dssi" "${HAS_UI}") target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui") set_target_properties("${NAME}-dssi-ui" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>" @@ -308,12 +327,12 @@ endfunction() # # Add build rules for an LV2 plugin. # -function(dpf__build_lv2 NAME DGL_LIBRARY MONOLITHIC) +function(dpf__build_lv2 NAME HAS_UI MONOLITHIC) dpf__create_dummy_source_list(_no_srcs) dpf__add_module("${NAME}-lv2" ${_no_srcs}) dpf__add_plugin_main("${NAME}-lv2" "lv2") - if(DGL_LIBRARY AND MONOLITHIC) + if(HAS_UI AND MONOLITHIC) dpf__set_module_export_list("${NAME}-lv2" "lv2") else() dpf__set_module_export_list("${NAME}-lv2" "lv2-dsp") @@ -325,15 +344,15 @@ function(dpf__build_lv2 NAME DGL_LIBRARY MONOLITHIC) OUTPUT_NAME "${NAME}_dsp" PREFIX "") - if(DGL_LIBRARY) + if(HAS_UI) if(MONOLITHIC) - dpf__add_ui_main("${NAME}-lv2" "lv2" "${DGL_LIBRARY}") + dpf__add_ui_main("${NAME}-lv2" "lv2" "${HAS_UI}") target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui") set_target_properties("${NAME}-lv2" PROPERTIES OUTPUT_NAME "${NAME}") else() dpf__add_module("${NAME}-lv2-ui" ${_no_srcs}) - dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${DGL_LIBRARY}") + dpf__add_ui_main("${NAME}-lv2-ui" "lv2" "${HAS_UI}") dpf__set_module_export_list("${NAME}-lv2-ui" "lv2-ui") target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui") set_target_properties("${NAME}-lv2-ui" PROPERTIES @@ -361,12 +380,12 @@ endfunction() # # Add build rules for a VST2 plugin. # -function(dpf__build_vst2 NAME DGL_LIBRARY) +function(dpf__build_vst2 NAME HAS_UI) dpf__create_dummy_source_list(_no_srcs) dpf__add_module("${NAME}-vst2" ${_no_srcs}) dpf__add_plugin_main("${NAME}-vst2" "vst2") - dpf__add_ui_main("${NAME}-vst2" "vst2" "${DGL_LIBRARY}") + dpf__add_ui_main("${NAME}-vst2" "vst2" "${HAS_UI}") dpf__set_module_export_list("${NAME}-vst2" "vst2") target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui") set_target_properties("${NAME}-vst2" PROPERTIES @@ -439,14 +458,14 @@ endfunction() # # Add build rules for a VST3 plugin. # -function(dpf__build_vst3 NAME DGL_LIBRARY) +function(dpf__build_vst3 NAME HAS_UI) dpf__determine_vst3_package_architecture(vst3_arch) dpf__create_dummy_source_list(_no_srcs) dpf__add_module("${NAME}-vst3" ${_no_srcs}) dpf__add_plugin_main("${NAME}-vst3" "vst3") - dpf__add_ui_main("${NAME}-vst3" "vst3" "${DGL_LIBRARY}") + dpf__add_ui_main("${NAME}-vst3" "vst3" "${HAS_UI}") dpf__set_module_export_list("${NAME}-vst3" "vst3") target_link_libraries("${NAME}-vst3" PRIVATE "${NAME}-dsp" "${NAME}-ui") set_target_properties("${NAME}-vst3" PROPERTIES @@ -481,12 +500,12 @@ endfunction() # # Add build rules for a VST2 plugin. # -function(dpf__build_clap NAME DGL_LIBRARY) +function(dpf__build_clap NAME HAS_UI) dpf__create_dummy_source_list(_no_srcs) dpf__add_module("${NAME}-clap" ${_no_srcs}) dpf__add_plugin_main("${NAME}-clap" "clap") - dpf__add_ui_main("${NAME}-clap" "clap" "${DGL_LIBRARY}") + dpf__add_ui_main("${NAME}-clap" "clap" "${HAS_UI}") dpf__set_module_export_list("${NAME}-clap" "clap") target_link_libraries("${NAME}-clap" PRIVATE "${NAME}-dsp" "${NAME}-ui") set_target_properties("${NAME}-clap" PROPERTIES diff --git a/examples/EmbedExternalUI/CMakeLists.txt b/examples/EmbedExternalUI/CMakeLists.txt new file mode 100644 index 000000000..f77208135 --- /dev/null +++ b/examples/EmbedExternalUI/CMakeLists.txt @@ -0,0 +1,13 @@ +# CMake file for DISTRHO Plugins # +# ------------------------------ # + +dpf_add_plugin(d_embed_external_ui + TARGETS lv2 vst2 vst3 clap + UI_TYPE external + FILES_DSP + EmbedExternalExamplePlugin.cpp + FILES_UI + EmbedExternalExampleUI.cpp) + +target_include_directories( + d_embed_external_ui PUBLIC ".") diff --git a/examples/EmbedExternalUI/DistrhoPluginInfo.h b/examples/EmbedExternalUI/DistrhoPluginInfo.h index 29deffed3..ab8131222 100644 --- a/examples/EmbedExternalUI/DistrhoPluginInfo.h +++ b/examples/EmbedExternalUI/DistrhoPluginInfo.h @@ -20,6 +20,7 @@ #define DISTRHO_PLUGIN_BRAND "DISTRHO" #define DISTRHO_PLUGIN_NAME "EmbedExternalUI" #define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/EmbedExternalUI" +#define DISTRHO_PLUGIN_CLAP_ID "studio.kx.distrho.examples.embed-external-ui" #define DISTRHO_PLUGIN_HAS_UI 1 #define DISTRHO_PLUGIN_HAS_EMBED_UI 1 diff --git a/examples/ExternalUI/CMakeLists.txt b/examples/ExternalUI/CMakeLists.txt new file mode 100644 index 000000000..ab56f635c --- /dev/null +++ b/examples/ExternalUI/CMakeLists.txt @@ -0,0 +1,13 @@ +# CMake file for DISTRHO Plugins # +# ------------------------------ # + +dpf_add_plugin(d_external_ui + TARGETS lv2 vst2 vst3 clap + UI_TYPE external + FILES_DSP + ExternalExamplePlugin.cpp + FILES_UI + ExternalExampleUI.cpp) + +target_include_directories( + d_external_ui PUBLIC ".") diff --git a/examples/ExternalUI/DistrhoPluginInfo.h b/examples/ExternalUI/DistrhoPluginInfo.h index 82834d8ca..253eb1581 100644 --- a/examples/ExternalUI/DistrhoPluginInfo.h +++ b/examples/ExternalUI/DistrhoPluginInfo.h @@ -20,6 +20,7 @@ #define DISTRHO_PLUGIN_BRAND "DISTRHO" #define DISTRHO_PLUGIN_NAME "ExternalUI" #define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/ExternalUI" +#define DISTRHO_PLUGIN_CLAP_ID "studio.kx.distrho.examples.external-ui" #define DISTRHO_PLUGIN_HAS_UI 1 #define DISTRHO_PLUGIN_HAS_EMBED_UI 1