FreeRDP/cmake/WebView2.cmake
Armin Novak cedc631b3e
[client,SDL] add windows WebView2 link
Add a CMake script to download and link WebView2 for SDL client
2024-06-05 13:52:10 +02:00

52 lines
1.6 KiB
CMake

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()