1 # Copyright (c) 2010-2011, Ethan Rublee
2 # Copyright (c) 2011-2013, Andrey Kamaev
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
8 # 1. Redistributions of source code must retain the above copyright notice,
9 # this list of conditions and the following disclaimer.
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.
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
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.
31 # ------------------------------------------------------------------------------
32 # Android CMake toolchain file, for use with the Android NDK r5-r8
33 # Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended).
34 # See home page: https://github.com/taka-no-me/android-cmake
36 # The file is mantained by the OpenCV project. The latest version can be get at
37 # http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake
40 # $ export ANDROID_NDK=/absolute/path/to/the/android-ndk
41 # $ mkdir build && cd build
42 # $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
45 # Usage Linux (using standalone toolchain):
46 # $ export ANDROID_STANDALONE_TOOLCHAIN=/absolute/path/to/android-toolchain
47 # $ mkdir build && cd build
48 # $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
52 # You need native port of make to build your project.
53 # Android NDK r7 (or newer) already has make.exe on board.
54 # For older NDK you have to install it separately.
55 # For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm
57 # $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk
58 # $ mkdir build && cd build
59 # $ cmake.exe -G"MinGW Makefiles"
60 # -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake
61 # -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" ..
62 # $ cmake.exe --build .
65 # Options (can be set as cmake parameters: -D<option_name>=<value>):
66 # ANDROID_NDK=/opt/android-ndk - path to the NDK root.
67 # Can be set as environment variable. Can be set only at first cmake run.
69 # ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to the
70 # standalone toolchain. This option is not used if full NDK is found
71 # (ignored if ANDROID_NDK is set).
72 # Can be set as environment variable. Can be set only at first cmake run.
74 # ANDROID_ABI=armeabi-v7a - specifies the target Application Binary
75 # Interface (ABI). This option nearly matches to the APP_ABI variable
76 # used by ndk-build tool from Android NDK.
78 # Possible targets are:
79 # "armeabi" - matches to the NDK ABI with the same name.
80 # See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation.
81 # "armeabi-v7a" - matches to the NDK ABI with the same name.
82 # See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation.
83 # "armeabi-v7a with NEON" - same as armeabi-v7a, but
84 # sets NEON as floating-point unit
85 # "armeabi-v7a with VFPV3" - same as armeabi-v7a, but
86 # sets VFPV3 as floating-point unit (has 32 registers instead of 16).
87 # "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP.
88 # "x86" - matches to the NDK ABI with the same name.
89 # See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation.
90 # "mips" - matches to the NDK ABI with the same name
91 # (It is not tested on real devices by the authos of this toolchain)
92 # See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation.
94 # ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for.
95 # Option is read-only when standalone toolchain is used.
97 # ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.6 - the name of compiler
98 # toolchain to be used. The list of possible values depends on the NDK
99 # version. For NDK r8c the possible values are:
101 # * arm-linux-androideabi-4.4.3
102 # * arm-linux-androideabi-4.6
103 # * arm-linux-androideabi-clang3.1
104 # * mipsel-linux-android-4.4.3
105 # * mipsel-linux-android-4.6
106 # * mipsel-linux-android-clang3.1
111 # ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions
112 # instead of Thumb. Is not available for "x86" (inapplicable) and
113 # "armeabi-v6 with VFP" (is forced to be ON) ABIs.
115 # ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker
116 # errors even if they are not used.
118 # ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared
119 # libraries. Automatically turned for NDK r5x and r6x due to GLESv2
122 # LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary
123 # files. See additional details below.
125 # ANDROID_SET_OBSOLETE_VARIABLES=ON - if set, then toolchain defines some
126 # obsolete variables which were used by previous versions of this file for
127 # backward compatibility.
129 # ANDROID_STL=gnustl_static - specify the runtime to use.
131 # Possible values are:
132 # none -> Do not configure the runtime.
133 # system -> Use the default minimal system C++ runtime library.
134 # Implies -fno-rtti -fno-exceptions.
135 # Is not available for standalone toolchain.
136 # system_re -> Use the default minimal system C++ runtime library.
137 # Implies -frtti -fexceptions.
138 # Is not available for standalone toolchain.
139 # gabi++_static -> Use the GAbi++ runtime as a static library.
140 # Implies -frtti -fno-exceptions.
141 # Available for NDK r7 and newer.
142 # Is not available for standalone toolchain.
143 # gabi++_shared -> Use the GAbi++ runtime as a shared library.
144 # Implies -frtti -fno-exceptions.
145 # Available for NDK r7 and newer.
146 # Is not available for standalone toolchain.
147 # stlport_static -> Use the STLport runtime as a static library.
148 # Implies -fno-rtti -fno-exceptions for NDK before r7.
149 # Implies -frtti -fno-exceptions for NDK r7 and newer.
150 # Is not available for standalone toolchain.
151 # stlport_shared -> Use the STLport runtime as a shared library.
152 # Implies -fno-rtti -fno-exceptions for NDK before r7.
153 # Implies -frtti -fno-exceptions for NDK r7 and newer.
154 # Is not available for standalone toolchain.
155 # gnustl_static -> Use the GNU STL as a static library.
156 # Implies -frtti -fexceptions.
157 # gnustl_shared -> Use the GNU STL as a shared library.
158 # Implies -frtti -fno-exceptions.
159 # Available for NDK r7b and newer.
160 # Silently degrades to gnustl_static if not available.
162 # ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on
163 # chosen runtime. If disabled, then the user is responsible for settings
167 # android-cmake toolchain searches for NDK/toolchain in the following order:
168 # ANDROID_NDK - cmake parameter
169 # ANDROID_NDK - environment variable
170 # ANDROID_STANDALONE_TOOLCHAIN - cmake parameter
171 # ANDROID_STANDALONE_TOOLCHAIN - environment variable
172 # ANDROID_NDK - default locations
173 # ANDROID_STANDALONE_TOOLCHAIN - default locations
175 # Make sure to do the following in your scripts:
176 # SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" )
177 # SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" )
178 # The flags will be prepopulated with critical flags, so don't loose them.
179 # Also be aware that toolchain also sets configuration-specific compiler
180 # flags and linker flags.
182 # ANDROID and BUILD_ANDROID will be set to true, you may test any of these
183 # variables to make necessary Android-specific configuration changes.
185 # Also ARMEABI or ARMEABI_V7A or X86 or MIPS will be set true, mutually
186 # exclusive. NEON option will be set true if VFP is set to NEON.
188 # LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where Android
189 # libraries will be installed.
190 # Default is ${CMAKE_SOURCE_DIR}, and the android libs will always be
191 # under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}
192 # (depending on the target ABI). This is convenient for Android packaging.
195 # - initial version December 2010
197 # [+] added possibility to build with NDK (without standalone toolchain)
198 # [+] support cross-compilation on Windows (native, no cygwin support)
199 # [+] added compiler option to force "char" type to be signed
200 # [+] added toolchain option to compile to 32-bit ARM instructions
201 # [+] added toolchain option to disable SWIG search
202 # [+] added platform "armeabi-v7a with VFPV3"
203 # [~] ARM_TARGETS renamed to ARM_TARGET
204 # [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows)
205 # [~] Fixed bug with ANDROID_API_LEVEL variable
206 # [~] turn off SWIG search if it is not found first time
208 # [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL
209 # [+] ANDROID_API_LEVEL is detected by toolchain if not specified
210 # [~] added guard to prevent changing of output directories on the first
212 # [~] toolchain exits with error if ARM_TARGET is not recognized
214 # [~] default NDK path is updated for version r5c
215 # [+] variable CMAKE_SYSTEM_PROCESSOR is set based on ARM_TARGET
216 # [~] toolchain install directory is added to linker paths
217 # [-] removed SWIG-related stuff from toolchain
218 # [+] added macro find_host_package, find_host_program to search
219 # packages/programs on the host system
220 # [~] fixed path to STL library
222 # [~] fixed options caching
223 # [~] search for all supported NDK versions
224 # [~] allowed spaces in NDK path
226 # [~] updated for NDK r6b
228 # [*] rewritten for NDK r7
229 # [+] x86 toolchain support (experimental)
230 # [+] added "armeabi-v6 with VFP" ABI for ARMv6 processors.
231 # [~] improved compiler and linker flags management
232 # [+] support different build flags for Release and Debug configurations
233 # [~] by default compiler flags the same as used by ndk-build (but only
235 # [~] ANDROID_NDK_TOOLCHAIN_ROOT is splitted to ANDROID_STANDALONE_TOOLCHAIN
236 # and ANDROID_TOOLCHAIN_ROOT
237 # [~] ARM_TARGET is renamed to ANDROID_ABI
238 # [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME
239 # [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL
241 # [+] added stlport_static support (experimental)
242 # [+] added special check for cygwin
243 # [+] filtered out hidden files (starting with .) while globbing inside NDK
244 # [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6
245 # [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags
247 # [+] updated for NDK r7b
248 # [~] fixed cmake try_compile() command
249 # [~] Fix for missing install_name_tool on OS X
251 # [~] fixed incorrect C compiler flags
252 # [~] fixed CMAKE_SYSTEM_PROCESSOR change on ANDROID_ABI change
253 # [+] improved toolchain loading speed
254 # [+] added assembler language support (.S)
255 # [+] allowed preset search paths and extra search suffixes
257 # [+] updated for NDK r7c
258 # [~] fixed most of problems with compiler/linker flags and caching
259 # [+] added option ANDROID_FUNCTION_LEVEL_LINKING
261 # [+] updated for NDK r8
262 # [+] added mips architecture support
264 # [+] updated for NDK r8b
265 # [~] all intermediate files generated by toolchain are moved to CMakeFiles
266 # [~] libstdc++ and libsupc are removed from explicit link libraries
267 # [+] added CCache support (via NDK_CCACHE environment or cmake variable)
268 # [+] added gold linker support for NDK r8b
269 # [~] fixed mips linker flags for NDK r8b
271 # [+] added NDK release name detection (see ANDROID_NDK_RELEASE)
272 # [+] added support for all C++ runtimes from NDK
273 # (system, gabi++, stlport, gnustl)
274 # [+] improved warnings on known issues of NDKs
275 # [~] use gold linker as default if available (NDK r8b)
276 # [~] globally turned off rpath
277 # [~] compiler options are aligned with NDK r8b
279 # [~] fixed C++ linking: explicitly link with math library (OpenCV #2426)
281 # [+] updated for NDK r8c
282 # [+] added support for clang compiler
284 # [+] suppress warning about unused CMAKE_TOOLCHAIN_FILE variable
285 # [+] adjust API level to closest compatible as NDK does
286 # [~] fixed ccache full path search
287 # [+] updated for NDK r8d
288 # [~] compiler options are aligned with NDK r8d
290 # [+] updated for NDK r8e (x86 version)
291 # [+] support x86_64 version of NDK
292 # ------------------------------------------------------------------------------
294 cmake_minimum_required( VERSION 2.6.3 )
296 if( DEFINED CMAKE_CROSSCOMPILING )
297 # subsequent toolchain loading is not really needed
301 if( CMAKE_TOOLCHAIN_FILE )
302 # touch toolchain variable only to suppress "unused variable" warning
305 get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
306 if( _CMAKE_IN_TRY_COMPILE )
307 include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL )
310 # this one is important
311 set( CMAKE_SYSTEM_NAME Linux )
312 # this one not so much
313 set( CMAKE_SYSTEM_VERSION 1 )
315 # rpath makes low sence for Android
316 set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." )
318 set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" )
319 if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS)
320 if( CMAKE_HOST_WIN32 )
321 file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS )
322 set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}/android-ndk" "$ENV{SystemDrive}/NVPACK/android-ndk" )
324 file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS )
325 set( ANDROID_NDK_SEARCH_PATHS /opt/android-ndk "${ANDROID_NDK_SEARCH_PATHS}/NVPACK/android-ndk" )
328 if(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH)
329 set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain )
332 set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" )
333 set( ANDROID_SUPPORTED_ABIS_x86 "x86" )
334 set( ANDROID_SUPPORTED_ABIS_mipsel "mips" )
336 set( ANDROID_DEFAULT_NDK_API_LEVEL 8 )
337 set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )
338 set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )
341 macro( __LIST_FILTER listvar regex )
343 foreach( __val ${${listvar}} )
344 if( __val MATCHES "${regex}" )
345 list( REMOVE_ITEM ${listvar} "${__val}" )
351 macro( __INIT_VARIABLE var_name )
353 foreach( __var ${ARGN} )
354 if( __var STREQUAL "PATH" )
359 if( __test_path AND NOT EXISTS "${${var_name}}" )
360 unset( ${var_name} CACHE )
362 if( "${${var_name}}" STREQUAL "" )
364 foreach( __var ${ARGN} )
365 if( __var STREQUAL "VALUES" )
367 elseif( NOT __var STREQUAL "PATH" )
369 if( __var MATCHES "^OBSOLETE_.*$" )
370 string( REPLACE "OBSOLETE_" "" __var "${__var}" )
373 if( __var MATCHES "^ENV_.*$" )
374 string( REPLACE "ENV_" "" __var "${__var}" )
375 set( __value "$ENV{${__var}}" )
376 elseif( DEFINED ${__var} )
377 set( __value "${${__var}}" )
380 set( __value "${__var}" )
385 if( NOT "${__value}" STREQUAL "" )
387 if( EXISTS "${__value}" )
388 file( TO_CMAKE_PATH "${__value}" ${var_name} )
389 if( __obsolete AND NOT _CMAKE_IN_TRY_COMPILE )
390 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." )
395 set( ${var_name} "${__value}" )
396 if( __obsolete AND NOT _CMAKE_IN_TRY_COMPILE )
397 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." )
407 elseif( __test_path )
408 file( TO_CMAKE_PATH "${${var_name}}" ${var_name} )
413 macro( __DETECT_NATIVE_API_LEVEL _var _path )
414 SET( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" )
415 FILE( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" )
416 if( NOT __apiFileContent )
417 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." )
419 string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" )
420 unset( __apiFileContent )
421 unset( __ndkApiLevelRegex )
424 macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root )
425 if( EXISTS "${_root}" )
426 file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" )
427 __LIST_FILTER( __gccExePath "^[.].*" )
428 list( LENGTH __gccExePath __gccExePathsCount )
429 if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE )
430 message( WARNING "Could not determine machine name for compiler from ${_root}" )
433 get_filename_component( __gccExeName "${__gccExePath}" NAME_WE )
434 string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" )
436 unset( __gccExePath )
437 unset( __gccExePathsCount )
438 unset( __gccExeName )
445 # fight against cygwin
446 set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools")
447 mark_as_advanced( ANDROID_FORBID_SYGWIN )
448 if( ANDROID_FORBID_SYGWIN )
450 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." )
453 if( CMAKE_HOST_WIN32 )
454 # remove cygwin from PATH
455 set( __new_path "$ENV{PATH}")
456 __LIST_FILTER( __new_path "cygwin" )
457 set(ENV{PATH} "${__new_path}")
463 # detect current host platform
464 if( NOT DEFINED ANDROID_NDK_HOST_X64 AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
465 set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" )
466 mark_as_advanced( ANDROID_NDK_HOST_X64 )
469 set( TOOL_OS_SUFFIX "" )
470 if( CMAKE_HOST_APPLE )
471 set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" )
472 set( ANDROID_NDK_HOST_SYSTEM_NAME2 "darwin-x86" )
473 elseif( CMAKE_HOST_WIN32 )
474 set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" )
475 set( ANDROID_NDK_HOST_SYSTEM_NAME2 "windows" )
476 set( TOOL_OS_SUFFIX ".exe" )
477 elseif( CMAKE_HOST_UNIX )
478 set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" )
479 set( ANDROID_NDK_HOST_SYSTEM_NAME2 "linux-x86" )
481 message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
484 if( NOT ANDROID_NDK_HOST_X64 )
485 set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} )
488 # see if we have path to Android NDK
489 __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK )
490 if( NOT ANDROID_NDK )
491 # see if we have path to Android standalone toolchain
492 __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN OBSOLETE_ANDROID_NDK_TOOLCHAIN_ROOT OBSOLETE_ENV_ANDROID_NDK_TOOLCHAIN_ROOT )
494 if( NOT ANDROID_STANDALONE_TOOLCHAIN )
495 #try to find Android NDK in one of the the default locations
496 set( __ndkSearchPaths )
497 foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} )
498 foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} )
499 list( APPEND __ndkSearchPaths "${__ndkSearchPath}${suffix}" )
502 __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} )
503 unset( __ndkSearchPaths )
506 message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" )
507 message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" )
509 #try to find Android standalone toolchain in one of the the default locations
510 __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
512 if( ANDROID_STANDALONE_TOOLCHAIN )
513 message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" )
514 message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" )
515 endif( ANDROID_STANDALONE_TOOLCHAIN )
517 endif( NOT ANDROID_STANDALONE_TOOLCHAIN )
518 endif( NOT ANDROID_NDK )
520 # remember found paths
522 get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE )
523 # try to detect change
525 string( LENGTH "${ANDROID_NDK}" __length )
526 string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath )
527 if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK )
528 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.
531 unset( __androidNdkPreviousPath )
534 set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE )
535 set( BUILD_WITH_ANDROID_NDK True )
536 if( EXISTS "${ANDROID_NDK}/RELEASE.TXT" )
537 file( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE_FULL LIMIT_COUNT 1 REGEX r[0-9]+[a-z]? )
538 string( REGEX MATCH r[0-9]+[a-z]? ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_FULL}" )
540 set( ANDROID_NDK_RELEASE "r1x" )
541 set( ANDROID_NDK_RELEASE_FULL "unreleased" )
543 elseif( ANDROID_STANDALONE_TOOLCHAIN )
544 get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE )
545 # try to detect change
547 string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length )
548 string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath )
549 if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN )
550 message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." )
552 unset( __androidStandaloneToolchainPreviousPath )
555 set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" FORCE )
556 set( BUILD_WITH_STANDALONE_TOOLCHAIN True )
558 list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH)
559 message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolchain.
560 You should either set an environment variable:
561 export ANDROID_NDK=~/my-android-ndk
563 export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain
564 or put the toolchain or NDK in the default path:
565 sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH}
566 sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" )
570 if( BUILD_WITH_ANDROID_NDK )
571 if( NOT DEFINED ANDROID_NDK_LAYOUT )
572 set( ANDROID_NDK_LAYOUT "RELEASE" )
574 set( ANDROID_NDK_LAYOUT "${ANDROID_NDK_LAYOUT}" CACHE STRING "The inner layout of NDK" )
575 mark_as_advanced( ANDROID_NDK_LAYOUT )
576 if( ANDROID_NDK_LAYOUT STREQUAL "LINARO" )
577 set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment
578 set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../${ANDROID_NDK_HOST_SYSTEM_NAME}/toolchain" )
579 set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" )
580 set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" )
581 else() # ANDROID_NDK_LAYOUT STREQUAL "RELEASE"
582 set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/toolchains" )
583 set( ANDROID_NDK_TOOLCHAINS_SUBPATH "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" )
584 set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME2}" )
588 # get all the details about standalone toolchain
589 if( BUILD_WITH_STANDALONE_TOOLCHAIN )
590 __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" )
591 set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
592 set( __availableToolchains "standalone" )
593 __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" )
594 if( NOT __availableToolchainMachines )
595 message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." )
597 if( __availableToolchainMachines MATCHES i686 )
598 set( __availableToolchainArchs "x86" )
599 elseif( __availableToolchainMachines MATCHES arm )
600 set( __availableToolchainArchs "arm" )
601 elseif( __availableToolchainMachines MATCHES mipsel )
602 set( __availableToolchainArchs "mipsel" )
604 execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion
605 OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE )
606 string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" )
607 if( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" )
608 list( APPEND __availableToolchains "standalone-clang" )
609 list( APPEND __availableToolchainMachines ${__availableToolchainMachines} )
610 list( APPEND __availableToolchainArchs ${__availableToolchainArchs} )
611 list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} )
615 macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath )
616 foreach( __toolchain ${${__availableToolchainsLst}} )
617 if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" )
618 string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" )
620 set( __gcc_toolchain "${__toolchain}" )
622 __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" )
624 string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" )
625 if( __machine MATCHES i686 )
627 elseif( __machine MATCHES arm )
629 elseif( __machine MATCHES mipsel )
630 set( __arch "mipsel" )
632 list( APPEND __availableToolchainMachines "${__machine}" )
633 list( APPEND __availableToolchainArchs "${__arch}" )
634 list( APPEND __availableToolchainCompilerVersions "${__version}" )
635 list( APPEND ${__availableToolchainsVar} "${__toolchain}" )
637 unset( __gcc_toolchain )
641 # get all the details about NDK
642 if( BUILD_WITH_ANDROID_NDK )
643 file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" )
644 string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" )
645 set( __availableToolchains "" )
646 set( __availableToolchainMachines "" )
647 set( __availableToolchainArchs "" )
648 set( __availableToolchainCompilerVersions "" )
649 if( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_TOOLCHAIN_NAME}/" )
650 # do not go through all toolchains if we know the name
651 set( __availableToolchainsLst "${ANDROID_TOOLCHAIN_NAME}" )
652 __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
653 if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 )
654 __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" )
655 if( __availableToolchains )
656 set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} )
660 if( NOT __availableToolchains )
661 file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" )
662 if( __availableToolchains )
663 list(SORT __availableToolchainsLst) # we need clang to go after gcc
665 __LIST_FILTER( __availableToolchainsLst "^[.]" )
666 __LIST_FILTER( __availableToolchainsLst "llvm" )
667 __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
668 if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 )
669 __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" )
670 if( __availableToolchains )
671 set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} )
675 if( NOT __availableToolchains )
676 message( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." )
680 # build list of available ABIs
681 set( ANDROID_SUPPORTED_ABIS "" )
682 set( __uniqToolchainArchNames ${__availableToolchainArchs} )
683 list( REMOVE_DUPLICATES __uniqToolchainArchNames )
684 list( SORT __uniqToolchainArchNames )
685 foreach( __arch ${__uniqToolchainArchNames} )
686 list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} )
688 unset( __uniqToolchainArchNames )
689 if( NOT ANDROID_SUPPORTED_ABIS )
690 message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." )
694 __INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ANDROID_SUPPORTED_ABIS} )
695 # verify that target ABI is supported
696 list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx )
697 if( __androidAbiIdx EQUAL -1 )
698 string( REPLACE ";" "\", \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" )
699 message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain.
700 Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\"
703 unset( __androidAbiIdx )
705 # set target ABI options
706 if( ANDROID_ABI STREQUAL "x86" )
708 set( ANDROID_NDK_ABI_NAME "x86" )
709 set( ANDROID_ARCH_NAME "x86" )
710 set( ANDROID_ARCH_FULLNAME "x86" )
711 set( ANDROID_LLVM_TRIPLE "i686-none-linux-android" )
712 set( CMAKE_SYSTEM_PROCESSOR "i686" )
713 elseif( ANDROID_ABI STREQUAL "mips" )
715 set( ANDROID_NDK_ABI_NAME "mips" )
716 set( ANDROID_ARCH_NAME "mips" )
717 set( ANDROID_ARCH_FULLNAME "mipsel" )
718 set( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" )
719 set( CMAKE_SYSTEM_PROCESSOR "mips" )
720 elseif( ANDROID_ABI STREQUAL "armeabi" )
722 set( ANDROID_NDK_ABI_NAME "armeabi" )
723 set( ANDROID_ARCH_NAME "arm" )
724 set( ANDROID_ARCH_FULLNAME "arm" )
725 set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" )
726 set( CMAKE_SYSTEM_PROCESSOR "armv5te" )
727 elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" )
728 set( ARMEABI_V6 true )
729 set( ANDROID_NDK_ABI_NAME "armeabi" )
730 set( ANDROID_ARCH_NAME "arm" )
731 set( ANDROID_ARCH_FULLNAME "arm" )
732 set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" )
733 set( CMAKE_SYSTEM_PROCESSOR "armv6" )
734 # need always fallback to older platform
736 elseif( ANDROID_ABI STREQUAL "armeabi-v7a")
737 set( ARMEABI_V7A true )
738 set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
739 set( ANDROID_ARCH_NAME "arm" )
740 set( ANDROID_ARCH_FULLNAME "arm" )
741 set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
742 set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
743 elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" )
744 set( ARMEABI_V7A true )
745 set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
746 set( ANDROID_ARCH_NAME "arm" )
747 set( ANDROID_ARCH_FULLNAME "arm" )
748 set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
749 set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
751 elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" )
752 set( ARMEABI_V7A true )
753 set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
754 set( ANDROID_ARCH_NAME "arm" )
755 set( ANDROID_ARCH_FULLNAME "arm" )
756 set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" )
757 set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
761 message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." )
764 if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" )
766 # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run...
767 file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" )
770 if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 )
771 __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF )
772 set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE )
773 mark_as_advanced( ANDROID_FORCE_ARM_BUILD )
775 unset( ANDROID_FORCE_ARM_BUILD CACHE )
779 if( ANDROID_TOOLCHAIN_NAME )
780 list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx )
781 if( __toolchainIdx EQUAL -1 )
782 list( SORT __availableToolchains )
783 string( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" )
784 set( toolchains_list " * ${toolchains_list}")
785 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.
786 To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n" )
788 list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch )
789 if( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME )
790 message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." )
793 set( __toolchainIdx -1 )
794 set( __applicableToolchains "" )
795 set( __toolchainMaxVersion "0.0.0" )
796 list( LENGTH __availableToolchains __availableToolchainsCount )
797 math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" )
798 foreach( __idx RANGE ${__availableToolchainsCount} )
799 list( GET __availableToolchainArchs ${__idx} __toolchainArch )
800 if( __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME )
801 list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion )
802 string( REPLACE "x" "99" __toolchainVersion "${__toolchainVersion}")
803 if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion )
804 set( __toolchainMaxVersion "${__toolchainVersion}" )
805 set( __toolchainIdx ${__idx} )
809 unset( __availableToolchainsCount )
810 unset( __toolchainMaxVersion )
811 unset( __toolchainVersion )
813 unset( __toolchainArch )
814 if( __toolchainIdx EQUAL -1 )
815 message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." )
817 list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME )
818 list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME )
819 list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION )
821 unset( __toolchainIdx )
822 unset( __availableToolchains )
823 unset( __availableToolchainMachines )
824 unset( __availableToolchainArchs )
825 unset( __availableToolchainCompilerVersions )
827 # choose native API level
828 __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 )
829 string( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" )
831 set( __real_api_level ${ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME}} )
832 foreach( __level ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
833 if( NOT __level GREATER ANDROID_NATIVE_API_LEVEL AND NOT __level LESS __real_api_level )
834 set( __real_api_level ${__level} )
837 if( __real_api_level AND NOT ANDROID_NATIVE_API_LEVEL EQUAL __real_api_level )
838 message( STATUS "Adjusting Android API level 'android-${ANDROID_NATIVE_API_LEVEL}' to 'android-${__real_api_level}'")
839 set( ANDROID_NATIVE_API_LEVEL ${__real_api_level} )
841 unset(__real_api_level)
843 list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx )
844 if( __levelIdx EQUAL -1 )
845 message( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain." )
847 if( BUILD_WITH_ANDROID_NDK )
848 __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" )
849 if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL )
850 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." )
852 unset( __realApiLevel )
854 set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
855 if( CMAKE_VERSION VERSION_GREATER "2.8" )
856 list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )
857 set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
863 # remember target ABI
864 set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE )
865 if( CMAKE_VERSION VERSION_GREATER "2.8" )
866 list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} )
867 set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} )
871 # runtime choice (STL, rtti, exceptions)
872 if( NOT ANDROID_STL )
873 # honor legacy ANDROID_USE_STLPORT
874 if( DEFINED ANDROID_USE_STLPORT )
875 if( ANDROID_USE_STLPORT )
876 set( ANDROID_STL stlport_static )
878 message( WARNING "You are using an obsolete variable ANDROID_USE_STLPORT to select the STL variant. Use -DANDROID_STL=stlport_static instead." )
880 if( NOT ANDROID_STL )
881 set( ANDROID_STL gnustl_static )
884 set( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" )
885 set( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" )
886 mark_as_advanced( ANDROID_STL ANDROID_STL_FORCE_FEATURES )
888 if( BUILD_WITH_ANDROID_NDK )
889 if( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared)$")
890 message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\".
891 The possible values are:
892 none -> Do not configure the runtime.
893 system -> Use the default minimal system C++ runtime library.
894 system_re -> Same as system but with rtti and exceptions.
895 gabi++_static -> Use the GAbi++ runtime as a static library.
896 gabi++_shared -> Use the GAbi++ runtime as a shared library.
897 stlport_static -> Use the STLport runtime as a static library.
898 stlport_shared -> Use the STLport runtime as a shared library.
899 gnustl_static -> (default) Use the GNU STL as a static library.
900 gnustl_shared -> Use the GNU STL as a shared library.
903 elseif( BUILD_WITH_STANDALONE_TOOLCHAIN )
904 if( NOT "${ANDROID_STL}" MATCHES "^(none|gnustl_static|gnustl_shared)$")
905 message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\".
906 The possible values are:
907 none -> Do not configure the runtime.
908 gnustl_static -> (default) Use the GNU STL as a static library.
909 gnustl_shared -> Use the GNU STL as a shared library.
914 unset( ANDROID_RTTI )
915 unset( ANDROID_EXCEPTIONS )
916 unset( ANDROID_STL_INCLUDE_DIRS )
920 if( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL "r7b" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES "gnustl" )
921 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).
922 You are strongly recommended to switch to another NDK release.
926 if( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" )
927 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:
928 See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc8093df6fee54454b8bcab6c2
929 diff --git a/ndk/platforms/android-9/arch-x86/include/machine/_types.h b/ndk/platforms/android-9/arch-x86/include/machine/_types.h
930 index 5e28c64..65892a1 100644
931 --- a/ndk/platforms/android-9/arch-x86/include/machine/_types.h
932 +++ b/ndk/platforms/android-9/arch-x86/include/machine/_types.h
933 @@ -51,7 +51,11 @@ typedef long int ssize_t;
937 -typedef long ptrdiff_t;
939 + typedef int ptrdiff_t;
941 + typedef long ptrdiff_t;
948 # setup paths and STL for standalone toolchain
949 if( BUILD_WITH_STANDALONE_TOOLCHAIN )
950 set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
951 set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
952 set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" )
954 if( NOT ANDROID_STL STREQUAL "none" )
955 set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" )
956 if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" )
957 list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" )
958 elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" )
959 list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" )
961 list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" )
963 # always search static GNU STL to get the location of libsupc++.a
964 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" )
965 set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" )
966 elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" )
967 set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" )
968 elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" )
969 set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" )
970 elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" )
971 set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" )
974 set( __libsupcxx "${__libstl}/libsupc++.a" )
975 set( __libstl "${__libstl}/libstdc++.a" )
977 if( NOT EXISTS "${__libsupcxx}" )
978 message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain.
979 Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c.
980 You need to either upgrade to newer NDK or manually copy
981 $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a
986 if( ANDROID_STL STREQUAL "gnustl_shared" )
987 if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" )
988 set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" )
989 elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" )
990 set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" )
991 elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" )
992 set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" )
999 if( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" )
1000 set( ANDROID_COMPILER_IS_CLANG 1 )
1001 execute_process( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE )
1002 string( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}")
1003 elseif( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" )
1004 string( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}")
1005 string( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-4.6" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" )
1006 if( NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}/bin/clang${TOOL_OS_SUFFIX}" )
1007 message( FATAL_ERROR "Could not find the Clang compiler driver" )
1009 set( ANDROID_COMPILER_IS_CLANG 1 )
1010 set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
1012 set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" )
1013 unset( ANDROID_COMPILER_IS_CLANG CACHE )
1016 string( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" )
1017 if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" )
1018 set( _clang_name "clang" )
1022 # setup paths and STL for NDK
1023 if( BUILD_WITH_ANDROID_NDK )
1024 set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" )
1025 set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" )
1027 if( ANDROID_STL STREQUAL "none" )
1029 elseif( ANDROID_STL STREQUAL "system" )
1030 set( ANDROID_RTTI OFF )
1031 set( ANDROID_EXCEPTIONS OFF )
1032 set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
1033 elseif( ANDROID_STL STREQUAL "system_re" )
1034 set( ANDROID_RTTI ON )
1035 set( ANDROID_EXCEPTIONS ON )
1036 set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
1037 elseif( ANDROID_STL MATCHES "gabi" )
1038 if( ANDROID_NDK_RELEASE STRLESS "r7" )
1039 message( FATAL_ERROR "gabi++ is not awailable in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.")
1041 set( ANDROID_RTTI ON )
1042 set( ANDROID_EXCEPTIONS OFF )
1043 set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/gabi++/include" )
1044 set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a" )
1045 elseif( ANDROID_STL MATCHES "stlport" )
1046 if( NOT ANDROID_NDK_RELEASE STRLESS "r8d" )
1047 set( ANDROID_EXCEPTIONS ON )
1049 set( ANDROID_EXCEPTIONS OFF )
1051 if( ANDROID_NDK_RELEASE STRLESS "r7" )
1052 set( ANDROID_RTTI OFF )
1054 set( ANDROID_RTTI ON )
1056 set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" )
1057 set( __libstl "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a" )
1058 elseif( ANDROID_STL MATCHES "gnustl" )
1059 set( ANDROID_EXCEPTIONS ON )
1060 set( ANDROID_RTTI ON )
1061 if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
1062 if( ARMEABI_V7A AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.7" AND ANDROID_NDK_RELEASE STREQUAL "r8d" )
1063 # gnustl binary for 4.7 compiler is buggy :(
1064 # TODO: look for right fix
1065 set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.6" )
1067 set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
1070 set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" )
1072 set( ANDROID_STL_INCLUDE_DIRS "${__libstl}/include" "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include" )
1073 if( EXISTS "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" )
1074 set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" )
1076 set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" )
1079 message( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" )
1081 # find libsupc++.a - rtti & exceptions
1082 if( ANDROID_STL STREQUAL "system_re" OR ANDROID_STL MATCHES "gnustl" )
1083 set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r8b or newer
1084 if( NOT EXISTS "${__libsupcxx}" )
1085 set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r7-r8
1087 if( NOT EXISTS "${__libsupcxx}" ) # before r7
1089 if( ANDROID_FORCE_ARM_BUILD )
1090 set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" )
1092 set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" )
1094 elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD )
1095 set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" )
1097 set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" )
1100 if( NOT EXISTS "${__libsupcxx}")
1101 message( ERROR "Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken.")
1107 # case of shared STL linkage
1108 if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl )
1109 string( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" )
1110 if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" )
1111 get_filename_component( __libstlname "${__libstl}" NAME )
1112 execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess )
1113 if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}")
1114 message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" )
1116 unset( __fileCopyProcess )
1117 unset( __libstlname )
1123 __INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE )
1125 if( DEFINED NDK_CCACHE AND NOT EXISTS NDK_CCACHE )
1126 unset( NDK_CCACHE CACHE )
1128 find_program( NDK_CCACHE "${_ndk_ccache}" DOC "The path to ccache binary")
1130 unset( NDK_CCACHE CACHE )
1132 unset( _ndk_ccache )
1135 # setup the cross-compiler
1136 if( NOT CMAKE_C_COMPILER )
1138 set( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" )
1139 set( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" )
1140 if( ANDROID_COMPILER_IS_CLANG )
1141 set( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler")
1142 set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler")
1144 set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler")
1145 set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler")
1148 if( ANDROID_COMPILER_IS_CLANG )
1149 set( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler")
1150 set( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler")
1152 set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" )
1153 set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" )
1156 set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" )
1157 set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" )
1158 set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
1159 set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" )
1160 set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" )
1161 set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" )
1162 set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" )
1163 set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" )
1166 set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" )
1167 if( CMAKE_VERSION VERSION_LESS 2.8.5 )
1168 set( CMAKE_ASM_COMPILER_ARG1 "-c" )
1171 find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )
1172 if( NOT CMAKE_INSTALL_NAME_TOOL )
1173 message( FATAL_ERROR "Could not find install_name_tool, please check your installation." )
1175 mark_as_advanced( CMAKE_INSTALL_NAME_TOOL )
1178 # Force set compilers because standard identification works badly for us
1179 include( CMakeForceCompiler )
1180 CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU )
1181 if( ANDROID_COMPILER_IS_CLANG )
1182 set( CMAKE_C_COMPILER_ID Clang)
1184 set( CMAKE_C_PLATFORM_ID Linux )
1185 set( CMAKE_C_SIZEOF_DATA_PTR 4 )
1186 set( CMAKE_C_HAS_ISYSROOT 1 )
1187 set( CMAKE_C_COMPILER_ABI ELF )
1188 CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU )
1189 if( ANDROID_COMPILER_IS_CLANG )
1190 set( CMAKE_CXX_COMPILER_ID Clang)
1192 set( CMAKE_CXX_PLATFORM_ID Linux )
1193 set( CMAKE_CXX_SIZEOF_DATA_PTR 4 )
1194 set( CMAKE_CXX_HAS_ISYSROOT 1 )
1195 set( CMAKE_CXX_COMPILER_ABI ELF )
1196 set( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C )
1197 # force ASM compiler (required for CMake < 2.8.5)
1198 set( CMAKE_ASM_COMPILER_ID_RUN TRUE )
1199 set( CMAKE_ASM_COMPILER_ID GNU )
1200 set( CMAKE_ASM_COMPILER_WORKS TRUE )
1201 set( CMAKE_ASM_COMPILER_FORCED TRUE )
1202 set( CMAKE_COMPILER_IS_GNUASM 1)
1203 set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm )
1205 # flags and definitions
1206 remove_definitions( -DANDROID )
1207 add_definitions( -DANDROID )
1209 if(ANDROID_SYSROOT MATCHES "[ ;\"]")
1210 set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" )
1211 if( NOT _CMAKE_IN_TRY_COMPILE )
1212 # quotes will break try_compile and compiler identification
1213 message(WARNING "Your Android system root has non-alphanumeric symbols. It can break compiler features detection and the whole build.")
1216 set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" )
1220 if( ARMEABI OR ARMEABI_V7A )
1221 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fpic -funwind-tables" )
1222 if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 )
1223 set( ANDROID_CXX_FLAGS_RELEASE "-mthumb -fomit-frame-pointer -fno-strict-aliasing" )
1224 set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" )
1225 if( NOT ANDROID_COMPILER_IS_CLANG )
1226 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -finline-limit=64" )
1229 # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI
1230 set( ANDROID_CXX_FLAGS_RELEASE "-marm -fomit-frame-pointer -fstrict-aliasing" )
1231 set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" )
1232 if( NOT ANDROID_COMPILER_IS_CLANG )
1233 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" )
1237 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
1238 if( NOT ANDROID_COMPILER_IS_CLANG )
1239 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" )
1241 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fPIC" )
1243 set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" )
1244 set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" )
1246 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fpic -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0" )
1247 set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" )
1248 set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" )
1249 if( NOT ANDROID_COMPILER_IS_CLANG )
1250 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" )
1251 set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" )
1254 set( ANDROID_CXX_FLAGS_RELEASE "" )
1255 set( ANDROID_CXX_FLAGS_DEBUG "" )
1258 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) # good/necessary when porting desktop libraries
1260 if( NOT X86 AND NOT ANDROID_COMPILER_IS_CLANG )
1261 set( ANDROID_CXX_FLAGS "-Wno-psabi ${ANDROID_CXX_FLAGS}" )
1264 if( NOT ANDROID_COMPILER_VERSION VERSION_LESS "4.6" )
1265 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -no-canonical-prefixes" ) # see https://android-review.googlesource.com/#/c/47564/
1268 # ABI-specific flags
1270 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" )
1272 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" )
1274 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" )
1276 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" )
1278 elseif( ARMEABI_V6 )
1279 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2
1281 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" )
1285 if( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" )
1286 if( ANDROID_STL MATCHES "gnustl" )
1287 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>" )
1288 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>" )
1289 set( CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
1291 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>" )
1292 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>" )
1293 set( CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
1295 if ( X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" )
1296 # workaround "undefined reference to `__dso_handle'" problem
1297 set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" )
1298 set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" )
1300 if( EXISTS "${__libstl}" )
1301 set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libstl}\"" )
1302 set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libstl}\"" )
1303 set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libstl}\"" )
1305 if( EXISTS "${__libsupcxx}" )
1306 set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" )
1307 set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" )
1308 set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libsupcxx}\"" )
1310 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>" )
1311 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>" )
1312 set( CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
1313 set( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" )
1314 set( CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" )
1315 set( CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} \"${__libsupcxx}\"" )
1317 if( ANDROID_STL MATCHES "gnustl" )
1318 set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} -lm" )
1319 set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} -lm" )
1320 set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -lm" )
1324 # variables controlling optional build flags
1325 if (ANDROID_NDK_RELEASE STRLESS "r7")
1326 # libGLESv2.so in NDK's prior to r7 refers to missing external symbols.
1327 # So this flag option is required for all projects using OpenGL from native.
1328 __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON )
1330 __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF )
1332 __INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON )
1333 __INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON )
1334 __INIT_VARIABLE( ANDROID_GOLD_LINKER VALUES ON )
1335 __INIT_VARIABLE( ANDROID_NOEXECSTACK VALUES ON )
1336 __INIT_VARIABLE( ANDROID_RELRO VALUES ON )
1338 set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" )
1339 set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
1340 set( ANDROID_FUNCTION_LEVEL_LINKING ${ANDROID_FUNCTION_LEVEL_LINKING} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
1341 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)" )
1342 set( ANDROID_NOEXECSTACK ${ANDROID_NOEXECSTACK} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
1343 set( ANDROID_RELRO ${ANDROID_RELRO} CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" )
1344 mark_as_advanced( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO )
1347 set( ANDROID_LINKER_FLAGS "" )
1350 # this is *required* to use the following linker flags that routes around
1351 # a CPU bug in some Cortex-A8 implementations:
1352 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" )
1355 if( ANDROID_NO_UNDEFINED )
1356 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" )
1359 if( ANDROID_SO_UNDEFINED )
1360 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" )
1363 if( ANDROID_FUNCTION_LEVEL_LINKING )
1364 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" )
1365 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" )
1368 if( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" )
1369 if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE STRGREATER "r8b") AND (ARMEABI OR ARMEABI_V7A OR X86) )
1370 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" )
1371 elseif( ANDROID_NDK_RELEASE STRGREATER "r8b")
1372 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" )
1373 elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE )
1374 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
1375 On Linux and OS X host platform you can workaround this problem using gold linker (default).
1376 Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems.
1379 endif() # version 4.6
1381 if( ANDROID_NOEXECSTACK )
1382 if( ANDROID_COMPILER_IS_CLANG )
1383 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" )
1385 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" )
1387 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" )
1391 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" )
1394 if( ANDROID_COMPILER_IS_CLANG )
1395 set( ANDROID_CXX_FLAGS "-Qunused-arguments ${ANDROID_CXX_FLAGS}" )
1396 if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD )
1397 set( ANDROID_CXX_FLAGS_RELEASE "-target thumbv7-none-linux-androideabi ${ANDROID_CXX_FLAGS_RELEASE}" )
1398 set( ANDROID_CXX_FLAGS_DEBUG "-target ${ANDROID_LLVM_TRIPLE} ${ANDROID_CXX_FLAGS_DEBUG}" )
1400 set( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} ${ANDROID_CXX_FLAGS}" )
1402 if( BUILD_WITH_ANDROID_NDK )
1403 set( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" )
1408 set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" )
1409 set( CMAKE_C_FLAGS "" CACHE STRING "c flags" )
1410 set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" )
1411 set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" )
1412 set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" )
1413 set( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" )
1414 set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags" )
1415 set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags" )
1416 set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" )
1418 # put flags to cache (for debug purpose only)
1419 set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Android specific c/c++ flags" )
1420 set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE}" CACHE INTERNAL "Android specific c/c++ Release flags" )
1421 set( ANDROID_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG}" CACHE INTERNAL "Android specific c/c++ Debug flags" )
1422 set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Android specific c/c++ linker flags" )
1425 set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
1426 set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" )
1427 set( CMAKE_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}" )
1428 set( CMAKE_C_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}" )
1429 set( CMAKE_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}" )
1430 set( CMAKE_C_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}" )
1431 set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" )
1432 set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" )
1433 set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" )
1435 if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" )
1436 set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" )
1437 set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" )
1438 set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" )
1442 if( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES )
1444 set( CMAKE_CXX_FLAGS "-frtti ${CMAKE_CXX_FLAGS}" )
1446 set( CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}" )
1450 # configure exceptios
1451 if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES )
1452 if( ANDROID_EXCEPTIONS )
1453 set( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" )
1454 set( CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}" )
1456 set( CMAKE_CXX_FLAGS "-fno-exceptions ${CMAKE_CXX_FLAGS}" )
1457 set( CMAKE_C_FLAGS "-fno-exceptions ${CMAKE_C_FLAGS}" )
1461 # global includes and link directories
1462 include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} )
1463 link_directories( "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" )
1465 # setup output directories
1466 set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" )
1467 set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
1469 if(NOT _CMAKE_IN_TRY_COMPILE)
1470 if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" )
1471 set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" )
1473 set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" )
1475 set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" )
1478 # set these global flags for cmake client scripts to change behavior
1480 set( BUILD_ANDROID True )
1482 # where is the target environment
1483 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" )
1485 # only search for libraries and includes in the ndk toolchain
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 )
1491 # macro to find packages on the host OS
1492 macro( find_host_package )
1493 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
1494 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
1495 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
1496 if( CMAKE_HOST_WIN32 )
1499 elseif( CMAKE_HOST_APPLE )
1503 find_package( ${ARGN} )
1507 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
1508 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
1509 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
1513 # macro to find programs on the host OS
1514 macro( find_host_program )
1515 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
1516 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
1517 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
1518 if( CMAKE_HOST_WIN32 )
1521 elseif( CMAKE_HOST_APPLE )
1525 find_program( ${ARGN} )
1529 set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
1530 set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
1531 set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
1535 macro( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR )
1536 if( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" )
1537 set( ${VAR} "armeabi" )
1538 elseif( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" )
1539 set( ${VAR} "armeabi-v7a" )
1540 elseif( "${TOOLCHAIN_FLAG}" STREQUAL "X86" )
1542 elseif( "${TOOLCHAIN_FLAG}" STREQUAL "MIPS" )
1543 set( ${VAR} "mips" )
1545 set( ${VAR} "unknown" )
1550 # export toolchain settings for the try_compile() command
1551 if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" )
1552 set( __toolchain_config "")
1553 foreach( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN ANDROID_SET_OBSOLETE_VARIABLES
1554 ANDROID_NDK_HOST_X64
1557 ANDROID_STANDALONE_TOOLCHAIN
1558 ANDROID_TOOLCHAIN_NAME
1560 ANDROID_NATIVE_API_LEVEL
1562 ANDROID_STL_FORCE_FEATURES
1563 ANDROID_FORCE_ARM_BUILD
1564 ANDROID_NO_UNDEFINED
1565 ANDROID_SO_UNDEFINED
1566 ANDROID_FUNCTION_LEVEL_LINKING
1571 if( DEFINED ${__var} )
1572 if( "${__var}" MATCHES " ")
1573 set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" )
1575 set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" )
1579 file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" )
1580 unset( __toolchain_config )
1584 # set some obsolete variables for backward compatibility
1585 set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" )
1586 mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES )
1587 if( ANDROID_SET_OBSOLETE_VARIABLES )
1588 set( ANDROID_API_LEVEL ${ANDROID_NATIVE_API_LEVEL} )
1589 set( ARM_TARGET "${ANDROID_ABI}" )
1590 set( ARMEABI_NDK_NAME "${ANDROID_NDK_ABI_NAME}" )
1594 # Variables controlling behavior or set by cmake toolchain:
1595 # ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips"
1596 # ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version)
1597 # ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none
1598 # ANDROID_FORBID_SYGWIN : ON/OFF
1599 # ANDROID_NO_UNDEFINED : ON/OFF
1600 # ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version)
1601 # ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF
1602 # ANDROID_GOLD_LINKER : ON/OFF
1603 # ANDROID_NOEXECSTACK : ON/OFF
1604 # ANDROID_RELRO : ON/OFF
1605 # ANDROID_FORCE_ARM_BUILD : ON/OFF
1606 # ANDROID_STL_FORCE_FEATURES : ON/OFF
1607 # ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF
1608 # Can be set only at the first run:
1610 # ANDROID_STANDALONE_TOOLCHAIN
1611 # ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain
1612 # ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems)
1613 # LIBRARY_OUTPUT_PATH_ROOT : <any valid path>
1614 # NDK_CCACHE : <path to your ccache executable>
1616 # ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL
1617 # ARM_TARGET : superseded by ANDROID_ABI
1618 # ARM_TARGETS : superseded by ANDROID_ABI (can be set only)
1619 # ANDROID_NDK_TOOLCHAIN_ROOT : superseded by ANDROID_STANDALONE_TOOLCHAIN (can be set only)
1620 # ANDROID_USE_STLPORT : superseded by ANDROID_STL=stlport_static
1621 # ANDROID_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed)
1623 # Primary read-only variables:
1624 # ANDROID : always TRUE
1625 # ARMEABI : TRUE for arm v6 and older devices
1626 # ARMEABI_V6 : TRUE for arm v6
1627 # ARMEABI_V7A : TRUE for arm v7a
1628 # NEON : TRUE if NEON unit is enabled
1629 # VFPV3 : TRUE if VFP version 3 is enabled
1630 # X86 : TRUE if configured for x86
1631 # MIPS : TRUE if configured for mips
1632 # BUILD_ANDROID : always TRUE
1633 # BUILD_WITH_ANDROID_NDK : TRUE if NDK is used
1634 # BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used
1635 # ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform
1636 # ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86" or "mips" depending on ANDROID_ABI
1637 # ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c, r8d, r8e; set only for NDK
1638 # ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI
1639 # ANDROID_SYSROOT : path to the compiler sysroot
1640 # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform
1641 # ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used
1643 # ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME
1645 # Secondary (less stable) read-only variables:
1646 # ANDROID_COMPILER_VERSION : GCC version used
1647 # ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform
1648 # ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI
1649 # ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux"
1650 # ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK)
1651 # ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools
1652 # ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK
1653 # ANDROID_STL_INCLUDE_DIRS : stl include paths
1654 # ANDROID_RTTI : if rtti is enabled by the runtime
1655 # ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime
1656 # ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used
1657 # ANDROID_CLANG_VERSION : version of clang compiler if clang is used
1660 # ANDROID_DEFAULT_NDK_API_LEVEL
1661 # ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH}
1662 # ANDROID_NDK_SEARCH_PATHS
1663 # ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH
1664 # ANDROID_SUPPORTED_ABIS_${ARCH}
1665 # ANDROID_SUPPORTED_NDK_VERSIONS