From b3c1a6adfdab2a68e4992e480a99d7f672134b56 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Jan 2024 00:58:39 +0100 Subject: [PATCH 1/7] Document CEF_RUNTIME_LIBRARY_FLAG switch for building CEF This must match the options used when building wx itself. Also mention CEF_USE_SANDBOX while discussing CEF build options. --- interface/wx/webview_chromium.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/interface/wx/webview_chromium.h b/interface/wx/webview_chromium.h index 09a2bdab1423..486ab3aa09e1 100644 --- a/interface/wx/webview_chromium.h +++ b/interface/wx/webview_chromium.h @@ -47,11 +47,16 @@ 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. 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. + distribution, which basically means using `cmake` to do it. Please note: + * Under Windows you must use `-DCEF_RUNTIME_LIBRARY_FLAG=/MD` option + to match the default wxWidgets build configuration. + * Under Unix remember that if you use `-DCMAKE_BUILD_TYPE=Debug` 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. + * Under all platforms you may want to use `-DCEF_USE_SANDBOX=OFF` + option to avoid linking with the sandbox library which is not + provided in the "Minimal Distribution" if you don't use this feature. 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 From 0fa605abb5f4c4dcdb36bc29c1ba45122c89c16e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Jan 2024 02:13:46 +0100 Subject: [PATCH 2/7] Only use CMAKE_BUILD_TYPE to set wxHAVE_CEF_DEBUG if it's defined If it isn't, as is the case for MSVS for example, we don't need to set wxHAVE_CEF_DEBUG anyhow, as it's set automatically if _DEBUG is defined during the build. Co-Authored-By: Maarten Bent --- build/cmake/setup.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/cmake/setup.cmake b/build/cmake/setup.cmake index 59899bff9a41..240fc808a66f 100644 --- a/build/cmake/setup.cmake +++ b/build/cmake/setup.cmake @@ -613,7 +613,8 @@ check_type_size(ssize_t SSIZE_T) test_big_endian(WORDS_BIGENDIAN) -if(wxUSE_WEBVIEW_CHROMIUM) +# For generators using build type, ensure that wxHAVE_CEF_DEBUG matches it. +if(wxUSE_WEBVIEW_CHROMIUM AND DEFINED CMAKE_BUILD_TYPE) string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) if(${build_type} STREQUAL DEBUG) set(wxHAVE_CEF_DEBUG ON) From 8463b13c148153e2aef2199bb28c4d47e43affee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 23 Jan 2024 03:28:17 +0100 Subject: [PATCH 3/7] Don't use -Wno-extra with MSVS when building wxWebviewChromium Only set it for the other compilers. This fixes a problem introduced in 26025e2652 (Disable -Wextra when building libcef_dll_wrapper, 2023-12-29). --- build/cmake/lib/webview_chromium/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/cmake/lib/webview_chromium/CMakeLists.txt b/build/cmake/lib/webview_chromium/CMakeLists.txt index 1c9e28314c7c..31a5374d9760 100644 --- a/build/cmake/lib/webview_chromium/CMakeLists.txt +++ b/build/cmake/lib/webview_chromium/CMakeLists.txt @@ -59,7 +59,6 @@ set(USE_SANDBOX OFF) # Disable usage of sandbox on windows add_subdirectory(${CEF_ROOT} ${CEF_BUILD_DIR} EXCLUDE_FROM_ALL) set_target_properties(libcef_dll_wrapper PROPERTIES FOLDER "Third Party Libraries" - COMPILE_FLAGS "-Wno-extra" OUTPUT_NAME "libcef_dll_wrapper" ) @@ -68,6 +67,8 @@ if(MSVC) get_target_property(cef_compile_options libcef_dll_wrapper COMPILE_OPTIONS) string(REGEX REPLACE "/MTd?;" "" cef_compile_options "${cef_compile_options}") set_target_properties(libcef_dll_wrapper PROPERTIES COMPILE_OPTIONS "${cef_compile_options}") +else() + set_target_properties(libcef_dll_wrapper PROPERTIES COMPILE_OPTIONS "-Wno-extra") endif() add_library(libcef SHARED IMPORTED GLOBAL) From 5480296dd0e6d699325a5291f91432104d87f38e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 23 Jan 2024 03:29:23 +0100 Subject: [PATCH 4/7] Use C++17 when using CEF and not C++14 CEF uses std::in_place_t which is not available in C++14. --- build/cmake/init.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index 5faa49a8065d..040df05f4d92 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -506,11 +506,11 @@ if(wxUSE_GUI) message(WARNING "WebviewChromium libcef_dll_wrapper can only be built with MSVC... disabled") wx_option_force_value(wxUSE_WEBVIEW_CHROMIUM OFF) endif() - if(wxUSE_WEBVIEW_CHROMIUM AND CMAKE_CXX_STANDARD LESS 14) + if(wxUSE_WEBVIEW_CHROMIUM AND CMAKE_CXX_STANDARD LESS 17) # We shouldn't disable this option as it's disabled by default and # if it is on, it means that CEF is meant to be used, but we can't # continue neither as libcef_dll_wrapper will fail to build. - message(FATAL_ERROR "WebviewChromium requires at least C++14 but configured to use C++${CMAKE_CXX_STANDARD}") + message(FATAL_ERROR "WebviewChromium requires at least C++17 but configured to use C++${CMAKE_CXX_STANDARD}") endif() endif() From fca0c75b2e8500b3195d114ea09055a647fc0b26 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 23 Jan 2024 03:45:59 +0100 Subject: [PATCH 5/7] Don't give an error if compiler supports C++17 by default Previously CMake would give an error if CMAKE_CXX_STANDARD wasn't explicitly set to C++17 or greater when using CEF, but this is not really needed if the compiler supports C++17 without any non-default options, so check for this too. --- build/cmake/init.cmake | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index 040df05f4d92..ca24b5b8486c 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -506,11 +506,36 @@ if(wxUSE_GUI) message(WARNING "WebviewChromium libcef_dll_wrapper can only be built with MSVC... disabled") wx_option_force_value(wxUSE_WEBVIEW_CHROMIUM OFF) endif() - if(wxUSE_WEBVIEW_CHROMIUM AND CMAKE_CXX_STANDARD LESS 17) - # We shouldn't disable this option as it's disabled by default and - # if it is on, it means that CEF is meant to be used, but we can't - # continue neither as libcef_dll_wrapper will fail to build. - message(FATAL_ERROR "WebviewChromium requires at least C++17 but configured to use C++${CMAKE_CXX_STANDARD}") + if(wxUSE_WEBVIEW_CHROMIUM) + # Check for C++17 support as it's required by CEF: we trust + # CMAKE_CXX_STANDARD if it is defined, but we need to compile a + # test program if it is not because the compiler could be + # supporting C++17 anyway. + if (DEFINED CMAKE_CXX_STANDARD) + if (CMAKE_CXX_STANDARD GREATER_EQUAL 17) + set(wxHAVE_CXX17 ON) + endif() + else() + check_cxx_source_compiles(" + #if defined(_MSVC_LANG) + #if _MSVC_LANG < 201703L + #error C++17 support is required + #endif + #elif __cplusplus < 201703L + #error C++17 support is required + #endif + int main() { + [[maybe_unused]] auto unused = 17; + }" + wxHAVE_CXX17) + endif() + + if (NOT wxHAVE_CXX17) + # We shouldn't disable this option as it's disabled by default and + # if it is on, it means that CEF is meant to be used, but we can't + # continue neither as libcef_dll_wrapper will fail to build. + message(FATAL_ERROR "WebviewChromium requires at least C++17 but configured to use C++${CMAKE_CXX_STANDARD}") + endif() endif() endif() From f05177db2a1a930649593f6f98a74af350b8bf6c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 24 Jan 2024 00:08:04 +0100 Subject: [PATCH 6/7] Improve CMake error message if C++17 is not used with CEF The previous error didn't make sense if CMAKE_CXX_STANDARD wasn't set, so use a slightly different message in this case. Also improve the comment explaining why we need C++17 in the first place. Co-Authored-By: Maarten Bent --- build/cmake/init.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index ca24b5b8486c..488586943b6f 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -533,8 +533,18 @@ if(wxUSE_GUI) if (NOT wxHAVE_CXX17) # We shouldn't disable this option as it's disabled by default and # if it is on, it means that CEF is meant to be used, but we can't - # continue neither as libcef_dll_wrapper will fail to build. - message(FATAL_ERROR "WebviewChromium requires at least C++17 but configured to use C++${CMAKE_CXX_STANDARD}") + # continue neither as libcef_dll_wrapper will fail to build + # (actually it may still succeed with CEF v116 which provided + # its own stand-in for std::in_place used in CEF headers, but + # not with the later versions, so just fail instead of trying + # to detect CEF version here, as even v116 officially only + # supports C++17 anyhow). + if (DEFINED CMAKE_CXX_STANDARD) + set(cxx17_error_details "configured to use C++${CMAKE_CXX_STANDARD}") + else() + set(cxx17_error_details "the compiler doesn't support C++17 by default and CMAKE_CXX_STANDARD is not set") + endif() + message(FATAL_ERROR "WebviewChromium requires at least C++17 but ${cxx17_error_details}") endif() endif() endif() From f26577552723f521916e780b33f51a8b03fe70ed Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 24 Jan 2024 00:14:03 +0100 Subject: [PATCH 7/7] Use C++17 for MSVS wxWebView project webview_chromium.cpp requires using C++17 as it includes CEF headers that require it (e.g. they use std::in_place) and we need to use the same options all files in this project as they share the same PCH, so just use C++17 for all of them -- it should do no harm. --- build/msw/wx_webview.vcxproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build/msw/wx_webview.vcxproj b/build/msw/wx_webview.vcxproj index 66a15ee1c538..d350da412ec4 100644 --- a/build/msw/wx_webview.vcxproj +++ b/build/msw/wx_webview.vcxproj @@ -152,6 +152,7 @@ Level4 true true + stdcpp17 _DEBUG;_CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;_UNICODE;WXBUILDING;%(PreprocessorDefinitions) @@ -187,6 +188,7 @@ Level4 true true + stdcpp17 _DEBUG;_CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;_UNICODE;WXBUILDING;%(PreprocessorDefinitions) @@ -225,6 +227,7 @@ Speed true true + stdcpp17 _CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;NDEBUG;_UNICODE;WXBUILDING;%(PreprocessorDefinitions) @@ -262,6 +265,7 @@ true Speed true + stdcpp17 _CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;NDEBUG;_UNICODE;WXBUILDING;%(PreprocessorDefinitions) @@ -298,6 +302,7 @@ Level4 true true + stdcpp17 _DEBUG;_CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;_UNICODE;WXBUILDING;WXDLLNAME=$(TargetName);WXUSINGDLL;WXMAKINGDLL_WEBVIEW;%(PreprocessorDefinitions) @@ -339,6 +344,7 @@ Level4 true true + stdcpp17 _DEBUG;_CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;_UNICODE;WXBUILDING;WXDLLNAME=$(TargetName);WXUSINGDLL;WXMAKINGDLL_WEBVIEW;%(PreprocessorDefinitions) @@ -380,6 +386,7 @@ true Speed true + stdcpp17 _CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;NDEBUG;_UNICODE;WXBUILDING;WXDLLNAME=$(TargetName);WXUSINGDLL;WXMAKINGDLL_WEBVIEW;%(PreprocessorDefinitions) @@ -424,6 +431,7 @@ true Speed true + stdcpp17 _CRT_SECURE_NO_DEPRECATE=1;_CRT_NON_CONFORMING_SWPRINTFS=1;_SCL_SECURE_NO_WARNINGS=1;__WXMSW__;NDEBUG;_UNICODE;WXBUILDING;WXDLLNAME=$(TargetName);WXUSINGDLL;WXMAKINGDLL_WEBVIEW;%(PreprocessorDefinitions)