-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
79 lines (67 loc) · 2.95 KB
/
Copy pathCMakeLists.txt
File metadata and controls
79 lines (67 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
cmake_minimum_required(VERSION 3.16)
project(PrivyWebViewWindows LANGUAGES CXX)
set(PLUGIN_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/x86_64")
add_library(PrivyWebView SHARED PrivyWebView.cpp)
# Ensure output is placed in the Unity plugin folder
set_target_properties(PrivyWebView PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
RUNTIME_OUTPUT_DIRECTORY "${PLUGIN_OUTPUT_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_OUTPUT_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${PLUGIN_OUTPUT_DIR}"
)
# WebView2 SDK support
# User can specify WEBVIEW2_ROOT to point to the WebView2 SDK root (contains include/ and lib/)
if(NOT WEBVIEW2_ROOT)
# ProgramFiles(x86) contains parentheses and cannot be referenced directly in CMake variables.
# Use cmd to expand it instead.
execute_process(COMMAND cmd /c "echo %ProgramFiles(x86)%" OUTPUT_VARIABLE _progfiles_x86 OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND cmd /c "echo %ProgramFiles%" OUTPUT_VARIABLE _progfiles OUTPUT_STRIP_TRAILING_WHITESPACE)
if(_progfiles_x86)
set(_webview2_candidate "${_progfiles_x86}/Microsoft WebView2 SDK")
elseif(_progfiles)
set(_webview2_candidate "${_progfiles}/Microsoft WebView2 SDK")
endif()
if(_webview2_candidate)
set(WEBVIEW2_ROOT "${_webview2_candidate}")
endif()
endif()
# Primary (recommended) include path
find_path(WEBVIEW2_INCLUDE_DIR WebView2.h
PATHS
"${WEBVIEW2_ROOT}/include"
"${WEBVIEW2_ROOT}/*/include"
NO_DEFAULT_PATH
)
# Primary lib path
find_library(WEBVIEW2_LIB WebView2LoaderStatic
PATHS
"${WEBVIEW2_ROOT}/x64"
"${WEBVIEW2_ROOT}/x86"
"${WEBVIEW2_ROOT}/*/x64"
"${WEBVIEW2_ROOT}/*/x86"
NO_DEFAULT_PATH
)
# Fallback: if we still don't find it, check the expected folder layout directly.
if(NOT WEBVIEW2_INCLUDE_DIR)
if(EXISTS "${WEBVIEW2_ROOT}/include/WebView2.h")
set(WEBVIEW2_INCLUDE_DIR "${WEBVIEW2_ROOT}/include")
endif()
endif()
if(NOT WEBVIEW2_LIB)
if(EXISTS "${WEBVIEW2_ROOT}/x64/WebView2LoaderStatic.lib")
set(WEBVIEW2_LIB "${WEBVIEW2_ROOT}/x64/WebView2LoaderStatic.lib")
elseif(EXISTS "${WEBVIEW2_ROOT}/x86/WebView2LoaderStatic.lib")
set(WEBVIEW2_LIB "${WEBVIEW2_ROOT}/x86/WebView2LoaderStatic.lib")
endif()
endif()
message(STATUS "WebView2 SDK root candidate: ${WEBVIEW2_ROOT}")
message(STATUS "Searching for WebView2.h under: ${WEBVIEW2_ROOT}/include")
if(WEBVIEW2_INCLUDE_DIR AND WEBVIEW2_LIB)
message(STATUS "Found WebView2 include: ${WEBVIEW2_INCLUDE_DIR}")
message(STATUS "Found WebView2 lib: ${WEBVIEW2_LIB}")
target_include_directories(PrivyWebView PRIVATE "${WEBVIEW2_INCLUDE_DIR}")
target_link_libraries(PrivyWebView PRIVATE "${WEBVIEW2_LIB}")
else()
message(FATAL_ERROR "WebView2 SDK not found. Please install WebView2 SDK (https://developer.microsoft.com/microsoft-edge/webview2/) and ensure WebView2.h and WebView2.lib are available. You can also set WEBVIEW2_ROOT to the SDK root folder.")
endif()