Android-Clang.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # This module is shared by multiple languages; use include blocker.
  4. if(__ANDROID_COMPILER_CLANG)
  5. return()
  6. endif()
  7. set(__ANDROID_COMPILER_CLANG 1)
  8. # Include the NDK hook.
  9. # It can be used by NDK to inject necessary fixes for an earlier cmake.
  10. if(CMAKE_ANDROID_NDK)
  11. include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Android-Clang.cmake OPTIONAL)
  12. endif()
  13. # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously
  14. # implemented in the CMake VS IDE generators. Avoid interfering with
  15. # that functionality for now. Later we may try to integrate this.
  16. if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
  17. macro(__android_compiler_clang lang)
  18. endmacro()
  19. return()
  20. endif()
  21. # Commonly used Android toolchain files that pre-date CMake upstream support
  22. # set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them.
  23. if(CMAKE_SYSTEM_VERSION EQUAL 1)
  24. macro(__android_compiler_clang lang)
  25. endmacro()
  26. return()
  27. endif()
  28. # Natively compiling on an Android host doesn't use the NDK cross-compilation
  29. # tools.
  30. if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
  31. macro(__android_compiler_clang lang)
  32. endmacro()
  33. return()
  34. endif()
  35. include(Platform/Android-Common)
  36. # The NDK toolchain configuration files at:
  37. #
  38. # <ndk>/[build/core/]toolchains/*-clang*/setup.mk
  39. #
  40. # contain logic to set LLVM_TRIPLE for Clang-based toolchains for each target.
  41. # We need to produce the same target here to produce compatible binaries.
  42. include(Platform/Android/abi-${CMAKE_ANDROID_ARCH_ABI}-Clang)
  43. macro(__android_compiler_clang lang)
  44. if(NOT "x${lang}" STREQUAL "xASM")
  45. __android_compiler_common(${lang})
  46. endif()
  47. if(NOT CMAKE_${lang}_COMPILER_TARGET)
  48. set(CMAKE_${lang}_COMPILER_TARGET "${_ANDROID_ABI_CLANG_TARGET}")
  49. if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
  50. string(APPEND CMAKE_${lang}_COMPILER_TARGET "${CMAKE_SYSTEM_VERSION}")
  51. endif()
  52. list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "--target=${CMAKE_${lang}_COMPILER_TARGET}")
  53. endif()
  54. if(CMAKE_GENERATOR MATCHES "Visual Studio")
  55. set(_ANDROID_STL_NOSTDLIBXX 1)
  56. endif()
  57. endmacro()
  58. # Include the NDK hook.
  59. # It can be used by NDK to inject necessary fixes for an earlier cmake.
  60. if(CMAKE_ANDROID_NDK)
  61. include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/post/Android-Clang.cmake OPTIONAL)
  62. endif()