Files
desktop-plugin/windows/runner/CMakeLists.txt
T
dzc 634d100542 feat(windows): 集成 VC++ 运行库到安装包(干净电脑缺 vcruntime140 等导致启动报错)
flutter_windows.dll 与 HiTi SDK 均动态依赖 VC++ runtime,开发机因 VS 而有、
干净电脑没有(用户实测:他人电脑安装后启动弹找不到 dll)。
方案=应用本地部署(微软官方允许):从 VS 的 VC\Redist 拷运行库 dll 到
windows/vendor/vcruntime/(gitignore 不忽略,随仓库),CMake POST_BUILD
自动拷到 exe 旁,安装包随之分发。
2026-09-21 18:20:17 +08:00

69 lines
3.3 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
cmake_minimum_required(VERSION 3.14)
project(runner LANGUAGES CXX)
# Define the application target. To change its name, change BINARY_NAME in the
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
# work.
#
# Any new source files that you add to the application should be added here.
add_executable(${BINARY_NAME} WIN32
"flutter_window.cpp"
"main.cpp"
"utils.cpp"
"win32_window.cpp"
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
"Runner.rc"
"runner.exe.manifest"
)
# Apply the standard set of build settings. This can be removed for applications
# that need different build settings.
apply_standard_settings(${BINARY_NAME})
# Add preprocessor definitions for the build version.
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
# Disable Windows macros that collide with C++ standard library functions.
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
# 源文件为 UTF-8:MSVC 默认按系统代码页(中文系统 GBK)解析源码,
# main.cpp 的中文宽字符串(窗口标题"资安信插件助手")会乱码,必须显式声明
target_compile_options(${BINARY_NAME} PRIVATE "/utf-8")
# Add dependency libraries and include directories. Add any application-specific
# dependencies here.
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib")
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
# Run the Flutter tool portions of the build. This must not be removed.
add_dependencies(${BINARY_NAME} flutter_assemble)
# HiTi PavoApi SDK(windows/vendor/)拷到可执行文件旁:
# Dart 侧 DynamicLibrary.open('PavoApiW_x64.dll') 按可执行文件目录查找;
# heatthcd.bin 为 SDK 运行数据,与其余 DLL 一并部署
add_custom_command(TARGET ${BINARY_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/../vendor/PavoApiW_x64.dll"
"${CMAKE_CURRENT_SOURCE_DIR}/../vendor/PavoCardSDK_x64.dll"
"${CMAKE_CURRENT_SOURCE_DIR}/../vendor/HeatTB3.dll"
"${CMAKE_CURRENT_SOURCE_DIR}/../vendor/heatthcd.bin"
$<TARGET_FILE_DIR:${BINARY_NAME}>
)
# VC++ 运行库(windows/vendor/vcruntime/):flutter_windows.dll 与 HiTi SDK 均依赖
# vcruntime140/msvcp140 等——开发机因装 VS 而有,干净电脑没有(安装后启动弹
# "找不到 VCRUNTIME140.dll")。应用本地部署(exe 旁优先加载)为微软官方允许的分发方式。
# 目录内容从开发机 VS 的 VC\Redist\MSVC\*\x64\Microsoft.VC143.CRT 拷入(见 README)。
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../vendor/vcruntime")
add_custom_command(TARGET ${BINARY_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/../vendor/vcruntime"
$<TARGET_FILE_DIR:${BINARY_NAME}>
)
endif()