CMake:Android: Use ANDROID_PLATFORM instead of ANDROID_NATIVE_API_LEVEL

ANDROID_NATIVE_API_LEVEL is an alias for ANDROID_PLATFORM and the
Android's CMake docs [1] uses directly ANDROID_PLATFORM so let's use
that as well. Also, NDK r23b seems to have removed the part of code from
android.toolchain.cmake that handles ANDROID_NATIVE_API_LEVEL to set
the correct value to ANDROID_PLATFORM.

With this change, CMake will pass the value from the configure argument
-android-ndk-platform as -DANDROID_PLATFORM instead of
-DANDROID_NATIVE_API_LEVEL. Otherwise, if if  -DANDROID_NATIVE_API_LEVEL
is passed directly to CMake, it should work as before.

[1] https://developer.android.com/ndk/guides/cmake#build-command

Pick-to: 6.3
Task-number: QTQAINFRA-4837
Change-Id: I5c21af53ac91e11a27c4b033313d22d1115c1abc
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Assam Boudjelthia 2022-03-08 15:08:00 +02:00
parent 888b75aa12
commit db2f47337b
7 changed files with 18 additions and 11 deletions

View File

@ -139,8 +139,10 @@ function(qt_auto_detect_android)
if(android_detected) if(android_detected)
message(STATUS "Android build detected, checking configuration defaults...") message(STATUS "Android build detected, checking configuration defaults...")
if(NOT DEFINED ANDROID_NATIVE_API_LEVEL) # ANDROID_NATIVE_API_LEVEL is an just an alias to ANDROID_PLATFORM, check for both
message(STATUS "ANDROID_NATIVE_API_LEVEL was not specified, using API level 23 as default") if(NOT DEFINED ANDROID_PLATFORM AND NOT DEFINED ANDROID_NATIVE_API_LEVEL)
message(STATUS "Neither ANDROID_PLATFORM nor ANDROID_NATIVE_API_LEVEL were specified, using API level 23 as default")
set(ANDROID_PLATFORM "android-23" CACHE STRING "")
set(ANDROID_NATIVE_API_LEVEL 23 CACHE STRING "") set(ANDROID_NATIVE_API_LEVEL 23 CACHE STRING "")
endif() endif()
if(NOT DEFINED ANDROID_STL) if(NOT DEFINED ANDROID_STL)

View File

@ -254,6 +254,7 @@ function(qt_internal_print_cmake_android_info)
message(STATUS "ANDROID_NDK: \"${ANDROID_NDK}\"") message(STATUS "ANDROID_NDK: \"${ANDROID_NDK}\"")
message(STATUS "ANDROID_ABI: \"${ANDROID_ABI}\"") message(STATUS "ANDROID_ABI: \"${ANDROID_ABI}\"")
message(STATUS "ANDROID_PLATFORM: \"${ANDROID_PLATFORM}\"") message(STATUS "ANDROID_PLATFORM: \"${ANDROID_PLATFORM}\"")
message(STATUS "ANDROID_NATIVE_API_LEVEL: \"${ANDROID_NATIVE_API_LEVEL}\"")
message(STATUS "ANDROID_STL: \"${ANDROID_STL}\"") message(STATUS "ANDROID_STL: \"${ANDROID_STL}\"")
message(STATUS "ANDROID_PIE: \"${ANDROID_PIE}\"") message(STATUS "ANDROID_PIE: \"${ANDROID_PIE}\"")
message(STATUS "ANDROID_CPP_FEATURES: \"${ANDROID_CPP_FEATURES}\"") message(STATUS "ANDROID_CPP_FEATURES: \"${ANDROID_CPP_FEATURES}\"")
@ -261,7 +262,6 @@ function(qt_internal_print_cmake_android_info)
message(STATUS "ANDROID_ARM_MODE: \"${ANDROID_ARM_MODE}\"") message(STATUS "ANDROID_ARM_MODE: \"${ANDROID_ARM_MODE}\"")
message(STATUS "ANDROID_ARM_NEON: \"${ANDROID_ARM_NEON}\"") message(STATUS "ANDROID_ARM_NEON: \"${ANDROID_ARM_NEON}\"")
message(STATUS "ANDROID_DISABLE_FORMAT_STRING_CHECKS: \"${ANDROID_DISABLE_FORMAT_STRING_CHECKS}\"") message(STATUS "ANDROID_DISABLE_FORMAT_STRING_CHECKS: \"${ANDROID_DISABLE_FORMAT_STRING_CHECKS}\"")
message(STATUS "ANDROID_NATIVE_API_LEVEL: \"${ANDROID_NATIVE_API_LEVEL}\"")
message(STATUS "ANDROID_LLVM_TRIPLE: \"${ANDROID_LLVM_TRIPLE}\"") message(STATUS "ANDROID_LLVM_TRIPLE: \"${ANDROID_LLVM_TRIPLE}\"")
endif() endif()
endfunction() endfunction()

View File

@ -792,7 +792,9 @@ function(qt_generate_global_device_pri_file)
string(APPEND content "DEFAULT_ANDROID_NDK_ROOT = ${ANDROID_NDK}\n") string(APPEND content "DEFAULT_ANDROID_NDK_ROOT = ${ANDROID_NDK}\n")
set(android_platform "android-23") set(android_platform "android-23")
if(ANDROID_NATIVE_API_LEVEL) if(ANDROID_PLATFORM)
set(android_platform "${ANDROID_PLATFORM}")
elseif(ANDROID_NATIVE_API_LEVEL)
set(android_platform "android-${ANDROID_NATIVE_API_LEVEL}") set(android_platform "android-${ANDROID_NATIVE_API_LEVEL}")
endif() endif()
string(APPEND content "DEFAULT_ANDROID_PLATFORM = ${android_platform}\n") string(APPEND content "DEFAULT_ANDROID_PLATFORM = ${android_platform}\n")

