@ -1,5 +1,5 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# A n d r o i d C M a k e t o o l c h a i n f i l e , f o r u s e w i t h t h e A n d r o i d N D K r 5 - r 7
# A n d r o i d C M a k e t o o l c h a i n f i l e , f o r u s e w i t h t h e A n d r o i d N D K r 5 - r 8
# R e q u i r e s c m a k e 2 . 6 . 3 o r newer ( 2.8.3 or newer is recommended ) .
# S e e h o m e p a g e : h t t p : / / c o d e . g o o g l e . c o m / p / a n d r o i d - c m a k e /
#
@ -20,7 +20,7 @@
#
# U s a g e W i n d o w s :
# Y o u n e e d n a t i v e p o r t o f m a k e t o b u i l d y o u r p r o j e c t .
# A n d r o i d N D K r 7 a l r e a d y h a s m a k e . e x e o n b o a r d .
# A n d r o i d N D K r7 ( or newer ) a l r e a d y h a s m a k e . e x e o n b o a r d .
# F o r o l d e r N D K y o u h a v e t o i n s t a l l i t s e p a r a t e l y .
# F o r e x a m p l e , t h i s o n e : h t t p : / / g n u w i n 3 2 . s o u r c e f o r g e . n e t / p a c k a g e s / m a k e . h t m
#
@ -177,6 +177,9 @@
# [ + ] u p d a t e d f o r N D K r 7 c
# [ ~ ] f i x e d m o s t o f p r o b l e m s w i t h c o m p i l e r / l i n k e r f l a g s a n d c a c h i n g
# [ + ] a d d e d o p t i o n 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
# - m o d i f i e d M a y 2 0 1 2
# [ + ] u p d a t e d f o r N D K r 8
# [ + ] a d d e d m i p s a r c h i t e c t u r e s u p p o r t
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cmake_minimum_required ( VERSION 2.6.3 )
@ -186,7 +189,8 @@ if( DEFINED CMAKE_CROSSCOMPILING )
return ( )
endif ( )
if ( PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" )
get_property ( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
if ( _CMAKE_IN_TRY_COMPILE )
include ( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL )
endif ( )
@ -195,7 +199,7 @@ set( CMAKE_SYSTEM_NAME Linux )
# t h i s o n e n o t s o m u c h
set ( CMAKE_SYSTEM_VERSION 1 )
set ( ANDROID_SUPPORTED_NDK_VERSIONS ${ ANDROID_EXTRA_NDK_VERSIONS } -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" )
set ( ANDROID_SUPPORTED_NDK_VERSIONS ${ ANDROID_EXTRA_NDK_VERSIONS } -r8 -r 7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" )
if ( NOT DEFINED ANDROID_NDK_SEARCH_PATHS )
if ( CMAKE_HOST_WIN32 )
file ( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS )
@ -211,9 +215,11 @@ endif()
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" )
set ( ANDROID_SUPPORTED_ABIS_mipsel "mips" )
set ( ANDROID_DEFAULT_NDK_API_LEVEL 8 )
set ( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )
set ( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )
macro ( __LIST_FILTER listvar regex )
@ -432,6 +438,7 @@ endif()
# g e t a l l t h e d e t a i l s a b o u t s t a n d a l o n e t o o l c h a i n
if ( BUILD_WITH_STANDALONE_TOOLCHAIN )
__DETECT_NATIVE_API_LEVEL ( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" )
set ( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ ANDROID_SUPPORTED_NATIVE_API_LEVELS } )
set ( __availableToolchains "standalone" )
__DETECT_TOOLCHAIN_MACHINE_NAME ( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" )
if ( NOT __availableToolchainMachines )
@ -441,6 +448,8 @@ if( BUILD_WITH_STANDALONE_TOOLCHAIN )
set ( __availableToolchainArchs "x86" )
elseif ( __availableToolchainMachines MATCHES arm )
set ( __availableToolchainArchs "arm" )
elseif ( __availableToolchainMachines MATCHES mipsel )
set ( __availableToolchainArchs "mipsel" )
endif ( )
if ( ANDROID_COMPILER_VERSION )
# d o n o t r u n g c c e v e r y t i m e b e c a u s e i t i s r e l a t e v e l y e x p e n c i v e
@ -513,16 +522,25 @@ if( ANDROID_ABI STREQUAL "x86" )
set ( X86 true )
set ( ANDROID_NDK_ABI_NAME "x86" )
set ( ANDROID_ARCH_NAME "x86" )
set ( ANDROID_ARCH_FULLNAME "x86" )
set ( CMAKE_SYSTEM_PROCESSOR "i686" )
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" )
elseif ( ANDROID_ABI STREQUAL "armeabi" )
set ( ARMEABI true )
set ( ANDROID_NDK_ABI_NAME "armeabi" )
set ( ANDROID_ARCH_NAME "arm" )
set ( ANDROID_ARCH_FULLNAME "arm" )
set ( CMAKE_SYSTEM_PROCESSOR "armv5te" )
elseif ( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" )
set ( ARMEABI_V6 true )
set ( ANDROID_NDK_ABI_NAME "armeabi" )
set ( ANDROID_ARCH_NAME "arm" )
set ( ANDROID_ARCH_FULLNAME "arm" )
set ( CMAKE_SYSTEM_PROCESSOR "armv6" )
# n e e d a l w a y s f a l l b a c k t o o l d e r p l a t f o r m
set ( ARMEABI true )
@ -530,17 +548,20 @@ elseif( ANDROID_ABI STREQUAL "armeabi-v7a")
set ( ARMEABI_V7A true )
set ( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
set ( ANDROID_ARCH_NAME "arm" )
set ( ANDROID_ARCH_FULLNAME "arm" )
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" )
set ( ANDROID_ARCH_FULLNAME "arm" )
set ( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
set ( VFPV3 true )
elseif ( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" )
set ( ARMEABI_V7A true )
set ( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
set ( ANDROID_ARCH_NAME "arm" )
set ( ANDROID_ARCH_FULLNAME "arm" )
set ( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
set ( VFPV3 true )
set ( NEON true )
@ -554,10 +575,10 @@ if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMa
file ( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \" ${ CMAKE_SYSTEM_PROCESSOR } \")\n" )
endif ( )
set ( ANDROID_SUPPORTED_ABIS ${ ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME } } CACHE INTERNAL "ANDROID_ABI can be changed only to one of these ABIs. Changing to any other ABI requires to reset cmake cache." )
set ( ANDROID_SUPPORTED_ABIS ${ ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULL NAME } } CACHE INTERNAL "ANDROID_ABI can be changed only to one of these ABIs. Changing to any other ABI requires to reset cmake cache." )
if ( CMAKE_VERSION VERSION_GREATER "2.8" )
list ( SORT ANDROID_SUPPORTED_ABIS_ ${ ANDROID_ARCH_NAME } )
set_property ( CACHE ANDROID_ABI PROPERTY STRINGS ${ ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME } } )
list ( SORT ANDROID_SUPPORTED_ABIS_ ${ ANDROID_ARCH_FULL NAME } )
set_property ( CACHE ANDROID_ABI PROPERTY STRINGS ${ ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULL NAME } } )
endif ( )
if ( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 )
@ -575,7 +596,7 @@ if( ANDROID_TOOLCHAIN_NAME )
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 )
if ( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME )
if ( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULL NAME )
message ( SEND_ERROR "Previously selected toolchain \" ${ ANDROID_TOOLCHAIN_NAME } \" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform. " )
endif ( )
else ( )
@ -586,7 +607,7 @@ else()
math ( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" )
foreach ( __idx RANGE ${ __availableToolchainsCount } )
list ( GET __availableToolchainArchs ${ __idx } __toolchainArch )
if ( __toolchainArch STREQUAL ANDROID_ARCH_NAME )
if ( __toolchainArch STREQUAL ANDROID_ARCH_FULL NAME )
list ( GET __availableToolchainCompilerVersions ${ __idx } __toolchainVersion )
if ( __toolchainVersion VERSION_GREATER __toolchainMaxVersion )
set ( __toolchainMaxVersion "${__toolchainVersion}" )
@ -614,7 +635,7 @@ unset( __availableToolchainArchs )
unset ( __availableToolchainCompilerVersions )
# c h o o s e n a t i v e A P I l e v e l
__INIT_VARIABLE ( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_ ${ ANDROID_ARCH_NAME } ANDROID_DEFAULT_NDK_API_LEVEL )
__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 )
string ( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" )
# v a l i d a t e
list ( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx )
@ -747,13 +768,6 @@ if( ARMEABI OR ARMEABI_V7A )
# N D K a l s o d e f i n e s - f f u n c t i o n - s e c t i o n s - f u n w i n d - t a b l e s b u t t h e y r e s u l t i n w o r s e O p e n C V p e r f o r m a n c e
set ( CMAKE_CXX_FLAGS "-fPIC -Wno-psabi" )
set ( CMAKE_C_FLAGS "-fPIC -Wno-psabi" )
if ( ANDROID_USE_STLPORT )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions" )
else ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fexceptions" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions" )
endif ( )
remove_definitions ( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ )
add_definitions ( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ )
# e x t r a a r m - s p e c i f i c f l a g s
@ -761,18 +775,23 @@ if( ARMEABI OR ARMEABI_V7A )
elseif ( X86 )
set ( CMAKE_CXX_FLAGS "-funwind-tables" )
set ( CMAKE_C_FLAGS "-funwind-tables" )
if ( ANDROID_USE_STLPORT )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions" )
else ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fexceptions" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions" )
endif ( )
elseif ( MIPS )
set ( CMAKE_CXX_FLAGS "-fpic -Wno-psabi -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" )
set ( CMAKE_CXX_FLAGS "-fpic -Wno-psabi -fno-strict-aliasing -finline-functions -ffunction-sections -funwind-tables -fmessage-length=0 -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" )
set ( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" )
else ( )
set ( CMAKE_CXX_FLAGS "" )
set ( CMAKE_C_FLAGS "" )
endif ( )
if ( ANDROID_USE_STLPORT )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions" )
else ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fexceptions" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions" )
endif ( )
# r e l e a s e a n d d e b u g f l a g s
if ( ARMEABI OR ARMEABI_V7A )
if ( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 )
@ -796,6 +815,11 @@ elseif( X86 )
set ( CMAKE_C_FLAGS_RELEASE "-O3 -fstrict-aliasing" )
set ( CMAKE_CXX_FLAGS_DEBUG "-O0 -finline-limit=300" )
set ( CMAKE_C_FLAGS_DEBUG "-O0 -finline-limit=300" )
elseif ( MIPS )
set ( CMAKE_CXX_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" )
set ( CMAKE_C_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" )
set ( CMAKE_CXX_FLAGS_DEBUG "-O0 -g" )
set ( CMAKE_C_FLAGS_DEBUG "-O0 -g" )
endif ( )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" )
@ -922,9 +946,15 @@ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Extra Androi
set ( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Extra Android linker flags" )
set ( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
set ( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" )
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}" )
if ( MIPS AND BUILD_WITH_ANDROID_NDK )
set ( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" )
set ( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.x ${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" )
else ( )
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}" )
endif ( )
# s e t t h e s e g l o b a l f l a g s f o r c m a k e c l i e n t s c r i p t s t o c h a n g e b e h a v i o r
set ( ANDROID True )
@ -1020,7 +1050,7 @@ endif()
# V a r i a b l e s c o n t r o l l i n g b e h a v i o r o r s e t b y c m a k e t o o l c h a i n :
# A N D R O I D _ A B I : " a r m e a b i - v 7 a " ( d e f a u l t ) , " a r m e a b i " , " a r m e a b i - v 7 a w i t h N E O N " , " a r m e a b i - v 7 a w i t h V F P V 3 " , " a r m e a b i - v 6 w i t h V F P " , " x 8 6 "
# A N D R O I D _ A B I : " a r m e a b i - v 7 a " ( d e f a u l t ) , " a r m e a b i " , " a r m e a b i - v 7 a w i t h N E O N " , " a r m e a b i - v 7 a w i t h V F P V 3 " , " a r m e a b i - v 6 w i t h V F P " , " x 8 6 " , " m i p s "
# A N D R O I D _ N A T I V E _ A P I _ L E V E L : 3 , 4 , 5 , 8 , 9 , 14 ( depends on NDK version )
# A N D R O I D _ S E T _ O B S O L E T E _ V A R I A B L E S : O N / O F F
# A N D R O I D _ U S E _ S T L P O R T : O F F / O N - E X P E R I M E N T A L ! ! !
@ -1054,7 +1084,7 @@ endif()
# B U I L D _ W I T H _ S T A N D A L O N E _ T O O L C H A I N : T R U E i f s t a n d a l o n e t o o l c h a i n i s u s e d
# A N D R O I D _ N D K _ H O S T _ S Y S T E M _ N A M E : " w i n d o w s " , " l i n u x - x 8 6 " o r " d a r w i n - x 8 6 " d e p e n d i n g o n h o s t p l a t f o r m
# A N D R O I D _ N D K _ A B I _ N A M E : " a r m e a b i " , " a r m e a b i - v 7 a " o r " x 8 6 " d e p e n d i n g o n A N D R O I D _ A B I
# A N D R O I D _ A R C H _ N A M E : " a r m " o r " x 8 6 " d e p e n d i n g o n A N D R O I D _ A B I
# A N D R O I D _ A R C H _ N A M E : " a r m " o r " x 8 6 " o r " m i p s " d e p e n d i n g o n A N D R O I D _ A B I
# T O O L _ O S _ S U F F I X : " " o r " . e x e " d e p e n d i n g o n h o s t p l a t f o r m
# A N D R O I D _ S Y S R O O T : p a t h t o t h e c o m p i l e r s y s r o o t
# A N D R O I D _ S Y S T E M _ I N C L U D E _ D I R S