diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index a125c10979..6dca1cc869 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -453,10 +453,6 @@ if(wxUSE_GUI) wx_option_force_value(wxUSE_WEBVIEW OFF) endif() elseif(WXMSW) - if(wxUSE_WEBVIEW_EDGE AND NOT EXISTS "${wxSOURCE_DIR}/3rdparty/webview2") - message("WebView2 SDK not found, WebviewEdge won't be available") - wx_option_force_value(wxUSE_WEBVIEW_EDGE OFF) - endif() if(NOT wxUSE_WEBVIEW_IE AND NOT wxUSE_WEBVIEW_EDGE) message(WARNING "WebviewIE and WebviewEdge not found or enabled, wxWebview won't be available") wx_option_force_value(wxUSE_WEBVIEW OFF) diff --git a/build/cmake/lib/webview/CMakeLists.txt b/build/cmake/lib/webview/CMakeLists.txt index 1e2e7057a9..56ab76375d 100644 --- a/build/cmake/lib/webview/CMakeLists.txt +++ b/build/cmake/lib/webview/CMakeLists.txt @@ -37,7 +37,36 @@ if(APPLE) wx_lib_link_libraries(wxwebview PUBLIC "-framework WebKit") elseif(WXMSW) if(wxUSE_WEBVIEW_EDGE) - wx_lib_include_directories(wxwebview PRIVATE "${PROJECT_SOURCE_DIR}/3rdparty/webview2/build/native/include") + # Update the following variables if updating WebView2 SDK + set(WEBVIEW2_VERSION "1.0.705.50") + set(WEBVIEW2_URL "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/${WEBVIEW2_VERSION}") + set(WEBVIEW2_SHA256 "6a34bb553e18cfac7297b4031f3eac2558e439f8d16a45945c22945ac404105d") + + set(WEBVIEW2_DEFAULT_PACKAGE_DIR "${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2.${WEBVIEW2_VERSION}") + + find_path(WEBVIEW2_PACKAGE_DIR + NAMES build/native/include/WebView2.h + PATHS + "${PROJECT_SOURCE_DIR}/3rdparty/webview2" + ${WEBVIEW2_DEFAULT_PACKAGE_DIR} + ) + mark_as_advanced(WEBVIEW2_PACKAGE_DIR) + + if (NOT WEBVIEW2_PACKAGE_DIR) + message(STATUS "WebView2 SDK not found locally, downloading...") + set(WEBVIEW2_PACKAGE_DIR ${WEBVIEW2_DEFAULT_PACKAGE_DIR} CACHE PATH "WebView2 SDK PATH" FORCE) + file(DOWNLOAD + ${WEBVIEW2_URL} + ${CMAKE_BINARY_DIR}/webview2.nuget + EXPECTED_HASH SHA256=${WEBVIEW2_SHA256}) + file(MAKE_DIRECTORY ${WEBVIEW2_PACKAGE_DIR}) + execute_process(COMMAND + ${CMAKE_COMMAND} -E tar x ${CMAKE_BINARY_DIR}/webview2.nuget + WORKING_DIRECTORY ${WEBVIEW2_PACKAGE_DIR} + ) + endif() + + wx_lib_include_directories(wxwebview PRIVATE "${WEBVIEW2_PACKAGE_DIR}/build/native/include") if (CMAKE_SIZEOF_VOID_P EQUAL 4) set(WEBVIEW2_ARCH x86) @@ -47,7 +76,7 @@ elseif(WXMSW) add_custom_command(TARGET wxwebview POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy - "${PROJECT_SOURCE_DIR}/3rdparty/webview2/build/native/${WEBVIEW2_ARCH}/WebView2Loader.dll" + "${WEBVIEW2_PACKAGE_DIR}/build/native/${WEBVIEW2_ARCH}/WebView2Loader.dll" "$/WebView2Loader.dll") endif() elseif(WXGTK) diff --git a/build/cmake/options.cmake b/build/cmake/options.cmake index f2e873ff74..5fee034106 100644 --- a/build/cmake/options.cmake +++ b/build/cmake/options.cmake @@ -445,7 +445,8 @@ if(WIN32) else() set(wxUSE_WINRT_DEFAULT OFF) endif() - if(MSVC_VERSION GREATER 1800 AND NOT CMAKE_VS_PLATFORM_TOOLSET MATCHES "_xp$") + if(MSVC_VERSION GREATER 1800 AND NOT CMAKE_VS_PLATFORM_TOOLSET MATCHES "_xp$" AND + EXISTS "${wxSOURCE_DIR}/3rdparty/webview2") set(wxUSE_WEBVIEW_EDGE_DEFAULT ON) else() set(wxUSE_WEBVIEW_EDGE_DEFAULT OFF) diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 98482df6d5..9decc0f56b 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -321,12 +321,14 @@ public: This backend is not enabled by default, to build it follow these steps: - Visual Studio 2015, or newer, is required - - Download the WebView2 SDK - nuget package (Version 1.0.622.22 or newer) - - Extract the package (it's a zip archive) to @c wxWidgets/3rdparty/webview2 - (you should have @c 3rdparty/webview2/build/native/include/WebView2.h - file after unpacking it) - - Enable @c wxUSE_WEBVIEW_EDGE in CMake or @c setup.h + - With CMake just enable @c wxUSE_WEBVIEW_EDGE + - When not using CMake: + - Download the WebView2 SDK + nuget package (Version 1.0.622.22 or newer) + - Extract the package (it's a zip archive) to @c wxWidgets/3rdparty/webview2 + (you should have @c 3rdparty/webview2/build/native/include/WebView2.h + file after unpacking it) + - Enable @c wxUSE_WEBVIEW_EDGE in @c setup.h - Build wxWidgets webview library - Copy @c WebView2Loader.dll from the subdirectory corresponding to the architecture used (x86 or x64) of @c wxWidgets/3rdparty/webview2/build/