Skip to content

Commit

Permalink
CMake: Add external UI support
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit d1a682345862ae6cc1cf83524febdb5076aa4827
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 2d162a16b6894879a941b131553aded7d451eebe
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 2cf060910e8d7589f9b21842f6b0ae802bc89d0a
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>
  • Loading branch information
AnClark authored and falkTX committed Dec 29, 2022
1 parent a325bf5 commit a338aa6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
69 changes: 44 additions & 25 deletions cmake/DPF-plugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ include(CMakeParseArguments)
# `jack`, `ladspa`, `dssi`, `lv2`, `vst2`, `vst3`, `clap`
#
# `UI_TYPE` <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
Expand All @@ -101,18 +101,26 @@ 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}")
set(_dgl_library dgl-cairo)
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)
Expand All @@ -127,44 +135,55 @@ 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))
target_link_libraries("${NAME}-ui" PRIVATE "dl")
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()

###
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()
Expand All @@ -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:>"
Expand Down Expand Up @@ -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)
Expand All @@ -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:>"
Expand All @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions examples/EmbedExternalUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions examples/EmbedExternalUI/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions examples/ExternalUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions examples/ExternalUI/DistrhoPluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a338aa6

Please sign in to comment.