Android-Initialize.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously
  6. # implemented in the CMake VS IDE generators. Avoid interfering with
  7. # that functionality for now.
  8. if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
  9. return()
  10. endif()
  11. # Commonly used Android toolchain files that pre-date CMake upstream support
  12. # set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them.
  13. if(CMAKE_SYSTEM_VERSION EQUAL 1)
  14. return()
  15. endif()
  16. set(CMAKE_BUILD_TYPE_INIT Debug)
  17. # Skip sysroot selection if the NDK has a unified toolchain.
  18. if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
  19. return()
  20. endif()
  21. # Natively compiling on an Android host doesn't use the NDK cross-compilation
  22. # tools.
  23. if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
  24. return()
  25. endif()
  26. if(NOT CMAKE_SYSROOT)
  27. if(CMAKE_ANDROID_NDK)
  28. set(CMAKE_SYSROOT "${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}/arch-${CMAKE_ANDROID_ARCH}")
  29. if(NOT CMAKE_ANDROID_NDK_DEPRECATED_HEADERS)
  30. set(CMAKE_SYSROOT_COMPILE "${CMAKE_ANDROID_NDK}/sysroot")
  31. endif()
  32. elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
  33. set(CMAKE_SYSROOT "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot")
  34. endif()
  35. endif()
  36. if(CMAKE_SYSROOT)
  37. if(NOT IS_DIRECTORY "${CMAKE_SYSROOT}")
  38. message(FATAL_ERROR
  39. "Android: The system root directory needed for the selected Android version and architecture does not exist:\n"
  40. " ${CMAKE_SYSROOT}\n"
  41. )
  42. endif()
  43. else()
  44. message(FATAL_ERROR
  45. "Android: No CMAKE_SYSROOT was selected."
  46. )
  47. endif()