Browse Source

CMake: Add external UI support

Squashed commit of the following:

commit d1a6823458
Author: AnClark <clarklaw4701@qq.com>
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_<PLUGIN_TYPE>) 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 2d162a16b6
Author: AnClark Liu <anclarkliu@outlook.com>
Date:   Tue Dec 13 23:13:49 2022 +0800

    Build ExternalUI and EmbedExternalUI example plugins with cmake

    Note: Build CLAP versions as well.

commit 2cf060910e
Author: AnClark Liu <anclarkliu@outlook.com>
Date:   Tue Dec 13 23:07:40 2022 +0800

    Add external UI support for cmake

Signed-off-by: falkTX <falktx@falktx.com>
pull/397/head
AnClark Liu falkTX <falktx@falktx.com> 2 years ago
parent
commit
a338aa6559
6 changed files with 74 additions and 26 deletions
  1. +2
    -1
      CMakeLists.txt
  2. +44
    -25
      cmake/DPF-plugin.cmake
  3. +13
    -0
      examples/EmbedExternalUI/CMakeLists.txt
  4. +1
    -0
      examples/EmbedExternalUI/DistrhoPluginInfo.h
  5. +13
    -0
      examples/ExternalUI/CMakeLists.txt
  6. +1
    -0
      examples/ExternalUI/DistrhoPluginInfo.h

+ 2
- 1
CMakeLists.txt View File

@@ -47,7 +47,8 @@ if(DPF_EXAMPLES)
add_subdirectory("examples/CairoUI") add_subdirectory("examples/CairoUI")
endif() endif()
endif() endif()
#add_subdirectory("examples/ExternalUI")
add_subdirectory("examples/ExternalUI")
add_subdirectory("examples/EmbedExternalUI")
add_subdirectory("examples/FileHandling") add_subdirectory("examples/FileHandling")
add_subdirectory("examples/Info") add_subdirectory("examples/Info")
add_subdirectory("examples/Latency") add_subdirectory("examples/Latency")


+ 44
- 25
cmake/DPF-plugin.cmake View File

@@ -75,7 +75,7 @@ include(CMakeParseArguments)
# `jack`, `ladspa`, `dssi`, `lv2`, `vst2`, `vst3`, `clap` # `jack`, `ladspa`, `dssi`, `lv2`, `vst2`, `vst3`, `clap`
# #
# `UI_TYPE` <type> # `UI_TYPE` <type>
# the user interface type: `opengl` (default), `cairo`
# the user interface type: `opengl` (default), `cairo`, `external`
# #
# `MONOLITHIC` # `MONOLITHIC`
# build LV2 as a single binary for UI and DSP # build LV2 as a single binary for UI and DSP
@@ -101,6 +101,7 @@ function(dpf_add_plugin NAME)
endif() endif()


set(_dgl_library) set(_dgl_library)
set(_dgl_external OFF)
if(_dpf_plugin_FILES_UI) if(_dpf_plugin_FILES_UI)
if(_dpf_plugin_UI_TYPE STREQUAL "cairo") if(_dpf_plugin_UI_TYPE STREQUAL "cairo")
dpf__add_dgl_cairo("${_dpf_plugin_NO_SHARED_RESOURCES}") 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") elseif(_dpf_plugin_UI_TYPE STREQUAL "opengl")
dpf__add_dgl_opengl("${_dpf_plugin_NO_SHARED_RESOURCES}") dpf__add_dgl_opengl("${_dpf_plugin_NO_SHARED_RESOURCES}")
set(_dgl_library dgl-opengl) set(_dgl_library dgl-opengl)
elseif(_dpf_plugin_UI_TYPE STREQUAL "external")
set(_dgl_external ON)
else() else()
message(FATAL_ERROR "Unrecognized UI type for plugin: ${_dpf_plugin_UI_TYPE}") message(FATAL_ERROR "Unrecognized UI type for plugin: ${_dpf_plugin_UI_TYPE}")
endif() endif()
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_COMMON)
dpf__ensure_sources_non_empty(_dpf_plugin_FILES_DSP) dpf__ensure_sources_non_empty(_dpf_plugin_FILES_DSP)
@@ -127,17 +135,20 @@ function(dpf_add_plugin NAME)
target_link_libraries("${NAME}" PRIVATE "dl") target_link_libraries("${NAME}" PRIVATE "dl")
endif() endif()


if(_dgl_library)
if(_dgl_library AND NOT _dgl_external)
# make sure that all code will see DGL_* definitions # make sure that all code will see DGL_* definitions
target_link_libraries("${NAME}" PUBLIC target_link_libraries("${NAME}" PUBLIC
"${_dgl_library}-definitions" "${_dgl_library}-definitions"
dgl-system-libs-definitions) dgl-system-libs-definitions)
elseif(_dgl_external)
target_link_libraries("${NAME}" PUBLIC
dgl-system-libs-definitions)
endif() endif()


dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP}) dpf__add_static_library("${NAME}-dsp" ${_dpf_plugin_FILES_DSP})
target_link_libraries("${NAME}-dsp" PUBLIC "${NAME}") 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}) dpf__add_static_library("${NAME}-ui" ${_dpf_plugin_FILES_UI})
target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library}) target_link_libraries("${NAME}-ui" PUBLIC "${NAME}" ${_dgl_library})
if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU)) if((NOT WIN32) AND (NOT APPLE) AND (NOT HAIKU))
@@ -145,6 +156,14 @@ function(dpf_add_plugin NAME)
endif() endif()
# add the files containing Objective-C classes # add the files containing Objective-C classes
dpf__add_plugin_specific_ui_sources("${NAME}-ui") 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() else()
add_library("${NAME}-ui" INTERFACE) add_library("${NAME}-ui" INTERFACE)
endif() endif()
@@ -152,19 +171,19 @@ function(dpf_add_plugin NAME)
### ###
foreach(_target ${_dpf_plugin_TARGETS}) foreach(_target ${_dpf_plugin_TARGETS})
if(_target STREQUAL "jack") if(_target STREQUAL "jack")
dpf__build_jack("${NAME}" "${_dgl_library}")
dpf__build_jack("${NAME}" "${_dgl_has_ui}")
elseif(_target STREQUAL "ladspa") elseif(_target STREQUAL "ladspa")
dpf__build_ladspa("${NAME}") dpf__build_ladspa("${NAME}")
elseif(_target STREQUAL "dssi") elseif(_target STREQUAL "dssi")
dpf__build_dssi("${NAME}" "${_dgl_library}")
dpf__build_dssi("${NAME}" "${_dgl_has_ui}")
elseif(_target STREQUAL "lv2") 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") elseif(_target STREQUAL "vst2")
dpf__build_vst2("${NAME}" "${_dgl_library}")
dpf__build_vst2("${NAME}" "${_dgl_has_ui}")
elseif(_target STREQUAL "vst3") elseif(_target STREQUAL "vst3")
dpf__build_vst3("${NAME}" "${_dgl_library}")
dpf__build_vst3("${NAME}" "${_dgl_has_ui}")
elseif(_target STREQUAL "clap") elseif(_target STREQUAL "clap")
dpf__build_clap("${NAME}" "${_dgl_library}")
dpf__build_clap("${NAME}" "${_dgl_has_ui}")
else() else()
message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}") message(FATAL_ERROR "Unrecognized target type for plugin: ${_target}")
endif() endif()
@@ -184,12 +203,12 @@ endfunction()
# #
# Add build rules for a JACK/Standalone program. # 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__create_dummy_source_list(_no_srcs)


dpf__add_executable("${NAME}-jack" ${_no_srcs}) dpf__add_executable("${NAME}-jack" ${_no_srcs})
dpf__add_plugin_main("${NAME}-jack" "jack") 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") target_link_libraries("${NAME}-jack" PRIVATE "${NAME}-dsp" "${NAME}-ui")
set_target_properties("${NAME}-jack" PROPERTIES set_target_properties("${NAME}-jack" PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>" RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/$<0:>"
@@ -267,7 +286,7 @@ endfunction()
# #
# Add build rules for a DSSI plugin. # Add build rules for a DSSI plugin.
# #
function(dpf__build_dssi NAME DGL_LIBRARY)
function(dpf__build_dssi NAME HAS_UI)
find_package(PkgConfig) find_package(PkgConfig)
pkg_check_modules(LIBLO "liblo") pkg_check_modules(LIBLO "liblo")
if(NOT LIBLO_FOUND) if(NOT LIBLO_FOUND)
@@ -288,9 +307,9 @@ function(dpf__build_dssi NAME DGL_LIBRARY)
OUTPUT_NAME "${NAME}-dssi" OUTPUT_NAME "${NAME}-dssi"
PREFIX "") PREFIX "")


if(DGL_LIBRARY)
if(HAS_UI)
dpf__add_executable("${NAME}-dssi-ui" ${_no_srcs}) 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") target_link_libraries("${NAME}-dssi-ui" PRIVATE "${NAME}-ui")
set_target_properties("${NAME}-dssi-ui" PROPERTIES set_target_properties("${NAME}-dssi-ui" PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>" RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/${NAME}-dssi/$<0:>"
@@ -308,12 +327,12 @@ endfunction()
# #
# Add build rules for an LV2 plugin. # 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__create_dummy_source_list(_no_srcs)


dpf__add_module("${NAME}-lv2" ${_no_srcs}) dpf__add_module("${NAME}-lv2" ${_no_srcs})
dpf__add_plugin_main("${NAME}-lv2" "lv2") 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") dpf__set_module_export_list("${NAME}-lv2" "lv2")
else() else()
dpf__set_module_export_list("${NAME}-lv2" "lv2-dsp") 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" OUTPUT_NAME "${NAME}_dsp"
PREFIX "") PREFIX "")


