与 CMake 集成
可以从 CMake 运行 windeployqt
和 macdeployqt
,但首先必须找到可执行文件的路径:
# Retrieve the absolute path to qmake and then use that path to find
# the binaries
get_target_property(_qmake_executable Qt5::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}")
find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${_qt_bin_dir}")
为了让 windeployqt
在其安装位置找到 Qt 库,必须将该文件夹添加到%PATH%
。要在构建之后为名为 myapp
的目标执行此操作:
add_custom_command(TARGET myapp POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E
env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}"
"$<TARGET_FILE:myapp>"
COMMENT "Running windeployqt..."
)
对于在绑定上运行 macdeployqt
,它将以这种方式完成:
add_custom_command(TARGET myapp POST_BUILD
COMMAND "${MACDEPLOYQT_EXECUTABLE}"
"$<TARGET_FILE_DIR:myapp>/../.."
-always-overwrite
COMMENT "Running macdeployqt..."
)