Skip to content

Commit

Permalink
Updating the Android Toolchain file to support using NDK23+ for building
Browse files Browse the repository at this point in the history
3rdParty packages.

The changes are taking from the
[Toolchain_android.cmake](https://github.com/o3de/o3de/blob/development/cmake/Platform/Android/Toolchain_android.cmake) in the o3de repo.

Signed-off-by: lumberyard-employee-dm <[email protected]>
  • Loading branch information
lemonade-dm committed Mar 28, 2022
1 parent 2eb975f commit ae937c6
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions Scripts/cmake/Platform/Android/Toolchain_android.cmake
Original file line number Diff line number Diff line change
@@ -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
#
#
Expand All @@ -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)
Expand All @@ -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")

Expand All @@ -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})
Expand All @@ -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)
Expand Down

0 comments on commit ae937c6

Please sign in to comment.