View File

@ -824,8 +824,7 @@ translate_path_input(android-sdk ANDROID_SDK_ROOT)
translate_path_input(android-ndk ANDROID_NDK_ROOT) translate_path_input(android-ndk ANDROID_NDK_ROOT)
if(DEFINED INPUT_android-ndk-platform) if(DEFINED INPUT_android-ndk-platform)
drop_input(android-ndk-platform) drop_input(android-ndk-platform)
string(REGEX REPLACE "^android-" "" INPUT_android-ndk-platform "${INPUT_android-ndk-platform}") push("-DANDROID_PLATFORM=${INPUT_android-ndk-platform}")
push("-DANDROID_NATIVE_API_LEVEL=${INPUT_android-ndk-platform}")
endif() endif()
if(DEFINED INPUT_android-abis) if(DEFINED INPUT_android-abis)
if(INPUT_android-abis MATCHES ",") if(INPUT_android-abis MATCHES ",")

View File

@ -184,13 +184,17 @@ set(__qt_chainload_toolchain_file \"\${__qt_initially_configured_toolchain_file}
list(APPEND init_platform "endif()") list(APPEND init_platform "endif()")
endif() endif()
elseif(ANDROID) elseif(ANDROID)
foreach(var ANDROID_NATIVE_API_LEVEL ANDROID_STL ANDROID_ABI foreach(var ANDROID_PLATFORM ANDROID_NATIVE_API_LEVEL ANDROID_STL
ANDROID_SDK_ROOT ANDROID_NDK_ROOT) ANDROID_ABI ANDROID_SDK_ROOT ANDROID_NDK_ROOT)
list(APPEND init_additional_used_variables list(APPEND init_additional_used_variables
"list(APPEND __qt_toolchain_used_variables ${var})") "list(APPEND __qt_toolchain_used_variables ${var})")
endforeach() endforeach()
list(APPEND init_platform list(APPEND init_platform
"set(ANDROID_NATIVE_API_LEVEL \"${ANDROID_NATIVE_API_LEVEL}\" CACHE STRING \"\")") "if(NOT DEFINED ANDROID_PLATFORM AND NOT DEFINED ANDROID_NATIVE_API_LEVEL)")
list(APPEND init_platform
" set(ANDROID_PLATFORM \"${ANDROID_PLATFORM}\" CACHE STRING \"\")")
list(APPEND init_platform "endif()")
list(APPEND init_platform "set(ANDROID_STL \"${ANDROID_STL}\" CACHE STRING \"\")") list(APPEND init_platform "set(ANDROID_STL \"${ANDROID_STL}\" CACHE STRING \"\")")
list(APPEND init_platform "set(ANDROID_ABI \"${ANDROID_ABI}\" CACHE STRING \"\")") list(APPEND init_platform "set(ANDROID_ABI \"${ANDROID_ABI}\" CACHE STRING \"\")")
list(APPEND init_platform "if (NOT DEFINED ANDROID_SDK_ROOT)") list(APPEND init_platform "if (NOT DEFINED ANDROID_SDK_ROOT)")

View File

@ -184,7 +184,7 @@ If you don't supply the configuration argument ``-DANDROID_ABI=...``, it will de
* x86_64: ``-DANDROID_ABI=x86_64`` * x86_64: ``-DANDROID_ABI=x86_64``
By default we set the android API level to 23. Should you need to change this supply the following By default we set the android API level to 23. Should you need to change this supply the following
configuration argument to the above CMake call: ``-DANDROID_NATIVE_API_LEVEL=${API_LEVEL}`` configuration argument to the above CMake call: ``-DANDROID_PLATFORM=android-${API_LEVEL}``.
### Cross compiling for iOS ### Cross compiling for iOS

View File

@ -92,7 +92,7 @@ The following table describes the mapping of configure options to CMake argument
| | | assumed. | | | | assumed. |
| -android-sdk <path> | -DANDROID_SDK_ROOT=<path> | | | -android-sdk <path> | -DANDROID_SDK_ROOT=<path> | |
| -android-ndk <path> | -DCMAKE_TOOLCHAIN_FILE=<toolchain file in NDK> | | | -android-ndk <path> | -DCMAKE_TOOLCHAIN_FILE=<toolchain file in NDK> | |
| -android-ndk-platform android-23 | -DANDROID_NATIVE_API_LEVEL=23 | | | -android-ndk-platform android-23 | -DANDROID_PLATFORM=android-23 | |
| -android-abis <abi_1>,...,<abi_n> | -DANDROID_ABI=<abi_1> | only one ABI can be specified | | -android-abis <abi_1>,...,<abi_n> | -DANDROID_ABI=<abi_1> | only one ABI can be specified |
| -android-style-assets | -DFEATURE_android_style_assets=ON | | | -android-style-assets | -DFEATURE_android_style_assets=ON | |
| -android-javac-source | -DQT_ANDROID_JAVAC_SOURCE=7 | Set the javac build source version. | | -android-javac-source | -DQT_ANDROID_JAVAC_SOURCE=7 | Set the javac build source version. |