summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2020-10-13 15:46:24 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-10-13 19:44:45 +0000
commit557d2adbe88770fd1a03afbcf420c63877356970 (patch)
tree34ccbb4987b6dcd89b9dadf6aae7759b92111c20 /cmake
parentba511b2fa4782d6618a5261bbbd50f0c57266a3a (diff)
CMake: Autodetect Android toolchain file and NDK
The Android toolchain file is now autodetected from the location of the NDK. The NDK location can be specified by setting the CMake variable ANDROID_NDK_ROOT. Auto-detection of the Android toolchain file is the only purpose of this variable. In recent Android SDK installations the path to the NDK is well-known and can be auto-detected too. If only ANDROID_SDK_ROOT is given, we try to detect ANDROID_NDK_ROOT first and from that the Android toolchain file. Adjust the build instructions in cmake/README.md, and remove the part where we suggest to set some environment variables that are only used to create the cmake call. Task-number: QTBUG-87068 Change-Id: Ia0df5df7651e98979e9cead1cdae7b17ecbc4afb Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtAutoDetect.cmake21
-rw-r--r--cmake/QtProcessConfigureArgs.cmake14
-rw-r--r--cmake/README.md17
3 files changed, 34 insertions, 18 deletions
diff --git a/cmake/QtAutoDetect.cmake b/cmake/QtAutoDetect.cmake
index cd5b3406cf..d2defe762c 100644
--- a/cmake/QtAutoDetect.cmake
+++ b/cmake/QtAutoDetect.cmake
@@ -6,6 +6,27 @@
# done when initially configuring qtbase.
function(qt_auto_detect_android)
+ # Auto-detect NDK root
+ if(NOT DEFINED CMAKE_ANDROID_NDK_ROOT AND DEFINED ANDROID_SDK_ROOT)
+ set(ndk_root "${ANDROID_SDK_ROOT}/ndk-bundle")
+ if(IS_DIRECTORY "${ndk_root}")
+ message(STATUS "Android NDK detected: ${ndk_root}")
+ set(ANDROID_NDK_ROOT "${ndk_root}" CACHE STRING "")
+ endif()
+ endif()
+
+ # Auto-detect toolchain file
+ if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ANDROID_NDK_ROOT)
+ set(toolchain_file "${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake")
+ if(EXISTS "${toolchain_file}")
+ message(STATUS "Android toolchain file within NDK detected: ${toolchain_file}")
+ set(CMAKE_TOOLCHAIN_FILE "${toolchain_file}" CACHE STRING "")
+ else()
+ message(FATAL_ERROR "Cannot find the toolchain file '${toolchain_file}'. "
+ "Please specify the toolchain file with -DCMAKE_TOOLCHAIN_FILE=<file>.")
+ endif()
+ endif()
+
if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT DEFINED QT_AUTODETECT_ANDROID)
file(READ ${CMAKE_TOOLCHAIN_FILE} toolchain_file_content OFFSET 0 LIMIT 80)
diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake
index 5fcc8aad90..a54edb3212 100644
--- a/cmake/QtProcessConfigureArgs.cmake
+++ b/cmake/QtProcessConfigureArgs.cmake
@@ -576,19 +576,7 @@ translate_string_input(qpa_default_platform QT_QPA_DEFAULT_PLATFORM)
translate_list_input(sanitize ECM_ENABLE_SANITIZERS)
translate_path_input(android-sdk ANDROID_SDK_ROOT)
-if(DEFINED INPUT_android-ndk)
- drop_input(android-ndk)
- set(toolchain_file "${INPUT_android-ndk}/build/cmake/android.toolchain.cmake")
- if(EXISTS "${toolchain_file}")
- message("Using CMake toolchain file: ${toolchain_file}")
- else()
- qtConfAddError("The toolchain file '${toolchain_file}' does not exist. "
- "This file path was deduced from the -android-ndk option. Consider specifying "
- "the correct toolchain file with -- -DCMAKE_TOOLCHAIN_FILE=<path>")
- endif()
- push("-DCMAKE_TOOLCHAIN_FILE=${toolchain_file}")
- unset(toolchain_file)
-endif()
+translate_path_input(android-ndk ANDROID_NDK_ROOT)
if(DEFINED INPUT_android-ndk-host)
drop_input(android-ndk-host)
qtConfAddWarning("The -android-ndk-host option is not supported with the CMake build. "
diff --git a/cmake/README.md b/cmake/README.md
index 504c7bedfc..8a3ba27c3c 100644
--- a/cmake/README.md
+++ b/cmake/README.md
@@ -154,13 +154,20 @@ The specified path needs to point to a directory that contains an installed host
In order to cross-compile Qt to Android, you need a host build (see instructions above) and an
Android build. In addition, it is necessary to install the Android NDK.
-The environment for Android can be set up using the following steps:
+The following CMake variables are required for an Android build:
+ * `ANDROID_SDK_ROOT` must point to where the Android SDK is installed
+ * `CMAKE_TOOLCHAIN_FILE` must point to the toolchain file that comes with the NDK
+ * `QT_HOST_PATH` must point to a host installation of Qt
- * Set the ``ANDROID_NDK_HOME`` environment variable to the path where you have installed the Android NDK.
- * Set the ``ANDROID_SDK_HOME`` environment variable to the path where you have installed the Android SDK.
+Call CMake with the following arguments:
+`-DCMAKE_TOOLCHAIN_FILE=<path/to/ndk>/build/cmake/android.toolchain.cmake -DQT_HOST_PATH=/path/to/your/host/build -DANDROID_SDK_ROOT=<path/to/sdk> -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH`
-When running cmake in qtbase, pass
-``-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake -DQT_HOST_PATH=/path/to/your/host/build -DANDROID_SDK_ROOT=$ANDROID_SDK_HOME -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH``
+The toolchain file is usually located below the NDK's root at "build/cmake/android.toolchain.cmake".
+Instead of specifying the toolchain file you may specify `ANDROID_NDK_ROOT` instead.
+This variable is exclusively used for auto-detecting the toolchain file.
+
+In a recent SDK installation, the NDK is located in a subdirectory "ndk_bundle" below the SDK's root
+directory. In that situation you may omit `ANDROID_NDK_ROOT` and `CMAKE_TOOLCHAIN_FILE`.
If you don't supply the configuration argument ``-DANDROID_ABI=...``, it will default to
``armeabi-v7a``. To target other architectures, use one of the following values: