diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2021-08-11 10:02:10 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2021-08-17 07:33:54 +0200 |
commit | 265d48f688b4169e60055b15702a90eb54262298 (patch) | |
tree | 944e0653e95a08a773d8146438819586809688a7 /src | |
parent | cc249cc1165f5f572b08e68ef256737b3ee64a4f (diff) |
CMake: Prevent multiple creation of the targets 'aab' and 'apk'
Suppose you have a project with multiple subdirectories. In the
subdirectories are find_package calls for Qt, but not in the top-level
file.
Example:
- CMakeLists.txt
- subdir1/CMakeLists.txt
find_package(Qt5 COMPONENTS Core)
- subdir2/CMakeLists.txt
find_package(Qt5 COMPONENTS Core)
Both find_package calls are local to their subdirectories, which means
that the second find_package is executed, even though the first was
already successful. Both calls try to create the targets 'apk' and
'aab'. This leads to the following CMake error:
add_custom_target cannot create target "apk" because another target
with the same name already exists.
Guard the add_custom_target calls such that they do not create a target
if it is already existent.
Fixes: QTBUG-87863
Change-Id: I132b0c7d9db9b2cb33b5e091cf0b216f06cd0d39
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/Qt5AndroidSupport.cmake | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/corelib/Qt5AndroidSupport.cmake b/src/corelib/Qt5AndroidSupport.cmake index 5512635f97..74d9e257d3 100644 --- a/src/corelib/Qt5AndroidSupport.cmake +++ b/src/corelib/Qt5AndroidSupport.cmake @@ -123,24 +123,28 @@ if (NOT ${PROJECT_NAME}-MultiAbiBuild) set(android_deploy_qt_platform "--android-platform ${ANDROID_SDK_PLATFORM}") endif() - add_custom_target(apk - COMMAND ${CMAKE_COMMAND} -E env JAVA_HOME=${JAVA_HOME} ${ANDROID_DEPLOY_QT} - --input "${CMAKE_BINARY_DIR}/android_deployment_settings.json" - --output "${CMAKE_BINARY_DIR}/android-build" - --apk "${CMAKE_BINARY_DIR}/android-build/${PROJECT_NAME}.apk" - ${android_deploy_qt_platform} - ${android_deploy_qt_jdk} - VERBATIM) - - add_custom_target(aab - COMMAND ${CMAKE_COMMAND} -E env JAVA_HOME=${JAVA_HOME} ${ANDROID_DEPLOY_QT} - --input "${CMAKE_BINARY_DIR}/android_deployment_settings.json" - --output "${CMAKE_BINARY_DIR}/android-build" - --apk "${CMAKE_BINARY_DIR}/android-build/${PROJECT_NAME}.apk" - --aab - ${android_deploy_qt_platform} - ${android_deploy_qt_jdk} - VERBATIM) + if(NOT TARGET apk) + add_custom_target(apk + COMMAND ${CMAKE_COMMAND} -E env JAVA_HOME=${JAVA_HOME} ${ANDROID_DEPLOY_QT} + --input "${CMAKE_BINARY_DIR}/android_deployment_settings.json" + --output "${CMAKE_BINARY_DIR}/android-build" + --apk "${CMAKE_BINARY_DIR}/android-build/${PROJECT_NAME}.apk" + ${android_deploy_qt_platform} + ${android_deploy_qt_jdk} + VERBATIM) + endif() + + if(NOT TARGET aab) + add_custom_target(aab + COMMAND ${CMAKE_COMMAND} -E env JAVA_HOME=${JAVA_HOME} ${ANDROID_DEPLOY_QT} + --input "${CMAKE_BINARY_DIR}/android_deployment_settings.json" + --output "${CMAKE_BINARY_DIR}/android-build" + --apk "${CMAKE_BINARY_DIR}/android-build/${PROJECT_NAME}.apk" + --aab + ${android_deploy_qt_platform} + ${android_deploy_qt_jdk} + VERBATIM) + endif() include(ExternalProject) macro (setup_library library_name android_abi) |