It is possible to run windeployqt
and macdeployqt
from CMake, but first the path to the executables must be found:
# 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}")
In order for windeployqt
to find the Qt libraries in their installed location, the folder must be added to %PATH%
. To do this for a target named myapp
after being built:
add_custom_command(TARGET myapp POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E
env PATH="${_qt_bin_dir}" "${WINDEPLOYQT_EXECUTABLE}"
"$<TARGET_FILE:myapp>"
COMMENT "Running windeployqt..."
)
For running macdeployqt
on a bundle, it would be done this way:
add_custom_command(TARGET myapp POST_BUILD
COMMAND "${MACDEPLOYQT_EXECUTABLE}"
"$<TARGET_FILE_DIR:myapp>/../.."
-always-overwrite
COMMENT "Running macdeployqt..."
)