Qt Qml Application Deploy (部署Qt程序以便发布到平台上执行)

QMake: (Add this in .pro)

isEmpty(TARGET_EXT) {
    win32 {
        TARGET_CUSTOM_EXT = .exe
    }
    macx {
        TARGET_CUSTOM_EXT = .app
    }
} else {
    TARGET_CUSTOM_EXT = $${TARGET_EXT}
}

DEPLOY_COMMAND = $$(QTDIR)/bin/windeployqt

CONFIG( debug, debug|release ) {
    # debug
    DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT}))
} else {
    # release
    DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT}))
}

QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_TARGET} \
    --qmldir $${PWD} \
    --no-translations \
    --no-system-d3d-compiler \
    --no-webkit2 \
    --no-angle \
    --no-opengl-sw \
    --no-virtualkeyboard
message($${QMAKE_POST_LINK})

CMake:

string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
get_target_property(_qmake_executable Qt5::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
find_program(DEPLOYQT_EXECUTABLE NAMES windeployqt HINTS "${_qt_bin_dir}")
add_custom_command(TARGET PROJECT_NAME
        POST_BUILD
        COMMAND ${DEPLOYQT_EXECUTABLE} "$<TARGET_FILE:PROJECT_NAME>"
        --force
        --${CMAKE_BUILD_TYPE_LOWER}
        --qmldir ${CMAKE_SOURCE_DIR}/qml
        --no-translations
        --no-system-d3d-compiler
        --no-webkit2
        --no-angle
        --no-opengl-sw
        --no-virtualkeyboard
    )
posted @ 2021-07-26 12:05  yinsua  阅读(221)  评论(0编辑  收藏  举报