summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2021-11-29 11:18:38 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2021-11-29 19:55:05 +0100
commit95ccdfa43276652f1b9ca5944a94b7e15c510dbd (patch)
treeff4d2a25bb67ba230aaebdf54cdb55612dc0e040
parent793417ce75bef47dd42e16a6cf9bf081db4238a5 (diff)
CMake: Fix Android platform detection
...if an Android platform < 10 is installed. The existing platform detection code preferred android-9 over android-31, because the sorting did not use natural comparison. Natural comparison was added to CMake in version 3.18. We simulate this feature for older CMake versions. Pick-to: 6.2 Fixes: QTBUG-98726 Change-Id: Ib2eb87bd47220feb672275fa5203df4f2b6d7ca7 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--cmake/QtPlatformAndroid.cmake29
1 files changed, 28 insertions, 1 deletions
diff --git a/cmake/QtPlatformAndroid.cmake b/cmake/QtPlatformAndroid.cmake
index 24185c1e21..eef6940886 100644
--- a/cmake/QtPlatformAndroid.cmake
+++ b/cmake/QtPlatformAndroid.cmake
@@ -35,6 +35,33 @@ endfunction()
# Minimum recommend android SDK api version
set(QT_ANDROID_API_VERSION "android-31")
+function(qt_internal_sort_android_platforms out_var)
+ if(CMAKE_VERSION GREATER_EQUAL 3.18)
+ set(platforms ${ARGN})
+ list(SORT platforms COMPARE NATURAL)
+ else()
+ # Simulate natural sorting:
+ # - prepend every platform with its version as three digits, zero-padded
+ # - regular sort
+ # - remove the padded version prefix
+ set(platforms)
+ foreach(platform IN LISTS ARGN)
+ set(version "000")
+ if(platform MATCHES ".*-([0-9]+)$")
+ set(version ${CMAKE_MATCH_1})
+ string(LENGTH "${version}" version_length)
+ math(EXPR padding_length "3 - ${version_length}")
+ string(REPEAT "0" ${padding_length} padding)
+ string(PREPEND version ${padding})
+ endif()
+ list(APPEND platforms "${version}~${platform}")
+ endforeach()
+ list(SORT platforms)
+ list(TRANSFORM platforms REPLACE "^.*~" "")
+ endif()
+ set("${out_var}" "${platforms}" PARENT_SCOPE)
+endfunction()
+
# Locate android.jar
set(QT_ANDROID_JAR "${ANDROID_SDK_ROOT}/platforms/${QT_ANDROID_API_VERSION}/android.jar")
if(NOT EXISTS "${QT_ANDROID_JAR}")
@@ -45,7 +72,7 @@ if(NOT EXISTS "${QT_ANDROID_JAR}")
"${ANDROID_SDK_ROOT}/platforms/*")
# If list is not empty
if(android_platforms)
- list(SORT android_platforms)
+ qt_internal_sort_android_platforms(android_platforms ${android_platforms})
list(REVERSE android_platforms)
list(GET android_platforms 0 android_platform_latest)
set(QT_ANDROID_API_VERSION ${android_platform_latest})