You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1749 lines
83 KiB

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