QT_DEPLOY_BIN_DIR
用于在某些目标平台上部署运行时二进制文件的、相对于前缀的子目录。
该变量由QT_DEPLOY_SUPPORT 指定的脚本定义。它仅应在安装过程中的部署环节或构建后规则中使用。
注意:这是一个 低级部署 API 变量,仅应用于高级使用场景,即那些未被更高层级 API 命令(如qt_generate_deploy_app_script)涵盖的场景。
该变量于 Qt 6.3 版本中引入。
项目应在部署脚本中使用 `QT_DEPLOY_BIN_DIR `,以避免在部署以下类型的二进制文件时硬编码特定的目录:
- 所有平台上的可执行文件。
- Windows 平台上的 DLL。
QT_DEPLOY_BIN_DIR 默认值为${CMAKE_INSTALL_BINDIR} (通常为bin ),该值由CMake的GNUInstallDirs模块提供。若要更改QT_DEPLOY_BIN_DIR 的值,请确保在找到Core 包之前,项目已设置CMAKE_INSTALL_BINDIR 。
QT_DEPLOY_BIN_DIR 的路径是相对于QT_DEPLOY_PREFIX的。
在将项目部署到 macOS 应用程序包时,该变量没有实际意义,因此不应在此场景下使用。
示例
cmake_minimum_required(VERSION 3.16...3.22)
project(MyThings)
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()
# Keep the QT_DEPLOY_* references below for the generated script to expand,
# see \l {QTP0008}.
qt_policy(SET QTP0008 NEW)
qt_add_executable(MyApp main.cpp)
set_target_properties(MyApp PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
# App bundles on macOS have an .app suffix
if(APPLE)
set(executable_path "$<TARGET_FILE_NAME:MyApp>.app")
else()
set(executable_path "\${QT_DEPLOY_BIN_DIR}/$<TARGET_FILE_NAME:MyApp>")
endif()
# Helper app, not necessarily built as part of this project.
qt_add_executable(HelperApp helper.cpp)
set(helper_app_path "\${QT_DEPLOY_BIN_DIR}/$<TARGET_FILE_NAME:HelperApp>")
# Generate a deployment script to be executed at install time
qt_generate_deploy_script(
TARGET MyApp
OUTPUT_SCRIPT deploy_script
CONTENT "
qt_deploy_runtime_dependencies(
EXECUTABLE \"${executable_path}\"
ADDITIONAL_EXECUTABLES \"${helper_app_path}\"
GENERATE_QT_CONF
VERBOSE
)")
# Omitting RUNTIME DESTINATION will install a non-bundle target to CMAKE_INSTALL_BINDIR,
# which coincides with the default value of QT_DEPLOY_BIN_DIR used above, './bin'.
# Installing macOS bundles always requires an explicit BUNDLE DESTINATION option.
install(TARGETS MyApp HelperApp # Install to CMAKE_INSTALL_PREFIX/bin/MyApp.exe
# and ./binHelperApp.exe
BUNDLE DESTINATION . # Install to CMAKE_INSTALL_PREFIX/MyApp.app/Contents/MacOS/MyApp
)
install(SCRIPT ${deploy_script}) # Add its runtime dependencies另请参阅 QT_DEPLOY_SUPPORT、QT_DEPLOY_PREFIX、QT_DEPLOY_LIBEXEC_DIR、QT_DEPLOY_LIB_DIR、QT_DEPLOY_PLUGINS_DIR、QT_DEPLOY_QML_DIR 以及QT_DEPLOY_TRANSLATIONS_DIR。
© 2026 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.