if(DGL_LIBRARY)
if(HAS_UI)
if(MONOLITHIC) 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") target_link_libraries("${NAME}-lv2" PRIVATE "${NAME}-ui")
set_target_properties("${NAME}-lv2" PROPERTIES set_target_properties("${NAME}-lv2" PROPERTIES
OUTPUT_NAME "${NAME}") OUTPUT_NAME "${NAME}")
else() else()
dpf__add_module("${NAME}-lv2-ui" ${_no_srcs}) 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") dpf__set_module_export_list("${NAME}-lv2-ui" "lv2-ui")
target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui") target_link_libraries("${NAME}-lv2-ui" PRIVATE "${NAME}-ui")
set_target_properties("${NAME}-lv2-ui" PROPERTIES set_target_properties("${NAME}-lv2-ui" PROPERTIES
@@ -361,12 +380,12 @@ endfunction()
# #
# Add build rules for a VST2 plugin. # 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__create_dummy_source_list(_no_srcs)


dpf__add_module("${NAME}-vst2" ${_no_srcs}) dpf__add_module("${NAME}-vst2" ${_no_srcs})
dpf__add_plugin_main("${NAME}-vst2" "vst2") 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") dpf__set_module_export_list("${NAME}-vst2" "vst2")
target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui") target_link_libraries("${NAME}-vst2" PRIVATE "${NAME}-dsp" "${NAME}-ui")
set_target_properties("${NAME}-vst2" PROPERTIES set_target_properties("${NAME}-vst2" PROPERTIES
@@ -439,14 +458,14 @@ endfunction()
# #
# Add build rules for a VST3 plugin. # 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__determine_vst3_package_architecture(vst3_arch)


dpf__create_dummy_source_list(_no_srcs) dpf__create_dummy_source_list(_no_srcs)


dpf__add_module("${NAME}-vst3" ${_no_srcs}) dpf__add_module("${NAME}-vst3" ${_no_srcs})
dpf__add_plugin_main("${NAME}-vst3" "vst3") 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") dpf__set_module_export_list("${NAME}-vst3" "vst3")
target_link_libraries("${NAME}-vst3" PRIVATE "${NAME}-dsp" "${NAME}-ui") target_link_libraries("${NAME}-vst3" PRIVATE "${NAME}-dsp" "${NAME}-ui")
set_target_properties("${NAME}-vst3" PROPERTIES set_target_properties("${NAME}-vst3" PROPERTIES
@@ -481,12 +500,12 @@ endfunction()
# #
# Add build rules for a VST2 plugin. # 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__create_dummy_source_list(_no_srcs)


dpf__add_module("${NAME}-clap" ${_no_srcs}) dpf__add_module("${NAME}-clap" ${_no_srcs})
dpf__add_plugin_main("${NAME}-clap" "clap") 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") dpf__set_module_export_list("${NAME}-clap" "clap")
target_link_libraries("${NAME}-clap" PRIVATE "${NAME}-dsp" "${NAME}-ui") target_link_libraries("${NAME}-clap" PRIVATE "${NAME}-dsp" "${NAME}-ui")
set_target_properties("${NAME}-clap" PROPERTIES set_target_properties("${NAME}-clap" PROPERTIES


+ 13
- 0
examples/EmbedExternalUI/CMakeLists.txt View File

@@ -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 ".")

+ 1
- 0
examples/EmbedExternalUI/DistrhoPluginInfo.h View File

@@ -20,6 +20,7 @@
#define DISTRHO_PLUGIN_BRAND "DISTRHO" #define DISTRHO_PLUGIN_BRAND "DISTRHO"
#define DISTRHO_PLUGIN_NAME "EmbedExternalUI" #define DISTRHO_PLUGIN_NAME "EmbedExternalUI"
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/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_UI 1
#define DISTRHO_PLUGIN_HAS_EMBED_UI 1 #define DISTRHO_PLUGIN_HAS_EMBED_UI 1


+ 13
- 0
examples/ExternalUI/CMakeLists.txt View File

@@ -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 ".")

+ 1
- 0
examples/ExternalUI/DistrhoPluginInfo.h View File

@@ -20,6 +20,7 @@
#define DISTRHO_PLUGIN_BRAND "DISTRHO" #define DISTRHO_PLUGIN_BRAND "DISTRHO"
#define DISTRHO_PLUGIN_NAME "ExternalUI" #define DISTRHO_PLUGIN_NAME "ExternalUI"
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/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_UI 1
#define DISTRHO_PLUGIN_HAS_EMBED_UI 1 #define DISTRHO_PLUGIN_HAS_EMBED_UI 1


Loading…
Cancel
Save