Toolchain_android.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #
  2. # 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.
  3. #
  4. # SPDX-License-Identifier: Apache-2.0 OR MIT
  5. #
  6. #
  7. if(LY_TOOLCHAIN_NDK_API_LEVEL)
  8. return()
  9. endif()
  10. # Verify that the NDK environment is set and points to the support NDK
  11. file(TO_CMAKE_PATH "${LY_NDK_DIR}" LY_NDK_DIR)
  12. if(NOT LY_NDK_DIR)
  13. message(FATAL_ERROR "Environment var for NDK is empty. Could not find the NDK installation folder")
  14. endif()
  15. set(LY_ANDROID_NDK_TOOLCHAIN ${LY_NDK_DIR}/build/cmake/android.toolchain.cmake)
  16. if(NOT LY_NDK_DIR)
  17. message(FATAL_ERROR "Invalid NDK Environment. Unable to locate android toolchain file: " ${LY_NDK_DIR})
  18. endif()
  19. # Set some default variables that are used by the NDK's toolchain file before processing
  20. if(NOT ANDROID_ABI)
  21. set(ANDROID_ABI arm64-v8a)
  22. endif()
  23. if(NOT ANDROID_ARM_MODE)
  24. set(ANDROID_ARM_MODE arm)
  25. endif()
  26. if(NOT ANDROID_ARM_NEON)
  27. set(ANDROID_ARM_NEON FALSE)
  28. endif()
  29. if(NOT ANDROID_NATIVE_API_LEVEL)
  30. set(ANDROID_NATIVE_API_LEVEL 21)
  31. endif()
  32. # Make a backup of the CMAKE_FIND_ROOT_PATH since it will be altered by the NDK toolchain file and needs to be restored after the input
  33. set(BACKUP_CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH})
  34. include(${LY_ANDROID_NDK_TOOLCHAIN})
  35. set(CMAKE_FIND_ROOT_PATH ${BACKUP_CMAKE_FIND_ROOT_PATH})
  36. # Force the ANDROID_LINKER_FLAGS that are set in the NDK's toolchain file into the LINKER_FLAGS for the build and reset
  37. # the standard libraries
  38. set(LINKER_FLAGS ${ANDROID_LINKER_FLAGS})
  39. set(CMAKE_CXX_STANDARD_LIBRARIES "")
  40. # We need to pass down the Android API Level, and the Package Revision's Major and Minor number as preprocessor values.
  41. # We will extract them from 'ANDROID_NDK_SOURCE_PROPERTIES' which will read from the NDK's properties file.
  42. # (note: we cannot use 'ANDROID_NDK_REVISION' because the toolchain combines the Major and Minor revisions
  43. string(REGEX MATCHALL "Pkg.Revision = (([0-9]+).([0-9]+).[0-9]+)" LY_NDK_PKG_REVISION_LINE ${ANDROID_NDK_SOURCE_PROPERTIES})
  44. set(LY_TOOLCHAIN_NDK_PKG_MAJOR ${CMAKE_MATCH_2})
  45. set(LY_TOOLCHAIN_NDK_PKG_MINOR ${CMAKE_MATCH_3})
  46. set(LY_TOOLCHAIN_NDK_API_LEVEL ${ANDROID_PLATFORM_LEVEL})
  47. set(MIN_NDK_VERSION 21)
  48. if(${LY_TOOLCHAIN_NDK_PKG_MAJOR} VERSION_LESS ${MIN_NDK_VERSION})
  49. 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")
  50. else()
  51. message(STATUS "Detected NDK Version ${LY_TOOLCHAIN_NDK_PKG_MAJOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}.${LY_TOOLCHAIN_NDK_PKG_MINOR}")
  52. endif()
  53. list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES LY_NDK_DIR)
  54. # The Native Activity Glue source file needs to be included in any project that will be loaded
  55. # through the android launcher APK. This source file resides directly in the NDK source folder structure
  56. # based on the configured NDK Path set with ${LY_NDK_DIR}
  57. # Locate and verify the source folder based on the NDK path
  58. set(LY_NDK_NATIVE_APP_GLUE_SRC_DIR "${LY_NDK_DIR}/sources/android/native_app_glue")
  59. file(TO_CMAKE_PATH ${LY_NDK_NATIVE_APP_GLUE_SRC_DIR} LY_NDK_NATIVE_APP_GLUE_SRC_DIR)
  60. if(NOT IS_DIRECTORY "${LY_NDK_NATIVE_APP_GLUE_SRC_DIR}")
  61. message(FATAL_ERROR "Could not find android native app glue directory: ${LY_NDK_NATIVE_APP_GLUE_SRC_DIR}")
  62. endif()