Skip to content

Commit

Permalink
WIP: Update android toolchain to NDK r21d
Browse files Browse the repository at this point in the history
Use (legacy) ANDROID_HOME and ANDROID_NDK_HOME environment variables,
as provided by Azure Pipelines.
  • Loading branch information
dg0yt committed Sep 16, 2020
1 parent b1e2899 commit a9133f7
Showing 1 changed file with 40 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ endif()
set(supported_ndks
ndk-r19c
ndk-r20 # compiler bugs pending, to be fixed in ndk-r21
ndk-r21d
)
set(ANDROID_TOOLCHAIN_VERSION "ndk-r19c" CACHE STRING
set(ANDROID_TOOLCHAIN_VERSION "ndk-r21d" CACHE STRING
"Version of the Android NDK toolchain to be used"
)
if(NOT ANDROID_TOOLCHAIN_VERSION IN_LIST supported_ndks)
Expand Down Expand Up @@ -97,12 +98,24 @@ if(CMAKE_BUILD_TYPE MATCHES Rel)
endif()
endif()

# Cf. https://developer.android.com/studio/command-line/variables
if(NOT DEFINED ANDROID_SDK_ROOT AND NOT "$ENV{ANDROID_HOME}" STREQUAL "")
message(STATUS "Using ANDROID_SDK_ROOT=ANDROID_HOME=$ENV{ANDROID_HOME}")
set(ANDROID_SDK_ROOT "$ENV{ANDROID_HOME}")
endif()
if(NOT DEFINED ANDROID_SDK_ROOT AND NOT "$ENV{ANDROID_SDK_ROOT}" STREQUAL "")
message(STATUS "Using ANDROID_SDK_ROOT=$ENV{ANDROID_SDK_ROOT}")
set(ANDROID_SDK_ROOT "$ENV{ANDROID_SDK_ROOT}")
endif()
if(NOT DEFINED ANDROID_NDK_ROOT AND NOT "$ENV{ANDROID_NDK_HOME}" STREQUAL "")
message(STATUS "Using ANDROID_NDK_ROOT=ANDROID_NDK_HOME=$ENV{ANDROID_NDK_HOME}")
set(ANDROID_NDK_ROOT "$ENV{ANDROID_NDK_HOME}")
endif()
if(NOT DEFINED ANDROID_NDK_ROOT AND NOT "$ENV{ANDROID_NDK_ROOT}" STREQUAL "")
message(STATUS "Using ANDROID_NDK_ROOT=$ENV{ANDROID_NDK_ROOT}")
set(ANDROID_NDK_ROOT "$ENV{ANDROID_NDK_ROOT}")
endif()

if(NOT "$ENV{ANDROID_PLATFORM}" STREQUAL "")
foreach(abi ${supported_abis})
set(system_platform_${abi} "$ENV{ANDROID_PLATFORM}")
Expand All @@ -112,39 +125,40 @@ elseif(DEFINED ANDROID_PLATFORM)
set(system_platform_${abi} "${ANDROID_PLATFORM}")
endforeach()
endif()

if(NOT DEFINED ANDROID_COMPILE_SDK AND NOT "$ENV{ANDROID_COMPILE_SDK}" STREQUAL "")
set(ANDROID_COMPILE_SDK "$ENV{ANDROID_COMPILE_SDK}")
else()
set(ANDROID_COMPILE_SDK android-28)
set(ANDROID_COMPILE_SDK android-29)
endif()

if(ANDROID_SDK_ROOT AND ANDROID_NDK_ROOT)
set(sdk_host "") # external SDK and NDK
elseif(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(sdk_host "darwin")
elseif(UNIX AND NOT APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR must be x86_64")
elseif(APPLE)
set(sdk_host "mac")
elseif(UNIX)
set(sdk_host "linux")
elseif(NOT ANDROID_SDK_ROOT)
message(FATAL_ERROR "ANDROID_SDK_ROOT must be set to an external SDK")
elseif(NOT ANDROID_NDK_ROOT)
message(FATAL_ERROR "ANDROID_NDK_ROOT must be set to an external NDK")
else()
set(sdk_host "windows")
endif()

set(android_toolchain_dependencies )


if(NOT ANDROID_SDK_ROOT)
# Download SDK tools, platform, platform tools, and build tools.
set(sdk_tools_version "4333796")
set(sdk_tools_darwin_${sdk_tools_version}_hash SHA256=ecb29358bc0f13d7c2fa0f9290135a5b608e38434aad9bf7067d0252c160853e)
set(sdk_tools_linux_${sdk_tools_version}_hash SHA256=92ffee5a1d98d856634e8b71132e8a95d96c83a63fde1099be3d86df3106def9)
set(build_tools_version "28.0.2")
# Download command line tools, platform tools, platform, and build tools.
set(sdk_tools_version "6609375")
set(sdk_tools_mac_${sdk_tools_version}_hash SHA256=2c3822db1c916655223e5ee8ce0fbf6b73d0b99012045c9dc8eaa6a5736c0c55)
set(sdk_tools_linux_${sdk_tools_version}_hash SHA256=89f308315e041c93a37a79e0627c47f21d5c5edbe5e80ea8dc0aac8a649e0e92)
set(build_tools_version "29.0.2")
string(CONCAT sdk_setup_sh [[
# Generated by ]] "${CMAKE_CURRENT_LIST_FILE}\n" [[
echo y | ./tools/bin/sdkmanager --install "platforms;]] "${ANDROID_COMPILE_SDK}" [["
echo y | ./tools/bin/sdkmanager --install "platform-tools"
echo y | ./tools/bin/sdkmanager --install "build-tools;]] "${build_tools_version}" [["
yes | ./tools/bin/sdkmanager --licenses
set -x
echo y | ./cmdline-tools/tools/bin/sdkmanager --update
echo y | ./cmdline-tools/tools/bin/sdkmanager --install "platforms;]] "${ANDROID_COMPILE_SDK}" [["
echo y | ./cmdline-tools/tools/bin/sdkmanager --install "platform-tools"
echo y | ./cmdline-tools/tools/bin/sdkmanager --install "build-tools;]] "${build_tools_version}" [["
yes | ./cmdline-tools/tools/bin/sdkmanager --licenses
]]
)
set(ANDROID_SDK_INSTALL_ROOT "${PROJECT_BINARY_DIR}/source" CACHE STRING
Expand All @@ -158,14 +172,14 @@ yes | ./tools/bin/sdkmanager --licenses
SOURCE_WRITE
sdk_setup.sh sdk_setup_sh
SOURCE
DOWNLOAD_NAME android-sdk-tools-${sdk_host}-${sdk_tools_version}.zip
URL https://dl.google.com/android/repository/sdk-tools-${sdk_host}-${sdk_tools_version}.zip
DOWNLOAD_NAME android-commandlinetools-${sdk_host}-${sdk_tools_version}_latest.zip
URL https://dl.google.com/android/repository/commandlinetools-${sdk_host}-${sdk_tools_version}_latest.zip
URL_HASH ${sdk_tools_${sdk_host}_${sdk_tools_version}_hash}
DOWNLOAD_NO_EXTRACT 1 # We extract manually from within the source directory.
PATCH_COMMAND
"${CMAKE_COMMAND}" -E make_directory "${ANDROID_SDK_ROOT}"
"${CMAKE_COMMAND}" -E make_directory "${ANDROID_SDK_ROOT}/cmdline-tools"
COMMAND
"${CMAKE_COMMAND}" -E chdir "${ANDROID_SDK_ROOT}"
"${CMAKE_COMMAND}" -E chdir "${ANDROID_SDK_ROOT}/cmdline-tools"
"${CMAKE_COMMAND}" -E tar xzf "<DOWNLOADED_FILE>"
COMMAND
"${CMAKE_COMMAND}" -E chdir "${ANDROID_SDK_ROOT}"
Expand All @@ -182,6 +196,8 @@ if(NOT ANDROID_NDK_ROOT)
set(ndk_r19c_linux_hash SHA1=fd94d0be6017c6acbd193eb95e09cf4b6f61b834)
set(ndk_r20_darwin_hash SHA1=96d5f1c50452596912d1982439c514194b5751e6)
set(ndk_r20_linux_hash SHA1=8665fc84a1b1f0d6ab3b5fdd1e30200cc7b9adff)
set(ndk_r21d_darwin_hash SHA1=ef06c9f9d7efd6f243eb3c05ac440562ae29ae12)
set(ndk_r21d_linux_hash SHA1=bcf4023eb8cb6976a4c7cff0a8a8f145f162bf4d)
set(ANDROID_NDK_INSTALL_ROOT "${PROJECT_BINARY_DIR}/source" CACHE STRING
"The directory where to install the downloaded NDK (i.e. the basedir of ANDROID_NDK_ROOT)"
)
Expand Down

0 comments on commit a9133f7

Please sign in to comment.