qt_generate_deploy_script

生成自定义部署脚本。

该命令定义在Qt6 软件包的Core 组件中,可以像这样加载:

find_package(Qt6 REQUIRED COMPONENTS Core)

此命令在 Qt 6.5 中引入。

简介

qt_generate_deploy_script(
    OUTPUT_SCRIPT <var>
    [TARGET target]
    [NAME script_name]
    [CONTENT content]
)

如果禁用了无版本命令,请使用qt6_generate_deploy_script() 代替。它支持与此命令相同的参数集。

说明

该命令生成一个脚本,其完整文件路径将保存在OUTPUT_SCRIPT 选项命名的变量中。该脚本仅在 CMake 生成时编写。该脚本应与install(SCRIPT)命令一起使用,后者应在使用install(TARGETS) 安装应用程序的目标后使用。

该命令负责生成一个文件,文件名适合多重配置生成器。文件中添加了必要的包含项,以便 Qt 的 CMake 部署函数和变量能被访问。

TARGET 参数指定脚本将部署的目标。除非指定NAME ,否则这将影响生成脚本的文件名。

NAME 参数控制部署脚本自动生成名称中的可识别部分。如果未给出NAMETARGET ,则NAME 参数默认为custom

CONTENT 参数指定写入部署脚本的代码。内容可包含生成器表达式。

此命令用于生成直接调用 Qt 部署 API 函数的自定义部署脚本。对于不太复杂的部署,使用qt_generate_deploy_app_script()qt_generate_deploy_qml_ app_script()会更方便。

示例

cmake_minimum_required(VERSION 3.16...3.22)
project(MyThings)

find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()

qt_add_executable(MyApp main.cpp)

install(TARGETS MyApp
    BUNDLE  DESTINATION .
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

qt_generate_deploy_script(
    TARGET MyApp
    OUTPUT_SCRIPT deploy_script
    CONTENT "
qt_deploy_runtime_dependencies(
    EXECUTABLE $<TARGET_FILE_NAME:MyApp>
)
")
install(SCRIPT ${deploy_script})

另请参阅 qt_generate_deploy_app_script()qt_generate_deploy_qml_app_script()

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.