From eb201ee2f5a985451f16a0cc4bf5a8e7bedb30f9 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 16 Sep 2020 09:23:08 +0200 Subject: [PATCH] WIP: Update android toolchain to NDK r21d Use (legacy) ANDROID_HOME and ANDROID_NDK_HOME environment variables, as provided by Azure Pipelines. --- ....cmake => android-toolchain-ndk-r21d.cmake | 113 ++++++++++-------- 1 file changed, 65 insertions(+), 48 deletions(-) rename android-toolchain-ndk-r19c.cmake => android-toolchain-ndk-r21d.cmake (85%) diff --git a/android-toolchain-ndk-r19c.cmake b/android-toolchain-ndk-r21d.cmake similarity index 85% rename from android-toolchain-ndk-r19c.cmake rename to android-toolchain-ndk-r21d.cmake index 654320f7..2e51c995 100644 --- a/android-toolchain-ndk-r19c.cmake +++ b/android-toolchain-ndk-r21d.cmake @@ -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) @@ -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}") @@ -112,39 +125,41 @@ 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() +string(REPLACE "mac" "darwin" ndk_host "${sdk_host}") 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 @@ -158,14 +173,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 "" COMMAND "${CMAKE_COMMAND}" -E chdir "${ANDROID_SDK_ROOT}" @@ -182,6 +197,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)" ) @@ -191,8 +208,8 @@ if(NOT ANDROID_NDK_ROOT) VERSION ${version} SOURCE - URL https://dl.google.com/android/repository/android-ndk-${version}-${sdk_host}-x86_64.zip - URL_HASH ${ndk_${version}_${sdk_host}_hash} + URL https://dl.google.com/android/repository/android-ndk-${version}-${ndk_host}-x86_64.zip + URL_HASH ${ndk_${version}_${ndk_host}_hash} DOWNLOAD_NO_EXTRACT 1 # We extract manually from within the source directory. PATCH_COMMAND "${CMAKE_COMMAND}" -E chdir "${ANDROID_NDK_INSTALL_ROOT}" @@ -298,7 +315,7 @@ if(NOT ANDROID_NDK_ROOT) SOURCE android-libcxx-${ANDROID_NDK_VERSION} - USING ANDROID_NDK_ROOT abi sdk_host system_platform_${abi} + USING ANDROID_NDK_ROOT abi ndk_host system_platform_${abi} BUILD [[ CONFIGURE_COMMAND "" BUILD_COMMAND @@ -309,7 +326,7 @@ if(NOT ANDROID_NDK_ROOT) "APP_PLATFORM=${system_platform_${abi}}" "APP_MODULES=c++_shared c++_static" "BIONIC_PATH=/bionic" - "NDK_UNIFIED_SYSROOT_PATH=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/sysroot" + "NDK_UNIFIED_SYSROOT_PATH=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/sysroot" "NDK_PLATFORMS_ROOT=${ANDROID_NDK_ROOT}/platforms" "NDK_TOOLCHAINS_ROOT=/toolchains" "NDK_PROJECT_PATH=null" @@ -361,7 +378,7 @@ foreach(abi ${enabled_abis}) sb_install_dir(install_dir ${system_name}) if(NOT DEFINED ${system_name}_ENV_PATH) - set(${system_name}_ENV_PATH "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin:${toolchain_dir}/bin:$ENV{PATH}" PARENT_SCOPE) + set(${system_name}_ENV_PATH "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin:${toolchain_dir}/bin:$ENV{PATH}" PARENT_SCOPE) endif() if(NOT DEFINED ${system_name}_INSTALL_PREFIX) @@ -404,8 +421,8 @@ set(CMAKE_FIND_ROOT_PATH "]] "${${system_name}_FIND_ROOT_PATH}" [[") list(APPEND CMAKE_FIND_ROOT_PATH "${ANDROID_NDK_ROOT}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-]] ${system_arch_${abi}} [[") set(CMAKE_SYSTEM_LIBRARY_PATH "/usr/lib/${SYSTEM_NAME}") -set(SUPERBUILD_CC "]] "${ANDROID_NDK_ROOT}" [[/toolchains/llvm/prebuilt/]] "${sdk_host}" [[-x86_64/bin/${SYSTEM_NAME}${ANDROID_NATIVE_API_LEVEL}-clang") -set(SUPERBUILD_CXX "]] "${ANDROID_NDK_ROOT}" [[/toolchains/llvm/prebuilt/]] "${sdk_host}" [[-x86_64/bin/${SYSTEM_NAME}${ANDROID_NATIVE_API_LEVEL}-clang++") +set(SUPERBUILD_CC "]] "${ANDROID_NDK_ROOT}" [[/toolchains/llvm/prebuilt/]] "${ndk_host}" [[-x86_64/bin/${SYSTEM_NAME}${ANDROID_NATIVE_API_LEVEL}-clang") +set(SUPERBUILD_CXX "]] "${ANDROID_NDK_ROOT}" [[/toolchains/llvm/prebuilt/]] "${ndk_host}" [[-x86_64/bin/${SYSTEM_NAME}${ANDROID_NATIVE_API_LEVEL}-clang++") # ANDROID_LINKER_FLAGS defines flags for ABI specific linking requirements. # Last not least, this includes the unwinding particularities of 32-bit ARM, # https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#Unwinding @@ -451,7 +468,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Enable verbose output from Makefile b USING md5 install_dir - sdk_host + ndk_host system_name ${system_name}_INSTALL_PREFIX ANDROID_NDK_ROOT @@ -483,67 +500,67 @@ set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Enable verbose output from Makefile b $<$:# Add tools with same prefix as compiler COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-ar" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-ar" "${INSTALL_DIR}/bin/${system_name}-ar" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-as" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-as" "${INSTALL_DIR}/bin/${system_name}-as" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-c++filt" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-c++filt" "${INSTALL_DIR}/bin/${system_name}-c++filt" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-dwp" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-dwp" "${INSTALL_DIR}/bin/${system_name}-dwp" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-elfedit" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-elfedit" "${INSTALL_DIR}/bin/${system_name}-gprof" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-ld" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-ld" "${INSTALL_DIR}/bin/${system_name}-ld" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-ld.bfd" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-ld.bfd" "${INSTALL_DIR}/bin/${system_name}-ld.bfd" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-ld.gold" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-ld.gold" "${INSTALL_DIR}/bin/${system_name}-ld.gold" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-nm" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-nm" "${INSTALL_DIR}/bin/${system_name}-nm" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-objcopy" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-objcopy" "${INSTALL_DIR}/bin/${system_name}-objcopy" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-objdump" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-objdump" "${INSTALL_DIR}/bin/${system_name}-objdump" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-ranlib" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-ranlib" "${INSTALL_DIR}/bin/${system_name}-ranlib" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-readelf" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-readelf" "${INSTALL_DIR}/bin/${system_name}-readelf" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-size" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-size" "${INSTALL_DIR}/bin/${system_name}-size" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-strings" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-strings" "${INSTALL_DIR}/bin/${system_name}-strings" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${sdk_host}-x86_64/bin/arm-linux-androideabi-strip" + "${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ndk_host}-x86_64/bin/arm-linux-androideabi-strip" "${INSTALL_DIR}/bin/${system_name}-strip" > ]]