diff --git a/Scripts/cmake/Platform/Android/Toolchain_android.cmake b/Scripts/cmake/Platform/Android/Toolchain_android.cmake index 6359811a..504cd52d 100644 --- a/Scripts/cmake/Platform/Android/Toolchain_android.cmake +++ b/Scripts/cmake/Platform/Android/Toolchain_android.cmake @@ -1,7 +1,7 @@ # # Copyright (c) Contributors to the Open 3D Engine Project. # For complete copyright and license terms please see the LICENSE at the root of this distribution. -# +# # SPDX-License-Identifier: Apache-2.0 OR MIT # # @@ -21,7 +21,7 @@ endif() file(TO_CMAKE_PATH "${LY_NDK_DIR}" LY_NDK_DIR) if(NOT LY_NDK_DIR) - message(FATAL_ERROR "Environment var LY_NDK_DIR is not set. Could not find the NDK installation folder") + message(FATAL_ERROR "Environment and cache var for NDK is empty. Could not find the NDK installation folder") endif() set(LY_ANDROID_NDK_TOOLCHAIN ${LY_NDK_DIR}/build/cmake/android.toolchain.cmake) @@ -34,16 +34,24 @@ endif() if(NOT ANDROID_ABI) set(ANDROID_ABI arm64-v8a) endif() -if(NOT ANDROID_ARM_MODE) - set(ANDROID_ARM_MODE arm) -endif() -if(NOT ANDROID_ARM_NEON) - set(ANDROID_ARM_NEON FALSE) + +# Only the 64-bit ANDROID ABIs arm supported +if(NOT ANDROID_ABI MATCHES "^arm64-") + message(FATAL_ERROR "Only the 64-bit ANDROID_ABI's are supported. arm64-v8a can be used if not set") endif() + +set(MIN_NATIVE_API_LEVEL 24) + if(NOT ANDROID_NATIVE_API_LEVEL) - set(ANDROID_NATIVE_API_LEVEL 21) + set(ANDROID_NATIVE_API_LEVEL ${MIN_NATIVE_API_LEVEL}) endif() +if(${ANDROID_NATIVE_API_LEVEL} VERSION_LESS ${MIN_NATIVE_API_LEVEL}) + message(FATAL_ERROR "Unsupported Android native API version ${ANDROID_NATIVE_API_LEVEL}. Must be ${MIN_NATIVE_API_LEVEL} or above") +endif() + +set(ANDROID_PLATFORM android-${ANDROID_NATIVE_API_LEVEL}) + set(CMAKE_C_FLAGS "-fPIC") set(CMAKE_CXX_FLAGS "-fPIC") @@ -54,6 +62,12 @@ include(${LY_ANDROID_NDK_TOOLCHAIN}) set(CMAKE_FIND_ROOT_PATH ${BACKUP_CMAKE_FIND_ROOT_PATH}) +# The CMake Android-Initialize.cmake(https://gitlab.kitware.com/cmake/cmake/-/blob/v3.21.2/Modules/Platform/Android-Initialize.cmake#L61) +# script sets CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH to OFF resulting in find_program calls being unable to locate host binaries +# https://gitlab.kitware.com/cmake/cmake/-/issues/22634 +# Setting back to true to fix our find_program calls +set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH ON) + # Force the ANDROID_LINKER_FLAGS that are set in the NDK's toolchain file into the LINKER_FLAGS for the build and reset # the standard libraries set(LINKER_FLAGS ${ANDROID_LINKER_FLAGS}) @@ -70,9 +84,9 @@ set(LY_TOOLCHAIN_NDK_API_LEVEL ${ANDROID_PLATFORM_LEVEL}) set(MIN_NDK_VERSION 21) if(${LY_TOOLCHAIN_NDK_PKG_MAJOR} VERSION_LESS ${MIN_NDK_VERSION}) - message(FATAL_ERROR "Unsupported NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}.${LY_TOOLCHAIN_NDK_API_LEVEL}. Must be version ${MIN_NDK_VERSION} or above") + message(FATAL_ERROR "Unsupported NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}. Must be version ${MIN_NDK_VERSION} or above") else() - message(STATUS "Detected NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}") + message(STATUS "Detected NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}") endif() list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES LY_NDK_DIR)