From 4816448cffbb3789036d9b079d469e4ee3e38ee7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 19 Sep 2023 00:36:07 +0200 Subject: [PATCH] Assume release CEF build by default under Unix This prevents wxWebViewChromium from referencing debug-only functions that are not defined in the release build of libcef_dll_wrapper. Unfortunately, CEF build doesn't provide any way to detect if the wrappers were built in debug or in release mode, so just assume the latter and add --enable-cef-debug configure option to build with a debug build of CEF wrapper if necessary. --- configure | 37 +++++++++++++++++++++++++++++++++ configure.ac | 11 ++++++++++ interface/wx/webview_chromium.h | 6 +++++- setup.h.in | 5 +++++ src/common/webview_chromium.cpp | 13 ++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 9a1e25bb86..74ff5ec0d6 100755 --- a/configure +++ b/configure @@ -1240,6 +1240,7 @@ enable_printarch enable_svg enable_webview enable_webviewchromium +enable_cef_debug enable_graphics_ctx enable_graphics_d2d enable_clipboard @@ -2210,6 +2211,7 @@ Optional Features: --enable-svg use wxSVGFileDC device context --enable-webview use wxWebView library --enable-webviewchromium use wxWebView Chromium backend + --enable-cef_debug use debug build of CEF wrapper --enable-graphics_ctx use graphics context 2D drawing API --enable-graphics-d2d use Direct2D-based graphics context --enable-clipboard use wxClipboard class @@ -8857,6 +8859,36 @@ fi eval "$wx_cv_use_webviewchromium" + + enablestring= + defaultval= + if test -z "$defaultval"; then + if test x"$enablestring" = xdisable; then + defaultval=yes + else + defaultval=no + fi + fi + + # Check whether --enable-cef_debug was given. +if test "${enable_cef_debug+set}" = set; then : + enableval=$enable_cef_debug; + if test "$enableval" = yes; then + wx_cv_use_cef_debug='wxUSE_CEF_DEBUG=yes' + else + wx_cv_use_cef_debug='wxUSE_CEF_DEBUG=no' + fi + +else + + wx_cv_use_cef_debug='wxUSE_CEF_DEBUG=${'DEFAULT_wxUSE_CEF_DEBUG":-$defaultval}" + +fi + + + eval "$wx_cv_use_cef_debug" + + if test "$wxUSE_MAC" != 1; then enablestring= @@ -39810,6 +39842,11 @@ $as_echo "$wx_cv_lib_cef" >&6; } USE_WEBVIEW_CHROMIUM=1 $as_echo "#define wxUSE_WEBVIEW_CHROMIUM 1" >>confdefs.h + + if test "$wxUSE_CEF_DEBUG" = "yes"; then + $as_echo "#define wxHAVE_CEF_DEBUG 1" >>confdefs.h + + fi else as_fn_error $? "CEF not detected: $cef_error diff --git a/configure.ac b/configure.ac index 51b0c6cee6..c6e7253811 100644 --- a/configure.ac +++ b/configure.ac @@ -789,6 +789,11 @@ dnl This one is not enabled by default as it requires CEF to be available under dnl 3rdparty/cef. WX_ARG_ENABLE(webviewchromium, [ --enable-webviewchromium use wxWebView Chromium backend], wxUSE_WEBVIEW_CHROMIUM) +dnl When using wxWebViewChromium, we assume that CEF wrapper DLL was built in +dnl release mode, use this option if it was built in debug one, i.e. with +dnl -DCMAKE_BUILD_TYPE=Debug +WX_ARG_ENABLE(cef_debug, [ --enable-cef_debug use debug build of CEF wrapper], wxUSE_CEF_DEBUG) + dnl wxDC is implemented in terms of wxGraphicsContext in wxOSX so the latter dnl can't be disabled, don't even provide an option to do it if test "$wxUSE_MAC" != 1; then @@ -6971,6 +6976,12 @@ if test "$wxUSE_WEBVIEW" = "yes"; then wxUSE_WEBVIEW="yes" USE_WEBVIEW_CHROMIUM=1 AC_DEFINE(wxUSE_WEBVIEW_CHROMIUM) + + dnl Just trust the option value, we don't really have any simple + dnl way to check the CEF wrapper DLL build type. + if test "$wxUSE_CEF_DEBUG" = "yes"; then + AC_DEFINE(wxHAVE_CEF_DEBUG) + fi else AC_MSG_ERROR([CEF not detected: $cef_error diff --git a/interface/wx/webview_chromium.h b/interface/wx/webview_chromium.h index 1532149c6f..4daf843896 100644 --- a/interface/wx/webview_chromium.h +++ b/interface/wx/webview_chromium.h @@ -47,7 +47,11 @@ 2. Unpack the archive into `3rdparty/cef` directory under wxWidgets source directory. 3. Build `libcef_dll_wrapper` using the instructions provided in the CEF - distribution, but, in short, just by using `cmake` to do it. + distribution, but, in short, just by using `cmake` to do it. Please note + that if you use `-DCMAKE_BUILD_TYPE=Debug` under Unix when building it, you + need to pass `--enable-cef_debug` option to wxWidgets configure to avoid + mismatches between various definitions in the wrapper itself and in + wxWidgets. 4. Copy the static library binary in the platform-dependent location: - Under MSW, copy `libcefl_dll_wrapper.lib` file to either `3rdparty/cef/Release` or `3rdparty/cef/Debug` depending on the build diff --git a/setup.h.in b/setup.h.in index 077a12ad16..884830cd23 100644 --- a/setup.h.in +++ b/setup.h.in @@ -601,6 +601,11 @@ #define wxUSE_SELECT_DISPATCHER 0 #define wxUSE_EPOLL_DISPATCHER 0 +/* + Use debug version of CEF in wxWebViewChromium. + */ +#undef wxHAVE_CEF_DEBUG + /* Use GStreamer for Unix. diff --git a/src/common/webview_chromium.cpp b/src/common/webview_chromium.cpp index 63c1ad8c5f..54b0d35090 100644 --- a/src/common/webview_chromium.cpp +++ b/src/common/webview_chromium.cpp @@ -29,6 +29,15 @@ #include #endif +// When not using debug version of CEF under Unix we need to make sure to +// predefine NDEBUG before including its headers to avoid ODR violations. +#ifndef wxHAVE_CEF_DEBUG + #ifndef NDEBUG + #define NDEBUG + #define wxUNDEF_NDEBUG + #endif +#endif + #ifdef __WXOSX__ #include "wx/osx/private/webview_chromium.h" #endif @@ -55,6 +64,10 @@ wxGCC_WARNING_RESTORE(unused-parameter) #pragma warning(pop) #endif +#ifdef wxUNDEF_NDEBUG + #undef NDEBUG +#endif + #if CHROME_VERSION_BUILD < 5845 #error "Unsupported CEF version" #endif