Skip to content

Commit ed81bbe

Browse files
Fix the CMake warning related to CMP0175 policy and improve the overall CMake configuration using modern practices. (#322)
1 parent 5e156e4 commit ed81bbe

File tree

4 files changed

+74
-15
lines changed

4 files changed

+74
-15
lines changed

example/windows/flutter/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
99
# https://github.com/flutter/flutter/issues/57146.
1010
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
1111

12+
# Set fallback configurations for older versions of the flutter tool.
13+
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
14+
set(FLUTTER_TARGET_PLATFORM "windows-x64")
15+
endif()
16+
1217
# === Flutter Library ===
1318
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
1419

@@ -91,7 +96,7 @@ add_custom_command(
9196
COMMAND ${CMAKE_COMMAND} -E env
9297
${FLUTTER_TOOL_ENVIRONMENT}
9398
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
94-
windows-x64 $<CONFIG>
99+
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
95100
VERBATIM
96101
)
97102
add_custom_target(flutter_assemble DEPENDS
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Generated file, do not edit.
3+
#
4+
5+
list(APPEND FLUTTER_PLUGIN_LIST
6+
screen_retriever
7+
webview_windows
8+
window_manager
9+
)
10+
11+
list(APPEND FLUTTER_FFI_PLUGIN_LIST
12+
)
13+
14+
set(PLUGIN_BUNDLED_LIBRARIES)
15+
16+
foreach(plugin ${FLUTTER_PLUGIN_LIST})
17+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
18+
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
19+
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
20+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
21+
endforeach(plugin)
22+
23+
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
24+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
25+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
26+
endforeach(ffi_plugin)

example/windows/runner/Runner.rc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
6060
// Version
6161
//
6262

63-
#ifdef FLUTTER_BUILD_NUMBER
64-
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
63+
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
64+
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
6565
#else
66-
#define VERSION_AS_NUMBER 1,0,0
66+
#define VERSION_AS_NUMBER 1,0,0,0
6767
#endif
6868

69-
#ifdef FLUTTER_BUILD_NAME
70-
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
69+
#if defined(FLUTTER_VERSION)
70+
#define VERSION_AS_STRING FLUTTER_VERSION
7171
#else
7272
#define VERSION_AS_STRING "1.0.0"
7373
#endif

windows/CMakeLists.txt

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
cmake_minimum_required(VERSION 3.15)
2+
3+
# Set CMP0175 to NEW to properly handle add_custom_command arguments
4+
if(POLICY CMP0175)
5+
cmake_policy(SET CMP0175 NEW)
6+
endif()
7+
28
set(PROJECT_NAME "webview_windows")
39

410
set(WIL_VERSION "1.0.220914.1")
@@ -15,6 +21,7 @@ set(PLUGIN_NAME "webview_windows_plugin")
1521
set(NUGET_URL https://dist.nuget.org/win-x86-commandline/v5.10.0/nuget.exe)
1622
set(NUGET_SHA256 852b71cc8c8c2d40d09ea49d321ff56fd2397b9d6ea9f96e532530307bbbafd3)
1723

24+
# Find or download NuGet
1825
find_program(NUGET nuget)
1926
if(NOT NUGET)
2027
message(NOTICE "Nuget is not installed.")
@@ -30,15 +37,21 @@ if(NOT NUGET)
3037
endif()
3138
endif()
3239

40+
# Create custom target for dependencies
3341
add_custom_target(${PROJECT_NAME}_DEPENDENCIES_DOWNLOAD ALL)
42+
43+
# Download dependencies using NuGet
44+
# Note: Removed DEPENDS keyword from TARGET version of add_custom_command
3445
add_custom_command(
3546
TARGET ${PROJECT_NAME}_DEPENDENCIES_DOWNLOAD PRE_BUILD
47+
COMMAND ${CMAKE_COMMAND} -E echo "Downloading dependencies..."
3648
COMMAND ${NUGET} install Microsoft.Windows.ImplementationLibrary -Version ${WIL_VERSION} -ExcludeVersion -OutputDirectory ${CMAKE_BINARY_DIR}/packages
3749
COMMAND ${NUGET} install Microsoft.Web.WebView2 -Version ${WEBVIEW_VERSION} -ExcludeVersion -OutputDirectory ${CMAKE_BINARY_DIR}/packages
38-
DEPENDS ${NUGET}
50+
COMMENT "Downloading and installing NuGet packages"
3951
)
4052

41-
add_library(${PLUGIN_NAME} SHARED
53+
# Define source files
54+
set(PLUGIN_SOURCES
4255
"webview_windows_plugin.cc"
4356
"webview_platform.cc"
4457
"webview.cc"
@@ -52,25 +65,40 @@ add_library(${PLUGIN_NAME} SHARED
5265
"util/string_converter.cc"
5366
)
5467

68+
# Create the plugin library
69+
add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SOURCES})
70+
71+
# Configure compiler options
5572
if(MSVC)
5673
target_compile_options(${PLUGIN_NAME} PRIVATE "/await")
5774
endif()
5875

76+
# Apply standard settings
5977
apply_standard_settings(${PLUGIN_NAME})
60-
target_compile_features(${PLUGIN_NAME} PUBLIC cxx_std_20) # For std::format support
6178

62-
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
79+
# Set C++ standard to 20 for std::format support
80+
target_compile_features(${PLUGIN_NAME} PUBLIC cxx_std_20)
6381

64-
target_link_libraries(${PLUGIN_NAME} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/Microsoft.Web.WebView2.targets)
65-
target_link_libraries(${PLUGIN_NAME} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.ImplementationLibrary/build/native/Microsoft.Windows.ImplementationLibrary.targets)
82+
# Configure visibility
83+
set_target_properties(${PLUGIN_NAME} PROPERTIES
84+
CXX_VISIBILITY_PRESET hidden
85+
)
86+
87+
# Add dependencies
88+
target_link_libraries(${PLUGIN_NAME} PRIVATE
89+
${CMAKE_BINARY_DIR}/packages/Microsoft.Web.WebView2/build/native/Microsoft.Web.WebView2.targets
90+
${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.ImplementationLibrary/build/native/Microsoft.Windows.ImplementationLibrary.targets
91+
flutter
92+
flutter_wrapper_plugin
93+
)
6694

95+
# Configure definitions and includes
6796
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
6897
target_include_directories(${PLUGIN_NAME} INTERFACE
6998
"${CMAKE_CURRENT_SOURCE_DIR}/include"
7099
)
71100

72-
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
73-
101+
# Set bundled libraries
74102
set(webview_windows_bundled_libraries
75103
PARENT_SCOPE
76-
)
104+
)

0 commit comments

Comments
 (0)