[client,SDL] add windows WebView2 link

Add a CMake script to download and link WebView2 for SDL client
This commit is contained in:
Armin Novak 2024-06-05 11:36:38 +02:00
parent 1a2374ea0b
commit cedc631b3e
No known key found for this signature in database
GPG Key ID: 2CF4A2D2D3D72105
2 changed files with 57 additions and 7 deletions

View File

@ -49,17 +49,12 @@ if (WITH_WEBVIEW)
wrapper/webview_impl.cpp wrapper/webview_impl.cpp
) )
if (WIN32) if(APPLE)
find_package(unofficial-webview2 CONFIG REQUIRED)
list(APPEND LIBS
unofficial::webview2::webview2
)
elseif(APPLE)
find_library(WEBKIT Webkit REQUIRED) find_library(WEBKIT Webkit REQUIRED)
list(APPEND LIBS list(APPEND LIBS
${WEBKIT} ${WEBKIT}
) )
else() elseif(NOT WIN32)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(WEBVIEW_GTK webkit2gtk-4.1) pkg_check_modules(WEBVIEW_GTK webkit2gtk-4.1)
if (NOT WEBVIEW_GTK_FOUND) if (NOT WEBVIEW_GTK_FOUND)
@ -93,4 +88,8 @@ target_compile_definitions(
PUBLIC PUBLIC
${DEFINITIONS} ${DEFINITIONS}
) )
if (WITH_WEBVIEW AND NOT WITH_WEBVIEW_QT)
include (WebView2)
target_link_webview2("sdl-common-aad-view")
endif()

51
cmake/WebView2.cmake Normal file
View File

@ -0,0 +1,51 @@
if(WIN32)
# WebView2 SDK
set(WEBVIEW2_VERSION "1.0.2535.41")
set(WEBVIEW2_URL "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/${WEBVIEW2_VERSION}")
set(WEBVIEW2_SHA256 "c9c5518e4d7efa9079ad87bafb64f3c8e8edca0e95d34df878034b880a7af56b")
set(WEBVIEW2_DEFAULT_PACKAGE_DIR "${CMAKE_CURRENT_BINARY_DIR}/packages/Microsoft.Web.WebView2.${WEBVIEW2_VERSION}")
if(NOT EXISTS ${WEBVIEW2_PACKAGE_DIR})
unset(WEBVIEW2_PACKAGE_DIR CACHE)
endif()
find_path(WEBVIEW2_PACKAGE_DIR
NAMES
"build/native/include/WebView2.h"
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH # dont prepend CMAKE_PREFIX
)
if(NOT WEBVIEW2_PACKAGE_DIR)
message(WARNING "WebView2 SDK not found locally, downloading ${WEBVIEW2_VERSION} ...")
set(WEBVIEW2_PACKAGE_DIR ${WEBVIEW2_DEFAULT_PACKAGE_DIR} CACHE PATH "WebView2 SDK PATH" FORCE)
file(
DOWNLOAD
${WEBVIEW2_URL}
${CMAKE_CURRENT_BINARY_DIR}/webview2.nuget
EXPECTED_HASH
SHA256=${WEBVIEW2_SHA256}
)
file(MAKE_DIRECTORY ${WEBVIEW2_PACKAGE_DIR})
execute_process(
COMMAND
"${CMAKE_COMMAND}" -E tar x "${CMAKE_CURRENT_BINARY_DIR}/webview2.nuget"
WORKING_DIRECTORY
"${WEBVIEW2_PACKAGE_DIR}"
)
endif()
set(WEBVIEW2_PACKAGE_DIR ${WEBVIEW2_PACKAGE_DIR} CACHE INTERNAL "" FORCE)
endif()
function(target_link_webview2 target)
if(WIN32)
target_include_directories(${target}
PRIVATE
"${WEBVIEW2_PACKAGE_DIR}/build/native/include"
)
target_link_libraries(${target}
PRIVATE
shlwapi
version
"${WEBVIEW2_PACKAGE_DIR}/build/native/${CMAKE_VS_PLATFORM_NAME}/WebView2LoaderStatic.lib"
)
endif()
endfunction()