你可以如何通过CMakeLists.txt为androiddeployqt设置额外的自定义参数?

huangapple go评论76阅读模式
英文:

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
&gt; # create a custom command that will run the androiddeployqt utility to generate the APK
&gt; add_custom_target(
&gt; apk
&gt; DEPENDS ${ARG_TARGET}
&gt; COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI} # it seems that recompiled libraries are not copied if we don&#39;t remove them first
&gt; COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI}
&gt; COMMAND ${CMAKE_COMMAND} -E copy $&lt;TARGET_FILE:${ARG_TARGET}&gt; ${CMAKE_CURRENT_BINARY_DIR}/libs/${ANDROID_ABI}
&gt; COMMAND ${ANDROID_DEPLOY_QT} $&lt;$&lt;BOOL:${CMAKE_VERBOSE_MAKEFILE}&gt;:--verbose&gt; --output ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_BINARY_DIR}/qtdeploy.json $&lt;$&lt;CONFIG:Debug&gt;:--no-strip&gt; $&lt;$&lt;CONFIG:RelWithDebInfo&gt;:--no-strip&gt; $&lt;$&lt;CONFIG:Release&gt;:--release&gt; $&lt;$&lt;CONFIG:RelWithDebInfo&gt;:--release&gt; $&lt;$&lt;CONFIG:MinSizeRel&gt;:--release&gt; --no-generated-assets-cache --jdk ${JAVA_HOME_DIR} --gradle ${TARGET_LEVEL_OPTIONS} ${SIGN_OPTIONS}
&gt; )
&gt;
&gt; # create a custom command that will install the APK on a connected android device
&gt; add_custom_target(
&gt; apk-install
&gt; DEPENDS apk
&gt; COMMAND ${ANDROID_DEPLOY_QT} $&lt;$&lt;BOOL:${CMAKE_VERBOSE_MAKEFILE}&gt;:--verbose&gt; --no-build --reinstall --output ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_BINARY_DIR}/qtdeploy.json $&lt;$&lt;CONFIG:Debug&gt;:--no-strip&gt; $&lt;$&lt;CONFIG:RelWithDebInfo&gt;:--no-strip&gt; $&lt;$&lt;CONFIG:Release&gt;:--release&gt; $&lt;$&lt;CONFIG:RelWithDebInfo&gt;:--release&gt; $&lt;$&lt;CONFIG:MinSizeRel&gt;:--release&gt; --no-generated-assets-cache --jdk ${JAVA_HOME_DIR} --gradle ${TARGET_LEVEL_OPTIONS} ${SIGN_OPTIONS}
&gt; )
&gt;

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.

huangapple
  • 本文由 发表于 2023年2月27日 11:53:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75576647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定