Skip to content

Commit a41cbf9

Browse files
Add windows support to desktop photo search. (#548)
1 parent 850eff6 commit a41cbf9

21 files changed

+1057
-3
lines changed

experimental/desktop_photo_search/pubspec.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ packages:
209209
description:
210210
path: "plugins/file_chooser"
211211
ref: HEAD
212-
resolved-ref: "9a0b3860bf11cd02bc98194e57d286a6e70df1b6"
212+
resolved-ref: dc5bad31ae93dd5d82e235e38d5c21b6a47445ab
213213
url: "https://github.com/google/flutter-desktop-embedding.git"
214214
source: git
215215
version: "0.2.0"
@@ -338,7 +338,7 @@ packages:
338338
description:
339339
path: "plugins/menubar"
340340
ref: HEAD
341-
resolved-ref: "9a0b3860bf11cd02bc98194e57d286a6e70df1b6"
341+
resolved-ref: dc5bad31ae93dd5d82e235e38d5c21b6a47445ab
342342
url: "https://github.com/google/flutter-desktop-embedding.git"
343343
source: git
344344
version: "0.1.0"
@@ -514,7 +514,7 @@ packages:
514514
name: source_span
515515
url: "https://pub.dartlang.org"
516516
source: hosted
517-
version: "1.8.0-nullsafety"
517+
version: "1.8.0-nullsafety.2"
518518
stack_trace:
519519
dependency: transitive
520520
description:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
flutter/ephemeral/
2+
3+
# Visual Studio user-specific files.
4+
*.suo
5+
*.user
6+
*.userosscache
7+
*.sln.docstates
8+
9+
# Visual Studio build-related files.
10+
x64/
11+
x86/
12+
13+
# Visual Studio cache files
14+
# files ending in .cache can be ignored
15+
*.[Cc]ache
16+
# but keep track of directories ending in .cache
17+
!*.[Cc]ache/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(desktop_photo_search LANGUAGES CXX)
3+
4+
set(BINARY_NAME "desktop_photo_search")
5+
6+
cmake_policy(SET CMP0063 NEW)
7+
8+
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
9+
10+
# Configure build options.
11+
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
12+
if(IS_MULTICONFIG)
13+
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
14+
CACHE STRING "" FORCE)
15+
else()
16+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
17+
set(CMAKE_BUILD_TYPE "Debug" CACHE
18+
STRING "Flutter build mode" FORCE)
19+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
20+
"Debug" "Profile" "Release")
21+
endif()
22+
endif()
23+
24+
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
25+
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
26+
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
27+
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
28+
29+
# Use Unicode for all projects.
30+
add_definitions(-DUNICODE -D_UNICODE)
31+
32+
# Compilation settings that should be applied to most targets.
33+
function(APPLY_STANDARD_SETTINGS TARGET)
34+
target_compile_features(${TARGET} PUBLIC cxx_std_17)
35+
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
36+
target_compile_options(${TARGET} PRIVATE /EHsc)
37+
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
38+
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
39+
endfunction()
40+
41+
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
42+
43+
# Flutter library and tool build rules.
44+
add_subdirectory(${FLUTTER_MANAGED_DIR})
45+
46+
# Application build
47+
add_subdirectory("runner")
48+
49+
# Generated plugin build rules, which manage building the plugins and adding
50+
# them to the application.
51+
include(flutter/generated_plugins.cmake)
52+
53+
54+
# === Installation ===
55+
# Support files are copied into place next to the executable, so that it can
56+
# run in place. This is done instead of making a separate bundle (as on Linux)
57+
# so that building and running from within Visual Studio will work.
58+
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
59+
# Make the "install" step default, as it's required to run.
60+
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
61+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
62+
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
63+
endif()
64+
65+
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
66+
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
67+
68+
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
69+
COMPONENT Runtime)
70+
71+
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
72+
COMPONENT Runtime)
73+
74+
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
75+
COMPONENT Runtime)
76+
77+
if(PLUGIN_BUNDLED_LIBRARIES)
78+
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
79+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
80+
COMPONENT Runtime)
81+
endif()
82+
83+
# Fully re-copy the assets directory on each build to avoid having stale files
84+
# from a previous install.
85+
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
86+
install(CODE "
87+
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
88+
" COMPONENT Runtime)
89+
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
90+
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
91+
92+
# Install the AOT library on non-Debug builds only.
93+
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
94+
CONFIGURATIONS Profile;Release
95+
COMPONENT Runtime)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4+
5+
# Configuration provided via flutter tool.
6+
include(${EPHEMERAL_DIR}/generated_config.cmake)
7+
8+
# TODO: Move the rest of this into files in ephemeral. See
9+
# https://github.com/flutter/flutter/issues/57146.
10+
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
11+
12+
# === Flutter Library ===
13+
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
14+
15+
# Published to parent scope for install step.
16+
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
17+
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
18+
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
19+
set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
20+
21+
list(APPEND FLUTTER_LIBRARY_HEADERS
22+
"flutter_export.h"
23+
"flutter_windows.h"
24+
"flutter_messenger.h"
25+
"flutter_plugin_registrar.h"
26+
)
27+
list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
28+
add_library(flutter INTERFACE)
29+
target_include_directories(flutter INTERFACE
30+
"${EPHEMERAL_DIR}"
31+
)
32+
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
33+
add_dependencies(flutter flutter_assemble)
34+
35+
# === Wrapper ===
36+
list(APPEND CPP_WRAPPER_SOURCES_CORE
37+
"core_implementations.cc"
38+
"standard_codec.cc"
39+
)
40+
list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
41+
list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
42+
"plugin_registrar.cc"
43+
)
44+
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
45+
list(APPEND CPP_WRAPPER_SOURCES_APP
46+
"flutter_engine.cc"
47+
"flutter_view_controller.cc"
48+
)
49+
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
50+
51+
# Wrapper sources needed for a plugin.
52+
add_library(flutter_wrapper_plugin STATIC
53+
${CPP_WRAPPER_SOURCES_CORE}
54+
${CPP_WRAPPER_SOURCES_PLUGIN}
55+
)
56+
apply_standard_settings(flutter_wrapper_plugin)
57+
set_target_properties(flutter_wrapper_plugin PROPERTIES
58+
POSITION_INDEPENDENT_CODE ON)
59+
set_target_properties(flutter_wrapper_plugin PROPERTIES
60+
CXX_VISIBILITY_PRESET hidden)
61+
target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
62+
target_include_directories(flutter_wrapper_plugin PUBLIC
63+
"${WRAPPER_ROOT}/include"
64+
)
65+
add_dependencies(flutter_wrapper_plugin flutter_assemble)
66+
67+
# Wrapper sources needed for the runner.
68+
add_library(flutter_wrapper_app STATIC
69+
${CPP_WRAPPER_SOURCES_CORE}
70+
${CPP_WRAPPER_SOURCES_APP}
71+
)
72+
apply_standard_settings(flutter_wrapper_app)
73+
target_link_libraries(flutter_wrapper_app PUBLIC flutter)
74+
target_include_directories(flutter_wrapper_app PUBLIC
75+
"${WRAPPER_ROOT}/include"
76+
)
77+
add_dependencies(flutter_wrapper_app flutter_assemble)
78+
79+
# === Flutter tool backend ===
80+
# _phony_ is a non-existent file to force this command to run every time,
81+
# since currently there's no way to get a full input/output list from the
82+
# flutter tool.
83+
set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
84+
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
85+
add_custom_command(
86+
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
87+
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
88+
${CPP_WRAPPER_SOURCES_APP}
89+
${PHONY_OUTPUT}
90+
COMMAND ${CMAKE_COMMAND} -E env
91+
${FLUTTER_TOOL_ENVIRONMENT}
92+
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
93+
windows-x64 $<CONFIG>
94+
)
95+
add_custom_target(flutter_assemble DEPENDS
96+
"${FLUTTER_LIBRARY}"
97+
${FLUTTER_LIBRARY_HEADERS}
98+
${CPP_WRAPPER_SOURCES_CORE}
99+
${CPP_WRAPPER_SOURCES_PLUGIN}
100+
${CPP_WRAPPER_SOURCES_APP}
101+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#include "generated_plugin_registrant.h"
6+
7+
#include <file_chooser/file_chooser_plugin.h>
8+
#include <menubar/menubar_plugin.h>
9+
#include <url_launcher_windows/url_launcher_plugin.h>
10+
11+
void RegisterPlugins(flutter::PluginRegistry* registry) {
12+
FileChooserPluginRegisterWithRegistrar(
13+
registry->GetRegistrarForPlugin("FileChooserPlugin"));
14+
MenubarPluginRegisterWithRegistrar(
15+
registry->GetRegistrarForPlugin("MenubarPlugin"));
16+
UrlLauncherPluginRegisterWithRegistrar(
17+
registry->GetRegistrarForPlugin("UrlLauncherPlugin"));
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#ifndef GENERATED_PLUGIN_REGISTRANT_
6+
#define GENERATED_PLUGIN_REGISTRANT_
7+
8+
#include <flutter/plugin_registry.h>
9+
10+
// Registers Flutter plugins.
11+
void RegisterPlugins(flutter::PluginRegistry* registry);
12+
13+
#endif // GENERATED_PLUGIN_REGISTRANT_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Generated file, do not edit.
3+
#
4+
5+
list(APPEND FLUTTER_PLUGIN_LIST
6+
file_chooser
7+
menubar
8+
url_launcher_windows
9+
)
10+
11+
set(PLUGIN_BUNDLED_LIBRARIES)
12+
13+
foreach(plugin ${FLUTTER_PLUGIN_LIST})
14+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
15+
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
16+
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
17+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
18+
endforeach(plugin)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(runner LANGUAGES CXX)
3+
4+
add_executable(${BINARY_NAME} WIN32
5+
"flutter_window.cpp"
6+
"main.cpp"
7+
"run_loop.cpp"
8+
"utils.cpp"
9+
"win32_window.cpp"
10+
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
11+
"Runner.rc"
12+
"runner.exe.manifest"
13+
)
14+
apply_standard_settings(${BINARY_NAME})
15+
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
16+
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
17+
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
18+
add_dependencies(${BINARY_NAME} flutter_assemble)

0 commit comments

Comments
 (0)