Skip to content

Commit bf0ffb4

Browse files
committed
Update runner code to work with the latest & greatest
1 parent 9191329 commit bf0ffb4

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

examples/multi_window_ref_app/windows/CMakeLists.txt

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
# Project-level configuration.
12
cmake_minimum_required(VERSION 3.14)
2-
project(dartpad_curve2_d_0 LANGUAGES CXX)
3+
project(multi_window_ref_app LANGUAGES CXX)
34

4-
set(BINARY_NAME "dartpad_curve2_d_0")
5+
# The name of the executable created for the application. Change this to change
6+
# the on-disk name of your application.
7+
set(BINARY_NAME "multi_window_ref_app")
58

9+
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
10+
# versions of CMake.
611
cmake_policy(VERSION 3.14...3.25)
712

8-
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
9-
10-
# Configure build options.
13+
# Define build configuration option.
1114
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
1215
if(IS_MULTICONFIG)
1316
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
@@ -20,7 +23,7 @@ else()
2023
"Debug" "Profile" "Release")
2124
endif()
2225
endif()
23-
26+
# Define settings for the Profile build mode.
2427
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
2528
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
2629
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
@@ -30,6 +33,10 @@ set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
3033
add_definitions(-DUNICODE -D_UNICODE)
3134

3235
# Compilation settings that should be applied to most targets.
36+
#
37+
# Be cautious about adding new options here, as plugins use this function by
38+
# default. In most cases, you should add new options to specific targets instead
39+
# of modifying this function.
3340
function(APPLY_STANDARD_SETTINGS TARGET)
3441
target_compile_features(${TARGET} PUBLIC cxx_std_17)
3542
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
@@ -38,14 +45,14 @@ function(APPLY_STANDARD_SETTINGS TARGET)
3845
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
3946
endfunction()
4047

41-
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
42-
4348
# Flutter library and tool build rules.
49+
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
4450
add_subdirectory(${FLUTTER_MANAGED_DIR})
4551

46-
# Application build
52+
# Application build; see runner/CMakeLists.txt.
4753
add_subdirectory("runner")
4854

55+
4956
# Generated plugin build rules, which manage building the plugins and adding
5057
# them to the application.
5158
include(flutter/generated_plugins.cmake)
@@ -80,6 +87,12 @@ if(PLUGIN_BUNDLED_LIBRARIES)
8087
COMPONENT Runtime)
8188
endif()
8289

90+
# Copy the native assets provided by the build.dart from all packages.
91+
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
92+
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
93+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
94+
COMPONENT Runtime)
95+
8396
# Fully re-copy the assets directory on each build to avoid having stale files
8497
# from a previous install.
8598
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")

examples/multi_window_ref_app/windows/flutter/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
cmake_minimum_required(VERSION 3.14)
33

44
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5+
set(CMAKE_CXX_STANDARD 20)
56

67
# Configuration provided via flutter tool.
78
include(${EPHEMERAL_DIR}/generated_config.cmake)
@@ -52,12 +53,16 @@ list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
5253
list(APPEND CPP_WRAPPER_SOURCES_APP
5354
"flutter_engine.cc"
5455
"flutter_view_controller.cc"
56+
"flutter_window_controller.cc"
57+
"flutter_win32_window.cc"
58+
"win32_window.cc"
5559
)
5660
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
5761

5862
# Wrapper sources needed for a plugin.
5963
add_library(flutter_wrapper_plugin STATIC
6064
${CPP_WRAPPER_SOURCES_CORE}
65+
${CPP_WRAPPER_SOURCES_WINDOWING}
6166
${CPP_WRAPPER_SOURCES_PLUGIN}
6267
)
6368
apply_standard_settings(flutter_wrapper_plugin)
@@ -74,6 +79,7 @@ add_dependencies(flutter_wrapper_plugin flutter_assemble)
7479
# Wrapper sources needed for the runner.
7580
add_library(flutter_wrapper_app STATIC
7681
${CPP_WRAPPER_SOURCES_CORE}
82+
${CPP_WRAPPER_SOURCES_WINDOWING}
7783
${CPP_WRAPPER_SOURCES_APP}
7884
)
7985
apply_standard_settings(flutter_wrapper_app)
@@ -91,7 +97,7 @@ set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
9197
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
9298
add_custom_command(
9399
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
94-
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
100+
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_WINDOWING} ${CPP_WRAPPER_SOURCES_PLUGIN}
95101
${CPP_WRAPPER_SOURCES_APP}
96102
${PHONY_OUTPUT}
97103
COMMAND ${CMAKE_COMMAND} -E env
@@ -104,6 +110,7 @@ add_custom_target(flutter_assemble DEPENDS
104110
"${FLUTTER_LIBRARY}"
105111
${FLUTTER_LIBRARY_HEADERS}
106112
${CPP_WRAPPER_SOURCES_CORE}
113+
${CPP_WRAPPER_SOURCES_WINDOWING}
107114
${CPP_WRAPPER_SOURCES_PLUGIN}
108115
${CPP_WRAPPER_SOURCES_APP}
109116
)

examples/multi_window_ref_app/windows/runner/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ project(runner LANGUAGES CXX)
77
#
88
# Any new source files that you add to the application should be added here.
99
add_executable(${BINARY_NAME} WIN32
10-
"flutter_window.cpp"
1110
"main.cpp"
1211
"utils.cpp"
13-
"win32_window.cpp"
1412
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
1513
"Runner.rc"
1614
"runner.exe.manifest"
@@ -33,6 +31,7 @@ target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
3331
# Add dependency libraries and include directories. Add any application-specific
3432
# dependencies here.
3533
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
34+
target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib")
3635
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
3736

3837
# Run the Flutter tool portions of the build. This must not be removed.

examples/multi_window_ref_app/windows/runner/main.cpp

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
// Copyright 2014 The Flutter Authors. All rights reserved.
2-
// Use of this source code is governed by a BSD-style license that can be
3-
// found in the LICENSE file.
4-
1+
#include <flutter/generated_plugin_registrant.h>
2+
#include <flutter/method_channel.h>
53
#include <flutter/dart_project.h>
6-
#include <flutter/flutter_view_controller.h>
4+
#include <flutter/flutter_window_controller.h>
75
#include <windows.h>
86

9-
#include "flutter_window.h"
107
#include "utils.h"
118

129
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
@@ -23,18 +20,14 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
2320

2421
flutter::DartProject project(L"data");
2522

26-
std::vector<std::string> command_line_arguments =
27-
GetCommandLineArguments();
23+
auto command_line_arguments{GetCommandLineArguments()};
2824

2925
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
3026

31-
FlutterWindow window(project);
32-
Win32Window::Point origin(10, 10);
33-
Win32Window::Size size(1280, 720);
34-
if (!window.CreateAndShow(L"flutter_api_samples", origin, size)) {
35-
return EXIT_FAILURE;
36-
}
37-
window.SetQuitOnClose(true);
27+
auto const engine{std::make_shared<flutter::FlutterEngine>(project)};
28+
RegisterPlugins(engine.get());
29+
flutter::FlutterWindowController::GetInstance().SetEngine(engine);
30+
engine->Run();
3831

3932
::MSG msg;
4033
while (::GetMessage(&msg, nullptr, 0, 0)) {

0 commit comments

Comments
 (0)