Android-Initialize.cmake 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # When CMAKE_SYSTEM_NAME is "Android", CMakeSystemSpecificInitialize loads this
  4. # module.
  5. # Include the NDK hook.
  6. # It can be used by NDK to inject necessary fixes for an earlier cmake.
  7. if(CMAKE_ANDROID_NDK)
  8. include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Android-Initialize.cmake OPTIONAL)
  9. endif()
  10. # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously
  11. # implemented in the CMake VS IDE generators. Avoid interfering with
  12. # that functionality for now.
  13. if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
  14. return()
  15. endif()
  16. # Commonly used Android toolchain files that pre-date CMake upstream support
  17. # set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them.
  18. if(CMAKE_SYSTEM_VERSION EQUAL 1)
  19. return()
  20. endif()
  21. set(CMAKE_BUILD_TYPE_INIT "RelWithDebInfo")
  22. # Skip sysroot selection if the NDK has a unified toolchain.
  23. if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
  24. return()
  25. endif()
  26. # Natively compiling on an Android host doesn't use the NDK cross-compilation
  27. # tools.
  28. if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
  29. return()
  30. endif()
  31. if(NOT CMAKE_SYSROOT)
  32. if(CMAKE_ANDROID_NDK)
  33. set(CMAKE_SYSROOT "${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}/arch-${CMAKE_ANDROID_ARCH}")
  34. if(NOT CMAKE_ANDROID_NDK_DEPRECATED_HEADERS)
  35. set(CMAKE_SYSROOT_COMPILE "${CMAKE_ANDROID_NDK}/sysroot")
  36. endif()
  37. elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
  38. set(CMAKE_SYSROOT "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot")
  39. endif()
  40. endif()
  41. if(CMAKE_SYSROOT)
  42. if(NOT IS_DIRECTORY "${CMAKE_SYSROOT}")
  43. message(FATAL_ERROR
  44. "Android: The system root directory needed for the selected Android version and architecture does not exist:\n"
  45. " ${CMAKE_SYSROOT}\n"
  46. )
  47. endif()
  48. else()
  49. message(FATAL_ERROR
  50. "Android: No CMAKE_SYSROOT was selected."
  51. )
  52. endif()
  53. # Include the NDK hook.
  54. # It can be used by NDK to inject necessary fixes for an earlier cmake.
  55. if(CMAKE_ANDROID_NDK)
  56. include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/post/Android-Initialize.cmake OPTIONAL)
  57. endif()