No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

1694 líneas
80KB

  1. # Copyright (c) 2010-2011, Ethan Rublee
  2. # Copyright (c) 2011-2014, Andrey Kamaev
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright notice,
  9. # this list of conditions and the following disclaimer.
  10. #
  11. # 2. Redistributions in binary form must reproduce the above copyright notice,
  12. # this list of conditions and the following disclaimer in the documentation
  13. # and/or other materials provided with the distribution.
  14. #
  15. # 3. Neither the name of the copyright holder nor the names of its
  16. # contributors may be used to endorse or promote products derived from this
  17. # software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  23. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. # POSSIBILITY OF SUCH DAMAGE.
  30. # ------------------------------------------------------------------------------
  31. # Android CMake toolchain file, for use with the Android NDK r5-r10d
  32. # Requires cmake 2.6.3 or newer (2.8.9 or newer is recommended).
  33. # See home page: https://github.com/taka-no-me/android-cmake
  34. #
  35. # Usage Linux:
  36. # $ export ANDROID_NDK=/absolute/path/to/the/android-ndk
  37. # $ mkdir build && cd build
  38. # $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
  39. # $ make -j8
  40. #
  41. # Usage Windows:
  42. # You need native port of make to build your project.
  43. # Android NDK r7 (and newer) already has make.exe on board.
  44. # For older NDK you have to install it separately.
  45. # For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm
  46. #
  47. # $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk
  48. # $ mkdir build && cd build
  49. # $ cmake.exe -G"MinGW Makefiles"
  50. # -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake
  51. # -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" ..
  52. # $ cmake.exe --build .
  53. #
  54. #
  55. # Options (can be set as cmake parameters: -D<option_name>=<value>):
  56. # ANDROID_NDK=/opt/android-ndk - path to the NDK root.
  57. # Can be set as environment variable. Can be set only at first cmake run.
  58. #
  59. # ANDROID_ABI=armeabi-v7a - specifies the target Application Binary
  60. # Interface (ABI). This option nearly matches to the APP_ABI variable
  61. # used by ndk-build tool from Android NDK.
  62. #
  63. # Possible targets are:
  64. # "armeabi" - ARMv5TE based CPU with software floating point operations
  65. # "armeabi-v7a" - ARMv7 based devices with hardware FPU instructions
  66. # this ABI target is used by default
  67. # "armeabi-v7a with NEON" - same as armeabi-v7a, but
  68. # sets NEON as floating-point unit
  69. # "armeabi-v7a with VFPV3" - same as armeabi-v7a, but
  70. # sets VFPV3 as floating-point unit (has 32 registers instead of 16)
  71. # "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP
  72. # "x86" - IA-32 instruction set
  73. # "mips" - MIPS32 instruction set
  74. #
  75. # 64-bit ABIs for NDK r10 and newer:
  76. # "arm64-v8a" - ARMv8 AArch64 instruction set
  77. # "x86_64" - Intel64 instruction set (r1)
  78. # "mips64" - MIPS64 instruction set (r6)
  79. #
  80. # ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for.
  81. # Option is read-only when standalone toolchain is used.
  82. # Note: building for "android-L" requires explicit configuration.
  83. #
  84. # ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 - the name of compiler
  85. # toolchain to be used. The list of possible values depends on the NDK
  86. # version. For NDK r10c the possible values are:
  87. #
  88. # * aarch64-linux-android-4.9
  89. # * aarch64-linux-android-clang3.4
  90. # * aarch64-linux-android-clang3.5
  91. # * arm-linux-androideabi-4.6
  92. # * arm-linux-androideabi-4.8
  93. # * arm-linux-androideabi-4.9 (default)
  94. # * arm-linux-androideabi-clang3.4
  95. # * arm-linux-androideabi-clang3.5
  96. # * mips64el-linux-android-4.9
  97. # * mips64el-linux-android-clang3.4
  98. # * mips64el-linux-android-clang3.5
  99. # * mipsel-linux-android-4.6
  100. # * mipsel-linux-android-4.8
  101. # * mipsel-linux-android-4.9
  102. # * mipsel-linux-android-clang3.4
  103. # * mipsel-linux-android-clang3.5
  104. # * x86-4.6
  105. # * x86-4.8
  106. # * x86-4.9
  107. # * x86-clang3.4
  108. # * x86-clang3.5
  109. # * x86_64-4.9
  110. # * x86_64-clang3.4
  111. # * x86_64-clang3.5
  112. #
  113. # ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions
  114. # instead of Thumb. Is not available for "armeabi-v6 with VFP"
  115. # (is forced to be ON) ABI.
  116. #
  117. # ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker
  118. # errors even if they are not used.
  119. #
  120. # ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared
  121. # libraries. Automatically turned for NDK r5x and r6x due to GLESv2
  122. # problems.
  123. #
  124. # ANDROID_STL=gnustl_static - specify the runtime to use.
  125. #
  126. # Possible values are:
  127. # none -> Do not configure the runtime.
  128. # system -> Use the default minimal system C++ runtime library.
  129. # Implies -fno-rtti -fno-exceptions.
  130. # Is not available for standalone toolchain.
  131. # system_re -> Use the default minimal system C++ runtime library.
  132. # Implies -frtti -fexceptions.
  133. # Is not available for standalone toolchain.
  134. # gabi++_static -> Use the GAbi++ runtime as a static library.
  135. # Implies -frtti -fno-exceptions.
  136. # Available for NDK r7 and newer.
  137. # Is not available for standalone toolchain.
  138. # gabi++_shared -> Use the GAbi++ runtime as a shared library.
  139. # Implies -frtti -fno-exceptions.
  140. # Available for NDK r7 and newer.
  141. # Is not available for standalone toolchain.
  142. # stlport_static -> Use the STLport runtime as a static library.
  143. # Implies -fno-rtti -fno-exceptions for NDK before r7.
  144. # Implies -frtti -fno-exceptions for NDK r7 and newer.
  145. # Is not available for standalone toolchain.
  146. # stlport_shared -> Use the STLport runtime as a shared library.
  147. # Implies -fno-rtti -fno-exceptions for NDK before r7.
  148. # Implies -frtti -fno-exceptions for NDK r7 and newer.
  149. # Is not available for standalone toolchain.
  150. # gnustl_static -> Use the GNU STL as a static library.
  151. # Implies -frtti -fexceptions.
  152. # gnustl_shared -> Use the GNU STL as a shared library.
  153. # Implies -frtti -fno-exceptions.
  154. # Available for NDK r7b and newer.
  155. # Silently degrades to gnustl_static if not available.
  156. #
  157. # ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on
  158. # chosen runtime. If disabled, then the user is responsible for settings
  159. # these options.
  160. #
  161. # What?:
  162. # android-cmake toolchain searches for NDK/toolchain in the following order:
  163. # ANDROID_NDK - cmake parameter
  164. # ANDROID_NDK - environment variable
  165. # ANDROID_STANDALONE_TOOLCHAIN - cmake parameter
  166. # ANDROID_STANDALONE_TOOLCHAIN - environment variable
  167. # ANDROID_NDK - default locations
  168. # ANDROID_STANDALONE_TOOLCHAIN - default locations
  169. #
  170. # Make sure to do the following in your scripts:
  171. # SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" )
  172. # SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" )
  173. # The flags will be prepopulated with critical flags, so don't loose them.
  174. # Also be aware that toolchain also sets configuration-specific compiler
  175. # flags and linker flags.
  176. #
  177. # ANDROID and BUILD_ANDROID will be set to true, you may test any of these
  178. # variables to make necessary Android-specific configuration changes.
  179. #
  180. # Also ARMEABI or ARMEABI_V7A or X86 or MIPS or ARM64_V8A or X86_64 or MIPS64
  181. # will be set true, mutually exclusive. NEON option will be set true
  182. # if VFP is set to NEON.
  183. #
  184. # ------------------------------------------------------------------------------
  185. cmake_minimum_required( VERSION 2.6.3 )
  186. if( DEFINED CMAKE_CROSSCOMPILING )
  187. # subsequent toolchain loading is not really needed
  188. return()
  189. endif()
  190. if( CMAKE_TOOLCHAIN_FILE )
  191. # touch toolchain variable to suppress "unused variable" warning
  192. endif()
  193. # inherit settings in recursive loads
  194. get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
  195. if( _CMAKE_IN_TRY_COMPILE )
  196. include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL )
  197. endif()
  198. # this one is important
  199. if( CMAKE_VERSION VERSION_GREATER "3.0.99" )
  200. set( CMAKE_SYSTEM_NAME Android )
  201. else()
  202. set( CMAKE_SYSTEM_NAME Linux )
  203. endif()
  204. # this one not so much
  205. set( CMAKE_SYSTEM_VERSION 1 )
  206. # rpath makes low sense for Android
  207. set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "" )
  208. set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." )
  209. # NDK search paths
  210. set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r10d -r10c -r10b -r10 -r9d -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" )
  211. if( NOT DEFINED ANDROID_NDK_SEARCH_PATHS )
  212. if( CMAKE_HOST_WIN32 )
  213. file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS )
  214. set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}" "$ENV{SystemDrive}/NVPACK" )
  215. else()
  216. file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS )
  217. set( ANDROID_NDK_SEARCH_PATHS /opt "${ANDROID_NDK_SEARCH_PATHS}/NVPACK" )
  218. endif()
  219. endif()
  220. if( NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
  221. set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain )
  222. endif()
  223. # known ABIs
  224. set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" )
  225. set( ANDROID_SUPPORTED_ABIS_arm64 "arm64-v8a" )
  226. set( ANDROID_SUPPORTED_ABIS_x86 "x86" )
  227. set( ANDROID_SUPPORTED_ABIS_x86_64 "x86_64" )
  228. set( ANDROID_SUPPORTED_ABIS_mips "mips" )
  229. set( ANDROID_SUPPORTED_ABIS_mips64 "mips64" )
  230. # API level defaults
  231. set( ANDROID_DEFAULT_NDK_API_LEVEL 8 )
  232. set( ANDROID_DEFAULT_NDK_API_LEVEL_arm64 21 )
  233. set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )
  234. set( ANDROID_DEFAULT_NDK_API_LEVEL_x86_64 21 )
  235. set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )
  236. set( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 )
  237. macro( __LIST_FILTER listvar regex )
  238. if( ${listvar} )
  239. foreach( __val ${${listvar}} )
  240. if( __val MATCHES "${regex}" )
  241. list( REMOVE_ITEM ${listvar} "${__val}" )
  242. endif()
  243. endforeach()
  244. endif()
  245. endmacro()
  246. macro( __INIT_VARIABLE var_name )
  247. set( __test_path 0 )
  248. foreach( __var ${ARGN} )
  249. if( __var STREQUAL "PATH" )
  250. set( __test_path 1 )
  251. break()
  252. endif()
  253. endforeach()
  254. if( __test_path AND NOT EXISTS "${${var_name}}" )
  255. unset( ${var_name} CACHE )
  256. endif()
  257. if( " ${${var_name}}" STREQUAL " " )
  258. set( __values 0 )
  259. foreach( __var ${ARGN} )
  260. if( __var STREQUAL "VALUES" )
  261. set( __values 1 )
  262. elseif( NOT __var STREQUAL "PATH" )
  263. if( __var MATCHES "^ENV_.*$" )
  264. string( REPLACE "ENV_" "" __var "${__var}" )
  265. set( __value "$ENV{${__var}}" )
  266. elseif( DEFINED ${__var} )
  267. set( __value "${${__var}}" )
  268. elseif( __values )
  269. set( __value "${__var}" )
  270. else()
  271. set( __value "" )
  272. endif()
  273. if( NOT " ${__value}" STREQUAL " " AND (NOT __test_path OR EXISTS "${__value}") )
  274. set( ${var_name} "${__value}" )
  275. break()
  276. endif()
  277. endif()
  278. endforeach()
  279. unset( __value )
  280. unset( __values )
  281. endif()
  282. if( __test_path )
  283. file( TO_CMAKE_PATH "${${var_name}}" ${var_name} )
  284. endif()
  285. unset( __test_path )
  286. endmacro()
  287. macro( __DETECT_NATIVE_API_LEVEL _var _path )
  288. set( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" )
  289. file( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" )
  290. if( NOT __apiFileContent )
  291. message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." )
  292. endif()
  293. string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" )
  294. unset( __apiFileContent )
  295. unset( __ndkApiLevelRegex )
  296. endmacro()
  297. macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root )
  298. if( EXISTS "${_root}" )
  299. file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" )
  300. __LIST_FILTER( __gccExePath "^[.].*" )
  301. list( LENGTH __gccExePath __gccExePathsCount )
  302. if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE )
  303. message( WARNING "Could not determine machine name for compiler from ${_root}" )
  304. set( ${_var} "" )
  305. else()
  306. get_filename_component( __gccExeName "${__gccExePath}" NAME_WE )
  307. string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" )
  308. endif()
  309. unset( __gccExePath )
  310. unset( __gccExePathsCount )
  311. unset( __gccExeName )
  312. else()
  313. set( ${_var} "" )
  314. endif()
  315. endmacro()
  316. # fight against cygwin
  317. set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools")
  318. mark_as_advanced( ANDROID_FORBID_SYGWIN )
  319. if( ANDROID_FORBID_SYGWIN )
  320. if( CYGWIN )
  321. message( FATAL_ERROR "Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake." )
  322. endif()
  323. if( CMAKE_HOST_WIN32 )
  324. # remove cygwin from PATH
  325. set( __new_path "$ENV{PATH}")
  326. __LIST_FILTER( __new_path "cygwin" )
  327. set(ENV{PATH} "${__new_path}")
  328. unset(__new_path)
  329. endif()
  330. endif()
  331. # detect current host platform
  332. if( NOT DEFINED ANDROID_NDK_HOST_X64 AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64" OR CMAKE_HOST_APPLE) )
  333. set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" )
  334. mark_as_advanced( ANDROID_NDK_HOST_X64 )
  335. endif()
  336. set( TOOL_OS_SUFFIX "" )
  337. if( CMAKE_HOST_APPLE )
  338. set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" )
  339. set( ANDROID_NDK_HOST_SYSTEM_NAME2 "darwin-x86" )
  340. elseif( CMAKE_HOST_WIN32 )
  341. set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" )
  342. set( ANDROID_NDK_HOST_SYSTEM_NAME2 "windows" )
  343. set( TOOL_OS_SUFFIX ".exe" )
  344. elseif( CMAKE_HOST_UNIX )
  345. set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" )
  346. set( ANDROID_NDK_HOST_SYSTEM_NAME2 "linux-x86" )
  347. else()
  348. message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
  349. endif()
  350. if( NOT ANDROID_NDK_HOST_X64 )
  351. set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} )
  352. endif()
  353. # see if we have path to Android NDK
  354. if( NOT ANDROID_NDK AND NOT ANDROID_STANDALONE_TOOLCHAIN )
  355. __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK )
  356. endif()
  357. if( NOT ANDROID_NDK )
  358. # see if we have path to Android standalone toolchain
  359. __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN )
  360. if( NOT ANDROID_STANDALONE_TOOLCHAIN )
  361. #try to find Android NDK in one of the the default locations
  362. set( __ndkSearchPaths )
  363. foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} )
  364. foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} )
  365. list( APPEND __ndkSearchPaths "${__ndkSearchPath}/android-ndk${suffix}" )
  366. endforeach()
  367. endforeach()
  368. __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} )
  369. unset( __ndkSearchPaths )
  370. if( ANDROID_NDK )
  371. message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" )
  372. message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" )
  373. else()
  374. #try to find Android standalone toolchain in one of the the default locations
  375. __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
  376. if( ANDROID_STANDALONE_TOOLCHAIN )
  377. message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" )
  378. message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" )
  379. endif( ANDROID_STANDALONE_TOOLCHAIN )
  380. endif( ANDROID_NDK )
  381. endif( NOT ANDROID_STANDALONE_TOOLCHAIN )
  382. endif( NOT ANDROID_NDK )
  383. # remember found paths
  384. if( ANDROID_NDK )
  385. get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE )
  386. set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE )
  387. set( BUILD_WITH_ANDROID_NDK True )
  388. if( EXISTS "${ANDROID_NDK}/RELEASE.TXT" )
  389. file( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE_FULL LIMIT_COUNT 1 REGEX "r[0-9]+[a-z]?" )
  390. string( REGEX MATCH "r([0-9]+)([a-z]?)" ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_FULL}" )
  391. else()
  392. set( ANDROID_NDK_RELEASE "r1x" )
  393. set( ANDROID_NDK_RELEASE_FULL "unreleased" )
  394. endif()
  395. string( REGEX REPLACE "r([0-9]+)([a-z]?)" "\\1*1000" ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE}" )
  396. string( FIND " abcdefghijklmnopqastuvwxyz" "${CMAKE_MATCH_2}" __ndkReleaseLetterNum )
  397. math( EXPR ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE_NUM}+${__ndkReleaseLetterNum}" )
  398. elseif( ANDROID_STANDALONE_TOOLCHAIN )
  399. get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE )
  400. # try to detect change
  401. if( CMAKE_AR )
  402. string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length )
  403. string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath )
  404. if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN )
  405. message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." )
  406. endif()
  407. unset( __androidStandaloneToolchainPreviousPath )
  408. unset( __length )
  409. endif()
  410. set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" FORCE )
  411. set( BUILD_WITH_STANDALONE_TOOLCHAIN True )
  412. else()
  413. list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH)
  414. message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolchain.
  415. You should either set an environment variable:
  416. export ANDROID_NDK=~/my-android-ndk
  417. or
  418. export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain
  419. or put the toolchain or NDK in the default path:
  420. sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH}/android-ndk
  421. sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" )
  422. endif()
  423. # android NDK layout
  424. if( BUILD_WITH_ANDROID_NDK )
  425. if( NOT DEFINED ANDROID_NDK_LAYOUT )
  426. # try to automatically detect the layout
  427. if( EXISTS "${ANDROID_NDK}/RELEASE.TXT")
  428. set( ANDROID_NDK_LAYOUT "RELEASE" )
  429. elseif( EXISTS "${ANDROID_NDK}/../../linux-x86/toolchain/" )
  430. set( ANDROID_NDK_LAYOUT "LINARO" )
  431. elseif( EXISTS "${ANDROID_NDK}/../../gcc/" )
  432. set( ANDROID_NDK_LAYOUT "ANDROID" )
  433. endif()
  434. endif()
  435. set( ANDROID_NDK_LAYOUT "${ANDROID_NDK_LAYOUT}" CACHE STRING "The inner layout of NDK" )
  436. mark_as_advanced( ANDROID_NDK_LAYOUT )
  437. if( ANDROID_NDK_LAYOUT STREQUAL "LINARO" )
  438. set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment
  439. set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../${ANDROID_NDK_HOST_SYSTEM_NAME}/toolchain" )
  440. set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" )
  441. set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" )
  442. elseif( ANDROID_NDK_LAYOUT STREQUAL "ANDROID" )
  443. set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment
  444. set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../gcc/${ANDROID_NDK_HOST_SYSTEM_NAME}/arm" )
  445. set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" )
  446. set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" )
  447. else() # ANDROID_NDK_LAYOUT STREQUAL "RELEASE"
  448. set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/toolchains" )
  449. set( ANDROID_NDK_TOOLCHAINS_SUBPATH "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" )
  450. set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME2}" )
  451. endif()
  452. get_filename_component( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK_TOOLCHAINS_PATH}" ABSOLUTE )
  453. # try to detect change of NDK
  454. if( CMAKE_AR )
  455. string( LENGTH "${ANDROID_NDK_TOOLCHAINS_PATH}" __length )
  456. string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath )
  457. if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK_TOOLCHAINS_PATH )
  458. message( FATAL_ERROR "It is not possible to change the path to the NDK on subsequent CMake run. You must remove all generated files from your build folder first.
  459. " )
  460. endif()
  461. unset( __androidNdkPreviousPath )
  462. unset( __length )
  463. endif()
  464. endif()
  465. # get all the details about standalone toolchain
  466. if( BUILD_WITH_STANDALONE_TOOLCHAIN )
  467. __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" )
  468. set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
  469. set( __availableToolchains "standalone" )
  470. __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" )
  471. if( NOT __availableToolchainMachines )
  472. message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." )
  473. endif()
  474. if( __availableToolchainMachines MATCHES x86_64 )
  475. set( __availableToolchainArchs "x86_64" )
  476. elseif( __availableToolchainMachines MATCHES i686 )
  477. set( __availableToolchainArchs "x86" )
  478. elseif( __availableToolchainMachines MATCHES aarch64 )
  479. set( __availableToolchainArchs "arm64" )
  480. elseif( __availableToolchainMachines MATCHES arm )
  481. set( __availableToolchainArchs "arm" )
  482. elseif( __availableToolchainMachines MATCHES mips64el )
  483. set( __availableToolchainArchs "mips64" )
  484. elseif( __availableToolchainMachines MATCHES mipsel )
  485. set( __availableToolchainArchs "mips" )
  486. endif()
  487. execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion
  488. OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE )
  489. string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" )
  490. if( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" )
  491. list( APPEND __availableToolchains "standalone-clang" )
  492. list( APPEND __availableToolchainMachines ${__availableToolchainMachines} )
  493. list( APPEND __availableToolchainArchs ${__availableToolchainArchs} )
  494. list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} )
  495. endif()
  496. endif()
  497. macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath )
  498. foreach( __toolchain ${${__availableToolchainsLst}} )
  499. if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" )
  500. SET( __toolchainVersionRegex "^TOOLCHAIN_VERSION[\t ]+:=[\t ]+(.*)$" )
  501. FILE( STRINGS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}/setup.mk" __toolchainVersionStr REGEX "${__toolchainVersionRegex}" )
  502. if( __toolchainVersionStr )
  503. string( REGEX REPLACE "${__toolchainVersionRegex}" "\\1" __toolchainVersionStr "${__toolchainVersionStr}" )
  504. string( REGEX REPLACE "-clang3[.][0-9]$" "-${__toolchainVersionStr}" __gcc_toolchain "${__toolchain}" )
  505. else()
  506. string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" )
  507. endif()
  508. unset( __toolchainVersionStr )
  509. unset( __toolchainVersionRegex )
  510. else()
  511. set( __gcc_toolchain "${__toolchain}" )
  512. endif()
  513. __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" )
  514. if( __machine )
  515. string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" )
  516. if( __machine MATCHES x86_64 )
  517. set( __arch "x86_64" )
  518. elseif( __machine MATCHES i686 )
  519. set( __arch "x86" )
  520. elseif( __machine MATCHES aarch64 )
  521. set( __arch "arm64" )
  522. elseif( __machine MATCHES arm )
  523. set( __arch "arm" )
  524. elseif( __machine MATCHES mips64el )
  525. set( __arch "mips64" )
  526. elseif( __machine MATCHES mipsel )
  527. set( __arch "mips" )
  528. else()
  529. set( __arch "" )
  530. endif()
  531. #message("machine: !${__machine}!\narch: !${__arch}!\nversion: !${__version}!\ntoolchain: !${__toolchain}!\n")
  532. if (__arch)
  533. list( APPEND __availableToolchainMachines "${__machine}" )
  534. list( APPEND __availableToolchainArchs "${__arch}" )
  535. list( APPEND __availableToolchainCompilerVersions "${__version}" )
  536. list( APPEND ${__availableToolchainsVar} "${__toolchain}" )
  537. endif()
  538. endif()
  539. unset( __gcc_toolchain )
  540. endforeach()
  541. endmacro()
  542. # get all the details about NDK
  543. if( BUILD_WITH_ANDROID_NDK )
  544. file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" )
  545. string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" )
  546. set( __availableToolchains "" )
  547. set( __availableToolchainMachines "" )
  548. set( __availableToolchainArchs "" )
  549. set( __availableToolchainCompilerVersions "" )
  550. if( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_TOOLCHAIN_NAME}/" )
  551. # do not go through all toolchains if we know the name
  552. set( __availableToolchainsLst "${ANDROID_TOOLCHAIN_NAME}" )
  553. __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
  554. if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 )
  555. __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" )
  556. if( __availableToolchains )
  557. set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} )
  558. endif()
  559. endif()
  560. endif()
  561. if( NOT __availableToolchains )
  562. file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" )
  563. if( __availableToolchainsLst )
  564. list(SORT __availableToolchainsLst) # we need clang to go after gcc
  565. endif()
  566. __LIST_FILTER( __availableToolchainsLst "^[.]" )
  567. __LIST_FILTER( __availableToolchainsLst "llvm" )
  568. __LIST_FILTER( __availableToolchainsLst "renderscript" )
  569. __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
  570. if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 )
  571. __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" )
  572. if( __availableToolchains )
  573. set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} )
  574. endif()
  575. endif()
  576. endif()
  577. if( NOT __availableToolchains )
  578. message( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." )
  579. endif()
  580. endif()
  581. # build list of available ABIs
  582. set( ANDROID_SUPPORTED_ABIS "" )
  583. set( __uniqToolchainArchNames ${__availableToolchainArchs} )
  584. list( REMOVE_DUPLICATES __uniqToolchainArchNames )
  585. list( SORT __uniqToolchainArchNames )
  586. foreach( __arch ${__uniqToolchainArchNames} )
  587. list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} )
  588. endforeach()
  589. unset( __uniqToolchainArchNames )
  590. if( NOT ANDROID_SUPPORTED_ABIS )
  591. message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." )
  592. endif()
  593. # choose target ABI
  594. __INIT_VARIABLE( ANDROID_ABI VALUES ${ANDROID_SUPPORTED_ABIS} )
  595. # verify that target ABI is supported
  596. list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx )
  597. if( __androidAbiIdx EQUAL -1 )
  598. string( REPLACE ";" "\", \"" PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" )
  599. message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain.
  600. Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\"
  601. " )
  602. endif()
  603. unset( __androidAbiIdx )
  604. # set target ABI options
  605. if( ANDROID_ABI STREQUAL "x86" )
  606. set( X86 true )
  607. set( ANDROID_NDK_ABI_NAME "x86" )
  608. set( ANDROID_ARCH_NAME "x86" )
  609. set( ANDROID_LLVM_TRIPLE "i686-none-linux-android" )
  610. set( CMAKE_SYSTEM_PROCESSOR "i686" )
  611. elseif( ANDROID_ABI STREQUAL "x86_64" )
  612. set( X86 true )
  613. set( X86_64 true )
  614. set( ANDROID_NDK_ABI_NAME "x86_64" )
  615. set( ANDROID_ARCH_NAME "x86_64" )
  616. set( CMAKE_SYSTEM_PROCESSOR "x86_64" )
  617. set( ANDROID_LLVM_TRIPLE "x86_64-none-linux-android" )
  618. elseif( ANDROID_ABI STREQUAL "mips64" )
  619. set( MIPS64 true )
  620. set( ANDROID_NDK_ABI_NAME "mips64" )
  621. set( ANDROID_ARCH_NAME "mips64" )
  622. set( ANDROID_LLVM_TRIPLE "mips64el-none-linux-android" )
  623. set( CMAKE_SYSTEM_PROCESSOR "mips64" )
  624. elseif( ANDROID_ABI STREQUAL "mips" )
  625. set( MIPS true )
  626. set( ANDROID_NDK_ABI_NAME "mips" )
  627. set( ANDROID_ARCH_NAME "mips" )
  628. set( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" )
  629. set( CMAKE_SYSTEM_PROCESSOR "mips" )
  630. elseif( ANDROID_ABI STREQUAL "arm64-v8a" )
  631. set( ARM64_V8A true )
  632. set( ANDROID_NDK_ABI_NAME "arm64-v8a" )
  633. set( ANDROID_ARCH_NAME "arm64" )
  634. set( ANDROID_LLVM_TRIPLE "aarch64-none-linux-android" )
  635. set( CMAKE_SYSTEM_PROCESSOR "aarch64" )
  636. set( VFPV3 true )
  637. set( NEON true )
  638. elseif( ANDROID_ABI STREQUAL "armeabi" )
  639. set( ARMEABI true )
  640. set( ANDROID_NDK_ABI_NAME "armeabi" )
  641. set( ANDROID_ARCH_NAME "arm" )
  642. set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" )
  643. set( CMAKE_SYSTEM_PROCESSOR "armv5te" )
  644. elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" )
  645. set( ARMEABI_V6 true )
  646. set( ANDROID_NDK_ABI_NAME "armeabi" )
  647. set( ANDROID_ARCH_NAME "arm" )
  648. set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" )
  649. set( CMAKE_SYSTEM_PROCESSOR "armv6" )
  650. # need always fallback to older platform
  651. set( ARMEABI true )
  652. elseif( ANDROID_ABI STREQUAL "armeabi-v7a")
  653. set( ARMEABI_V7A true )
  654. set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
  655. set( ANDROID_ARCH_NAME "arm" )
  656. set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
  657. set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
  658. elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" )
  659. set( ARMEABI_V7A true )
  660. set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
  661. set( ANDROID_ARCH_NAME "arm" )
  662. set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
  663. set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
  664. set( VFPV3 true )
  665. elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" )
  666. set( ARMEABI_V7A true )
  667. set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
  668. set( ANDROID_ARCH_NAME "arm" )
  669. set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
  670. set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
  671. set( VFPV3 true )
  672. set( NEON true )
  673. else()
  674. message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." )
  675. endif()
  676. if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" )
  677. # really dirty hack
  678. # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run...
  679. file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" )
  680. endif()
  681. if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 )
  682. __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD VALUES OFF )
  683. set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE )
  684. mark_as_advanced( ANDROID_FORCE_ARM_BUILD )
  685. else()
  686. unset( ANDROID_FORCE_ARM_BUILD CACHE )
  687. endif()
  688. # choose toolchain
  689. if( ANDROID_TOOLCHAIN_NAME )
  690. list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx )
  691. if( __toolchainIdx EQUAL -1 )
  692. list( SORT __availableToolchains )
  693. string( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" )
  694. set( toolchains_list " * ${toolchains_list}")
  695. message( FATAL_ERROR "Specified toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain.
  696. To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n" )
  697. endif()
  698. list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch )
  699. if( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME )
  700. message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." )
  701. endif()
  702. else()
  703. set( __toolchainIdx -1 )
  704. set( __applicableToolchains "" )
  705. set( __toolchainMaxVersion "0.0.0" )
  706. list( LENGTH __availableToolchains __availableToolchainsCount )
  707. math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" )
  708. foreach( __idx RANGE ${__availableToolchainsCount} )
  709. list( GET __availableToolchainArchs ${__idx} __toolchainArch )
  710. if( __toolchainArch STREQUAL ANDROID_ARCH_NAME )
  711. list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion )
  712. string( REPLACE "x" "99" __toolchainVersion "${__toolchainVersion}")
  713. if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion )
  714. set( __toolchainMaxVersion "${__toolchainVersion}" )
  715. set( __toolchainIdx ${__idx} )
  716. endif()
  717. endif()
  718. endforeach()
  719. unset( __availableToolchainsCount )
  720. unset( __toolchainMaxVersion )
  721. unset( __toolchainVersion )
  722. endif()
  723. unset( __toolchainArch )
  724. if( __toolchainIdx EQUAL -1 )
  725. message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." )
  726. endif()
  727. list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME )
  728. list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME )
  729. list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION )
  730. unset( __toolchainIdx )
  731. unset( __availableToolchains )
  732. unset( __availableToolchainMachines )
  733. unset( __availableToolchainArchs )
  734. unset( __availableToolchainCompilerVersions )
  735. # choose native API level
  736. __INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL )
  737. string( REPLACE "android-" "" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" )
  738. string( STRIP "${ANDROID_NATIVE_API_LEVEL}" ANDROID_NATIVE_API_LEVEL )
  739. # adjust API level
  740. set( __real_api_level ${ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME}} )
  741. foreach( __level ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
  742. if( (__level LESS ANDROID_NATIVE_API_LEVEL OR __level STREQUAL ANDROID_NATIVE_API_LEVEL) AND NOT __level LESS __real_api_level )
  743. set( __real_api_level ${__level} )
  744. endif()
  745. endforeach()
  746. if( __real_api_level AND NOT ANDROID_NATIVE_API_LEVEL STREQUAL __real_api_level )
  747. message( STATUS "Adjusting Android API level 'android-${ANDROID_NATIVE_API_LEVEL}' to 'android-${__real_api_level}'")
  748. set( ANDROID_NATIVE_API_LEVEL ${__real_api_level} )
  749. endif()
  750. unset(__real_api_level)
  751. # validate
  752. list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx )
  753. if( __levelIdx EQUAL -1 )
  754. message( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain." )
  755. else()
  756. if( BUILD_WITH_ANDROID_NDK )
  757. __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" )
  758. if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL AND NOT __realApiLevel GREATER 9000 )
  759. message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." )
  760. endif()
  761. unset( __realApiLevel )
  762. endif()
  763. set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
  764. set( CMAKE_ANDROID_API ${ANDROID_NATIVE_API_LEVEL} )
  765. if( CMAKE_VERSION VERSION_GREATER "2.8" )
  766. list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )
  767. set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
  768. endif()
  769. endif()
  770. unset( __levelIdx )
  771. # remember target ABI
  772. set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE )
  773. if( CMAKE_VERSION VERSION_GREATER "2.8" )
  774. list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} )
  775. set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} )
  776. endif()
  777. # runtime choice (STL, rtti, exceptions)
  778. if( NOT ANDROID_STL )
  779. set( ANDROID_STL gnustl_static )
  780. endif()
  781. set( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" )
  782. set( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" )
  783. mark_as_advanced( ANDROID_STL ANDROID_STL_FORCE_FEATURES )
  784. if( BUILD_WITH_ANDROID_NDK )
  785. if( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared)$")
  786. message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\".
  787. The possible values are:
  788. none -> Do not configure the runtime.
  789. system -> Use the default minimal system C++ runtime library.
  790. system_re -> Same as system but with rtti and exceptions.
  791. gabi++_static -> Use the GAbi++ runtime as a static library.
  792. gabi++_shared -> Use the GAbi++ runtime as a shared library.
  793. stlport_static -> Use the STLport runtime as a static library.
  794. stlport_shared -> Use the STLport runtime as a shared library.
  795. gnustl_static -> (default) Use the GNU STL as a static library.
  796. gnustl_shared -> Use the GNU STL as a shared library.
  797. " )
  798. endif()
  799. elseif( BUILD_WITH_STANDALONE_TOOLCHAIN )
  800. if( NOT "${ANDROID_STL}" MATCHES "^(none|gnustl_static|gnustl_shared)$")
  801. message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\".
  802. The possible values are:
  803. none -> Do not configure the runtime.
  804. gnustl_static -> (default) Use the GNU STL as a static library.
  805. gnustl_shared -> Use the GNU STL as a shared library.
  806. " )
  807. endif()
  808. endif()
  809. unset( ANDROID_RTTI )
  810. unset( ANDROID_EXCEPTIONS )
  811. unset( ANDROID_STL_INCLUDE_DIRS )
  812. unset( __libstl )
  813. unset( __libsupcxx )
  814. if( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL "r7b" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES "gnustl" )
  815. message( WARNING "The GNU STL armeabi-v7a binaries from NDK r7b can crash non-NEON devices. The files provided with NDK r7b were not configured properly, resulting in crashes on Tegra2-based devices and others when trying to use certain floating-point functions (e.g., cosf, sinf, expf).
  816. You are strongly recommended to switch to another NDK release.
  817. " )
  818. endif()
  819. if( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" )
  820. message( WARNING "The x86 system header file from NDK r6 has incorrect definition for ptrdiff_t. You are recommended to upgrade to a newer NDK release or manually patch the header:
  821. See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc8093df6fee54454b8bcab6c2
  822. diff --git a/ndk/platforms/android-9/arch-x86/include/machine/_types.h b/ndk/platforms/android-9/arch-x86/include/machine/_types.h
  823. index 5e28c64..65892a1 100644
  824. --- a/ndk/platforms/android-9/arch-x86/include/machine/_types.h
  825. +++ b/ndk/platforms/android-9/arch-x86/include/machine/_types.h
  826. @@ -51,7 +51,11 @@ typedef long int ssize_t;
  827. #endif
  828. #ifndef _PTRDIFF_T
  829. #define _PTRDIFF_T
  830. -typedef long ptrdiff_t;
  831. +# ifdef __ANDROID__
  832. + typedef int ptrdiff_t;
  833. +# else
  834. + typedef long ptrdiff_t;
  835. +# endif
  836. #endif
  837. " )
  838. endif()
  839. # setup paths and STL for standalone toolchain
  840. if( BUILD_WITH_STANDALONE_TOOLCHAIN )
  841. set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
  842. set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
  843. set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" )
  844. if( NOT ANDROID_STL STREQUAL "none" )
  845. set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" )
  846. if( NOT EXISTS "${ANDROID_STL_INCLUDE_DIRS}" )
  847. # old location ( pre r8c )
  848. set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" )
  849. endif()
  850. if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" )
  851. list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" )
  852. elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" )
  853. list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" )
  854. else()
  855. list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" )
  856. endif()
  857. # always search static GNU STL to get the location of libsupc++.a
  858. if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" )
  859. set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" )
  860. elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" )
  861. set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" )
  862. elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" )
  863. set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" )
  864. elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" )
  865. set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" )
  866. endif()
  867. if( __libstl )
  868. set( __libsupcxx "${__libstl}/libsupc++.a" )
  869. set( __libstl "${__libstl}/libstdc++.a" )
  870. endif()
  871. if( NOT EXISTS "${__libsupcxx}" )
  872. message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain.
  873. Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c.
  874. You need to either upgrade to newer NDK or manually copy
  875. $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a
  876. to
  877. ${__libsupcxx}
  878. " )
  879. endif()
  880. if( ANDROID_STL STREQUAL "gnustl_shared" )
  881. if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" )
  882. set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" )
  883. elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" )
  884. set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" )
  885. elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" )
  886. set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" )
  887. endif()
  888. endif()
  889. endif()
  890. endif()
  891. # clang
  892. if( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" )
  893. set( ANDROID_COMPILER_IS_CLANG 1 )
  894. execute_process( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE )
  895. string( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}")
  896. elseif( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" )
  897. string( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}")
  898. string( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-${ANDROID_COMPILER_VERSION}" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" )
  899. if( NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}/bin/clang${TOOL_OS_SUFFIX}" )
  900. message( FATAL_ERROR "Could not find the Clang compiler driver" )
  901. endif()
  902. set( ANDROID_COMPILER_IS_CLANG 1 )
  903. set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
  904. else()
  905. set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" )
  906. unset( ANDROID_COMPILER_IS_CLANG CACHE )
  907. endif()
  908. string( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" )
  909. if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" )
  910. set( _clang_name "clang" )
  911. endif()
  912. # setup paths and STL for NDK
  913. if( BUILD_WITH_ANDROID_NDK )
  914. set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
  915. set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" )
  916. if( ANDROID_STL STREQUAL "none" )
  917. # do nothing
  918. elseif( ANDROID_STL STREQUAL "system" )
  919. set( ANDROID_RTTI OFF )
  920. set( ANDROID_EXCEPTIONS OFF )
  921. set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
  922. elseif( ANDROID_STL STREQUAL "system_re" )
  923. set( ANDROID_RTTI ON )
  924. set( ANDROID_EXCEPTIONS ON )
  925. set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
  926. elseif( ANDROID_STL MATCHES "gabi" )
  927. if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7
  928. message( FATAL_ERROR "gabi++ is not available in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.")
  929. endif()
  930. set( ANDROID_RTTI ON )
  931. set( ANDROID_EXCEPTIONS OFF )
  932. set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/gabi++/include" )
  933. set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a" )
  934. elseif( ANDROID_STL MATCHES "stlport" )
  935. if( NOT ANDROID_NDK_RELEASE_NUM LESS 8004 ) # before r8d
  936. set( ANDROID_EXCEPTIONS ON )
  937. else()
  938. set( ANDROID_EXCEPTIONS OFF )
  939. endif()
  940. if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7
  941. set( ANDROID_RTTI OFF )
  942. else()
  943. set( ANDROID_RTTI ON )
  944. endif()
  945. set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" )
  946. set( __libstl "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a" )
  947. elseif( ANDROID_STL MATCHES "gnustl" )
  948. set( ANDROID_EXCEPTIONS ON )
  949. set( ANDROID_RTTI ON )
  950. if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
  951. if( ARMEABI_V7A AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.7" AND ANDROID_NDK_RELEASE STREQUAL "r8d" )
  952. # gnustl binary for 4.7 compiler is buggy :(
  953. # TODO: look for right fix
  954. set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.6" )
  955. else()
  956. set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
  957. endif()
  958. else()
  959. set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" )
  960. endif()
  961. set( ANDROID_STL_INCLUDE_DIRS "${__libstl}/include" "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include" "${__libstl}/include/backward" )
  962. if( EXISTS "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" )
  963. set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" )
  964. else()
  965. set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" )
  966. endif()
  967. else()
  968. message( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" )
  969. endif()
  970. # find libsupc++.a - rtti & exceptions
  971. if( ANDROID_STL STREQUAL "system_re" OR ANDROID_STL MATCHES "gnustl" )
  972. set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r8b or newer
  973. if( NOT EXISTS "${__libsupcxx}" )
  974. set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r7-r8
  975. endif()
  976. if( NOT EXISTS "${__libsupcxx}" ) # before r7
  977. if( ARMEABI_V7A )
  978. if( ANDROID_FORCE_ARM_BUILD )
  979. set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" )
  980. else()
  981. set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" )
  982. endif()
  983. elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD )
  984. set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" )
  985. else()
  986. set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" )
  987. endif()
  988. endif()
  989. if( NOT EXISTS "${__libsupcxx}")
  990. message( ERROR "Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken.")
  991. endif()
  992. endif()
  993. endif()
  994. # case of shared STL linkage
  995. if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl )
  996. string( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" )
  997. # TODO: check if .so file exists before the renaming
  998. endif()
  999. # ccache support
  1000. __INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE )
  1001. if( _ndk_ccache )
  1002. if( DEFINED NDK_CCACHE AND NOT EXISTS NDK_CCACHE )
  1003. unset( NDK_CCACHE CACHE )
  1004. endif()
  1005. find_program( NDK_CCACHE "${_ndk_ccache}" DOC "The path to ccache binary")
  1006. else()
  1007. unset( NDK_CCACHE CACHE )
  1008. endif()
  1009. unset( _ndk_ccache )
  1010. # setup the cross-compiler
  1011. if( NOT CMAKE_C_COMPILER )
  1012. if( NDK_CCACHE AND NOT ANDROID_SYSROOT MATCHES "[ ;\"]" )
  1013. set( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" )
  1014. set( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" )
  1015. if( ANDROID_COMPILER_IS_CLANG )
  1016. set( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler")
  1017. set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler")
  1018. else()
  1019. set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler")
  1020. set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler")
  1021. endif()
  1022. else()
  1023. if( ANDROID_COMPILER_IS_CLANG )
  1024. set( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler")
  1025. set( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler")
  1026. else()
  1027. set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" )
  1028. set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" )
  1029. endif()
  1030. endif()
  1031. set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" )
  1032. set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" )
  1033. if( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" )
  1034. # Use gcc-ar if we have it for better LTO support.
  1035. set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
  1036. else()
  1037. set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
  1038. endif()
  1039. set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" )
  1040. set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" )
  1041. set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" )
  1042. set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" )
  1043. set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" )
  1044. endif()
  1045. set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" )
  1046. if( CMAKE_VERSION VERSION_LESS 2.8.5 )
  1047. set( CMAKE_ASM_COMPILER_ARG1 "-c" )
  1048. endif()
  1049. if( APPLE )
  1050. find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )
  1051. if( NOT CMAKE_INSTALL_NAME_TOOL )
  1052. message( FATAL_ERROR "Could not find install_name_tool, please check your installation." )
  1053. endif()
  1054. mark_as_advanced( CMAKE_INSTALL_NAME_TOOL )
  1055. endif()
  1056. # Force set compilers because standard identification works badly for us
  1057. include( CMakeForceCompiler )
  1058. CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU )
  1059. if( ANDROID_COMPILER_IS_CLANG )
  1060. set( CMAKE_C_COMPILER_ID Clang )
  1061. endif()
  1062. set( CMAKE_C_PLATFORM_ID Linux )
  1063. if( X86_64 OR MIPS64 OR ARM64_V8A )
  1064. set( CMAKE_C_SIZEOF_DATA_PTR 8 )
  1065. else()
  1066. set( CMAKE_C_SIZEOF_DATA_PTR 4 )
  1067. endif()
  1068. set( CMAKE_C_HAS_ISYSROOT 1 )
  1069. set( CMAKE_C_COMPILER_ABI ELF )
  1070. CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU )
  1071. if( ANDROID_COMPILER_IS_CLANG )
  1072. set( CMAKE_CXX_COMPILER_ID Clang)
  1073. endif()
  1074. set( CMAKE_CXX_PLATFORM_ID Linux )
  1075. set( CMAKE_CXX_SIZEOF_DATA_PTR ${CMAKE_C_SIZEOF_DATA_PTR} )
  1076. set( CMAKE_CXX_HAS_ISYSROOT 1 )
  1077. set( CMAKE_CXX_COMPILER_ABI ELF )
  1078. set( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C )
  1079. # force ASM compiler (required for CMake < 2.8.5)
  1080. set( CMAKE_ASM_COMPILER_ID_RUN TRUE )
  1081. set( CMAKE_ASM_COMPILER_ID GNU )
  1082. set( CMAKE_ASM_COMPILER_WORKS TRUE )
  1083. set( CMAKE_ASM_COMPILER_FORCED TRUE )
  1084. set( CMAKE_COMPILER_IS_GNUASM 1)
  1085. set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm )
  1086. foreach( lang C CXX ASM )
  1087. if( ANDROID_COMPILER_IS_CLANG )
  1088. set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_CLANG_VERSION} )
  1089. else()
  1090. set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_COMPILER_VERSION} )
  1091. endif()
  1092. endforeach()
  1093. # flags and definitions
  1094. remove_definitions( -DANDROID )
  1095. add_definitions( -DANDROID )
  1096. if( ANDROID_SYSROOT MATCHES "[ ;\"]" )
  1097. if( CMAKE_HOST_WIN32 )
  1098. # try to convert path to 8.3 form
  1099. file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "@echo %~s1" )
  1100. execute_process( COMMAND "$ENV{ComSpec}" /c "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "${ANDROID_SYSROOT}"
  1101. OUTPUT_VARIABLE __path OUTPUT_STRIP_TRAILING_WHITESPACE
  1102. RESULT_VARIABLE __result ERROR_QUIET )
  1103. if( __result EQUAL 0 )
  1104. file( TO_CMAKE_PATH "${__path}" ANDROID_SYSROOT )
  1105. set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" )
  1106. else()
  1107. set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" )
  1108. endif()
  1109. else()
  1110. set( ANDROID_CXX_FLAGS "'--sysroot=${ANDROID_SYSROOT}'" )
  1111. endif()
  1112. if( NOT _CMAKE_IN_TRY_COMPILE )
  1113. # quotes can break try_compile and compiler identification
  1114. message(WARNING "Path to your Android NDK (or toolchain) has non-alphanumeric symbols.\nThe build might be broken.\n")
  1115. endif()
  1116. else()
  1117. set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" )
  1118. endif()
  1119. # NDK flags
  1120. if (ARM64_V8A )
  1121. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
  1122. set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" )
  1123. set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" )
  1124. if( NOT ANDROID_COMPILER_IS_CLANG )
  1125. set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" )
  1126. endif()
  1127. elseif( ARMEABI OR ARMEABI_V7A)
  1128. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
  1129. if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 )
  1130. set( ANDROID_CXX_FLAGS_RELEASE "-mthumb -fomit-frame-pointer -fno-strict-aliasing" )
  1131. set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" )
  1132. if( NOT ANDROID_COMPILER_IS_CLANG )
  1133. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -finline-limit=64" )
  1134. endif()
  1135. else()
  1136. # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI
  1137. set( ANDROID_CXX_FLAGS_RELEASE "-marm -fomit-frame-pointer -fstrict-aliasing" )
  1138. set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" )
  1139. if( NOT ANDROID_COMPILER_IS_CLANG )
  1140. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" )
  1141. endif()
  1142. endif()
  1143. elseif( X86 OR X86_64 )
  1144. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
  1145. if( NOT ANDROID_COMPILER_IS_CLANG )
  1146. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" )
  1147. endif()
  1148. set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" )
  1149. set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" )
  1150. elseif( MIPS OR MIPS64 )
  1151. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-strict-aliasing -finline-functions -funwind-tables -fmessage-length=0" )
  1152. set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" )
  1153. set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" )
  1154. if( NOT ANDROID_COMPILER_IS_CLANG )
  1155. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" )
  1156. set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" )
  1157. endif()
  1158. elseif()
  1159. set( ANDROID_CXX_FLAGS_RELEASE "" )
  1160. set( ANDROID_CXX_FLAGS_DEBUG "" )
  1161. endif()
  1162. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) # good/necessary when porting desktop libraries
  1163. if( NOT X86 AND NOT ANDROID_COMPILER_IS_CLANG )
  1164. set( ANDROID_CXX_FLAGS "-Wno-psabi ${ANDROID_CXX_FLAGS}" )
  1165. endif()
  1166. if( NOT ANDROID_COMPILER_VERSION VERSION_LESS "4.6" )
  1167. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -no-canonical-prefixes" ) # see https://android-review.googlesource.com/#/c/47564/
  1168. endif()
  1169. # ABI-specific flags
  1170. if( ARMEABI_V7A )
  1171. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" )
  1172. if( NEON )
  1173. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" )
  1174. elseif( VFPV3 )
  1175. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" )
  1176. else()
  1177. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" )
  1178. endif()
  1179. elseif( ARMEABI_V6 )
  1180. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2
  1181. elseif( ARMEABI )
  1182. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" )
  1183. endif()
  1184. if( ANDROID_STL MATCHES "gnustl" AND (EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}") )
  1185. set( CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
  1186. set( CMAKE_CXX_CREATE_SHARED_MODULE "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
  1187. set( CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
  1188. else()
  1189. set( CMAKE_CXX_CREATE_SHARED_LIBRARY "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
  1190. set( CMAKE_CXX_CREATE_SHARED_MODULE "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
  1191. set( CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
  1192. endif()
  1193. # STL
  1194. if( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" )
  1195. if( EXISTS "${__libstl}" )
  1196. set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libstl}\"" )
  1197. set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libstl}\"" )
  1198. set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libstl}\"" )
  1199. endif()
  1200. if( EXISTS "${__libsupcxx}" )
  1201. set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" )
  1202. set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" )
  1203. set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libsupcxx}\"" )
  1204. # C objects:
  1205. set( CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
  1206. set( CMAKE_C_CREATE_SHARED_MODULE "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
  1207. set( CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
  1208. set( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" )
  1209. set( CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" )
  1210. set( CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} \"${__libsupcxx}\"" )
  1211. endif()
  1212. if( ANDROID_STL MATCHES "gnustl" )
  1213. if( NOT EXISTS "${ANDROID_LIBM_PATH}" )
  1214. set( ANDROID_LIBM_PATH -lm )
  1215. endif()
  1216. set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}" )
  1217. set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}" )
  1218. set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}" )
  1219. endif()
  1220. endif()
  1221. # variables controlling optional build flags
  1222. if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7
  1223. # libGLESv2.so in NDK's prior to r7 refers to missing external symbols.
  1224. # So this flag option is required for all projects using OpenGL from native.
  1225. __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON )
  1226. else()
  1227. __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF )
  1228. endif()
  1229. __INIT_VARIABLE( ANDROID_NO_UNDEFINED VALUES ON )
  1230. __INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON )
  1231. __INIT_VARIABLE( ANDROID_GOLD_LINKER VALUES ON )
  1232. __INIT_VARIABLE( ANDROID_NOEXECSTACK VALUES ON )
  1233. __INIT_VARIABLE( ANDROID_RELRO VALUES ON )
  1234. set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" )
  1235. set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
  1236. set( ANDROID_FUNCTION_LEVEL_LINKING ${ANDROID_FUNCTION_LEVEL_LINKING} CACHE BOOL "Put each function in separate section and enable garbage collection of unused input sections at link time" )
  1237. set( ANDROID_GOLD_LINKER ${ANDROID_GOLD_LINKER} CACHE BOOL "Enables gold linker" )
  1238. set( ANDROID_NOEXECSTACK ${ANDROID_NOEXECSTACK} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
  1239. set( ANDROID_RELRO ${ANDROID_RELRO} CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" )
  1240. mark_as_advanced( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO )
  1241. # linker flags
  1242. set( ANDROID_LINKER_FLAGS "" )
  1243. if( ARMEABI_V7A )
  1244. # this is *required* to use the following linker flags that routes around
  1245. # a CPU bug in some Cortex-A8 implementations:
  1246. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" )
  1247. endif()
  1248. if( ANDROID_NO_UNDEFINED )
  1249. if( MIPS )
  1250. # there is some sysroot-related problem in mips linker...
  1251. if( NOT ANDROID_SYSROOT MATCHES "[ ;\"]" )
  1252. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib" )
  1253. endif()
  1254. else()
  1255. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" )
  1256. endif()
  1257. endif()
  1258. if( ANDROID_SO_UNDEFINED )
  1259. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" )
  1260. endif()
  1261. if( ANDROID_FUNCTION_LEVEL_LINKING )
  1262. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" )
  1263. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" )
  1264. endif()
  1265. if( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" )
  1266. if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE_NUM GREATER 8002) AND (ARMEABI OR ARMEABI_V7A OR X86) )
  1267. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" )
  1268. elseif( ANDROID_NDK_RELEASE_NUM GREATER 8002 ) # after r8b
  1269. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" )
  1270. elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE )
  1271. message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342
  1272. On Linux and OS X host platform you can workaround this problem using gold linker (default).
  1273. Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems.
  1274. " )
  1275. endif()
  1276. endif() # version 4.6
  1277. if( ANDROID_NOEXECSTACK )
  1278. if( ANDROID_COMPILER_IS_CLANG )
  1279. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" )
  1280. else()
  1281. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" )
  1282. endif()
  1283. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" )
  1284. endif()
  1285. if( ANDROID_RELRO )
  1286. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" )
  1287. endif()
  1288. if( ANDROID_COMPILER_IS_CLANG )
  1289. set( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} -Qunused-arguments ${ANDROID_CXX_FLAGS}" )
  1290. if( BUILD_WITH_ANDROID_NDK )
  1291. set( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" )
  1292. endif()
  1293. endif()
  1294. # cache flags
  1295. set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" )
  1296. set( CMAKE_C_FLAGS "" CACHE STRING "c flags" )
  1297. set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" )
  1298. set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" )
  1299. set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" )
  1300. set( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" )
  1301. set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags" )
  1302. set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags" )
  1303. set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" )
  1304. # put flags to cache (for debug purpose only)
  1305. set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Android specific c/c++ flags" )
  1306. set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE}" CACHE INTERNAL "Android specific c/c++ Release flags" )
  1307. set( ANDROID_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG}" CACHE INTERNAL "Android specific c/c++ Debug flags" )
  1308. set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Android specific c/c++ linker flags" )
  1309. # finish flags
  1310. set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
  1311. set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" )
  1312. set( CMAKE_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}" )
  1313. set( CMAKE_C_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}" )
  1314. set( CMAKE_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}" )
  1315. set( CMAKE_C_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}" )
  1316. set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" )
  1317. set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" )
  1318. set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" )
  1319. if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" )
  1320. set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" )
  1321. set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" )
  1322. set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" )
  1323. endif()
  1324. # pie/pic
  1325. if( NOT (ANDROID_NATIVE_API_LEVEL LESS 16) AND (NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE) AND (CMAKE_VERSION VERSION_GREATER 2.8.8) )
  1326. set( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
  1327. set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
  1328. else()
  1329. set( CMAKE_POSITION_INDEPENDENT_CODE FALSE )
  1330. set( CMAKE_CXX_FLAGS "-fpic ${CMAKE_CXX_FLAGS}" )
  1331. set( CMAKE_C_FLAGS "-fpic ${CMAKE_C_FLAGS}" )
  1332. endif()
  1333. # configure rtti
  1334. if( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES )
  1335. if( ANDROID_RTTI )
  1336. set( CMAKE_CXX_FLAGS "-frtti ${CMAKE_CXX_FLAGS}" )
  1337. else()
  1338. set( CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}" )
  1339. endif()
  1340. endif()
  1341. # configure exceptios
  1342. if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES )
  1343. if( ANDROID_EXCEPTIONS )
  1344. set( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" )
  1345. set( CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}" )
  1346. else()
  1347. set( CMAKE_CXX_FLAGS "-fno-exceptions ${CMAKE_CXX_FLAGS}" )
  1348. set( CMAKE_C_FLAGS "-fno-exceptions ${CMAKE_C_FLAGS}" )
  1349. endif()
  1350. endif()
  1351. # global includes and link directories
  1352. include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} )
  1353. get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning
  1354. link_directories( "${__android_install_path}" )
  1355. # detect if need link crtbegin_so.o explicitly
  1356. if( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK )
  1357. set( __cmd "${CMAKE_CXX_CREATE_SHARED_LIBRARY}" )
  1358. string( REPLACE "<CMAKE_CXX_COMPILER>" "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" __cmd "${__cmd}" )
  1359. string( REPLACE "<CMAKE_C_COMPILER>" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" __cmd "${__cmd}" )
  1360. string( REPLACE "<CMAKE_SHARED_LIBRARY_CXX_FLAGS>" "${CMAKE_CXX_FLAGS}" __cmd "${__cmd}" )
  1361. string( REPLACE "<LANGUAGE_COMPILE_FLAGS>" "" __cmd "${__cmd}" )
  1362. string( REPLACE "<LINK_FLAGS>" "${CMAKE_SHARED_LINKER_FLAGS}" __cmd "${__cmd}" )
  1363. string( REPLACE "<CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>" "-shared" __cmd "${__cmd}" )
  1364. string( REPLACE "<CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG>" "" __cmd "${__cmd}" )
  1365. string( REPLACE "<TARGET_SONAME>" "" __cmd "${__cmd}" )
  1366. string( REPLACE "<TARGET>" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toolchain_crtlink_test.so" __cmd "${__cmd}" )
  1367. string( REPLACE "<OBJECTS>" "\"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" __cmd "${__cmd}" )
  1368. string( REPLACE "<LINK_LIBRARIES>" "" __cmd "${__cmd}" )
  1369. separate_arguments( __cmd )
  1370. foreach( __var ANDROID_NDK ANDROID_NDK_TOOLCHAINS_PATH ANDROID_STANDALONE_TOOLCHAIN )
  1371. if( ${__var} )
  1372. set( __tmp "${${__var}}" )
  1373. separate_arguments( __tmp )
  1374. string( REPLACE "${__tmp}" "${${__var}}" __cmd "${__cmd}")
  1375. endif()
  1376. endforeach()
  1377. string( REPLACE "'" "" __cmd "${__cmd}" )
  1378. string( REPLACE "\"" "" __cmd "${__cmd}" )
  1379. execute_process( COMMAND ${__cmd} RESULT_VARIABLE __cmd_result OUTPUT_QUIET ERROR_QUIET )
  1380. if( __cmd_result EQUAL 0 )
  1381. set( ANDROID_EXPLICIT_CRT_LINK ON )
  1382. else()
  1383. set( ANDROID_EXPLICIT_CRT_LINK OFF )
  1384. endif()
  1385. endif()
  1386. if( ANDROID_EXPLICIT_CRT_LINK )
  1387. set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" )
  1388. set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" )
  1389. endif()
  1390. # setup output directories
  1391. set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
  1392. if( DEFINED LIBRARY_OUTPUT_PATH_ROOT
  1393. OR EXISTS "${CMAKE_SOURCE_DIR}/AndroidManifest.xml"
  1394. OR (EXISTS "${CMAKE_SOURCE_DIR}/../AndroidManifest.xml" AND EXISTS "${CMAKE_SOURCE_DIR}/../jni/") )
  1395. set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "Root for binaries output, set this to change where Android libs are installed to" )
  1396. if( NOT _CMAKE_IN_TRY_COMPILE )
  1397. if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" )
  1398. set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" )
  1399. else()
  1400. set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" )
  1401. endif()
  1402. set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for Android libs" )
  1403. endif()
  1404. endif()
  1405. # copy shaed stl library to build directory
  1406. if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" AND DEFINED LIBRARY_OUTPUT_PATH )
  1407. get_filename_component( __libstlname "${__libstl}" NAME )
  1408. execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess )
  1409. if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}")
  1410. message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" )
  1411. endif()
  1412. unset( __fileCopyProcess )
  1413. unset( __libstlname )
  1414. endif()
  1415. # set these global flags for cmake client scripts to change behavior
  1416. set( ANDROID True )
  1417. set( BUILD_ANDROID True )
  1418. # where is the target environment
  1419. set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" )
  1420. # only search for libraries and includes in the ndk toolchain
  1421. set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
  1422. set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
  1423. set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
  1424. # macro to find packages on the host OS
  1425. macro( find_host_package )
  1426. set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
  1427. set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
  1428. set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
  1429. if( CMAKE_HOST_WIN32 )
  1430. SET( WIN32 1 )
  1431. SET( UNIX )
  1432. elseif( CMAKE_HOST_APPLE )
  1433. SET( APPLE 1 )
  1434. SET( UNIX )
  1435. endif()
  1436. find_package( ${ARGN} )
  1437. SET( WIN32 )
  1438. SET( APPLE )
  1439. SET( UNIX 1 )
  1440. set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
  1441. set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
  1442. set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
  1443. endmacro()
  1444. # macro to find programs on the host OS
  1445. macro( find_host_program )
  1446. set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
  1447. set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
  1448. set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
  1449. if( CMAKE_HOST_WIN32 )
  1450. SET( WIN32 1 )
  1451. SET( UNIX )
  1452. elseif( CMAKE_HOST_APPLE )
  1453. SET( APPLE 1 )
  1454. SET( UNIX )
  1455. endif()
  1456. find_program( ${ARGN} )
  1457. SET( WIN32 )
  1458. SET( APPLE )
  1459. SET( UNIX 1 )
  1460. set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
  1461. set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
  1462. set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
  1463. endmacro()
  1464. # export toolchain settings for the try_compile() command
  1465. if( NOT _CMAKE_IN_TRY_COMPILE )
  1466. set( __toolchain_config "")
  1467. foreach( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN
  1468. ANDROID_NDK_HOST_X64
  1469. ANDROID_NDK
  1470. ANDROID_NDK_LAYOUT
  1471. ANDROID_STANDALONE_TOOLCHAIN
  1472. ANDROID_TOOLCHAIN_NAME
  1473. ANDROID_ABI
  1474. ANDROID_NATIVE_API_LEVEL
  1475. ANDROID_STL
  1476. ANDROID_STL_FORCE_FEATURES
  1477. ANDROID_FORCE_ARM_BUILD
  1478. ANDROID_NO_UNDEFINED
  1479. ANDROID_SO_UNDEFINED
  1480. ANDROID_FUNCTION_LEVEL_LINKING
  1481. ANDROID_GOLD_LINKER
  1482. ANDROID_NOEXECSTACK
  1483. ANDROID_RELRO
  1484. ANDROID_LIBM_PATH
  1485. ANDROID_EXPLICIT_CRT_LINK
  1486. ANDROID_APP_PIE
  1487. )
  1488. if( DEFINED ${__var} )
  1489. if( ${__var} MATCHES " ")
  1490. set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" )
  1491. else()
  1492. set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" )
  1493. endif()
  1494. endif()
  1495. endforeach()
  1496. file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" )
  1497. unset( __toolchain_config )
  1498. endif()
  1499. # force cmake to produce / instead of \ in build commands for Ninja generator
  1500. if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 )
  1501. # it is a bad hack after all
  1502. # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW
  1503. set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW
  1504. set( CMAKE_CROSSCOMPILING TRUE ) # stop recursion
  1505. enable_language( C )
  1506. enable_language( CXX )
  1507. # unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it
  1508. unset( MINGW )
  1509. endif()
  1510. # Variables controlling behavior or set by cmake toolchain:
  1511. # ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips", "arm64-v8a", "x86_64", "mips64"
  1512. # ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version)
  1513. # ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none
  1514. # ANDROID_FORBID_SYGWIN : ON/OFF
  1515. # ANDROID_NO_UNDEFINED : ON/OFF
  1516. # ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version)
  1517. # ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF
  1518. # ANDROID_GOLD_LINKER : ON/OFF
  1519. # ANDROID_NOEXECSTACK : ON/OFF
  1520. # ANDROID_RELRO : ON/OFF
  1521. # ANDROID_FORCE_ARM_BUILD : ON/OFF
  1522. # ANDROID_STL_FORCE_FEATURES : ON/OFF
  1523. # ANDROID_LIBM_PATH : path to libm.so (set to something like $(TOP)/out/target/product/<product_name>/obj/lib/libm.so) to workaround unresolved `sincos`
  1524. # Can be set only at the first run:
  1525. # ANDROID_NDK : path to your NDK install
  1526. # NDK_CCACHE : path to your ccache executable
  1527. # ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain
  1528. # ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems)
  1529. # ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID)
  1530. # LIBRARY_OUTPUT_PATH_ROOT : <any valid path>
  1531. # ANDROID_STANDALONE_TOOLCHAIN
  1532. #
  1533. # Primary read-only variables:
  1534. # ANDROID : always TRUE
  1535. # ARMEABI : TRUE for arm v6 and older devices
  1536. # ARMEABI_V6 : TRUE for arm v6
  1537. # ARMEABI_V7A : TRUE for arm v7a
  1538. # ARM64_V8A : TRUE for arm64-v8a
  1539. # NEON : TRUE if NEON unit is enabled
  1540. # VFPV3 : TRUE if VFP version 3 is enabled
  1541. # X86 : TRUE if configured for x86
  1542. # X86_64 : TRUE if configured for x86_64
  1543. # MIPS : TRUE if configured for mips
  1544. # MIPS64 : TRUE if configured for mips64
  1545. # BUILD_WITH_ANDROID_NDK : TRUE if NDK is used
  1546. # BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used
  1547. # ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform
  1548. # ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86", "mips", "arm64-v8a", "x86_64", "mips64" depending on ANDROID_ABI
  1549. # ANDROID_NDK_RELEASE : from r5 to r10d; set only for NDK
  1550. # ANDROID_NDK_RELEASE_NUM : numeric ANDROID_NDK_RELEASE version (1000*major+minor)
  1551. # ANDROID_ARCH_NAME : "arm", "x86", "mips", "arm64", "x86_64", "mips64" depending on ANDROID_ABI
  1552. # ANDROID_SYSROOT : path to the compiler sysroot
  1553. # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform
  1554. # ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used
  1555. #
  1556. # Secondary (less stable) read-only variables:
  1557. # ANDROID_COMPILER_VERSION : GCC version used (not Clang version)
  1558. # ANDROID_CLANG_VERSION : version of clang compiler if clang is used
  1559. # ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform
  1560. # ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI
  1561. # ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux"
  1562. # ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK)
  1563. # ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools
  1564. # ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK
  1565. # ANDROID_STL_INCLUDE_DIRS : stl include paths
  1566. # ANDROID_RTTI : if rtti is enabled by the runtime
  1567. # ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime
  1568. # ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used
  1569. #
  1570. # Defaults:
  1571. # ANDROID_DEFAULT_NDK_API_LEVEL
  1572. # ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH}
  1573. # ANDROID_NDK_SEARCH_PATHS
  1574. # ANDROID_SUPPORTED_ABIS_${ARCH}
  1575. # ANDROID_SUPPORTED_NDK_VERSIONS