2011-11-19 19:02:00 +01:00
# ------------------------------------------------------------------------------
2012-05-03 12:40:29 +02:00
# Android CMake toolchain file, for use with the Android NDK r5-r8
2012-08-16 23:23:25 +02:00
# Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended).
2011-05-03 10:13:50 +02:00
# See home page: http://code.google.com/p/android-cmake/
#
2012-09-01 23:02:50 +02:00
# The file is mantained by the OpenCV project. The latest version can be get at
2012-08-06 12:48:23 +02:00
# http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake
2012-03-04 13:30:03 +01:00
#
2011-05-03 10:13:50 +02:00
# Usage Linux:
2011-11-19 19:02:00 +01:00
# $ export ANDROID_NDK=/absolute/path/to/the/android-ndk
# $ mkdir build && cd build
# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
# $ make -j8
2011-05-03 10:13:50 +02:00
#
# Usage Linux (using standalone toolchain):
2011-11-19 19:02:00 +01:00
# $ export ANDROID_STANDALONE_TOOLCHAIN=/absolute/path/to/android-toolchain
# $ mkdir build && cd build
# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
# $ make -j8
2011-05-03 10:13:50 +02:00
#
# Usage Windows:
# You need native port of make to build your project.
2012-05-03 12:40:29 +02:00
# Android NDK r7 (or newer) already has make.exe on board.
2011-11-19 19:02:00 +01:00
# For older NDK you have to install it separately.
# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm
2011-05-03 10:13:50 +02:00
#
2011-11-19 19:02:00 +01:00
# $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk
# $ mkdir build && cd build
# $ cmake.exe -G"MinGW Makefiles"
# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake
# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" ..
2012-09-01 23:02:50 +02:00
# $ cmake.exe --build .
2011-05-03 10:13:50 +02:00
#
#
2011-11-19 19:02:00 +01:00
# Options (can be set as cmake parameters: -D<option_name>=<value>):
# ANDROID_NDK=/opt/android-ndk - path to the NDK root.
2011-11-16 15:32:10 +01:00
# Can be set as environment variable. Can be set only at first cmake run.
2011-05-03 10:13:50 +02:00
#
2012-06-14 16:38:04 +02:00
# ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to the
2011-11-19 19:02:00 +01:00
# standalone toolchain. This option is not used if full NDK is found
# (ignored if ANDROID_NDK is set).
# Can be set as environment variable. Can be set only at first cmake run.
2011-05-03 10:13:50 +02:00
#
2012-09-01 23:02:50 +02:00
# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary
2012-06-14 16:38:04 +02:00
# Interface (ABI). This option nearly matches to the APP_ABI variable
2011-11-19 19:02:00 +01:00
# used by ndk-build tool from Android NDK.
2012-08-16 23:23:25 +02:00
#
# Possible targets are:
2011-11-19 19:02:00 +01:00
# "armeabi" - matches to the NDK ABI with the same name.
# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation.
# "armeabi-v7a" - matches to the NDK ABI with the same name.
# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation.
# "armeabi-v7a with NEON" - same as armeabi-v7a, but
# sets NEON as floating-point unit
# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but
# sets VFPV3 as floating-point unit (has 32 registers instead of 16).
# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP.
# "x86" - matches to the NDK ABI with the same name.
2012-08-16 23:23:25 +02:00
# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation.
# "mips" - matches to the NDK ABI with the same name
2012-09-01 23:02:50 +02:00
# (It is not tested on real devices by the authos of this toolchain)
# See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation.
2011-05-03 10:13:50 +02:00
#
2011-11-19 19:02:00 +01:00
# ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for.
2012-09-01 23:02:50 +02:00
# Option is read-only when standalone toolchain is used.
2011-05-03 10:13:50 +02:00
#
2012-09-01 23:02:50 +02:00
# ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions
# instead of Thumb. Is not available for "x86" (inapplicable) and
# "armeabi-v6 with VFP" (is forced to be ON) ABIs.
2011-05-03 10:13:50 +02:00
#
2012-09-01 23:02:50 +02:00
# ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker
2011-11-19 19:02:00 +01:00
# errors even if they are not used.
2011-05-03 10:13:50 +02:00
#
2012-09-01 23:02:50 +02:00
# ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared
# libraries. Automatically turned for NDK r5x and r6x due to GLESv2
2012-01-20 15:35:57 +01:00
# problems.
#
2011-11-19 19:02:00 +01:00
# LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary
# files. See additional details below.
2011-11-16 15:32:10 +01:00
#
2012-09-01 23:02:50 +02:00
# ANDROID_SET_OBSOLETE_VARIABLES=ON - if set, then toolchain defines some
# obsolete variables which were used by previous versions of this file for
2011-11-19 19:02:00 +01:00
# backward compatibility.
2011-05-03 10:13:50 +02:00
#
2012-09-03 01:54:06 +02:00
# ANDROID_STL=gnustl_static - specify the runtime to use.
#
# Possible values are:
# none -> Do not configure the runtime.
# system -> Use the default minimal system C++ runtime library.
# Implies -fno-rtti -fno-exceptions.
2012-09-03 17:13:51 +02:00
# Is not available for standalone toolchain.
2012-09-03 01:54:06 +02:00
# system_re -> Use the default minimal system C++ runtime library.
# Implies -frtti -fexceptions.
2012-09-03 17:13:51 +02:00
# Is not available for standalone toolchain.
2012-09-03 01:54:06 +02:00
# gabi++_static -> Use the GAbi++ runtime as a static library.
# Implies -frtti -fno-exceptions.
# Available for NDK r7 and newer.
2012-09-03 17:13:51 +02:00
# Is not available for standalone toolchain.
2012-09-03 01:54:06 +02:00
# gabi++_shared -> Use the GAbi++ runtime as a shared library.
# Implies -frtti -fno-exceptions.
# Available for NDK r7 and newer.
2012-09-03 17:13:51 +02:00
# Is not available for standalone toolchain.
2012-09-03 01:54:06 +02:00
# stlport_static -> Use the STLport runtime as a static library.
# Implies -fno-rtti -fno-exceptions for NDK before r7.
# Implies -frtti -fno-exceptions for NDK r7 and newer.
2012-09-03 17:13:51 +02:00
# Is not available for standalone toolchain.
2012-09-03 01:54:06 +02:00
# stlport_shared -> Use the STLport runtime as a shared library.
# Implies -fno-rtti -fno-exceptions for NDK before r7.
# Implies -frtti -fno-exceptions for NDK r7 and newer.
2012-09-03 17:13:51 +02:00
# Is not available for standalone toolchain.
2012-09-03 01:54:06 +02:00
# gnustl_static -> Use the GNU STL as a static library.
# Implies -frtti -fexceptions.
# gnustl_shared -> Use the GNU STL as a shared library.
# Implies -frtti -fno-exceptions.
# Available for NDK r7b and newer.
2012-09-03 17:13:51 +02:00
# Silently degrades to gnustl_static if not available.
2012-09-03 01:54:06 +02:00
#
# ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on
# chosen runtime. If disabled, then the user is responsible for settings
# these options.
2011-05-03 10:13:50 +02:00
#
# What?:
2011-11-19 19:02:00 +01:00
# android-cmake toolchain searches for NDK/toolchain in the following order:
# ANDROID_NDK - cmake parameter
# ANDROID_NDK - environment variable
# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter
# ANDROID_STANDALONE_TOOLCHAIN - environment variable
# ANDROID_NDK - default locations
# ANDROID_STANDALONE_TOOLCHAIN - default locations
#
# Make sure to do the following in your scripts:
# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" )
2012-03-04 13:30:03 +01:00
# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" )
2012-09-01 23:02:50 +02:00
# The flags will be prepopulated with critical flags, so don't loose them.
# Also be aware that toolchain also sets configuration-specific compiler
# flags and linker flags.
2012-06-14 16:38:04 +02:00
#
# ANDROID and BUILD_ANDROID will be set to true, you may test any of these
2011-11-19 19:02:00 +01:00
# variables to make necessary Android-specific configuration changes.
2012-06-14 16:38:04 +02:00
#
2012-09-01 23:02:50 +02:00
# Also ARMEABI or ARMEABI_V7A or X86 or MIPS will be set true, mutually
# exclusive. NEON option will be set true if VFP is set to NEON.
2011-05-03 10:13:50 +02:00
#
2011-11-19 19:02:00 +01:00
# LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where Android
# libraries will be installed.
# Default is ${CMAKE_SOURCE_DIR}, and the android libs will always be
# under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}
# (depending on the target ABI). This is convenient for Android packaging.
2011-05-03 10:13:50 +02:00
#
2012-04-30 16:33:52 +02:00
# Authors:
# Ethan Rublee ethan.ruble@gmail.com
# Andrey Kamaev andrey.kamaev@itseez.com
2012-03-04 13:30:03 +01:00
#
2011-11-19 19:02:00 +01:00
# Change Log:
2012-04-30 16:33:52 +02:00
# - initial version December 2010
# - modified April 2011
2011-05-03 10:13:50 +02:00
# [+] added possibility to build with NDK (without standalone toolchain)
2011-11-19 19:02:00 +01:00
# [+] support cross-compilation on Windows (native, no cygwin support)
2011-05-03 10:13:50 +02:00
# [+] added compiler option to force "char" type to be signed
# [+] added toolchain option to compile to 32-bit ARM instructions
# [+] added toolchain option to disable SWIG search
# [+] added platform "armeabi-v7a with VFPV3"
# [~] ARM_TARGETS renamed to ARM_TARGET
# [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows)
# [~] Fixed bug with ANDROID_API_LEVEL variable
# [~] turn off SWIG search if it is not found first time
2012-04-30 16:33:52 +02:00
# - modified May 2011
2011-05-03 10:13:50 +02:00
# [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL
# [+] ANDROID_API_LEVEL is detected by toolchain if not specified
2011-11-19 19:02:00 +01:00
# [~] added guard to prevent changing of output directories on the first
# cmake pass
2011-05-03 10:13:50 +02:00
# [~] toolchain exits with error if ARM_TARGET is not recognized
2012-04-30 16:33:52 +02:00
# - modified June 2011
2012-06-14 16:38:04 +02:00
# [~] default NDK path is updated for version r5c
2011-06-16 22:25:15 +02:00
# [+] variable CMAKE_SYSTEM_PROCESSOR is set based on ARM_TARGET
# [~] toolchain install directory is added to linker paths
2011-06-22 12:38:57 +02:00
# [-] removed SWIG-related stuff from toolchain
2011-11-19 19:02:00 +01:00
# [+] added macro find_host_package, find_host_program to search
# packages/programs on the host system
2011-06-24 17:40:27 +02:00
# [~] fixed path to STL library
2012-04-30 16:33:52 +02:00
# - modified July 2011
2011-07-12 19:20:48 +02:00
# [~] fixed options caching
2011-07-13 15:06:14 +02:00
# [~] search for all supported NDK versions
2011-07-13 16:48:16 +02:00
# [~] allowed spaces in NDK path
2012-04-30 16:33:52 +02:00
# - modified September 2011
2011-09-02 13:13:32 +02:00
# [~] updated for NDK r6b
2012-04-30 16:33:52 +02:00
# - modified November 2011
2011-11-19 19:02:00 +01:00
# [*] rewritten for NDK r7
2011-11-16 15:32:10 +01:00
# [+] x86 toolchain support (experimental)
2011-11-21 11:55:55 +01:00
# [+] added "armeabi-v6 with VFP" ABI for ARMv6 processors.
2011-11-16 15:32:10 +01:00
# [~] improved compiler and linker flags management
# [+] support different build flags for Release and Debug configurations
2011-11-19 19:02:00 +01:00
# [~] by default compiler flags the same as used by ndk-build (but only
# where reasonable)
# [~] ANDROID_NDK_TOOLCHAIN_ROOT is splitted to ANDROID_STANDALONE_TOOLCHAIN
# and ANDROID_TOOLCHAIN_ROOT
# [~] ARM_TARGET is renamed to ANDROID_ABI
2011-11-16 15:32:10 +01:00
# [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME
# [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL
2012-04-30 16:33:52 +02:00
# - modified January 2012
2012-01-18 15:33:39 +01:00
# [+] added stlport_static support (experimental)
2012-01-20 15:35:57 +01:00
# [+] added special check for cygwin
# [+] filtered out hidden files (starting with .) while globbing inside NDK
# [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6
2012-02-03 12:26:49 +01:00
# [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags
2012-04-30 16:33:52 +02:00
# - modified February 2012
2012-03-04 13:30:03 +01:00
# [+] updated for NDK r7b
# [~] fixed cmake try_compile() command
# [~] Fix for missing install_name_tool on OS X
2012-04-30 16:33:52 +02:00
# - modified March 2012
2012-03-12 17:17:42 +01:00
# [~] fixed incorrect C compiler flags
# [~] fixed CMAKE_SYSTEM_PROCESSOR change on ANDROID_ABI change
# [+] improved toolchain loading speed
# [+] added assembler language support (.S)
2012-03-16 10:16:31 +01:00
# [+] allowed preset search paths and extra search suffixes
2012-04-30 16:33:52 +02:00
# - modified April 2012
2012-04-13 23:50:59 +02:00
# [+] updated for NDK r7c
2012-04-30 16:33:52 +02:00
# [~] fixed most of problems with compiler/linker flags and caching
# [+] added option ANDROID_FUNCTION_LEVEL_LINKING
2012-05-03 12:40:29 +02:00
# - modified May 2012
# [+] updated for NDK r8
# [+] added mips architecture support
2012-08-03 15:00:18 +02:00
# - modified August 2012
# [+] updated for NDK r8b
2012-09-01 23:02:50 +02:00
# [~] all intermediate files generated by toolchain are moved to CMakeFiles
2012-08-16 23:23:25 +02:00
# [~] libstdc++ and libsupc are removed from explicit link libraries
2012-08-27 17:45:24 +02:00
# [+] added CCache support (via NDK_CCACHE environment or cmake variable)
# [+] added gold linker support for NDK r8b
2012-08-27 18:16:54 +02:00
# [~] fixed mips linker flags for NDK r8b
2012-09-01 23:11:41 +02:00
# - modified September 2012
# [+] added NDK release name detection (see ANDROID_NDK_RELEASE)
2012-09-03 17:13:51 +02:00
# [+] added support for all C++ runtimes from NDK
# (system, gabi++, stlport, gnustl)
2012-10-11 14:10:01 +02:00
# [+] improved warnings on known issues of NDKs
# [~] use gold linker as default if available (NDK r8b)
# [~] globally turned off rpath
# [~] compiler options are aligned with NDK r8b
# - modified October 2012
# [~] fixed C++ linking: explicitly link with math library (OpenCV #2426)
2011-11-19 19:02:00 +01:00
# ------------------------------------------------------------------------------
2011-05-03 10:13:50 +02:00
2012-03-04 13:30:03 +01:00
cmake_minimum_required ( VERSION 2.6.3 )
2012-03-12 17:17:42 +01:00
if ( DEFINED CMAKE_CROSSCOMPILING )
2012-08-16 23:23:25 +02:00
# subsequent toolchain loading is not really needed
2012-03-12 17:17:42 +01:00
return ( )
endif ( )
2012-09-01 23:02:50 +02:00
get_property ( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
2012-05-03 12:40:29 +02:00
if ( _CMAKE_IN_TRY_COMPILE )
2012-03-04 21:36:50 +01:00
include ( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL )
2012-03-04 13:30:03 +01:00
endif ( )
2011-05-03 10:13:50 +02:00
# this one is important
set ( CMAKE_SYSTEM_NAME Linux )
2012-08-16 23:23:25 +02:00
# this one not so much
2011-05-03 10:13:50 +02:00
set ( CMAKE_SYSTEM_VERSION 1 )
2012-09-05 18:31:09 +02:00
# rpath makes low sence for Android
set ( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." )
2012-08-03 15:00:18 +02:00
set ( ANDROID_SUPPORTED_NDK_VERSIONS ${ ANDROID_EXTRA_NDK_VERSIONS } -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" )
2012-03-16 10:16:31 +01:00
if ( NOT DEFINED ANDROID_NDK_SEARCH_PATHS )
if ( CMAKE_HOST_WIN32 )
file ( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS )
set ( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}/android-ndk" "$ENV{SystemDrive}/NVPACK/android-ndk" )
else ( )
file ( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS )
set ( ANDROID_NDK_SEARCH_PATHS /opt/android-ndk "${ANDROID_NDK_SEARCH_PATHS}/NVPACK/android-ndk" )
endif ( )
endif ( )
if ( NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
set ( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain )
2011-05-03 10:13:50 +02:00
endif ( )
2012-03-16 10:16:31 +01:00
2011-11-16 15:32:10 +01:00
set ( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" )
set ( ANDROID_SUPPORTED_ABIS_x86 "x86" )
2012-05-03 12:40:29 +02:00
set ( ANDROID_SUPPORTED_ABIS_mipsel "mips" )
2011-11-16 15:32:10 +01:00
set ( ANDROID_DEFAULT_NDK_API_LEVEL 8 )
set ( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )
2012-05-03 12:40:29 +02:00
set ( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )
2011-11-16 15:32:10 +01:00
2012-01-20 15:35:57 +01:00
macro ( __LIST_FILTER listvar regex )
if ( ${ listvar } )
foreach ( __val ${ ${listvar } } )
if ( __val MATCHES "${regex}" )
list ( REMOVE_ITEM ${ listvar } "${__val}" )
endif ( )
endforeach ( )
endif ( )
endmacro ( )
2012-01-18 15:33:39 +01:00
2011-11-16 15:32:10 +01:00
macro ( __INIT_VARIABLE var_name )
set ( __test_path 0 )
foreach ( __var ${ ARGN } )
if ( __var STREQUAL "PATH" )
set ( __test_path 1 )
2011-07-13 15:06:14 +02:00
break ( )
endif ( )
endforeach ( )
2011-11-16 15:32:10 +01:00
if ( __test_path AND NOT EXISTS "${${var_name}}" )
unset ( ${ var_name } CACHE )
endif ( )
if ( "${${var_name}}" STREQUAL "" )
set ( __values 0 )
foreach ( __var ${ ARGN } )
if ( __var STREQUAL "VALUES" )
set ( __values 1 )
elseif ( NOT __var STREQUAL "PATH" )
set ( __obsolete 0 )
if ( __var MATCHES "^OBSOLETE_.*$" )
string ( REPLACE "OBSOLETE_" "" __var "${__var}" )
set ( __obsolete 1 )
endif ( )
if ( __var MATCHES "^ENV_.*$" )
string ( REPLACE "ENV_" "" __var "${__var}" )
set ( __value "$ENV{${__var}}" )
elseif ( DEFINED ${ __var } )
set ( __value "${${__var}}" )
else ( )
if ( __values )
set ( __value "${__var}" )
else ( )
set ( __value "" )
endif ( )
endif ( )
if ( NOT "${__value}" STREQUAL "" )
if ( __test_path )
if ( EXISTS "${__value}" )
2012-09-01 23:02:50 +02:00
file ( TO_CMAKE_PATH "${__value}" ${ var_name } )
if ( __obsolete AND NOT _CMAKE_IN_TRY_COMPILE )
2011-11-16 15:32:10 +01:00
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." )
endif ( )
break ( )
endif ( )
else ( )
set ( ${ var_name } "${__value}" )
2012-09-01 23:02:50 +02:00
if ( __obsolete AND NOT _CMAKE_IN_TRY_COMPILE )
2011-11-16 15:32:10 +01:00
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." )
endif ( )
break ( )
endif ( )
endif ( )
endif ( )
endforeach ( )
unset ( __value )
unset ( __values )
unset ( __obsolete )
2012-09-01 23:02:50 +02:00
elseif ( __test_path )
file ( TO_CMAKE_PATH "${${var_name}}" ${ var_name } )
2011-11-16 15:32:10 +01:00
endif ( )
unset ( __test_path )
endmacro ( )
macro ( __DETECT_NATIVE_API_LEVEL _var _path )
SET ( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" )
FILE ( STRINGS ${ _path } __apiFileContent REGEX "${__ndkApiLevelRegex}" )
if ( NOT __apiFileContent )
2011-11-17 16:28:11 +01:00
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." )
2011-11-16 15:32:10 +01:00
endif ( )
string ( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${ _var } "${__apiFileContent}" )
unset ( __apiFileContent )
unset ( __ndkApiLevelRegex )
endmacro ( )
2011-07-13 15:06:14 +02:00
2011-11-16 15:32:10 +01:00
macro ( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root )
2012-09-01 23:02:50 +02:00
if ( EXISTS "${_root}" )
file ( GLOB __gccExePath "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" )
__LIST_FILTER ( __gccExePath "bin/[.].*-gcc${TOOL_OS_SUFFIX}$" )
list ( LENGTH __gccExePath __gccExePathsCount )
if ( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE )
message ( WARNING "Could not determine machine name for compiler from ${_root}" )
set ( ${ _var } "" )
else ( )
get_filename_component ( __gccExeName "${__gccExePath}" NAME_WE )
string ( REPLACE "-gcc" "" ${ _var } "${__gccExeName}" )
endif ( )
unset ( __gccExePath )
unset ( __gccExePathsCount )
unset ( __gccExeName )
2011-05-03 10:13:50 +02:00
else ( )
2012-09-01 23:02:50 +02:00
set ( ${ _var } "" )
2011-05-03 10:13:50 +02:00
endif ( )
2011-11-16 15:32:10 +01:00
endmacro ( )
2011-05-03 10:13:50 +02:00
2012-01-20 15:35:57 +01:00
2012-08-16 23:23:25 +02:00
# fight against cygwin
2012-01-20 15:35:57 +01:00
set ( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools" )
mark_as_advanced ( ANDROID_FORBID_SYGWIN )
if ( ANDROID_FORBID_SYGWIN )
if ( CYGWIN )
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." )
endif ( )
if ( CMAKE_HOST_WIN32 )
2012-08-16 23:23:25 +02:00
# remove cygwin from PATH
2012-01-20 15:35:57 +01:00
set ( __new_path "$ENV{PATH}" )
__LIST_FILTER ( __new_path "cygwin" )
set ( ENV{PATH} "${__new_path}" )
unset ( __new_path )
endif ( )
endif ( )
2012-08-16 23:23:25 +02:00
# detect current host platform
2011-11-16 15:32:10 +01:00
set ( TOOL_OS_SUFFIX "" )
if ( CMAKE_HOST_APPLE )
set ( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" )
elseif ( CMAKE_HOST_WIN32 )
set ( ANDROID_NDK_HOST_SYSTEM_NAME "windows" )
set ( TOOL_OS_SUFFIX ".exe" )
elseif ( CMAKE_HOST_UNIX )
set ( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" )
else ( )
message ( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
endif ( )
2011-05-03 10:13:50 +02:00
2012-08-16 23:23:25 +02:00
# see if we have path to Android NDK
2011-11-16 15:32:10 +01:00
__INIT_VARIABLE ( ANDROID_NDK PATH ENV_ANDROID_NDK )
if ( NOT ANDROID_NDK )
2012-08-16 23:23:25 +02:00
# see if we have path to Android standalone toolchain
2011-11-16 15:32:10 +01:00
__INIT_VARIABLE ( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN OBSOLETE_ANDROID_NDK_TOOLCHAIN_ROOT OBSOLETE_ENV_ANDROID_NDK_TOOLCHAIN_ROOT )
if ( NOT ANDROID_STANDALONE_TOOLCHAIN )
#try to find Android NDK in one of the the default locations
set ( __ndkSearchPaths )
2012-02-20 15:50:23 +01:00
foreach ( __ndkSearchPath ${ ANDROID_NDK_SEARCH_PATHS } )
foreach ( suffix ${ ANDROID_SUPPORTED_NDK_VERSIONS } )
list ( APPEND __ndkSearchPaths "${__ndkSearchPath}${suffix}" )
endforeach ( )
2011-11-16 15:32:10 +01:00
endforeach ( )
__INIT_VARIABLE ( ANDROID_NDK PATH VALUES ${ __ndkSearchPaths } )
unset ( __ndkSearchPaths )
if ( ANDROID_NDK )
message ( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" )
message ( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" )
else ( )
#try to find Android standalone toolchain in one of the the default locations
__INIT_VARIABLE ( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
if ( ANDROID_STANDALONE_TOOLCHAIN )
message ( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" )
message ( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" )
endif ( ANDROID_STANDALONE_TOOLCHAIN )
endif ( ANDROID_NDK )
endif ( NOT ANDROID_STANDALONE_TOOLCHAIN )
endif ( NOT ANDROID_NDK )
2012-08-16 23:23:25 +02:00
# remember found paths
2011-11-16 15:32:10 +01:00
if ( ANDROID_NDK )
get_filename_component ( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE )
2012-08-16 23:23:25 +02:00
# try to detect change
2011-11-16 15:32:10 +01:00
if ( CMAKE_AR )
string ( LENGTH "${ANDROID_NDK}" __length )
string ( SUBSTRING "${CMAKE_AR}" 0 ${ __length } __androidNdkPreviousPath )
if ( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK )
2012-09-04 14:33:24 +02:00
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.
2012-09-01 23:02:50 +02:00
" )
2011-11-16 15:32:10 +01:00
endif ( )
unset ( __androidNdkPreviousPath )
unset ( __length )
2011-05-03 10:13:50 +02:00
endif ( )
2012-09-01 23:02:50 +02:00
set ( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE )
2011-05-03 10:13:50 +02:00
set ( BUILD_WITH_ANDROID_NDK True )
2012-09-01 23:11:41 +02:00
file ( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE LIMIT_COUNT 1 REGEX r[0-9]+[a-z]? )
2011-11-16 15:32:10 +01:00
elseif ( ANDROID_STANDALONE_TOOLCHAIN )
get_filename_component ( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE )
2012-08-16 23:23:25 +02:00
# try to detect change
2011-11-16 15:32:10 +01:00
if ( CMAKE_AR )
string ( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length )
string ( SUBSTRING "${CMAKE_AR}" 0 ${ __length } __androidStandaloneToolchainPreviousPath )
if ( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN )
message ( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." )
endif ( )
unset ( __androidStandaloneToolchainPreviousPath )
unset ( __length )
2011-05-03 10:13:50 +02:00
endif ( )
2012-09-01 23:02:50 +02:00
set ( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" FORCE )
2011-11-16 15:32:10 +01:00
set ( BUILD_WITH_STANDALONE_TOOLCHAIN True )
else ( )
2012-02-20 15:50:23 +01:00
list ( GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH )
2012-09-07 16:27:47 +02:00
message ( FATAL_ERROR " Could not find neither Android NDK nor Android standalone toolchain.
2011-05-03 10:13:50 +02:00
Y o u s h o u l d e i t h e r s e t a n e n v i r o n m e n t v a r i a b l e :
e x p o r t A N D R O I D _ N D K = ~ / m y - a n d r o i d - n d k
o r
2011-11-16 15:32:10 +01:00
e x p o r t A N D R O I D _ S T A N D A L O N E _ T O O L C H A I N = ~ / m y - a n d r o i d - t o o l c h a i n
2011-05-03 10:13:50 +02:00
o r p u t t h e t o o l c h a i n o r N D K i n t h e d e f a u l t p a t h :
2011-11-16 15:32:10 +01:00
s u d o l n - s ~ / m y - a n d r o i d - n d k $ { A N D R O I D _ N D K _ S E A R C H _ P A T H }
s u d o l n - s ~ / m y - a n d r o i d - t o o l c h a i n $ { A N D R O I D _ S T A N D A L O N E _ T O O L C H A I N _ S E A R C H _ P A T H } " )
endif ( )
2011-05-03 10:13:50 +02:00
2012-08-16 23:23:25 +02:00
# get all the details about standalone toolchain
2011-11-16 15:32:10 +01:00
if ( BUILD_WITH_STANDALONE_TOOLCHAIN )
__DETECT_NATIVE_API_LEVEL ( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" )
2012-05-03 12:40:29 +02:00
set ( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ ANDROID_SUPPORTED_NATIVE_API_LEVELS } )
2011-11-16 15:32:10 +01:00
set ( __availableToolchains "standalone" )
__DETECT_TOOLCHAIN_MACHINE_NAME ( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" )
if ( NOT __availableToolchainMachines )
message ( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." )
endif ( )
if ( __availableToolchainMachines MATCHES i686 )
set ( __availableToolchainArchs "x86" )
elseif ( __availableToolchainMachines MATCHES arm )
set ( __availableToolchainArchs "arm" )
2012-05-03 12:40:29 +02:00
elseif ( __availableToolchainMachines MATCHES mipsel )
set ( __availableToolchainArchs "mipsel" )
2011-11-16 15:32:10 +01:00
endif ( )
if ( ANDROID_COMPILER_VERSION )
2012-08-16 23:23:25 +02:00
# do not run gcc every time because it is relatevely expencive
2011-11-16 15:32:10 +01:00
set ( __availableToolchainCompilerVersions "${ANDROID_COMPILER_VERSION}" )
else ( )
execute_process ( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version
O U T P U T _ V A R I A B L E _ _ a v a i l a b l e T o o l c h a i n C o m p i l e r V e r s i o n s O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
2012-09-03 17:13:51 +02:00
string ( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" )
2011-11-16 15:32:10 +01:00
endif ( )
2011-05-03 10:13:50 +02:00
endif ( )
2012-08-16 23:23:25 +02:00
# get all the details about NDK
2011-11-16 15:32:10 +01:00
if ( BUILD_WITH_ANDROID_NDK )
file ( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" )
string ( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" )
file ( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" )
2012-01-20 15:35:57 +01:00
__LIST_FILTER ( __availableToolchains "^[.]" )
2011-11-16 15:32:10 +01:00
set ( __availableToolchainMachines "" )
set ( __availableToolchainArchs "" )
set ( __availableToolchainCompilerVersions "" )
foreach ( __toolchain ${ __availableToolchains } )
__DETECT_TOOLCHAIN_MACHINE_NAME ( __machine "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" )
if ( __machine )
2012-09-03 17:13:51 +02:00
string ( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?$" __version "${__toolchain}" )
2011-11-16 15:32:10 +01:00
string ( REGEX MATCH "^[^-]+" __arch "${__toolchain}" )
2012-08-03 15:00:18 +02:00
list ( APPEND __availableToolchainMachines "${__machine}" )
list ( APPEND __availableToolchainArchs "${__arch}" )
list ( APPEND __availableToolchainCompilerVersions "${__version}" )
2011-11-16 15:32:10 +01:00
else ( )
list ( REMOVE_ITEM __availableToolchains "${__toolchain}" )
endif ( )
endforeach ( )
if ( NOT __availableToolchains )
message ( FATAL_ERROR "Could not any working toolchain in the NDK. Probably your Android NDK is broken." )
endif ( )
2011-05-03 10:13:50 +02:00
endif ( )
2011-11-16 15:32:10 +01:00
2012-08-16 23:23:25 +02:00
# build list of available ABIs
2011-11-16 15:32:10 +01:00
if ( NOT ANDROID_SUPPORTED_ABIS )
set ( ANDROID_SUPPORTED_ABIS "" )
set ( __uniqToolchainArchNames ${ __availableToolchainArchs } )
list ( REMOVE_DUPLICATES __uniqToolchainArchNames )
list ( SORT __uniqToolchainArchNames )
foreach ( __arch ${ __uniqToolchainArchNames } )
list ( APPEND ANDROID_SUPPORTED_ABIS ${ ANDROID_SUPPORTED_ABIS_${__arch } } )
endforeach ( )
unset ( __uniqToolchainArchNames )
if ( NOT ANDROID_SUPPORTED_ABIS )
message ( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." )
endif ( )
2011-09-18 17:30:36 +02:00
endif ( )
2011-05-03 10:13:50 +02:00
2012-08-16 23:23:25 +02:00
# choose target ABI
2011-11-16 15:32:10 +01:00
__INIT_VARIABLE ( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ ANDROID_SUPPORTED_ABIS } )
2012-08-16 23:23:25 +02:00
# verify that target ABI is supported
2011-11-16 15:32:10 +01:00
list ( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx )
if ( __androidAbiIdx EQUAL -1 )
string ( REPLACE ";" "\" , \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" )
message ( FATAL_ERROR "Specified ANDROID_ABI = \" ${ ANDROID_ABI } \" is not supported by this cmake toolchain or your NDK/toolchain.
S u p p o r t e d v a l u e s a r e : \ " $ { P R I N T A B L E _ A N D R O I D _ S U P P O R T E D _ A B I S } \ "
" )
endif ( )
unset ( __androidAbiIdx )
2012-08-16 23:23:25 +02:00
# remember target ABI
2011-11-16 15:32:10 +01:00
set ( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE )
2012-08-16 23:23:25 +02:00
# set target ABI options
2011-11-16 15:32:10 +01:00
if ( ANDROID_ABI STREQUAL "x86" )
set ( X86 true )
set ( ANDROID_NDK_ABI_NAME "x86" )
set ( ANDROID_ARCH_NAME "x86" )
2012-05-03 12:40:29 +02:00
set ( ANDROID_ARCH_FULLNAME "x86" )
2011-11-16 15:32:10 +01:00
set ( CMAKE_SYSTEM_PROCESSOR "i686" )
2012-05-03 12:40:29 +02:00
elseif ( ANDROID_ABI STREQUAL "mips" )
set ( MIPS true )
set ( ANDROID_NDK_ABI_NAME "mips" )
set ( ANDROID_ARCH_NAME "mips" )
set ( ANDROID_ARCH_FULLNAME "mipsel" )
set ( CMAKE_SYSTEM_PROCESSOR "mips" )
2011-11-16 15:32:10 +01:00
elseif ( ANDROID_ABI STREQUAL "armeabi" )
2011-05-03 10:13:50 +02:00
set ( ARMEABI true )
2011-11-16 15:32:10 +01:00
set ( ANDROID_NDK_ABI_NAME "armeabi" )
set ( ANDROID_ARCH_NAME "arm" )
2012-05-03 12:40:29 +02:00
set ( ANDROID_ARCH_FULLNAME "arm" )
2011-06-03 14:01:55 +02:00
set ( CMAKE_SYSTEM_PROCESSOR "armv5te" )
2011-11-16 15:32:10 +01:00
elseif ( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" )
set ( ARMEABI_V6 true )
set ( ANDROID_NDK_ABI_NAME "armeabi" )
set ( ANDROID_ARCH_NAME "arm" )
2012-05-03 12:40:29 +02:00
set ( ANDROID_ARCH_FULLNAME "arm" )
2011-11-16 15:32:10 +01:00
set ( CMAKE_SYSTEM_PROCESSOR "armv6" )
2012-08-16 23:23:25 +02:00
# need always fallback to older platform
2011-11-16 15:32:10 +01:00
set ( ARMEABI true )
elseif ( ANDROID_ABI STREQUAL "armeabi-v7a" )
set ( ARMEABI_V7A true )
set ( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
set ( ANDROID_ARCH_NAME "arm" )
2012-05-03 12:40:29 +02:00
set ( ANDROID_ARCH_FULLNAME "arm" )
2011-11-16 15:32:10 +01:00
set ( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
elseif ( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" )
set ( ARMEABI_V7A true )
set ( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
set ( ANDROID_ARCH_NAME "arm" )
2012-05-03 12:40:29 +02:00
set ( ANDROID_ARCH_FULLNAME "arm" )
2011-11-16 15:32:10 +01:00
set ( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
set ( VFPV3 true )
elseif ( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" )
2011-05-03 10:13:50 +02:00
set ( ARMEABI_V7A true )
2011-11-16 15:32:10 +01:00
set ( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
set ( ANDROID_ARCH_NAME "arm" )
2012-05-03 12:40:29 +02:00
set ( ANDROID_ARCH_FULLNAME "arm" )
2011-06-03 14:01:55 +02:00
set ( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
2011-11-16 15:32:10 +01:00
set ( VFPV3 true )
set ( NEON true )
else ( )
message ( SEND_ERROR "Unknown ANDROID_ABI=\" ${ ANDROID_ABI } \" is specified. " )
endif ( )
2012-03-12 17:17:42 +01:00
if ( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" )
2012-08-16 23:23:25 +02:00
# really dirty hack
# it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run...
2012-03-12 17:17:42 +01:00
file ( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \" ${ CMAKE_SYSTEM_PROCESSOR } \")\n" )
endif ( )
2012-09-01 23:02:50 +02:00
set ( ANDROID_SUPPORTED_ABIS ${ ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME } } CACHE INTERNAL "ANDROID_ABI can be changed only to one of these ABIs. Changing to any other ABI requires to reset cmake cache." FORCE )
2011-11-16 15:32:10 +01:00
if ( CMAKE_VERSION VERSION_GREATER "2.8" )
2012-05-03 12:40:29 +02:00
list ( SORT ANDROID_SUPPORTED_ABIS_ ${ ANDROID_ARCH_FULLNAME } )
set_property ( CACHE ANDROID_ABI PROPERTY STRINGS ${ ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME } } )
2011-05-03 10:13:50 +02:00
endif ( )
2011-11-16 15:32:10 +01:00
if ( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 )
__INIT_VARIABLE ( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF )
set ( ANDROID_FORCE_ARM_BUILD ${ ANDROID_FORCE_ARM_BUILD } CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE )
2012-01-20 15:35:57 +01:00
mark_as_advanced ( ANDROID_FORCE_ARM_BUILD )
2011-11-16 15:32:10 +01:00
else ( )
unset ( ANDROID_FORCE_ARM_BUILD CACHE )
endif ( )
2012-08-16 23:23:25 +02:00
# choose toolchain
2011-11-16 15:32:10 +01:00
if ( ANDROID_TOOLCHAIN_NAME )
list ( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx )
if ( __toolchainIdx EQUAL -1 )
message ( FATAL_ERROR "Previously selected toolchain \" ${ ANDROID_TOOLCHAIN_NAME } \" is missing. You need to remove CMakeCache.txt and rerun cmake manually to change the toolchain " )
endif ( )
list ( GET __availableToolchainArchs ${ __toolchainIdx } __toolchainArch )
2012-05-03 12:40:29 +02:00
if ( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME )
2011-11-17 16:28:11 +01:00
message ( SEND_ERROR "Previously selected toolchain \" ${ ANDROID_TOOLCHAIN_NAME } \" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform. " )
2011-11-16 15:32:10 +01:00
endif ( )
else ( )
set ( __toolchainIdx -1 )
set ( __applicableToolchains "" )
set ( __toolchainMaxVersion "0.0.0" )
list ( LENGTH __availableToolchains __availableToolchainsCount )
math ( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" )
foreach ( __idx RANGE ${ __availableToolchainsCount } )
list ( GET __availableToolchainArchs ${ __idx } __toolchainArch )
2012-05-03 12:40:29 +02:00
if ( __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME )
2011-11-16 15:32:10 +01:00
list ( GET __availableToolchainCompilerVersions ${ __idx } __toolchainVersion )
if ( __toolchainVersion VERSION_GREATER __toolchainMaxVersion )
set ( __toolchainMaxVersion "${__toolchainVersion}" )
set ( __toolchainIdx ${ __idx } )
endif ( )
endif ( )
endforeach ( )
unset ( __availableToolchainsCount )
unset ( __toolchainMaxVersion )
unset ( __toolchainVersion )
endif ( )
unset ( __toolchainArch )
if ( __toolchainIdx EQUAL -1 )
message ( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." )
endif ( )
list ( GET __availableToolchains ${ __toolchainIdx } ANDROID_TOOLCHAIN_NAME )
list ( GET __availableToolchainMachines ${ __toolchainIdx } ANDROID_TOOLCHAIN_MACHINE_NAME )
list ( GET __availableToolchainCompilerVersions ${ __toolchainIdx } ANDROID_COMPILER_VERSION )
2012-09-01 23:02:50 +02:00
set ( ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" CACHE INTERNAL "Name of toolchain used" FORCE )
set ( ANDROID_COMPILER_VERSION "${ANDROID_COMPILER_VERSION}" CACHE INTERNAL "compiler version from selected toolchain" FORCE )
2011-11-16 15:32:10 +01:00
unset ( __toolchainIdx )
unset ( __availableToolchains )
unset ( __availableToolchainMachines )
unset ( __availableToolchainArchs )
unset ( __availableToolchainCompilerVersions )
2012-08-16 23:23:25 +02:00
# choose native API level
2012-05-03 12:40:29 +02:00
__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 )
2011-11-16 15:32:10 +01:00
string ( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" )
2012-08-16 23:23:25 +02:00
# validate
2011-11-16 15:32:10 +01:00
list ( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx )
if ( __levelIdx EQUAL -1 )
2011-11-17 16:28:11 +01:00
message ( SEND_ERROR "Specified Android native API level (${ANDROID_NATIVE_API_LEVEL}) is not supported by your NDK/toolchain." )
2011-11-16 15:32:10 +01:00
endif ( )
unset ( __levelIdx )
if ( BUILD_WITH_ANDROID_NDK )
__DETECT_NATIVE_API_LEVEL ( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" )
if ( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL )
2011-11-17 16:28:11 +01:00
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." )
2011-11-16 15:32:10 +01:00
endif ( )
unset ( __realApiLevel )
endif ( )
set ( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
if ( CMAKE_VERSION VERSION_GREATER "2.8" )
list ( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )
set_property ( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ ANDROID_SUPPORTED_NATIVE_API_LEVELS } )
endif ( )
2012-09-03 01:54:06 +02:00
# setup output directories
set ( LIBRARY_OUTPUT_PATH_ROOT ${ CMAKE_SOURCE_DIR } CACHE PATH "root for library output, set this to change where android libs are installed to" )
set ( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
if ( NOT _CMAKE_IN_TRY_COMPILE )
if ( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" )
set ( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" )
else ( )
set ( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" )
endif ( )
set ( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" )
2011-11-16 15:32:10 +01:00
endif ( )
2012-09-03 01:54:06 +02:00
# runtime choice (STL, rtti, exceptions)
if ( NOT ANDROID_STL )
2012-09-03 17:13:51 +02:00
# honor legacy ANDROID_USE_STLPORT
2012-09-03 01:54:06 +02:00
if ( DEFINED ANDROID_USE_STLPORT )
if ( ANDROID_USE_STLPORT )
set ( ANDROID_STL stlport_static )
endif ( )
2012-09-04 12:59:26 +02:00
message ( WARNING "You are using an obsolete variable ANDROID_USE_STLPORT to select the STL variant. Use -DANDROID_STL=stlport_static instead." )
2012-09-03 01:54:06 +02:00
endif ( )
if ( NOT ANDROID_STL )
set ( ANDROID_STL gnustl_static )
endif ( )
endif ( )
set ( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" )
set ( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" )
mark_as_advanced ( ANDROID_STL ANDROID_STL_FORCE_FEATURES )
2012-09-03 17:13:51 +02:00
if ( BUILD_WITH_ANDROID_NDK )
if ( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared)$" )
message ( FATAL_ERROR "ANDROID_STL is set to invalid value \" ${ ANDROID_STL } \".
2012-09-03 01:54:06 +02:00
T h e p o s s i b l e v a l u e s a r e :
n o n e - > D o n o t c o n f i g u r e t h e r u n t i m e .
s y s t e m - > U s e t h e d e f a u l t m i n i m a l s y s t e m C + + r u n t i m e l i b r a r y .
s y s t e m _ r e - > S a m e a s s y s t e m b u t w i t h r t t i a n d e x c e p t i o n s .
g a b i + + _ s t a t i c - > U s e t h e G A b i + + r u n t i m e a s a s t a t i c l i b r a r y .
g a b i + + _ s h a r e d - > U s e t h e G A b i + + r u n t i m e a s a s h a r e d l i b r a r y .
s t l p o r t _ s t a t i c - > U s e t h e S T L p o r t r u n t i m e a s a s t a t i c l i b r a r y .
s t l p o r t _ s h a r e d - > U s e t h e S T L p o r t r u n t i m e a s a s h a r e d l i b r a r y .
g n u s t l _ s t a t i c - > ( d e f a u l t ) U s e t h e G N U S T L a s a s t a t i c l i b r a r y .
g n u s t l _ s h a r e d - > U s e t h e G N U S T L a s a s h a r e d l i b r a r y .
2012-09-03 17:13:51 +02:00
" )
endif ( )
elseif ( BUILD_WITH_STANDALONE_TOOLCHAIN )
if ( NOT "${ANDROID_STL}" MATCHES "^(none|gnustl_static|gnustl_shared)$" )
message ( FATAL_ERROR "ANDROID_STL is set to invalid value \" ${ ANDROID_STL } \".
T h e p o s s i b l e v a l u e s a r e :
n o n e - > D o n o t c o n f i g u r e t h e r u n t i m e .
g n u s t l _ s t a t i c - > ( d e f a u l t ) U s e t h e G N U S T L a s a s t a t i c l i b r a r y .
g n u s t l _ s h a r e d - > U s e t h e G N U S T L a s a s h a r e d l i b r a r y .
" )
endif ( )
2012-09-03 01:54:06 +02:00
endif ( )
unset ( ANDROID_RTTI )
unset ( ANDROID_EXCEPTIONS )
unset ( ANDROID_STL_INCLUDE_DIRS )
unset ( __libstl )
unset ( __libsupcxx )
2012-09-04 12:59:26 +02:00
if ( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL "r7b" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES "gnustl" )
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 ) .
Y o u a r e s t r o n g l y r e c o m m e n d e d t o s w i t c h t o a n o t h e r N D K r e l e a s e .
" )
endif ( )
2012-09-07 16:27:47 +02:00
if ( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" )
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:
S e e h t t p s : / / a n d r o i d . g o o g l e s o u r c e . c o m / p l a t f o r m / d e v e l o p m e n t . g i t f 9 0 7 f 4 f 9 d 4 e 5 6 c c c 8 0 9 3 d f 6 f e e 5 4 4 5 4 b 8 b c a b 6 c 2
d i f f - - g i t a / n d k / p l a t f o r m s / a n d r o i d - 9 / a r c h - x 8 6 / i n c l u d e / m a c h i n e / _ t y p e s . h b / n d k / p l a t f o r m s / a n d r o i d - 9 / a r c h - x 8 6 / i n c l u d e / m a c h i n e / _ t y p e s . h
i n d e x 5 e 2 8 c 6 4 . . 6 5 8 9 2 a 1 1 0 0 6 4 4
- - - a / n d k / p l a t f o r m s / a n d r o i d - 9 / a r c h - x 8 6 / i n c l u d e / m a c h i n e / _ t y p e s . h
+ + + b / n d k / p l a t f o r m s / a n d r o i d - 9 / a r c h - x 8 6 / i n c l u d e / m a c h i n e / _ t y p e s . h
@ @ - 5 1 , 7 + 5 1 , 1 1 @ @ t y p e d e f l o n g i n t s s i z e _ t ;
#endif
#ifndef _PTRDIFF_T
#define _PTRDIFF_T
- t y p e d e f l o n g p t r d i f f _ t ;
+ # ifdef __ANDROID__
+ t y p e d e f i n t p t r d i f f _ t ;
+ # else
+ t y p e d e f l o n g p t r d i f f _ t ;
+ # endif
#endif
" )
endif ( )
2012-09-03 01:54:06 +02:00
# setup paths and STL for NDK
2011-11-16 15:32:10 +01:00
if ( BUILD_WITH_ANDROID_NDK )
set ( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" )
set ( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" )
2012-09-03 01:54:06 +02:00
if ( ANDROID_STL STREQUAL "none" )
# do nothing
elseif ( ANDROID_STL STREQUAL "system" )
set ( ANDROID_RTTI OFF )
set ( ANDROID_EXCEPTIONS OFF )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
elseif ( ANDROID_STL STREQUAL "system_re" )
set ( ANDROID_RTTI ON )
set ( ANDROID_EXCEPTIONS ON )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" )
elseif ( ANDROID_STL MATCHES "gabi" )
if ( ANDROID_NDK_RELEASE STRLESS "r7" )
message ( FATAL_ERROR "gabi++ is not awailable in your NDK. You have to upgrade to NDK r7 or newer to use gabi++." )
endif ( )
set ( ANDROID_RTTI ON )
set ( ANDROID_EXCEPTIONS OFF )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/gabi++/include" )
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a" )
elseif ( ANDROID_STL MATCHES "stlport" )
set ( ANDROID_EXCEPTIONS OFF )
if ( ANDROID_NDK_RELEASE STRLESS "r7" )
set ( ANDROID_RTTI OFF )
else ( )
set ( ANDROID_RTTI ON )
endif ( )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" )
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a" )
elseif ( ANDROID_STL MATCHES "gnustl" )
set ( ANDROID_EXCEPTIONS ON )
set ( ANDROID_RTTI ON )
2012-08-03 15:00:18 +02:00
if ( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
2012-09-03 01:54:06 +02:00
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
else ( )
set ( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" )
endif ( )
set ( ANDROID_STL_INCLUDE_DIRS "${__libstl}/include" "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include" )
if ( EXISTS "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" )
set ( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" )
2012-08-03 15:00:18 +02:00
else ( )
2012-09-03 01:54:06 +02:00
set ( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" )
endif ( )
else ( )
message ( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" )
endif ( )
2012-09-03 18:58:14 +02:00
# find libsupc++.a - rtti & exceptions
2012-09-03 01:54:06 +02:00
if ( ANDROID_STL STREQUAL "system_re" OR ANDROID_STL MATCHES "gnustl" )
if ( ANDROID_NDK_RELEASE STRGREATER "r8" ) # r8b
set ( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" )
elseif ( NOT ANDROID_NDK_RELEASE STRLESS "r7" AND ANDROID_NDK_RELEASE STRLESS "r8b" )
set ( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" )
else ( ANDROID_NDK_RELEASE STRLESS "r7" )
if ( ARMEABI_V7A )
if ( ANDROID_FORCE_ARM_BUILD )
set ( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" )
else ( )
set ( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" )
endif ( )
elseif ( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD )
set ( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" )
else ( )
set ( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" )
endif ( )
endif ( )
if ( NOT EXISTS "${__libsupcxx}" )
message ( ERROR "Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken." )
2012-08-03 15:00:18 +02:00
endif ( )
2012-01-18 15:33:39 +01:00
endif ( )
2011-11-16 15:32:10 +01:00
endif ( )
2012-09-03 01:54:06 +02:00
# setup paths and STL for standalone toolchain
if ( BUILD_WITH_STANDALONE_TOOLCHAIN )
set ( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
set ( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" )
2012-09-03 17:13:51 +02:00
if ( NOT ANDROID_STL STREQUAL "none" )
set ( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" )
if ( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" )
list ( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" )
elseif ( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" )
list ( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" )
else ( )
list ( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" )
endif ( )
2012-09-03 18:58:14 +02:00
# always search static GNU STL to get the location of libsupc++.a
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" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" )
elseif ( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" )
elseif ( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" )
elseif ( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" )
endif ( )
if ( __libstl )
set ( __libsupcxx "${__libstl}/libsupc++.a" )
set ( __libstl "${__libstl}/libstdc++.a" )
endif ( )
if ( NOT EXISTS "${__libsupcxx}" )
2012-09-04 12:59:26 +02:00
message ( FATAL_ERROR " The required libstdsupc++.a is missing in your standalone toolchain.
U s u a l l y i t h a p p e n s b e c a u s e o f b u g i n m a k e - s t a n d a l o n e - t o o l c h a i n . s h s c r i p t f r o m N D K r 7 , r 7 b a n d r 7 c .
Y o u n e e d t o e i t h e r u p g r a d e t o n e w e r N D K o r m a n u a l l y c o p y
$ A N D R O I D _ N D K / s o u r c e s / c x x - s t l / g n u - l i b s t d c + + / l i b s / $ { A N D R O I D _ N D K _ A B I _ N A M E } / l i b s u p c + + . a
t o
$ { _ _ l i b s u p c x x }
" )
2012-09-03 18:58:14 +02:00
endif ( )
if ( ANDROID_STL STREQUAL "gnustl_shared" )
if ( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" )
elseif ( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" )
elseif ( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" )
set ( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" )
endif ( )
endif ( )
2012-09-03 17:13:51 +02:00
endif ( )
2012-09-03 01:54:06 +02:00
endif ( )
2012-09-03 18:58:14 +02:00
# case of shared STL linkage
2012-09-03 01:54:06 +02:00
if ( ANDROID_STL MATCHES "shared" AND DEFINED __libstl )
string ( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" )
2012-09-03 18:58:14 +02:00
if ( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" )
get_filename_component ( __libstlname "${__libstl}" NAME )
execute_process ( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess )
if ( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}" )
message ( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" )
endif ( )
unset ( __fileCopyProcess )
unset ( __libstlname )
2012-09-03 01:54:06 +02:00
endif ( )
endif ( )
2012-08-27 16:22:00 +02:00
# ccache support
2012-08-28 18:39:10 +02:00
__INIT_VARIABLE ( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE )
if ( _ndk_ccache )
find_program ( NDK_CCACHE "${_ndk_ccache}" DOC "The path to ccache binary" )
2012-08-27 16:22:00 +02:00
else ( )
2012-08-28 18:39:10 +02:00
unset ( NDK_CCACHE CACHE )
2012-08-27 16:22:00 +02:00
endif ( )
2012-08-28 18:39:10 +02:00
unset ( _ndk_ccache )
2012-08-27 16:22:00 +02:00
2012-09-04 14:33:24 +02:00
# setup the cross-compiler
if ( NOT CMAKE_C_COMPILER )
if ( NDK_CCACHE )
set ( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" )
set ( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" )
set ( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" )
set ( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" )
else ( )
set ( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" )
set ( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" )
endif ( )
set ( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" )
set ( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" )
set ( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
set ( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" )
set ( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" )
set ( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" )
set ( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" )
set ( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" )
2012-08-27 16:22:00 +02:00
endif ( )
2012-09-04 14:33:24 +02:00
set ( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" )
2012-03-12 17:17:42 +01:00
if ( CMAKE_VERSION VERSION_LESS 2.8.5 )
set ( CMAKE_ASM_COMPILER_ARG1 "-c" )
endif ( )
2012-03-04 13:30:03 +01:00
if ( APPLE )
find_program ( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )
if ( NOT CMAKE_INSTALL_NAME_TOOL )
message ( FATAL_ERROR "Could not find install_name_tool, please check your installation." )
endif ( )
mark_as_advanced ( CMAKE_INSTALL_NAME_TOOL )
endif ( )
2012-08-16 23:23:25 +02:00
2012-02-24 10:35:59 +01:00
# Force set compilers because standard identification works badly for us
include ( CMakeForceCompiler )
CMAKE_FORCE_C_COMPILER ( "${CMAKE_C_COMPILER}" GNU )
2012-03-12 17:17:42 +01:00
set ( CMAKE_C_PLATFORM_ID Linux )
2012-02-24 10:35:59 +01:00
set ( CMAKE_C_SIZEOF_DATA_PTR 4 )
2012-03-12 17:17:42 +01:00
set ( CMAKE_C_HAS_ISYSROOT 1 )
set ( CMAKE_C_COMPILER_ABI ELF )
CMAKE_FORCE_CXX_COMPILER ( "${CMAKE_CXX_COMPILER}" GNU )
set ( CMAKE_CXX_PLATFORM_ID Linux )
2012-02-24 10:35:59 +01:00
set ( CMAKE_CXX_SIZEOF_DATA_PTR 4 )
2012-03-12 17:17:42 +01:00
set ( CMAKE_CXX_HAS_ISYSROOT 1 )
set ( CMAKE_CXX_COMPILER_ABI ELF )
2012-08-16 23:23:25 +02:00
# force ASM compiler (required for CMake < 2.8.5)
2012-03-12 17:17:42 +01:00
set ( CMAKE_ASM_COMPILER_ID_RUN TRUE )
set ( CMAKE_ASM_COMPILER_ID GNU )
set ( CMAKE_ASM_COMPILER_WORKS TRUE )
set ( CMAKE_ASM_COMPILER_FORCED TRUE )
set ( CMAKE_COMPILER_IS_GNUASM 1 )
2012-08-29 01:03:36 +02:00
set ( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm )
2012-02-24 10:35:59 +01:00
2012-09-05 18:31:09 +02:00
# flags and definitions
remove_definitions ( -DANDROID )
add_definitions ( -DANDROID )
if ( ANDROID_SYSROOT MATCHES "[ ;\" ] " )
set ( ANDROID_CXX_FLAGS "--sysroot=\" ${ ANDROID_SYSROOT } \"" )
if ( NOT _CMAKE_IN_TRY_COMPILE )
# quotes will break try_compile and compiler identification
message ( WARNING "Your Android system root has non-alphanumeric symbols. It can break compiler features detection and the whole build." )
endif ( )
2011-05-03 10:13:50 +02:00
else ( )
2012-09-05 18:31:09 +02:00
set ( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" )
2011-05-03 10:13:50 +02:00
endif ( )
2012-09-05 18:31:09 +02:00
# NDK flags
2011-11-16 15:32:10 +01:00
if ( ARMEABI OR ARMEABI_V7A )
2012-09-05 18:31:09 +02:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fpic -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__" )
2011-11-16 15:32:10 +01:00
if ( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 )
2012-08-16 23:23:25 +02:00
# It is recommended to use the -mthumb compiler flag to force the generation
# of 16-bit Thumb-1 instructions (the default being 32-bit ARM ones).
2012-09-05 18:31:09 +02:00
set ( ANDROID_CXX_FLAGS_RELEASE "-mthumb" )
set ( ANDROID_CXX_FLAGS_DEBUG "-marm -finline-limit=64" )
2011-11-16 15:32:10 +01:00
else ( )
# always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI
# O3 instead of O2/Os in release mode - like cmake sets for desktop gcc
2012-09-05 18:31:09 +02:00
set ( ANDROID_CXX_FLAGS_RELEASE "-marm" )
set ( ANDROID_CXX_FLAGS_DEBUG "-marm -finline-limit=300" )
2011-11-16 15:32:10 +01:00
endif ( )
elseif ( X86 )
2012-09-05 18:31:09 +02:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" )
set ( ANDROID_CXX_FLAGS_RELEASE "" )
set ( ANDROID_CXX_FLAGS_DEBUG "-finline-limit=300" )
2012-05-03 12:40:29 +02:00
elseif ( MIPS )
2012-09-05 18:31:09 +02:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fpic -funwind-tables -fmessage-length=0 -fno-inline-functions-called-once -frename-registers" )
set ( ANDROID_CXX_FLAGS_RELEASE "-finline-limit=300 -fno-strict-aliasing" )
set ( ANDROID_CXX_FLAGS_DEBUG "-finline-functions -fgcse-after-reload -frerun-cse-after-loop" )
elseif ( )
set ( ANDROID_CXX_FLAGS_RELEASE "" )
set ( ANDROID_CXX_FLAGS_DEBUG "" )
endif ( )
if ( NOT X86 )
set ( ANDROID_CXX_FLAGS "-Wno-psabi ${ANDROID_CXX_FLAGS}" )
2011-05-03 10:13:50 +02:00
endif ( )
2012-09-05 18:31:09 +02:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) # good/necessary when porting desktop libraries
set ( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -fomit-frame-pointer" )
set ( ANDROID_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer" )
2011-05-03 10:13:50 +02:00
2012-08-16 23:23:25 +02:00
# ABI-specific flags
2011-05-03 10:13:50 +02:00
if ( ARMEABI_V7A )
2011-11-16 15:32:10 +01:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" )
2011-05-03 10:13:50 +02:00
if ( NEON )
2011-11-16 15:32:10 +01:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" )
2011-05-03 10:13:50 +02:00
elseif ( VFPV3 )
2011-11-16 15:32:10 +01:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" )
else ( )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfp" )
2011-05-03 10:13:50 +02:00
endif ( )
2011-11-16 15:32:10 +01:00
elseif ( ARMEABI_V6 )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" )
elseif ( ARMEABI )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" )
2011-05-03 10:13:50 +02:00
endif ( )
2012-08-16 23:23:25 +02:00
# STL
2012-09-05 18:31:09 +02:00
if ( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" )
if ( ANDROID_STL MATCHES "gnustl" )
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>" )
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>" )
set ( CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
else ( )
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>" )
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>" )
set ( CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
endif ( )
2012-09-07 16:27:47 +02:00
if ( X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" )
# workaround "undefined reference to `__dso_handle'" problem
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \" ${ ANDROID_SYSROOT } /usr/lib/crtbegin_so.o\ "" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \" ${ ANDROID_SYSROOT } /usr/lib/crtbegin_so.o\ "" )
endif ( )
2012-09-03 01:54:06 +02:00
if ( EXISTS "${__libstl}" )
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \" ${ __libstl } \"" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \" ${ __libstl } \"" )
set ( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \" ${ __libstl } \"" )
2012-01-18 15:33:39 +01:00
endif ( )
2012-09-03 01:54:06 +02:00
if ( EXISTS "${__libsupcxx}" )
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \" ${ __libsupcxx } \"" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \" ${ __libsupcxx } \"" )
set ( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \" ${ __libsupcxx } \"" )
2012-09-03 16:42:13 +02:00
# C objects:
2012-09-03 18:58:14 +02:00
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>" )
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>" )
set ( CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" )
2012-09-05 18:31:09 +02:00
set ( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} \" ${ __libsupcxx } \"" )
set ( CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE} \" ${ __libsupcxx } \"" )
set ( CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} \" ${ __libsupcxx } \"" )
2012-01-18 15:33:39 +01:00
endif ( )
2012-10-11 14:10:01 +02:00
if ( ANDROID_STL MATCHES "gnustl" )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} -lm" )
set ( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} -lm" )
set ( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -lm" )
endif ( )
2012-09-03 01:54:06 +02:00
endif ( )
2011-11-16 15:32:10 +01:00
2012-09-05 18:31:09 +02:00
# variables controlling optional build flags
if ( ANDROID_NDK_RELEASE STRLESS "r7" )
# libGLESv2.so in NDK's prior to r7 refers to missing external symbols.
# So this flag option is required for all projects using OpenGL from native.
__INIT_VARIABLE ( ANDROID_SO_UNDEFINED VALUES ON )
else ( )
__INIT_VARIABLE ( ANDROID_SO_UNDEFINED VALUES OFF )
endif ( )
__INIT_VARIABLE ( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON )
__INIT_VARIABLE ( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON )
__INIT_VARIABLE ( ANDROID_GOLD_LINKER VALUES ON )
__INIT_VARIABLE ( ANDROID_NOEXECSTACK VALUES ON )
__INIT_VARIABLE ( ANDROID_RELRO VALUES ON )
set ( ANDROID_NO_UNDEFINED ${ ANDROID_NO_UNDEFINED } CACHE BOOL "Show all undefined symbols as linker errors" )
set ( ANDROID_SO_UNDEFINED ${ ANDROID_SO_UNDEFINED } CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
set ( ANDROID_FUNCTION_LEVEL_LINKING ${ ANDROID_FUNCTION_LEVEL_LINKING } CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
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)" )
set ( ANDROID_NOEXECSTACK ${ ANDROID_NOEXECSTACK } CACHE BOOL "Allows or disallows undefined symbols in shared libraries" )
set ( ANDROID_RELRO ${ ANDROID_RELRO } CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" )
mark_as_advanced ( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO )
2012-09-03 01:54:06 +02:00
# linker flags
set ( ANDROID_LINKER_FLAGS "" )
2011-11-16 15:32:10 +01:00
2012-09-05 18:31:09 +02:00
if ( ARMEABI_V7A )
# this is *required* to use the following linker flags that routes around
# a CPU bug in some Cortex-A8 implementations:
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" )
2012-01-20 15:35:57 +01:00
endif ( )
2012-09-05 18:31:09 +02:00
if ( ANDROID_NO_UNDEFINED )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" )
2012-01-20 15:35:57 +01:00
endif ( )
2012-04-30 16:33:52 +02:00
2012-01-20 15:35:57 +01:00
if ( ANDROID_SO_UNDEFINED )
2012-04-30 16:33:52 +02:00
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" )
endif ( )
if ( ANDROID_FUNCTION_LEVEL_LINKING )
2012-09-05 18:31:09 +02:00
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" )
2011-11-16 15:32:10 +01:00
endif ( )
2011-05-03 10:13:50 +02:00
2012-09-07 16:27:47 +02:00
if ( ANDROID_GOLD_LINKER AND CMAKE_HOST_UNIX AND ( ARMEABI OR ARMEABI_V7A OR X86 ) AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" )
elseif ( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" AND NOT _CMAKE_IN_TRY_COMPILE )
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
O n L i n u x a n d O S X h o s t p l a t f o r m y o u c a n w o r k a r o u n d t h i s p r o b l e m u s i n g g o l d linker ( default ) .
R e r u n c m a k e w i t h - D A N D R O I D _ G O L D _ L I N K E R = O N o p t i o n .
" )
2012-08-27 17:45:24 +02:00
endif ( )
2012-09-05 18:31:09 +02:00
if ( ANDROID_NOEXECSTACK )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" )
endif ( )
if ( ANDROID_RELRO )
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" )
endif ( )
2012-08-16 23:23:25 +02:00
# cache flags
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" )
set ( CMAKE_C_FLAGS "" CACHE STRING "c flags" )
2012-09-13 18:25:53 +02:00
set ( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" )
set ( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" )
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" )
set ( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" )
set ( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags" )
set ( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags" )
set ( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" )
2011-11-16 15:32:10 +01:00
2012-08-16 23:23:25 +02:00
# finish flags
2012-04-30 16:33:52 +02:00
set ( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" )
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}" )
set ( CMAKE_C_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}" )
set ( CMAKE_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}" )
set ( CMAKE_C_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}" )
set ( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" )
set ( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" )
2012-09-01 23:11:41 +02:00
if ( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" )
2012-09-05 18:31:09 +02:00
set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" )
set ( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" )
2012-05-03 12:40:29 +02:00
endif ( )
2011-05-03 10:13:50 +02:00
2012-09-03 01:54:06 +02:00
# configure rtti
if ( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES )
if ( ANDROID_RTTI )
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_FLAGS "-frtti ${CMAKE_CXX_FLAGS}" )
2012-09-03 01:54:06 +02:00
else ( )
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}" )
2012-09-03 01:54:06 +02:00
endif ( )
endif ( )
# configure exceptios
if ( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES )
if ( ANDROID_EXCEPTIONS )
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}" )
2012-09-03 01:54:06 +02:00
else ( )
2012-09-05 18:31:09 +02:00
set ( CMAKE_CXX_FLAGS "-fno-exceptions ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_C_FLAGS "-fno-exceptions ${CMAKE_C_FLAGS}" )
2012-09-03 01:54:06 +02:00
endif ( )
endif ( )
2012-09-03 18:58:14 +02:00
# global includes and link directories
2012-09-05 14:25:14 +02:00
include_directories ( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ ANDROID_STL_INCLUDE_DIRS } )
2012-09-03 18:58:14 +02:00
link_directories ( "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" )
2012-08-16 23:23:25 +02:00
# set these global flags for cmake client scripts to change behavior
2011-05-03 10:13:50 +02:00
set ( ANDROID True )
set ( BUILD_ANDROID True )
2012-06-14 16:38:04 +02:00
# where is the target environment
2011-11-16 15:32:10 +01:00
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" )
# only search for libraries and includes in the ndk toolchain
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
2012-03-04 13:30:03 +01:00
2012-08-16 23:23:25 +02:00
# macro to find packages on the host OS
2011-11-16 15:32:10 +01:00
macro ( find_host_package )
2011-06-22 12:38:57 +02:00
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
2011-07-02 17:12:07 +02:00
if ( CMAKE_HOST_WIN32 )
SET ( WIN32 1 )
SET ( UNIX )
elseif ( CMAKE_HOST_APPLE )
SET ( APPLE 1 )
SET ( UNIX )
endif ( )
find_package ( ${ ARGN } )
SET ( WIN32 )
SET ( APPLE )
2011-11-16 15:32:10 +01:00
SET ( UNIX 1 )
2011-05-03 10:13:50 +02:00
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
2011-06-22 12:38:57 +02:00
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
2011-05-03 10:13:50 +02:00
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
2011-06-22 12:38:57 +02:00
endmacro ( )
2012-03-04 13:30:03 +01:00
2012-08-16 23:23:25 +02:00
# macro to find programs on the host OS
2011-11-16 15:32:10 +01:00
macro ( find_host_program )
2011-06-22 12:38:57 +02:00
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
2011-07-02 17:12:07 +02:00
if ( CMAKE_HOST_WIN32 )
SET ( WIN32 1 )
SET ( UNIX )
elseif ( CMAKE_HOST_APPLE )
SET ( APPLE 1 )
SET ( UNIX )
endif ( )
find_program ( ${ ARGN } )
SET ( WIN32 )
SET ( APPLE )
2011-11-16 15:32:10 +01:00
SET ( UNIX 1 )
2011-06-22 12:38:57 +02:00
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
endmacro ( )
2011-07-12 17:59:31 +02:00
2012-03-04 13:30:03 +01:00
2012-02-03 12:26:49 +01:00
macro ( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR )
if ( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" )
set ( ${ VAR } "armeabi" )
elseif ( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" )
2012-09-05 18:31:09 +02:00
set ( ${ VAR } "armeabi-v7a" )
2012-02-03 12:26:49 +01:00
elseif ( "${TOOLCHAIN_FLAG}" STREQUAL "X86" )
2012-09-05 18:31:09 +02:00
set ( ${ VAR } "x86" )
elseif ( "${TOOLCHAIN_FLAG}" STREQUAL "MIPS" )
set ( ${ VAR } "mips" )
2012-02-03 12:26:49 +01:00
else ( )
2012-09-05 18:31:09 +02:00
set ( ${ VAR } "unknown" )
2012-02-03 12:26:49 +01:00
endif ( )
endmacro ( )
2012-03-04 13:30:03 +01:00
2012-03-04 21:36:50 +01:00
# export toolchain settings for the try_compile() command
if ( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" )
set ( __toolchain_config "" )
2012-09-05 18:31:09 +02:00
foreach ( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN ANDROID_SET_OBSOLETE_VARIABLES
A N D R O I D _ N D K
A N D R O I D _ S T A N D A L O N E _ T O O L C H A I N
A N D R O I D _ T O O L C H A I N _ N A M E
A N D R O I D _ A B I
A N D R O I D _ N A T I V E _ A P I _ L E V E L
A N D R O I D _ S T L
A N D R O I D _ S T L _ F O R C E _ F E A T U R E S
A N D R O I D _ F O R C E _ A R M _ B U I L D
A N D R O I D _ N O _ U N D E F I N E D
A N D R O I D _ S O _ U N D E F I N E D
A N D R O I D _ F U N C T I O N _ L E V E L _ L I N K I N G
A N D R O I D _ G O L D _ L I N K E R
A N D R O I D _ N O E X E C S T A C K
A N D R O I D _ R E L R O
)
2012-03-04 21:36:50 +01:00
if ( DEFINED ${ __var } )
2012-08-16 23:23:25 +02:00
if ( "${__var}" MATCHES " " )
set ( __toolchain_config "${__toolchain_config}set( ${__var} \" ${ ${__var } }\ " CACHE INTERNAL \" \" ) \ n " )
else ( )
set ( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \" \" ) \ n " )
endif ( )
2012-03-04 21:36:50 +01:00
endif ( )
endforeach ( )
2012-08-06 12:48:23 +02:00
file ( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" )
2012-03-04 21:36:50 +01:00
unset ( __toolchain_config )
endif ( )
# set some obsolete variables for backward compatibility
2011-11-16 15:32:10 +01:00
set ( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" )
2012-01-20 15:35:57 +01:00
mark_as_advanced ( ANDROID_SET_OBSOLETE_VARIABLES )
2011-11-16 15:32:10 +01:00
if ( ANDROID_SET_OBSOLETE_VARIABLES )
set ( ANDROID_API_LEVEL ${ ANDROID_NATIVE_API_LEVEL } )
set ( ARM_TARGET "${ANDROID_ABI}" )
set ( ARMEABI_NDK_NAME "${ANDROID_NDK_ABI_NAME}" )
endif ( )
2012-03-12 17:17:42 +01:00
2011-11-19 19:02:00 +01:00
# Variables controlling behavior or set by cmake toolchain:
2012-05-03 12:40:29 +02:00
# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips"
2011-11-16 15:32:10 +01:00
# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version)
# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF
2012-01-20 15:35:57 +01:00
# ANDROID_FORBID_SYGWIN : ON/OFF
2012-04-30 16:33:52 +02:00
# ANDROID_NO_UNDEFINED : ON/OFF
# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version)
# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF
2012-09-05 18:31:09 +02:00
# ANDROID_GOLD_LINKER : ON/OFF
# ANDROID_NOEXECSTACK : ON/OFF
# ANDROID_RELRO : ON/OFF
2012-04-30 16:33:52 +02:00
# Variables that takes effect only at first run:
# ANDROID_FORCE_ARM_BUILD : ON/OFF
2012-09-03 01:54:06 +02:00
# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none
# ANDROID_STL_FORCE_FEATURES : ON/OFF
2012-04-30 16:33:52 +02:00
# LIBRARY_OUTPUT_PATH_ROOT : <any valid path>
2012-08-27 17:45:24 +02:00
# NDK_CCACHE : <path to your ccache executable>
2011-11-16 15:32:10 +01:00
# Can be set only at the first run:
# ANDROID_NDK
# ANDROID_STANDALONE_TOOLCHAIN
2012-08-06 12:48:23 +02:00
# ANDROID_TOOLCHAIN_NAME : "arm-linux-androideabi-4.4.3" or "arm-linux-androideabi-4.6" or "mipsel-linux-android-4.4.3" or "mipsel-linux-android-4.6" or "x86-4.4.3" or "x86-4.6"
2011-11-16 15:32:10 +01:00
# Obsolete:
# ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL
# ARM_TARGET : superseded by ANDROID_ABI
# ARM_TARGETS : superseded by ANDROID_ABI (can be set only)
# ANDROID_NDK_TOOLCHAIN_ROOT : superseded by ANDROID_STANDALONE_TOOLCHAIN (can be set only)
2012-09-03 01:54:06 +02:00
# ANDROID_USE_STLPORT : superseded by ANDROID_STL=stlport_static
2011-11-16 15:32:10 +01:00
# ANDROID_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed)
#
# Primary read-only variables:
# ANDROID : always TRUE
# ARMEABI : TRUE for arm v6 and older devices
# ARMEABI_V6 : TRUE for arm v6
# ARMEABI_V7A : TRUE for arm v7a
# NEON : TRUE if NEON unit is enabled
2011-11-19 19:02:00 +01:00
# VFPV3 : TRUE if VFP version 3 is enabled
2011-11-16 15:32:10 +01:00
# X86 : TRUE if configured for x86
2012-09-01 23:02:50 +02:00
# MIPS : TRUE if configured for mips
2011-11-16 15:32:10 +01:00
# BUILD_ANDROID : always TRUE
# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used
# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used
# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform
2012-09-01 23:02:50 +02:00
# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86" or "mips" depending on ANDROID_ABI
2012-09-01 23:11:41 +02:00
# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b; set only for NDK
2012-05-03 12:40:29 +02:00
# ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI
2012-04-30 16:33:52 +02:00
# ANDROID_SYSROOT : path to the compiler sysroot
2012-09-01 23:02:50 +02:00
# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform
2011-11-16 15:32:10 +01:00
# Obsolete:
# ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME
#
# Secondary (less stable) read-only variables:
# ANDROID_COMPILER_VERSION : GCC version used
# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform
# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI
# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux"
# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK)
# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK
2012-09-03 01:54:06 +02:00
# ANDROID_STL_INCLUDE_DIRS : stl include paths
# ANDROID_RTTI : if rtti is enabled by the runtime
# ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime
2011-11-16 15:32:10 +01:00
#
# Defaults:
# ANDROID_DEFAULT_NDK_API_LEVEL
# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH}
2012-02-20 15:50:23 +01:00
# ANDROID_NDK_SEARCH_PATHS
2011-11-16 15:32:10 +01:00
# ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH
# ANDROID_SUPPORTED_ABIS_${ARCH}
# ANDROID_SUPPORTED_NDK_VERSIONS