From 472cda840ed527b779faa9db9abbdab6be161002 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 11 May 2024 11:03:20 +0200 Subject: [PATCH] Cleanup build flags and config, error out early Signed-off-by: falkTX --- Makefile.base.mk | 42 +++++++++++++++++++------ Makefile.plugins.mk | 4 +-- dgl/Base.hpp | 29 +++++++++++++++++ dgl/Window.hpp | 12 +++---- dgl/src/Window.cpp | 4 +-- dgl/src/WindowPrivateData.cpp | 18 +++++------ dgl/src/WindowPrivateData.hpp | 4 +-- distrho/extra/FileBrowserDialogImpl.hpp | 6 +++- distrho/extra/WebViewImpl.hpp | 2 +- distrho/src/DistrhoPluginChecks.h | 26 +++++++-------- distrho/src/DistrhoUI.cpp | 6 ++++ examples/EmbedExternalUI/Makefile | 2 +- examples/FileHandling/Makefile | 1 + 13 files changed, 109 insertions(+), 47 deletions(-) diff --git a/Makefile.base.mk b/Makefile.base.mk index 167cbd53..99f1c1be 100644 --- a/Makefile.base.mk +++ b/Makefile.base.mk @@ -28,7 +28,8 @@ # USE_OPENGL3=true # USE_NANOVG_FBO=true # USE_NANOVG_FREETYPE=true -# USE_WEBVIEW=true +# USE_FILE_BROWSER=true +# USE_WEB_VIEW=true # STATIC_BUILD=true # Tweak build to be able to generate fully static builds (e.g. skip use of libdl) @@ -234,6 +235,27 @@ ifeq ($(MACOS),true) UNIX = true endif +# --------------------------------------------------------------------------------------------------------------------- +# Compatibility checks + +ifeq ($(FILE_BROWSER_DISABLED),true) +$(error FILE_BROWSER_DISABLED has been replaced by USE_FILE_BROWSER (opt-in vs opt-out)) +endif + +ifeq ($(USE_FILEBROWSER),true) +$(error typo detected use USE_FILE_BROWSER instead of USE_FILEBROWSER) +endif + +ifeq ($(USE_WEBVIEW),true) +$(error typo detected use USE_WEB_VIEW instead of USE_WEBVIEW) +endif + +# --------------------------------------------------------------------------------------------------------------------- +# Set optional flags + +USE_FILE_BROWSER ?= true +USE_WEB_VIEW ?= false + # --------------------------------------------------------------------------------------------------------------------- # Set build and link flags @@ -440,7 +462,7 @@ else ifeq ($(MACOS),true) DGL_SYSTEM_LIBS += -framework Cocoa DGL_SYSTEM_LIBS += -framework CoreVideo -ifeq ($(USE_WEBVIEW),true) +ifeq ($(USE_WEB_VIEW),true) DGL_SYSTEM_LIBS += -framework WebKit endif @@ -457,7 +479,7 @@ DGL_SYSTEM_LIBS += -lcomdlg32 DGL_SYSTEM_LIBS += -ldwmapi DGL_SYSTEM_LIBS += -lgdi32 # DGL_SYSTEM_LIBS += -lole32 -ifeq ($(USE_WEBVIEW),true) +ifeq ($(USE_WEB_VIEW),true) DGL_SYSTEM_LIBS += -lole32 DGL_SYSTEM_LIBS += -luuid endif @@ -486,7 +508,7 @@ ifeq ($(HAVE_XRANDR),true) DGL_FLAGS += $(shell $(PKG_CONFIG) --cflags xrandr) -DHAVE_XRANDR DGL_SYSTEM_LIBS += $(shell $(PKG_CONFIG) --libs xrandr) endif -ifeq ($(USE_WEBVIEW),true) +ifeq ($(USE_WEB_VIEW),true) DGL_FLAGS += -pthread DGL_SYSTEM_LIBS += -pthread -lrt endif @@ -630,10 +652,6 @@ ifneq ($(NVG_FONT_TEXTURE_FLAGS),) BUILD_CXX_FLAGS += -DNVG_FONT_TEXTURE_FLAGS=$(NVG_FONT_TEXTURE_FLAGS) endif -ifeq ($(FILE_BROWSER_DISABLED),true) -BUILD_CXX_FLAGS += -DDGL_FILE_BROWSER_DISABLED -endif - ifneq ($(WINDOWS_ICON_ID),) BUILD_CXX_FLAGS += -DDGL_WINDOWS_ICON_ID=$(WINDOWS_ICON_ID) endif @@ -670,8 +688,12 @@ ifeq ($(USE_RGBA),true) BUILD_CXX_FLAGS += -DDGL_USE_RGBA endif -ifeq ($(USE_WEBVIEW),true) -BUILD_CXX_FLAGS += -DDGL_USE_WEBVIEW +ifeq ($(USE_FILE_BROWSER),true) +BUILD_CXX_FLAGS += -DDGL_USE_FILE_BROWSER +endif + +ifeq ($(USE_WEB_VIEW),true) +BUILD_CXX_FLAGS += -DDGL_USE_WEB_VIEW endif # --------------------------------------------------------------------------------------------------------------------- diff --git a/Makefile.plugins.mk b/Makefile.plugins.mk index bd1160db..a5f2530d 100644 --- a/Makefile.plugins.mk +++ b/Makefile.plugins.mk @@ -255,10 +255,10 @@ ifeq ($(UI_TYPE),web) DGL_FLAGS += -DDGL_WEB -DHAVE_DGL DGL_LIB = $(DGL_BUILD_DIR)/libdgl-stub.a HAVE_DGL = true -USE_WEBVIEW = true +USE_WEB_VIEW = true endif -ifeq ($(HAVE_DGL)$(LINUX)$(USE_WEBVIEW),truetruetrue) +ifeq ($(HAVE_DGL)$(LINUX)$(USE_WEB_VIEW),truetruetrue) DGL_LIB_SHARED = $(shell $(CC) -print-file-name=Scrt1.o) endif diff --git a/dgl/Base.hpp b/dgl/Base.hpp index 1cc7190a..51e77048 100644 --- a/dgl/Base.hpp +++ b/dgl/Base.hpp @@ -20,6 +20,35 @@ #include "../distrho/extra/LeakDetector.hpp" #include "../distrho/extra/ScopedPointer.hpp" +// -------------------------------------------------------------------------------------------------------------------- +// Compatibility checks + +#if defined(DGL_CAIRO) && defined(DGL_EXTERNAL) +# error invalid build config: trying to build for both cairo and external at the same time +#elif defined(DGL_CAIRO) && defined(DGL_OPENGL) +# error invalid build config: trying to build for both cairo and opengl at the same time +#elif defined(DGL_CAIRO) && defined(DGL_VULKAN) +# error invalid build config: trying to build for both cairo and vulkan at the same time +#elif defined(DGL_EXTERNAL) && defined(DGL_OPENGL) +# error invalid build config: trying to build for both external and opengl at the same time +#elif defined(DGL_EXTERNAL) && defined(DGL_VULKAN) +# error invalid build config: trying to build for both external and vulkan at the same time +#elif defined(DGL_OPENGL) && defined(DGL_VULKAN) +# error invalid build config: trying to build for both opengl and vulkan at the same time +#endif + +#ifdef DGL_USE_FILEBROWSER +# error typo detected use DGL_USE_FILE_BROWSER instead of DGL_USE_FILEBROWSER +#endif + +#ifdef DGL_UI_USE_WEBVIEW +# error typo detected use DGL_UI_USE_WEB_VIEW instead of DGL_UI_USE_WEBVIEW +#endif + +#if defined(DGL_FILE_BROWSER_DISABLED) +# error DGL_FILE_BROWSER_DISABLED has been replaced by DGL_USE_FILE_BROWSER (opt-in vs opt-out) +#endif + // -------------------------------------------------------------------------------------------------------------------- // Define namespace diff --git a/dgl/Window.hpp b/dgl/Window.hpp index 2b5271fa..ac6b89cd 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2022 Filipe Coelho + * Copyright (C) 2012-2024 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -19,7 +19,7 @@ #include "Geometry.hpp" -#ifndef DGL_FILE_BROWSER_DISABLED +#ifdef DGL_USE_FILE_BROWSER # include "FileBrowserDialog.hpp" #endif @@ -394,7 +394,7 @@ public: */ void focus(); -#ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER /** Open a file browser dialog with this window as transient parent. A few options can be specified to setup the dialog. @@ -405,7 +405,7 @@ public: This function does not block the event loop. */ bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options = FileBrowserOptions()); -#endif + #endif /** Request repaint of this window, for the entire area. @@ -517,7 +517,7 @@ protected: */ virtual void onScaleFactorChanged(double scaleFactor); -#ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER /** A function called when a path is selected by the user, as triggered by openFileBrowser(). This action happens after the user confirms the action, so the file browser dialog will be closed at this point. @@ -528,7 +528,7 @@ protected: /** DEPRECATED Use onFileSelected(). */ DISTRHO_DEPRECATED_BY("onFileSelected(const char*)") inline virtual void fileBrowserSelected(const char* filename) { return onFileSelected(filename); } -#endif + #endif private: PrivateData* const pData; diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 4899ba51..b21e5c4c 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -414,7 +414,7 @@ void Window::focus() pData->focus(); } -#ifndef DGL_FILE_BROWSER_DISABLED +#ifdef DGL_USE_FILE_BROWSER bool Window::openFileBrowser(const FileBrowserOptions& options) { return pData->openFileBrowser(options); @@ -574,7 +574,7 @@ void Window::onScaleFactorChanged(double) { } -#ifndef DGL_FILE_BROWSER_DISABLED +#ifdef DGL_USE_FILE_BROWSER void Window::onFileSelected(const char*) { } diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp index 14fdf341..a2afec6b 100644 --- a/dgl/src/WindowPrivateData.cpp +++ b/dgl/src/WindowPrivateData.cpp @@ -128,7 +128,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s) waitingForClipboardEvents(false), clipboardTypeId(0), filenameToRenderInto(nullptr), - #ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER fileBrowserHandle(nullptr), #endif modal() @@ -158,7 +158,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* c waitingForClipboardEvents(false), clipboardTypeId(0), filenameToRenderInto(nullptr), - #ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER fileBrowserHandle(nullptr), #endif modal(ppData) @@ -190,7 +190,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, waitingForClipboardEvents(false), clipboardTypeId(0), filenameToRenderInto(nullptr), - #ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER fileBrowserHandle(nullptr), #endif modal() @@ -225,7 +225,7 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, waitingForClipboardEvents(false), clipboardTypeId(0), filenameToRenderInto(nullptr), - #ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER fileBrowserHandle(nullptr), #endif modal() @@ -244,7 +244,7 @@ Window::PrivateData::~PrivateData() if (isEmbed) { - #ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER if (fileBrowserHandle != nullptr) fileBrowserClose(fileBrowserHandle); #endif @@ -394,7 +394,7 @@ void Window::PrivateData::hide() if (modal.enabled) stopModal(); -#ifndef DGL_FILE_BROWSER_DISABLED +#ifdef DGL_USE_FILE_BROWSER if (fileBrowserHandle != nullptr) { fileBrowserClose(fileBrowserHandle); @@ -435,7 +435,7 @@ void Window::PrivateData::setResizable(const bool resizable) void Window::PrivateData::idleCallback() { -#ifndef DGL_FILE_BROWSER_DISABLED +#ifdef DGL_USE_FILE_BROWSER if (fileBrowserHandle != nullptr && fileBrowserIdle(fileBrowserHandle)) { self->onFileSelected(fileBrowserGetPath(fileBrowserHandle)); @@ -477,7 +477,7 @@ bool Window::PrivateData::removeIdleCallback(IdleCallback* const callback) return puglStopTimer(view, (uintptr_t)callback) == PUGL_SUCCESS; } -#ifndef DGL_FILE_BROWSER_DISABLED +#ifdef DGL_USE_FILE_BROWSER // ----------------------------------------------------------------------- // file handling @@ -498,7 +498,7 @@ bool Window::PrivateData::openFileBrowser(const FileBrowserOptions& options) return fileBrowserHandle != nullptr; } -#endif // ! DGL_FILE_BROWSER_DISABLED +#endif // DGL_USE_FILE_BROWSER // ----------------------------------------------------------------------- // modal handling diff --git a/dgl/src/WindowPrivateData.hpp b/dgl/src/WindowPrivateData.hpp index 70544f66..0983a6dc 100644 --- a/dgl/src/WindowPrivateData.hpp +++ b/dgl/src/WindowPrivateData.hpp @@ -90,7 +90,7 @@ struct Window::PrivateData : IdleCallback { /** Render to a picture file when non-null, automatically free+unset after saving. */ char* filenameToRenderInto; - #ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER /** Handle for file browser dialog operations. */ DGL_NAMESPACE::FileBrowserHandle fileBrowserHandle; #endif @@ -168,7 +168,7 @@ struct Window::PrivateData : IdleCallback { bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs); bool removeIdleCallback(IdleCallback* callback); - #ifndef DGL_FILE_BROWSER_DISABLED + #ifdef DGL_USE_FILE_BROWSER // file handling bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options); #endif diff --git a/distrho/extra/FileBrowserDialogImpl.hpp b/distrho/extra/FileBrowserDialogImpl.hpp index db01719b..8f5f4f00 100644 --- a/distrho/extra/FileBrowserDialogImpl.hpp +++ b/distrho/extra/FileBrowserDialogImpl.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2022 Filipe Coelho + * Copyright (C) 2012-2024 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -18,6 +18,10 @@ # error bad include #endif +#if !defined(DGL_USE_FILE_BROWSER) && defined(DISTRHO_UI_FILE_BROWSER) && DISTRHO_UI_FILE_BROWSER == 0 +# error To use File Browser in DPF plugins please set DISTRHO_UI_FILE_BROWSER to 1 +#endif + // -------------------------------------------------------------------------------------------------------------------- // File Browser Dialog stuff diff --git a/distrho/extra/WebViewImpl.hpp b/distrho/extra/WebViewImpl.hpp index c0f4e116..627cff14 100644 --- a/distrho/extra/WebViewImpl.hpp +++ b/distrho/extra/WebViewImpl.hpp @@ -18,7 +18,7 @@ # error bad include #endif -#if defined(DISTRHO_UI_WEB_VIEW) && DISTRHO_UI_WEB_VIEW == 0 +#if !defined(DGL_UI_USE_WEB_VIEW) && defined(DISTRHO_UI_WEB_VIEW) && DISTRHO_UI_WEB_VIEW == 0 # error To use WebViews in DPF plugins please set DISTRHO_UI_WEB_VIEW to 1 #endif diff --git a/distrho/src/DistrhoPluginChecks.h b/distrho/src/DistrhoPluginChecks.h index 37caaf2c..7552c88d 100644 --- a/distrho/src/DistrhoPluginChecks.h +++ b/distrho/src/DistrhoPluginChecks.h @@ -121,14 +121,14 @@ # define DISTRHO_UI_USE_NANOVG 0 #endif -#ifndef DISTRHO_UI_USE_WEBVIEW -# define DISTRHO_UI_USE_WEBVIEW 0 +#ifndef DISTRHO_UI_USE_WEB_VIEW +# define DISTRHO_UI_USE_WEB_VIEW 0 #endif // -------------------------------------------------------------------------------------------------------------------- // Define DISTRHO_UI_WEB_VIEW if needed -#if DISTRHO_UI_USE_WEBVIEW && !DISTRHO_UI_WEB_VIEW +#if DISTRHO_UI_USE_WEB_VIEW && !DISTRHO_UI_WEB_VIEW # undef DISTRHO_UI_WEB_VIEW # define DISTRHO_UI_WEB_VIEW 1 #endif @@ -151,20 +151,20 @@ # error DISTRHO_PLUGIN_HAS_EXTERNAL_UI has been replaced by DISTRHO_UI_USE_EXTERNAL #endif -#if defined(DGL_CAIRO) && defined(DGL_OPENGL) -# error invalid build config: trying to build for both cairo and opengl at the same time -#elif defined(DGL_EXTERNAL) && defined(DGL_CAIRO) -# error invalid build config: trying to build for both external and cairo at the same time -#elif defined(DGL_EXTERNAL) && defined(DGL_OPENGL) -# error invalid build config: trying to build for both external and opengl at the same time +#ifdef DISTRHO_UI_FILEBROWSER +# error typo detected use DGL_USE_FILE_BROWSER instead of DISTRHO_UI_FILEBROWSER #endif -#if DISTRHO_UI_FILE_BROWSER && defined(DGL_FILE_BROWSER_DISABLED) -# error invalid build config: file browser requested but `FILE_BROWSER_DISABLED` build option is set +#ifdef DISTRHO_UI_USE_WEBVIEW +# error typo detected use DISTRHO_UI_USE_WEB_VIEW instead of DISTRHO_UI_USE_WEBVIEW #endif -#if DISTRHO_UI_USE_WEBVIEW && !defined(DGL_USE_WEBVIEW) -# error invalid build config: web view requested but `USE_WEBVIEW` build option is not set +#if DISTRHO_UI_FILE_BROWSER && !defined(DGL_USE_FILE_BROWSER) +# error invalid build config: file browser requested but `USE_FILE_BROWSER` build option is not set +#endif + +#if DISTRHO_UI_USE_WEB_VIEW && !defined(DGL_UI_USE_WEB_VIEW) +# error invalid build config: web view requested but `USE_WEB_VIEW` build option is not set #endif // -------------------------------------------------------------------------------------------------------------------- diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp index f2877889..e65608da 100644 --- a/distrho/src/DistrhoUI.cpp +++ b/distrho/src/DistrhoUI.cpp @@ -30,7 +30,9 @@ # include # include #elif defined(HAVE_X11) +# define Window X11Window # include +# undef Window #endif #if DISTRHO_UI_FILE_BROWSER && !defined(DISTRHO_OS_MAC) @@ -57,7 +59,9 @@ START_NAMESPACE_DISTRHO # include "../extra/FileBrowserDialogImpl.hpp" END_NAMESPACE_DISTRHO +# define Window X11Window # include "../extra/FileBrowserDialogImpl.cpp" +# undef Window #endif #if DISTRHO_UI_WEB_VIEW && !defined(DISTRHO_OS_MAC) @@ -67,7 +71,9 @@ END_NAMESPACE_DISTRHO START_NAMESPACE_DISTRHO # include "../extra/WebViewImpl.hpp" END_NAMESPACE_DISTRHO +# define Window X11Window # include "../extra/WebViewImpl.cpp" +# undef Window #endif #include "src/TopLevelWidgetPrivateData.hpp" diff --git a/examples/EmbedExternalUI/Makefile b/examples/EmbedExternalUI/Makefile index 1aef0ba1..4538f1a9 100644 --- a/examples/EmbedExternalUI/Makefile +++ b/examples/EmbedExternalUI/Makefile @@ -21,7 +21,7 @@ FILES_UI = \ # -------------------------------------------------------------- # Do some magic -USE_WEBVIEW = true +USE_WEB_VIEW = true UI_TYPE = external include ../../Makefile.plugins.mk diff --git a/examples/FileHandling/Makefile b/examples/FileHandling/Makefile index 1ebd4027..028edb11 100644 --- a/examples/FileHandling/Makefile +++ b/examples/FileHandling/Makefile @@ -22,6 +22,7 @@ FILES_UI = \ # -------------------------------------------------------------- # Do some magic +USE_FILE_BROWSER = true include ../../Makefile.plugins.mk # --------------------------------------------------------------