英文:
How can I set extra, custom arguments for androiddeployqt via CMakeLists.txt?
问题
在CMakeLists.txt中通过androiddeployqt
调用附加参数是否可能(Qt 6.4+)?
英文:
Is it possible to append an argument to the androiddeployqt
call via CMakeLists.txt (Qt 6.4+)?
答案1
得分: 1
从源代码看,我认为目前答案是否定的。在撰写本文时,Android/Androiddeployqt.cmake文件的最新版本工作方式如下:
# 创建一个自定义命令,用于运行androiddeployqt实用程序以生成APK
add_custom_target(
apk
DEPENDS ${ARG_TARGET}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI} # 似乎如果不先删除它们,重新编译的库不会被复制
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${ARG_TARGET}> ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI}
COMMAND ${ANDROID_DEPLOY_QT} $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> --output ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_BINARY_DIR}/qtdeploy.json $<$<CONFIG:Debug>:--no-strip> $<$<CONFIG:RelWithDebInfo>:--no-strip> $<$<CONFIG:Release>:--release> $<$<CONFIG:RelWithDebInfo>:--release> $<$<CONFIG:MinSizeRel>:--release> --no-generated-assets-cache --jdk ${JAVA_HOME_DIR} --gradle ${TARGET_LEVEL_OPTIONS} ${SIGN_OPTIONS}
)
# 创建一个自定义命令,用于在连接的Android设备上安装APK
add_custom_target(
apk-install
DEPENDS apk
COMMAND ${ANDROID_DEPLOY_QT} $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> --no-build --reinstall --output ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_BINARY_DIR}/qtdeploy.json $<$<CONFIG:Debug>:--no-strip> $<$<CONFIG:RelWithDebInfo>:--no-strip> $<$<CONFIG:Release>:--release> $<$<CONFIG:RelWithDebInfo>:--release> $<$<CONFIG:MinSizeRel>:--release> --no-generated-assets-cache --jdk ${JAVA_HOME_DIR} --gradle ${TARGET_LEVEL_OPTIONS} ${SIGN_OPTIONS}
)
我没有看到添加额外内容的地方。SIGN_OPTIONS
看起来不是一个可自由配置的点。如果您想要这样的功能,请创建一个问题反馈,并解释为什么这会很有用。如果这样做,请在此回答下面留下问题反馈的链接,以备将来查阅。如果您不想这样做,或者需要紧急进行此类更改,唯一的选择就是自己修补 Android/Androiddeployqt.cmake
。
英文:
Looking at the source code, I think the answer is currently no. At the time of this writing, the latest version of the Android/Androiddeployqt.cmake
file works like this:
> cmake
> # create a custom command that will run the androiddeployqt utility to generate the APK
> add_custom_target(
> apk
> DEPENDS ${ARG_TARGET}
> COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI} # it seems that recompiled libraries are not copied if we don't remove them first
> COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI}
> COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${ARG_TARGET}> ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI}
> COMMAND ${ANDROID_DEPLOY_QT} $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> --output ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_BINARY_DIR}/qtdeploy.json $<$<CONFIG:Debug>:--no-strip> $<$<CONFIG:RelWithDebInfo>:--no-strip> $<$<CONFIG:Release>:--release> $<$<CONFIG:RelWithDebInfo>:--release> $<$<CONFIG:MinSizeRel>:--release> --no-generated-assets-cache --jdk ${JAVA_HOME_DIR} --gradle ${TARGET_LEVEL_OPTIONS} ${SIGN_OPTIONS}
> )
>
> # create a custom command that will install the APK on a connected android device
> add_custom_target(
> apk-install
> DEPENDS apk
> COMMAND ${ANDROID_DEPLOY_QT} $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> --no-build --reinstall --output ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_BINARY_DIR}/qtdeploy.json $<$<CONFIG:Debug>:--no-strip> $<$<CONFIG:RelWithDebInfo>:--no-strip> $<$<CONFIG:Release>:--release> $<$<CONFIG:RelWithDebInfo>:--release> $<$<CONFIG:MinSizeRel>:--release> --no-generated-assets-cache --jdk ${JAVA_HOME_DIR} --gradle ${TARGET_LEVEL_OPTIONS} ${SIGN_OPTIONS}
> )
>
I don't see any points for adding extra things. SIGN_OPTIONS
does not look to be a free configuration point. You can create an issue ticket requesting such functionality and explaining why it would be useful. If you do, please comment under this answer with a link to that issue ticket for posterity. The only other option you have if you don't want to do that, or need to make such changes urgently, is to patch the Android/Androiddeployqt.cmake
yourself.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论