···11+# Copyright (C) PlayControl Software, LLC.
22+# Eric Wing <ewing . public @ playcontrol.net>
33+#
44+# This is a "Prebuilt" Android Makefile provided as an example/template (or direct use if no tweaking is required).
55+# The idea is that you have already built the lua .so and .a libraries using CMake.
66+# Now you want to use those prebuilt libraries in your own project.
77+# Android support prebuilt exteneral modules through its ndk-build system, but you need to have all the pieces setup and in the right place. This is one of those pieces.
88+#
99+# This file assumes you built all your lua libs and put things into a directory structure like so:
1010+#
1111+# Android.mk (this file)
1212+# libs/armeabi/liblua.a
1313+# libs/armeabi/liblua.so
1414+# libs/armeabi-v7a/liblua.a
1515+# libs/armeabi-v7a/liblua.so
1616+# libs/x86/liblua.a
1717+# libs/x86/liblua.so
1818+#
1919+# include/lua/lua.h
2020+# ... (the other header files here)
2121+#
2222+# Note that this file is copied into the directory above libs and include.
2323+# Below is the code you need to make this Makefile export the correct headers, libraries, and flags for both dynamic and static versions.
2424+2525+# LOCAL_PATH needs to be before include
2626+LOCAL_PATH := $(call my-dir)
2727+2828+# For the dynamic library
2929+include $(CLEAR_VARS)
3030+# This is the name of module the caller will use in LOCAL_SHARED_LIBRARIES
3131+LOCAL_MODULE := SDL_gpu_shared
3232+LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libSDL2_gpu.so
3333+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
3434+# Use LOCAL_EXPORT_CFLAGS to automatically export the correct flags (as necessary) to the calling module so the caller doesn't need to know the details.
3535+# LOCAL_EXPORT_CFLAGS :=
3636+# The .so is already linked so we don't really need to export this.
3737+#LOCAL_EXPORT_LDLIBS := -lm
3838+include $(PREBUILT_SHARED_LIBRARY)
3939+4040+4141+## For the static library
4242+#include $(CLEAR_VARS)
4343+## This is the name of module the caller will use in LOCAL_STATIC_LIBRARIES
4444+#LOCAL_MODULE := ALmixerLuaBindings_static
4545+#LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libALmixerLuaBindings.a
4646+# Use LOCAL_EXPORT_CFLAGS to automatically export the correct flags (as necessary) to the calling module so the caller doesn't need to know the details.
4747+#LOCAL_EXPORT_CFLAGS :=
4848+## Since the .a isn't linked, it's link dependencies must be passed on to the calling project.
4949+# LOCAL_EXPORT_LDLIBS :=
5050+#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/lua
5151+#include $(PREBUILT_STATIC_LIBRARY)
5252+5353+5454+5555+# Two other pieces are needed to make this work which fall outside the scope of this file.
5656+# First, you must have a directory convention for the calling makefile.
5757+# So let's say we put all the above in a directory called lua. The layout looks like this:
5858+# lua/
5959+# Android.mk (this file)
6060+# libs/armeabi/liblua.a
6161+# libs/armeabi/liblua.so
6262+# libs/armeabi-v7a/liblua.a
6363+# libs/armeabi-v7a/liblua.so
6464+# libs/x86/liblua.a
6565+# libs/x86/liblua.so
6666+#
6767+# include/lua.h
6868+# ... (the other header files here)
6969+7070+# So the calling makefile looks something like:
7171+# LOCAL_PATH := $(call my-dir)
7272+# include $(CLEAR_VARS)
7373+# LOCAL_MODULE := hello-jni
7474+# LOCAL_SRC_FILES := hello-jni.c
7575+# These are the LOCAL_MODULE names as defined in the prebuilt module's Android.mk. Define either shared or static, but not both. If you use dynamic, don't forget you need to do a System.loadLibrary("lua") in your Java code.
7676+# LOCAL_SHARED_LIBRARIES := lua_shared
7777+# #LOCAL_STATIC_LIBRARIES := lua_static
7878+# include $(BUILD_SHARED_LIBRARY)
7979+# Android build system will look for folder `lua` in all import paths:
8080+# $(call import-module,lua)
8181+# ------ end -----
8282+8383+# Second, you need to set the environmental variable NDK_MODULE_PATH to list the directory containing lua.
8484+# So if lua is in /Library/Frameworks/Android/PrebuiltModules
8585+# export NDK_MODULE_PATH=/Library/Frameworks/Android/PrebuiltModules
8686+# Note that NDK_MODULE_PATH may contain multiple directories like the PATH environmental variable.
8787+
+80
AndroidCMake/InitialCache_Android.cmake
···11+22+# Required BLURRR_SDK_ROOT to be passed in or env
33+IF(NOT BLURRR_ROOT)
44+ IF(NOT DEFINED ENV{BLURRR_ROOT})
55+ MESSAGE(AUTHOR_WARNING "BLURRR_SDK_ROOT not passed in")
66+ ELSE()
77+ SET(BLURRR_ROOT $ENV{BLURRR_ROOT})
88+ ENDIF()
99+ENDIF()
1010+1111+# Probably want to use this form
1212+IF(NOT BLURRR_SDK_PATH)
1313+ IF(DEFINED ENV{BLURRR_SDK_PATH})
1414+ SET(BLURRR_SDK_PATH $ENV{BLURRR_SDK_PATH})
1515+ ENDIF()
1616+MESSAGE("ENV BLURRR_SDK_PATH $ENV{BLURRR_SDK_PATH}")
1717+1818+ENDIF()
1919+MESSAGE("BLURRR_SDK_PATH ${BLURRR_SDK_PATH}")
2020+2121+# CMake doesn't know how to handle multiple architectures.
2222+# So we must manually fake it by running CMake multiple times, each time specifying the architecture.
2323+IF(NOT ANDROID_ABI)
2424+ MESSAGE(FATAL_ERROR "ANDROID_ABI not passed in")
2525+ENDIF()
2626+IF(NOT BLURRR_CMAKE_ANDROID_REAL_BINARY_DIR)
2727+ MESSAGE(FATAL_ERROR "BLURRR_CMAKE_ANDROID_REAL_BINARY_DIR not passed in")
2828+ENDIF()
2929+3030+3131+# Allow for the possibility that the user defined CMAKE_LIBRARY_PATH, etc. and the normal CMake stuff will work without the initial cache.
3232+IF(BLURRR_ROOT OR BLURRR_SDK_PATH)
3333+ IF(NOT BLURRR_SDK_PATH)
3434+ # Convenience variables
3535+ SET(BLURRR_SDK_PATH "${BLURRR_ROOT}/Libraries/Android/SDK/C" CACHE INTERNAL "Blurrr SDK path. (Read-only)")
3636+ ENDIF()
3737+3838+ # Note: The layout is a little different than the other platforms.
3939+ # This is because I'm trying to conform to the official NDK_MODULE_PATH external module system.
4040+ # The Android system has a hard limitation in that it requires environmental variables
4141+ # which Android Studio refuses to support,
4242+ # and the other hard limitation in that it can't handle any modules in paths with spaces.
4343+ # This is one reason I'm not directly using it.
4444+ # But for advanced use cases that need to link to my modules that don't use this
4545+ # build system, it is really handy to comply with this official mechanism.
4646+4747+ # Because we are generating CMake multiple times in their own little subdirectories,
4848+ # we need an anchor back to the real build directory root so the build system can interact with
4949+ # shared/common stuff like resources.
5050+ SET(BLURRR_CMAKE_ANDROID_REAL_BINARY_DIR "${BLURRR_CMAKE_ANDROID_REAL_BINARY_DIR}" CACHE INTERNAL "Real CMake binary directory. (Read-only)")
5151+5252+5353+ # SET(BLURRR_INCLUDE_PATH "${BLURRR_SDK_PATH}/include" CACHE STRING "Blurrr SDK include path. (Read-only)")
5454+ # SET(BLURRR_LIBRARY_PATH "${BLURRR_SDK_PATH}/libs/${BLURRR_ANDROID_ARCH}" CACHE STRING "Blurrr SDK library path. (Read-only)")
5555+5656+# SET(ALMIXER_INCLUDE_DIR "${BLURRR_SDK_PATH}/ALmixer/include" CACHE STRING "ALmixer include directory")
5757+# SET(ALMIXER_LIBRARY "${BLURRR_SDK_PATH}/ALmixer/libs/${ANDROID_ABI}/libALmixer.so" CACHE STRING "ALmixer library")
5858+5959+# SET(OPENAL_INCLUDE_DIR "${BLURRR_SDK_PATH}/openal-soft/jni/OpenAL/include/AL" CACHE STRING "OpenAL include directory")
6060+# SET(OPENAL_LIBRARY "${BLURRR_SDK_PATH}/openal-soft/libs/${ANDROID_ABI}/libopenal.so" CACHE STRING "OpenAL library")
6161+6262+# SET(CHIPMUNK_INCLUDE_DIR "${BLURRR_SDK_PATH}/chipmunk/include/chipmunk" CACHE STRING "Chipmunk include directory")
6363+# SET(CHIPMUNK_LIBRARY "${BLURRR_SDK_PATH}/chipmunk/libs/${ANDROID_ABI}/libchipmunk.so" CACHE STRING "Chipmunk library")
6464+6565+ SET(SDL_INCLUDE_DIR "${BLURRR_SDK_PATH}/SDL2/include" CACHE STRING "SDL include directory")
6666+ SET(SDL_LIBRARY "${BLURRR_SDK_PATH}/SDL2/libs/${ANDROID_ABI}/libSDL2.so" CACHE STRING "SDL library")
6767+ SET(SDL_LIBRARY_MAIN "${BLURRR_SDK_PATH}/SDL2/libs/${ANDROID_ABI}/libSDL2main.so" CACHE STRING "SDLmain library")
6868+6969+ SET(SDL2_INCLUDE_DIR "${BLURRR_SDK_PATH}/SDL2/include" CACHE STRING "SDL include directory")
7070+ SET(SDL2_LIBRARY "${BLURRR_SDK_PATH}/SDL2/libs/${ANDROID_ABI}/libSDL2.so" CACHE STRING "SDL library")
7171+ SET(SDL2_LIBRARY_MAIN "${BLURRR_SDK_PATH}/SDL2/libs/${ANDROID_ABI}/libSDL2main.so" CACHE STRING "SDLmain library")
7272+7373+7474+7575+# SET(LUA_INCLUDE_DIR "${BLURRR_SDK_PATH}/lua/include" CACHE STRING "Lua include directory")
7676+# SET(LUA_LIBRARY "${BLURRR_SDK_PATH}/lua/libs/${ANDROID_ABI}/liblua.so" CACHE STRING "Lua library")
7777+7878+7979+8080+ENDIF(BLURRR_ROOT OR BLURRR_SDK_PATH)
···11+# ------------------------------------------------------------------------------
22+# Android CMake toolchain file, for use with the Android NDK r5-r8
33+# Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended).
44+# See home page: http://code.google.com/p/android-cmake/
55+#
66+# The file is mantained by the OpenCV project. And also can be found at
77+# http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake
88+#
99+# Note: There are now two flavors of this toolchain file: 32-bit toolchain and 64-bit toolchain.
1010+#
1111+# Usage Linux:
1212+# $ export ANDROID_NDK_ROOT=/absolute/path/to/the/android-ndk
1313+# $ mkdir build && cd build
1414+# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
1515+# $ make -j8
1616+#
1717+# Usage Linux (using standalone toolchain):
1818+# $ export ANDROID_STANDALONE_TOOLCHAIN=/absolute/path/to/android-toolchain
1919+# $ mkdir build && cd build
2020+# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake ..
2121+# $ make -j8
2222+#
2323+# Usage Windows:
2424+# You need native port of make to build your project.
2525+# Android NDK r7 (or newer) already has make.exe on board.
2626+# For older NDK you have to install it separately.
2727+# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm
2828+#
2929+# $ SET ANDROID_NDK_ROOT=C:\absolute\path\to\the\android-ndk
3030+# $ mkdir build && cd build
3131+# $ cmake.exe -G"MinGW Makefiles"
3232+# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake
3333+# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK_ROOT%\prebuilt\windows\bin\make.exe" ..
3434+# $ "%ANDROID_NDK_ROOT%\prebuilt\windows\bin\make.exe"
3535+#
3636+#
3737+# Options (can be set as cmake parameters: -D<option_name>=<value>):
3838+# ANDROID_NDK=/opt/android-ndk - path to the NDK root.
3939+# Can be set as environment variable ANDROID_NDK_ROOT. Can be set only at first cmake run.
4040+#
4141+# ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to the
4242+# standalone toolchain. This option overrides ANDROID_NDK
4343+# (and subsequentally the enviroment variable ANDROID_NDK_ROOT).
4444+# Can be set as environment variable. Can be set only at first cmake run.
4545+#
4646+# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary
4747+# Interface (ABI). This option nearly matches to the APP_ABI variable
4848+# used by ndk-build tool from Android NDK.
4949+#
5050+# Possible targets are:
5151+# "armeabi" - matches to the NDK ABI with the same name.
5252+# See ${ANDROID_NDK_ROOT}/docs/CPU-ARCH-ABIS.html for the documentation.
5353+# "armeabi-v7a" - matches to the NDK ABI with the same name.
5454+# See ${ANDROID_NDK_ROOT}/docs/CPU-ARCH-ABIS.html for the documentation.
5555+# "armeabi-v7a with NEON" - same as armeabi-v7a, but
5656+# sets NEON as floating-point unit
5757+# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but
5858+# sets VFPV3 as floating-point unit (has 32 registers instead of 16).
5959+# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP.
6060+# "x86" - matches to the NDK ABI with the same name.
6161+# See ${ANDROID_NDK_ROOT}/docs/CPU-ARCH-ABIS.html for the documentation.
6262+# "mips" - matches to the NDK ABI with the same name
6363+# (not testes on real devices)
6464+#
6565+# ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for.
6666+# Option is read-only when standalone toolchain used.
6767+#
6868+# ANDROID_FORCE_ARM_BUILD=OFF - set true to generate 32-bit ARM instructions
6969+# instead of Thumb-1. Is not available for "x86" (inapplicable) and
7070+# "armeabi-v6 with VFP" (forced) ABIs.
7171+#
7272+# ANDROID_NO_UNDEFINED=ON - set true to show all undefined symbols as linker
7373+# errors even if they are not used.
7474+#
7575+# ANDROID_SO_UNDEFINED=OFF - set true to allow undefined symbols in shared
7676+# libraries. Automatically turned on for NDK r5x and r6x due to GLESv2
7777+# problems.
7878+#
7979+# LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary
8080+# files. See additional details below.
8181+#
8282+# ANDROID_SET_OBSOLETE_VARIABLES=ON - it set, then toolchain defines some
8383+# obsolete variables which were set by previous versions of this file for
8484+# backward compatibility.
8585+#
8686+#
8787+# What?:
8888+# android-cmake toolchain searches for NDK/toolchain in the following order:
8989+# ANDROID_NDK - cmake parameter
9090+# ANDROID_NDK_ROOT - environment variable
9191+# (ANDROID_NDK - environment variable as legacy fallback)
9292+# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter
9393+# ANDROID_STANDALONE_TOOLCHAIN - environment variable
9494+# ANDROID_NDK - default locations
9595+# ANDROID_STANDALONE_TOOLCHAIN - default locations
9696+#
9797+# Make sure to do the following in your scripts:
9898+# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" )
9999+# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" )
100100+# The flags will be prepopulated with critical flags, so don't loose them.
101101+# Also be aware that toolchain also sets configuration-specific compiler
102102+# flags and linker flags.
103103+#
104104+# ANDROID and BUILD_ANDROID will be set to true, you may test any of these
105105+# variables to make necessary Android-specific configuration changes.
106106+#
107107+# Also ARMEABI or ARMEABI_V7A or X86 will be set true, mutually exclusive.
108108+# NEON option will be set true if VFP is set to NEON.
109109+#
110110+# LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where Android
111111+# libraries will be installed.
112112+# Default is ${CMAKE_SOURCE_DIR}, and the android libs will always be
113113+# under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}
114114+# (depending on the target ABI). This is convenient for Android packaging.
115115+#
116116+# Authors:
117117+# Ethan Rublee ethan.ruble@gmail.com
118118+# Andrey Kamaev andrey.kamaev@itseez.com
119119+# Eric Wing <ewing . public |-at-| gmail . com>
120120+#
121121+# Change Log:
122122+# - initial version December 2010
123123+# - modified April 2011
124124+# [+] added possibility to build with NDK (without standalone toolchain)
125125+# [+] support cross-compilation on Windows (native, no cygwin support)
126126+# [+] added compiler option to force "char" type to be signed
127127+# [+] added toolchain option to compile to 32-bit ARM instructions
128128+# [+] added toolchain option to disable SWIG search
129129+# [+] added platform "armeabi-v7a with VFPV3"
130130+# [~] ARM_TARGETS renamed to ARM_TARGET
131131+# [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows)
132132+# [~] Fixed bug with ANDROID_API_LEVEL variable
133133+# [~] turn off SWIG search if it is not found first time
134134+# - modified May 2011
135135+# [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL
136136+# [+] ANDROID_API_LEVEL is detected by toolchain if not specified
137137+# [~] added guard to prevent changing of output directories on the first
138138+# cmake pass
139139+# [~] toolchain exits with error if ARM_TARGET is not recognized
140140+# - modified June 2011
141141+# [~] default NDK path is updated for version r5c
142142+# [+] variable CMAKE_SYSTEM_PROCESSOR is set based on ARM_TARGET
143143+# [~] toolchain install directory is added to linker paths
144144+# [-] removed SWIG-related stuff from toolchain
145145+# [+] added macro find_host_package, find_host_program to search
146146+# packages/programs on the host system
147147+# [~] fixed path to STL library
148148+# - modified July 2011
149149+# [~] fixed options caching
150150+# [~] search for all supported NDK versions
151151+# [~] allowed spaces in NDK path
152152+# - modified September 2011
153153+# [~] updated for NDK r6b
154154+# - modified November 2011
155155+# [*] rewritten for NDK r7
156156+# [+] x86 toolchain support (experimental)
157157+# [+] added "armeabi-v6 with VFP" ABI for ARMv6 processors.
158158+# [~] improved compiler and linker flags management
159159+# [+] support different build flags for Release and Debug configurations
160160+# [~] by default compiler flags the same as used by ndk-build (but only
161161+# where reasonable)
162162+# [~] ANDROID_NDK_TOOLCHAIN_ROOT is splitted to ANDROID_STANDALONE_TOOLCHAIN
163163+# and ANDROID_TOOLCHAIN_ROOT
164164+# [~] ARM_TARGET is renamed to ANDROID_ABI
165165+# [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME
166166+# [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL
167167+# - modified January 2012
168168+# [+] added stlport_static support (experimental)
169169+# [+] added special check for cygwin
170170+# [+] filtered out hidden files (starting with .) while globbing inside NDK
171171+# [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6
172172+# [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags
173173+# - modified February 2012
174174+# [+] updated for NDK r7b
175175+# [~] fixed cmake try_compile() command
176176+# [~] Fix for missing install_name_tool on OS X
177177+# - modified March 2012
178178+# [~] fixed incorrect C compiler flags
179179+# [~] fixed CMAKE_SYSTEM_PROCESSOR change on ANDROID_ABI change
180180+# [+] improved toolchain loading speed
181181+# [+] added assembler language support (.S)
182182+# [+] allowed preset search paths and extra search suffixes
183183+# - modified April 2012
184184+# [+] updated for NDK r7c
185185+# [~] fixed most of problems with compiler/linker flags and caching
186186+# [+] added option ANDROID_FUNCTION_LEVEL_LINKING
187187+# - modified May 2012
188188+# [+] updated for NDK r8
189189+# [+] added mips architecture support
190190+# - modified August 2012
191191+# [+] updated for NDK r8b
192192+# [~] all intermediate files generated by toolchain are moved into CMakeFiles
193193+# [~] libstdc++ and libsupc are removed from explicit link libraries
194194+# - modified August 2013 (EW)
195195+# [+] updated for NDK r9 (standalone)
196196+# [+] Addded Perl helper scripts to make it easier to build multiple architectures in one shot.
197197+# [~] Breaking change of behavior to so that ANDROID_STANDALONE_TOOLCHAIN overrides ANDROID_NDK because the latter uses semi-standard environmental variables that people may already have defined for other conflicting purposes.
198198+# [~] Changed environmental variable to look for ANDROID_NDK_ROOT because this is the semi-official/blessed one according to Google via the NDK mailing list. ANDROID_NDK is still checked for backwards compatibility.
199199+# [~] Changed a lot of flags to try to match stock Android more closely due build problems I was trying to track down. In the end, I lost track of which specific flags were the problem. See Additional Notes for flag differences between this and stock.
200200+# [~] Changed armeabi-v7a to use -mfpu=vfpv3-d16 instead of -mfpu=vfp to conform with stock Android.
201201+# [~] Changed VFPV3 mode to use -mfpu=vfpv3-d32
202202+# [~] Use --sysroot=${ANDROID_SYSROOT} to match stock Android
203203+# [~] Use -fstack-protector -no-canonical-prefixes -Wa,--noexecstack to match stock Android
204204+# [~] Use -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now to match stock Android
205205+# [~] Use -lc -lm to match stock Android
206206+# [~] Removed -fsigned-char and -Wno-psabi because these don't appear in stock Android
207207+# [~] Removed -f[no]exceptions flags from C flags because those are C++ options
208208+# [~] Changed arm debug optimization level to O0 from Os
209209+# [~] Added -funswitch-loops -finline-limit=300 to match stock Android
210210+# [~] Changed arm debug optimization level to O0 from Os
211211+# [~] Separated ANDROID_CXX_FLAGS into ANDROID_CXX_FLAGS and ANDROID_C_FLAGS
212212+# [*] Note: MIPs settings were not changed/tested.
213213+#
214214+#
215215+# (EW) Additional Notes:
216216+# Looking at the switches used by compiling the hello-jni example from ndk-build V=1 in r8d, I see the following compiler flags:
217217+# armeabi
218218+# -MMD -MP -MF /foo/hello-jni.o.d
219219+# -fpic -ffunction-sections -funwind-tables -fstack-protector
220220+# -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -no-canonical-prefixes
221221+# -march=armv5te -mtune=xscale -msoft-float
222222+# -mthumb
223223+# -Os -g -DNDEBUG
224224+# -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64
225225+#
226226+# -O0 -UNDEBUG (debug only, not in release)
227227+# -marm -fno-omit-frame-pointer (debug only, not in release)
228228+#
229229+# -DANDROID -Wa,--noexecstack
230230+231231+232232+# armeabi-v7a
233233+# -MMD -MP -MF /foo/hello-jni.o.d
234234+# -fpic -ffunction-sections -funwind-tables -fstack-protector
235235+# -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -no-canonical-prefixes
236236+# -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
237237+# -mthumb
238238+# -Os -g -DNDEBUG
239239+# -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64
240240+#
241241+# -O0 -UNDEBUG (debug only, not in release)
242242+# -marm -fno-omit-frame-pointer (debug only, not in release)
243243+#
244244+# -DANDROID -Wa,--noexecstack
245245+246246+# x86
247247+# -MMD -MP -MF /foo/hello-jni.o.d
248248+# -ffunction-sections -funwind-tables -no-canonical-prefixes -fstack-protector
249249+# -O2 -g -DNDEBUG
250250+# -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300
251251+#
252252+# -O0 -UNDEBUG (debug only, not in release)
253253+# -fno-omit-frame-pointer -fno-strict-aliasing (debug only, not in release)
254254+#
255255+# -DANDROID -Wa,--noexecstack
256256+257257+# The link flags are:
258258+259259+260260+# armeabi
261261+# -Wl,-soname,libhello-jni.so -shared
262262+# --sysroot=/fee/android-ndk/platforms/android-14/arch-arm
263263+# /foo/hello-jni.o
264264+# -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -lc -lm
265265+266266+# armeabi-v7a
267267+# -Wl,-soname,libhello-jni.so -shared
268268+# --sysroot=/fee/android-ndk/platforms/android-14/arch-arm
269269+# /foo/hello-jni.o
270270+# -no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -lc -lm
271271+272272+# x86
273273+# -Wl,-soname,libhello-jni.so -shared
274274+# --sysroot=/fee/android-ndk/platforms/android-14/arch-x86
275275+# /foo/hello-jni.o
276276+# -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -lc -lm
277277+278278+279279+# Some interesting observations are that debug doesn't have different flags, but overrides set flags with additional switches.
280280+281281+# Differences from Stock Android:
282282+# This toolchain has deviated from the stock flags.
283283+#
284284+# I don't do the override technique as described directly above.
285285+#
286286+# -ffunction-sections has been separated into the option ANDROID_FUNCTION_LEVEL_LINKING.
287287+# But this also brings in -fdata-sections and the linker flags -Wl,--gc-sections which are not in the Android defaults
288288+#
289289+# -funwind-tables has been completely removed for arm by this file. It looks like the author intentionally did this for performance.
290290+#
291291+# Optimization flags are using O3 in this file as opposed to stock 02 for Release. It looks like the original authors have done some benchmarking so I am deferring to them.
292292+# I am however changing the Os to O0 for debug.
293293+#
294294+# ------------------------------------------------------------------------------
295295+296296+cmake_minimum_required( VERSION 2.6.3 )
297297+298298+if( DEFINED CMAKE_CROSSCOMPILING )
299299+ # subsequent toolchain loading is not really needed
300300+ return()
301301+endif()
302302+303303+get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
304304+if( _CMAKE_IN_TRY_COMPILE )
305305+ include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL )
306306+endif()
307307+308308+# this one is important
309309+set( CMAKE_SYSTEM_NAME Linux )
310310+# this one not so much
311311+set( CMAKE_SYSTEM_VERSION 1 )
312312+313313+# There was an Android NDK bug with armv7 and vfpv3 in r7b which caused crashes according to
314314+# http://stackoverflow.com/questions/11831648/android-ndk-arm-build-settings-to-run-on-most-devices
315315+# Not supporting r7b or below seems wiser. Supporting ancient Android NDKs is rather pointless since part of the reason for the updates is to fix bugs.
316316+#set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8d -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" )
317317+set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r9 -r8d -r8b -r8 -r7c "" )
318318+if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS)
319319+ if( CMAKE_HOST_WIN32 )
320320+ file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS )
321321+ set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}/android-ndk" "$ENV{SystemDrive}/NVPACK/android-ndk" )
322322+ else()
323323+ file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS )
324324+ set( ANDROID_NDK_SEARCH_PATHS /opt/android-ndk "${ANDROID_NDK_SEARCH_PATHS}/NVPACK/android-ndk" )
325325+ endif()
326326+endif()
327327+if(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH)
328328+ set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain )
329329+endif()
330330+331331+set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" )
332332+set( ANDROID_SUPPORTED_ABIS_x86 "x86" )
333333+set( ANDROID_SUPPORTED_ABIS_mipsel "mips" )
334334+335335+set( ANDROID_DEFAULT_NDK_API_LEVEL 8 )
336336+set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 )
337337+set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 )
338338+339339+340340+macro( __LIST_FILTER listvar regex )
341341+ if( ${listvar} )
342342+ foreach( __val ${${listvar}} )
343343+ if( __val MATCHES "${regex}" )
344344+ list( REMOVE_ITEM ${listvar} "${__val}" )
345345+ endif()
346346+ endforeach()
347347+ endif()
348348+endmacro()
349349+350350+macro( __INIT_VARIABLE var_name )
351351+ set( __test_path 0 )
352352+ foreach( __var ${ARGN} )
353353+ if( __var STREQUAL "PATH" )
354354+ set( __test_path 1 )
355355+ break()
356356+ endif()
357357+ endforeach()
358358+ if( __test_path AND NOT EXISTS "${${var_name}}" )
359359+ unset( ${var_name} CACHE )
360360+ endif()
361361+ if( "${${var_name}}" STREQUAL "" )
362362+ set( __values 0 )
363363+ foreach( __var ${ARGN} )
364364+ if( __var STREQUAL "VALUES" )
365365+ set( __values 1 )
366366+ elseif( NOT __var STREQUAL "PATH" )
367367+ set( __obsolete 0 )
368368+ if( __var MATCHES "^OBSOLETE_.*$" )
369369+ string( REPLACE "OBSOLETE_" "" __var "${__var}" )
370370+ set( __obsolete 1 )
371371+ endif()
372372+ if( __var MATCHES "^ENV_.*$" )
373373+ string( REPLACE "ENV_" "" __var "${__var}" )
374374+ set( __value "$ENV{${__var}}" )
375375+ elseif( DEFINED ${__var} )
376376+ set( __value "${${__var}}" )
377377+ else()
378378+ if( __values )
379379+ set( __value "${__var}" )
380380+ else()
381381+ set( __value "" )
382382+ endif()
383383+ endif()
384384+ if( NOT "${__value}" STREQUAL "" )
385385+ if( __test_path )
386386+ if( EXISTS "${__value}" )
387387+ set( ${var_name} "${__value}" )
388388+ if( __obsolete )
389389+ 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." )
390390+ endif()
391391+ break()
392392+ endif()
393393+ else()
394394+ set( ${var_name} "${__value}" )
395395+ if( __obsolete )
396396+ 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." )
397397+ endif()
398398+ break()
399399+ endif()
400400+ endif()
401401+ endif()
402402+ endforeach()
403403+ unset( __value )
404404+ unset( __values )
405405+ unset( __obsolete )
406406+ endif()
407407+ unset( __test_path )
408408+endmacro()
409409+410410+macro( __DETECT_NATIVE_API_LEVEL _var _path )
411411+ SET( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" )
412412+ FILE( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" )
413413+ if( NOT __apiFileContent )
414414+ 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." )
415415+ endif()
416416+ string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" )
417417+ unset( __apiFileContent )
418418+ unset( __ndkApiLevelRegex )
419419+endmacro()
420420+421421+macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root )
422422+ file( GLOB __gccExePath "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" )
423423+ __LIST_FILTER( __gccExePath "bin/[.].*-gcc${TOOL_OS_SUFFIX}$" )
424424+ list( LENGTH __gccExePath __gccExePathsCount )
425425+ if( NOT __gccExePathsCount EQUAL 1 )
426426+ message( WARNING "Could not uniquely determine machine name for compiler from ${_root}." )
427427+ set( ${_var} "" )
428428+ else()
429429+ get_filename_component( __gccExeName "${__gccExePath}" NAME_WE )
430430+ string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" )
431431+ endif()
432432+ unset( __gccExePath )
433433+ unset( __gccExePathsCount )
434434+ unset( __gccExeName )
435435+endmacro()
436436+437437+macro( __COPY_IF_DIFFERENT _source _destination )
438438+ execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${_source}" "${_destination}" RESULT_VARIABLE __fileCopyProcess )
439439+ if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${_destination}")
440440+ message( SEND_ERROR "Failed copying of ${_source} to the ${_destination}" )
441441+ endif()
442442+ unset( __fileCopyProcess )
443443+endmacro()
444444+445445+446446+# stl version: by default gnustl_static will be used
447447+set( ANDROID_USE_STLPORT FALSE CACHE BOOL "Experimental: use stlport_static instead of gnustl_static")
448448+mark_as_advanced( ANDROID_USE_STLPORT )
449449+450450+# fight against cygwin
451451+set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools")
452452+mark_as_advanced( ANDROID_FORBID_SYGWIN )
453453+if( ANDROID_FORBID_SYGWIN )
454454+ if( CYGWIN )
455455+ 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." )
456456+ endif()
457457+458458+ if( CMAKE_HOST_WIN32 )
459459+ # remove cygwin from PATH
460460+ set( __new_path "$ENV{PATH}")
461461+ __LIST_FILTER( __new_path "cygwin" )
462462+ set(ENV{PATH} "${__new_path}")
463463+ unset(__new_path)
464464+ endif()
465465+endif()
466466+467467+# detect current host platform
468468+set( TOOL_OS_SUFFIX "" )
469469+if( CMAKE_HOST_APPLE )
470470+ set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" )
471471+elseif( CMAKE_HOST_WIN32 )
472472+ set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" )
473473+ set( TOOL_OS_SUFFIX ".exe" )
474474+elseif( CMAKE_HOST_UNIX )
475475+ set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" )
476476+else()
477477+ message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
478478+endif()
479479+480480+# see if we have path to Android NDK
481481+# but only if the user hasn't tried to provide a standalone toolchain as an override.
482482+if( NOT ANDROID_STANDALONE_TOOLCHAIN )
483483+ __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK )
484484+ # According to a Google engineer on the Android NDK mailing list, the semi-official/blessed environmental variable is ANDROID_NDK_ROOT, not ANDROID_NDK.
485485+ if ( NOT ANDROID_NDK )
486486+ __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK_ROOT )
487487+ endif( NOT ANDROID_NDK )
488488+endif( NOT ANDROID_STANDALONE_TOOLCHAIN )
489489+490490+if( NOT ANDROID_NDK )
491491+ # see if we have path to Android standalone toolchain
492492+ __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN OBSOLETE_ANDROID_NDK_TOOLCHAIN_ROOT OBSOLETE_ENV_ANDROID_NDK_TOOLCHAIN_ROOT )
493493+494494+ if( NOT ANDROID_STANDALONE_TOOLCHAIN )
495495+ #try to find Android NDK in one of the the default locations
496496+ set( __ndkSearchPaths )
497497+ foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} )
498498+ foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} )
499499+ list( APPEND __ndkSearchPaths "${__ndkSearchPath}${suffix}" )
500500+ endforeach()
501501+ endforeach()
502502+ __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} )
503503+ unset( __ndkSearchPaths )
504504+505505+ if( ANDROID_NDK )
506506+ message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" )
507507+ message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" )
508508+ else()
509509+ #try to find Android standalone toolchain in one of the the default locations
510510+ __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH )
511511+512512+ if( ANDROID_STANDALONE_TOOLCHAIN )
513513+ message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" )
514514+ message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" )
515515+ endif( ANDROID_STANDALONE_TOOLCHAIN )
516516+ endif( ANDROID_NDK )
517517+ endif( NOT ANDROID_STANDALONE_TOOLCHAIN )
518518+endif( NOT ANDROID_NDK )
519519+520520+# remember found paths
521521+if( ANDROID_NDK )
522522+ get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE )
523523+ # try to detect change
524524+ if( CMAKE_AR )
525525+ string( LENGTH "${ANDROID_NDK}" __length )
526526+ string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath )
527527+ if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK )
528528+ message( FATAL_ERROR "It is not possible to change path to the NDK on subsequent run." )
529529+ endif()
530530+ unset( __androidNdkPreviousPath )
531531+ unset( __length )
532532+ endif()
533533+ set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" )
534534+ set( BUILD_WITH_ANDROID_NDK True )
535535+elseif( ANDROID_STANDALONE_TOOLCHAIN )
536536+ get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE )
537537+ # try to detect change
538538+ if( CMAKE_AR )
539539+ string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length )
540540+ string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath )
541541+ if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN )
542542+ message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." )
543543+ endif()
544544+ unset( __androidStandaloneToolchainPreviousPath )
545545+ unset( __length )
546546+ endif()
547547+ set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" )
548548+ set( BUILD_WITH_STANDALONE_TOOLCHAIN True )
549549+else()
550550+ list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH)
551551+ message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolcahin.
552552+ You should either set an environment variable:
553553+ export ANDROID_NDK=~/my-android-ndk
554554+ or
555555+ export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain
556556+ or put the toolchain or NDK in the default path:
557557+ sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH}
558558+ sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" )
559559+endif()
560560+561561+# get all the details about standalone toolchain
562562+if( BUILD_WITH_STANDALONE_TOOLCHAIN )
563563+ __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" )
564564+ set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
565565+ set( __availableToolchains "standalone" )
566566+ __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" )
567567+ if( NOT __availableToolchainMachines )
568568+ message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." )
569569+ endif()
570570+ if( __availableToolchainMachines MATCHES i686 )
571571+ set( __availableToolchainArchs "x86" )
572572+ elseif( __availableToolchainMachines MATCHES arm )
573573+ set( __availableToolchainArchs "arm" )
574574+ elseif( __availableToolchainMachines MATCHES mipsel )
575575+ set( __availableToolchainArchs "mipsel" )
576576+ endif()
577577+ if( ANDROID_COMPILER_VERSION )
578578+ # do not run gcc every time because it is relatevely expencive
579579+ set( __availableToolchainCompilerVersions "${ANDROID_COMPILER_VERSION}" )
580580+ else()
581581+ execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version
582582+ OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE )
583583+ # arm-linux-androideabi-gcc (GCC) 4.6 20120106 (prerelease)
584584+ string( REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" )
585585+ if( NOT __availableToolchainCompilerVersions )
586586+ # arm-linux-androideabi-gcc (GCC) 4.8
587587+ execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version
588588+ OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE )
589589+ string( REGEX MATCH "[0-9]+.[0-9]+" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" )
590590+ endif()
591591+ endif()
592592+endif()
593593+594594+# get all the details about NDK
595595+if( BUILD_WITH_ANDROID_NDK )
596596+ file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" )
597597+ string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" )
598598+ file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" )
599599+ __LIST_FILTER( __availableToolchains "^[.]" )
600600+ set( __availableToolchainMachines "" )
601601+ set( __availableToolchainArchs "" )
602602+ set( __availableToolchainCompilerVersions "" )
603603+ foreach( __toolchain ${__availableToolchains} )
604604+ __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" )
605605+ if( __machine )
606606+ string( REGEX MATCH "[0-9]+[.][0-9]+[.]*[0-9]*$" __version "${__toolchain}" )
607607+ string( REGEX MATCH "^[^-]+" __arch "${__toolchain}" )
608608+ list( APPEND __availableToolchainMachines "${__machine}" )
609609+ list( APPEND __availableToolchainArchs "${__arch}" )
610610+ list( APPEND __availableToolchainCompilerVersions "${__version}" )
611611+ else()
612612+ list( REMOVE_ITEM __availableToolchains "${__toolchain}" )
613613+ endif()
614614+ endforeach()
615615+ if( NOT __availableToolchains )
616616+ message( FATAL_ERROR "Could not any working toolchain in the NDK. Probably your Android NDK is broken." )
617617+ endif()
618618+endif()
619619+620620+# build list of available ABIs
621621+if( NOT ANDROID_SUPPORTED_ABIS )
622622+ set( ANDROID_SUPPORTED_ABIS "" )
623623+ set( __uniqToolchainArchNames ${__availableToolchainArchs} )
624624+ list( REMOVE_DUPLICATES __uniqToolchainArchNames )
625625+ list( SORT __uniqToolchainArchNames )
626626+ foreach( __arch ${__uniqToolchainArchNames} )
627627+ list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} )
628628+ endforeach()
629629+ unset( __uniqToolchainArchNames )
630630+ if( NOT ANDROID_SUPPORTED_ABIS )
631631+ message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." )
632632+ endif()
633633+endif()
634634+635635+# choose target ABI
636636+__INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ANDROID_SUPPORTED_ABIS} )
637637+# verify that target ABI is supported
638638+list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx )
639639+if( __androidAbiIdx EQUAL -1 )
640640+ string( REPLACE ";" "\", \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" )
641641+ message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain.
642642+ Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\"
643643+ " )
644644+endif()
645645+unset( __androidAbiIdx )
646646+647647+# remember target ABI
648648+set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE )
649649+650650+# set target ABI options
651651+if( ANDROID_ABI STREQUAL "x86" )
652652+ set( X86 true )
653653+ set( ANDROID_NDK_ABI_NAME "x86" )
654654+ set( ANDROID_ARCH_NAME "x86" )
655655+ set( ANDROID_ARCH_FULLNAME "x86" )
656656+ set( CMAKE_SYSTEM_PROCESSOR "i686" )
657657+elseif( ANDROID_ABI STREQUAL "mips" )
658658+ set( MIPS true )
659659+ set( ANDROID_NDK_ABI_NAME "mips" )
660660+ set( ANDROID_ARCH_NAME "mips" )
661661+ set( ANDROID_ARCH_FULLNAME "mipsel" )
662662+ set( CMAKE_SYSTEM_PROCESSOR "mips" )
663663+elseif( ANDROID_ABI STREQUAL "armeabi" )
664664+ set( ARMEABI true )
665665+ set( ANDROID_NDK_ABI_NAME "armeabi" )
666666+ set( ANDROID_ARCH_NAME "arm" )
667667+ set( ANDROID_ARCH_FULLNAME "arm" )
668668+ set( CMAKE_SYSTEM_PROCESSOR "armv5te" )
669669+elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" )
670670+ set( ARMEABI_V6 true )
671671+ set( ANDROID_NDK_ABI_NAME "armeabi" )
672672+ set( ANDROID_ARCH_NAME "arm" )
673673+ set( ANDROID_ARCH_FULLNAME "arm" )
674674+ set( CMAKE_SYSTEM_PROCESSOR "armv6" )
675675+ # need always fallback to older platform
676676+ set( ARMEABI true )
677677+elseif( ANDROID_ABI STREQUAL "armeabi-v7a")
678678+ set( ARMEABI_V7A true )
679679+ set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
680680+ set( ANDROID_ARCH_NAME "arm" )
681681+ set( ANDROID_ARCH_FULLNAME "arm" )
682682+ set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
683683+elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" )
684684+ set( ARMEABI_V7A true )
685685+ set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
686686+ set( ANDROID_ARCH_NAME "arm" )
687687+ set( ANDROID_ARCH_FULLNAME "arm" )
688688+ set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
689689+ set( VFPV3 true )
690690+elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" )
691691+ set( ARMEABI_V7A true )
692692+ set( ANDROID_NDK_ABI_NAME "armeabi-v7a" )
693693+ set( ANDROID_ARCH_NAME "arm" )
694694+ set( ANDROID_ARCH_FULLNAME "arm" )
695695+ set( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
696696+ set( VFPV3 true )
697697+ set( NEON true )
698698+else()
699699+ message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." )
700700+endif()
701701+702702+if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" )
703703+ # really dirty hack
704704+ # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run...
705705+ file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" )
706706+endif()
707707+708708+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." )
709709+if( CMAKE_VERSION VERSION_GREATER "2.8" )
710710+ list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} )
711711+ set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} )
712712+endif()
713713+714714+if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 )
715715+ __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF )
716716+ set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE )
717717+ mark_as_advanced( ANDROID_FORCE_ARM_BUILD )
718718+else()
719719+ unset( ANDROID_FORCE_ARM_BUILD CACHE )
720720+endif()
721721+722722+# choose toolchain
723723+if( ANDROID_TOOLCHAIN_NAME )
724724+ list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx )
725725+ if( __toolchainIdx EQUAL -1 )
726726+ 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" )
727727+ endif()
728728+ list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch )
729729+ if( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME )
730730+ message( SEND_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." )
731731+ endif()
732732+else()
733733+ set( __toolchainIdx -1 )
734734+ set( __applicableToolchains "" )
735735+ set( __toolchainMaxVersion "0.0.0" )
736736+ list( LENGTH __availableToolchains __availableToolchainsCount )
737737+ math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" )
738738+ foreach( __idx RANGE ${__availableToolchainsCount} )
739739+ list( GET __availableToolchainArchs ${__idx} __toolchainArch )
740740+ if( __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME )
741741+ list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion )
742742+ if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion )
743743+ set( __toolchainMaxVersion "${__toolchainVersion}" )
744744+ set( __toolchainIdx ${__idx} )
745745+ endif()
746746+ endif()
747747+ endforeach()
748748+ unset( __availableToolchainsCount )
749749+ unset( __toolchainMaxVersion )
750750+ unset( __toolchainVersion )
751751+endif()
752752+unset( __toolchainArch )
753753+if( __toolchainIdx EQUAL -1 )
754754+ message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." )
755755+endif()
756756+list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME )
757757+list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME )
758758+list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION )
759759+set( ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" CACHE INTERNAL "Name of toolchain used" )
760760+set( ANDROID_COMPILER_VERSION "${ANDROID_COMPILER_VERSION}" CACHE INTERNAL "compiler version from selected toolchain" )
761761+unset( __toolchainIdx )
762762+unset( __availableToolchains )
763763+unset( __availableToolchainMachines )
764764+unset( __availableToolchainArchs )
765765+unset( __availableToolchainCompilerVersions )
766766+767767+# choose native API level
768768+__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 )
769769+string( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" )
770770+# validate
771771+list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx )
772772+if( __levelIdx EQUAL -1 )
773773+ message( SEND_ERROR "Specified Android native API level (${ANDROID_NATIVE_API_LEVEL}) is not supported by your NDK/toolchain." )
774774+endif()
775775+unset( __levelIdx )
776776+if( BUILD_WITH_ANDROID_NDK )
777777+ __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" )
778778+ if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL )
779779+ 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." )
780780+ endif()
781781+ unset( __realApiLevel )
782782+endif()
783783+set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
784784+if( CMAKE_VERSION VERSION_GREATER "2.8" )
785785+ list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )
786786+ set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
787787+endif()
788788+789789+# setup paths
790790+if( BUILD_WITH_STANDALONE_TOOLCHAIN )
791791+ set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
792792+ set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" )
793793+ set( __stlLibPath "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" )
794794+endif()
795795+if( BUILD_WITH_ANDROID_NDK )
796796+ set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" )
797797+ set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" )
798798+ if( ANDROID_USE_STLPORT )
799799+ set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" )
800800+ set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}" )
801801+ else()
802802+ if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" )
803803+ set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/include" )
804804+ set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}" )
805805+ else()
806806+ set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include" )
807807+ set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}" )
808808+ endif()
809809+ endif()
810810+endif()
811811+812812+# specify the cross compiler
813813+set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" )
814814+set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" )
815815+set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "Assembler" )
816816+if( CMAKE_VERSION VERSION_LESS 2.8.5 )
817817+ set( CMAKE_ASM_COMPILER_ARG1 "-c" )
818818+endif()
819819+# there may be a way to make cmake deduce these TODO deduce the rest of the tools
820820+set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" )
821821+set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" )
822822+set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" )
823823+set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" )
824824+set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" )
825825+set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" )
826826+set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" )
827827+set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" )
828828+if( APPLE )
829829+ find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )
830830+ if( NOT CMAKE_INSTALL_NAME_TOOL )
831831+ message( FATAL_ERROR "Could not find install_name_tool, please check your installation." )
832832+ endif()
833833+ mark_as_advanced( CMAKE_INSTALL_NAME_TOOL )
834834+endif()
835835+836836+# export directories
837837+set( ANDROID_SYSTEM_INCLUDE_DIRS "" )
838838+set( ANDROID_SYSTEM_LIB_DIRS "" )
839839+840840+# setup output directories
841841+set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" )
842842+set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" )
843843+844844+if(NOT _CMAKE_IN_TRY_COMPILE)
845845+ if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" )
846846+ set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" )
847847+ else()
848848+ set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" )
849849+ endif()
850850+ set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" )
851851+endif()
852852+853853+# includes
854854+list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_SYSROOT}/usr/include" )
855855+if( __stlIncludePath AND EXISTS "${__stlIncludePath}" )
856856+ list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${__stlIncludePath}" )
857857+endif()
858858+859859+# c++ bits includes
860860+if( __stlLibPath AND EXISTS "${__stlLibPath}/include" )
861861+ list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${__stlLibPath}/include" )
862862+endif()
863863+if( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/thumb/bits" )
864864+ list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/thumb" )
865865+elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" )
866866+ list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" )
867867+elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" )
868868+ list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" )
869869+elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/bits" )
870870+ list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" )
871871+endif()
872872+873873+# flags and definitions
874874+if(ANDROID_SYSROOT MATCHES "[ ;\"]")
875875+ set( ANDROID_C_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" )
876876+ set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" )
877877+ # quotes will break try_compile and compiler identification
878878+ message(WARNING "Your Android system root has non-alphanumeric symbols. It can break compiler features detection and the whole build.")
879879+else()
880880+ set( ANDROID_C_FLAGS "--sysroot=${ANDROID_SYSROOT}" )
881881+ set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" )
882882+endif()
883883+884884+remove_definitions( -DANDROID )
885885+add_definitions( -DANDROID )
886886+887887+# Force set compilers because standard identification works badly for us
888888+include( CMakeForceCompiler )
889889+CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU )
890890+set( CMAKE_C_PLATFORM_ID Linux )
891891+set( CMAKE_C_SIZEOF_DATA_PTR 4 )
892892+set( CMAKE_C_HAS_ISYSROOT 1 )
893893+set( CMAKE_C_COMPILER_ABI ELF )
894894+CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU )
895895+set( CMAKE_CXX_PLATFORM_ID Linux )
896896+set( CMAKE_CXX_SIZEOF_DATA_PTR 4 )
897897+set( CMAKE_CXX_HAS_ISYSROOT 1 )
898898+set( CMAKE_CXX_COMPILER_ABI ELF )
899899+# force ASM compiler (required for CMake < 2.8.5)
900900+set( CMAKE_ASM_COMPILER_ID_RUN TRUE )
901901+set( CMAKE_ASM_COMPILER_ID GNU )
902902+set( CMAKE_ASM_COMPILER_WORKS TRUE )
903903+set( CMAKE_ASM_COMPILER_FORCED TRUE )
904904+set( CMAKE_COMPILER_IS_GNUASM 1)
905905+906906+# NDK flags
907907+if( ARMEABI OR ARMEABI_V7A )
908908+ # NDK also defines -ffunction-sections -funwind-tables but they result in worse OpenCV performance
909909+ set( _CMAKE_CXX_FLAGS "-fpic -fstack-protector -no-canonical-prefixes -Wa,--noexecstack" )
910910+ set( _CMAKE_C_FLAGS "-fpic -fstack-protector -no-canonical-prefixes -Wa,--noexecstack" )
911911+ remove_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ )
912912+ add_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ )
913913+ # extra arm-specific flags
914914+ # The default Android build process does not pass -fsigned-char.
915915+ # set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -fsigned-char" )
916916+ # set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" )
917917+elseif( X86 )
918918+ set( _CMAKE_CXX_FLAGS "-no-canonical-prefixes -funwind-tables -fstack-protector -Wa,--noexecstack" )
919919+ set( _CMAKE_C_FLAGS "-no-canonical-prefixes -funwind-tables -fstack-protector -Wa,--noexecstack" )
920920+elseif( MIPS )
921921+ 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" )
922922+ set( _CMAKE_C_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" )
923923+ # The default Android build process does not pass -fsigned-char.
924924+ # set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -fsigned-char" )
925925+ # set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" )
926926+else()
927927+ set( _CMAKE_CXX_FLAGS "" )
928928+ set( _CMAKE_C_FLAGS "" )
929929+endif()
930930+931931+if( ANDROID_USE_STLPORT )
932932+ set( _CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions" )
933933+ # set( _CMAKE_C_FLAGS "${_CMAKE_C_FLAGS}" )
934934+else()
935935+ set( _CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS} -frtti -fexceptions" )
936936+ # set( _CMAKE_C_FLAGS "${_CMAKE_C_FLAGS}" )
937937+endif()
938938+939939+# release and debug flags
940940+if( ARMEABI OR ARMEABI_V7A )
941941+ if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 )
942942+ # It is recommended to use the -mthumb compiler flag to force the generation
943943+ # of 16-bit Thumb-1 instructions (the default being 32-bit ARM ones).
944944+ # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc
945945+ # EW: Note that Android's normal build process uses
946946+ # -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64
947947+ # and for debug, appends: -O0 -UNDEBUG -marm -fno-omit-frame-pointer
948948+ set( _CMAKE_CXX_FLAGS_RELEASE "-mthumb -O3 -finline-limit=64" )
949949+ set( _CMAKE_C_FLAGS_RELEASE "-mthumb -O3 -finline-limit=64" )
950950+ set( _CMAKE_CXX_FLAGS_DEBUG "-marm -O0 -g -finline-limit=64" )
951951+ set( _CMAKE_C_FLAGS_DEBUG "-marm -O0 -g -finline-limit=64" )
952952+ else()
953953+ # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI
954954+ # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc
955955+ set( _CMAKE_CXX_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" )
956956+ set( _CMAKE_C_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" )
957957+ set( _CMAKE_CXX_FLAGS_DEBUG "-marm -O0 -finline-limit=300" )
958958+ set( _CMAKE_C_FLAGS_DEBUG "-marm -O0 -finline-limit=300" )
959959+ endif()
960960+elseif( X86 )
961961+ set( _CMAKE_CXX_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" )
962962+ set( _CMAKE_C_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" )
963963+ set( _CMAKE_CXX_FLAGS_DEBUG "-O0 -g -funswitch-loops -finline-limit=300" )
964964+ set( _CMAKE_C_FLAGS_DEBUG "-O0 -g -funswitch-loops -finline-limit=300" )
965965+elseif( MIPS )
966966+ set( _CMAKE_CXX_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" )
967967+ set( _CMAKE_C_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" )
968968+ set( _CMAKE_CXX_FLAGS_DEBUG "-O0 -g" )
969969+ set( _CMAKE_C_FLAGS_DEBUG "-O0 -g" )
970970+endif()
971971+set( _CMAKE_CXX_FLAGS_RELEASE "${_CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" )
972972+set( _CMAKE_C_FLAGS_RELEASE "${_CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" )
973973+set( _CMAKE_CXX_FLAGS_DEBUG "${_CMAKE_CXX_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" )
974974+set( _CMAKE_C_FLAGS_DEBUG "${_CMAKE_C_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" )
975975+976976+# ABI-specific flags
977977+if( ARMEABI_V7A )
978978+ set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -march=armv7-a -mfloat-abi=softfp" )
979979+ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" )
980980+ if( NEON )
981981+ set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -mfpu=neon" )
982982+ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" )
983983+ elseif( VFPV3 )
984984+ set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -mfpu=vfpv3-d32" )
985985+ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d32" )
986986+ else()
987987+ # Default Android armv7 builds with -mfpu=vfpv3-d16.
988988+ # According to this:
989989+ # http://stackoverflow.com/questions/11831648/android-ndk-arm-build-settings-to-run-on-most-devices
990990+ # there was a bug in r7b which caused crashes.
991991+ # But r9 is the current as of this writing so developers really need to upgrade their ndk.
992992+ set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -mfpu=vfpv3-d16" )
993993+ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" )
994994+ endif()
995995+elseif( ARMEABI_V6 )
996996+ set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" )
997997+ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" )
998998+elseif( ARMEABI )
999999+ set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -march=armv5te -mtune=xscale -msoft-float" )
10001000+ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" )
10011001+elseif( X86 )
10021002+ set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS}" )#sse?
10031003+ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" )#sse?
10041004+endif()
10051005+10061006+# linker flags
10071007+if( NOT DEFINED __ndklibspath )
10081008+ set( __ndklibspath "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ndklibs/${ANDROID_NDK_ABI_NAME}" )
10091009+endif()
10101010+list( APPEND ANDROID_SYSTEM_LIB_DIRS "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" )
10111011+set( ANDROID_LINKER_FLAGS "" )
10121012+10131013+# STL
10141014+if( ANDROID_USE_STLPORT )
10151015+ if( EXISTS "${__stlLibPath}/libstlport_static.a" )
10161016+ 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> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES> \"${__stlLibPath}/libstlport_static.a\"")
10171017+ 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> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES> \"${__stlLibPath}/libstlport_static.a\"")
10181018+ endif()
10191019+else( ANDROID_USE_STLPORT )
10201020+ if( EXISTS "${__stlLibPath}/libgnustl_static.a" )
10211021+ __COPY_IF_DIFFERENT( "${__stlLibPath}/libgnustl_static.a" "${__ndklibspath}/libstdc++.a" )
10221022+ elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" )
10231023+ __COPY_IF_DIFFERENT( "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" "${__ndklibspath}/libstdc++.a" )
10241024+ elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" )
10251025+ __COPY_IF_DIFFERENT( "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" "${__ndklibspath}/libstdc++.a" )
10261026+ elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/thumb/libstdc++.a" )
10271027+ __COPY_IF_DIFFERENT( "${__stlLibPath}/thumb/libstdc++.a" "${__ndklibspath}/libstdc++.a" )
10281028+ elseif( EXISTS "${__stlLibPath}/libstdc++.a" )
10291029+ __COPY_IF_DIFFERENT( "${__stlLibPath}/libstdc++.a" "${__ndklibspath}/libstdc++.a" )
10301030+ endif()
10311031+ if( EXISTS "${__stlLibPath}/libsupc++.a" )
10321032+ __COPY_IF_DIFFERENT( "${__stlLibPath}/libsupc++.a" "${__ndklibspath}/libsupc++.a" )
10331033+ elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" )
10341034+ __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" "${__ndklibspath}/libsupc++.a" )
10351035+ elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" )
10361036+ __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" "${__ndklibspath}/libsupc++.a" )
10371037+ elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" )
10381038+ __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" "${__ndklibspath}/libsupc++.a" )
10391039+ elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" )
10401040+ __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" "${__ndklibspath}/libsupc++.a" )
10411041+ endif()
10421042+ list( APPEND ANDROID_SYSTEM_LIB_DIRS "${__ndklibspath}" )
10431043+endif( ANDROID_USE_STLPORT )
10441044+10451045+# cleanup for STL search
10461046+unset( __stlIncludePath )
10471047+unset( __stlLibPath )
10481048+10491049+# other linker flags
10501050+__INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON )
10511051+set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" FORCE )
10521052+mark_as_advanced( ANDROID_NO_UNDEFINED )
10531053+if( ANDROID_NO_UNDEFINED )
10541054+ set( ANDROID_LINKER_FLAGS "-Wl,--no-undefined ${ANDROID_LINKER_FLAGS}" )
10551055+endif()
10561056+10571057+if (ANDROID_NDK MATCHES "-r[56].?$")
10581058+ # libGLESv2.so in NDK's prior to r7 refers to exteranal symbols. So this flag option is required for all projects using OpenGL from native.
10591059+ __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON )
10601060+else()
10611061+ __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF )
10621062+endif()
10631063+10641064+set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" FORCE )
10651065+mark_as_advanced( ANDROID_SO_UNDEFINED )
10661066+if( ANDROID_SO_UNDEFINED )
10671067+ set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" )
10681068+endif()
10691069+10701070+# Android by default passes --function-sections for C and C++ but does not pass -fdata-sections.
10711071+# Android also does not pass -Wl,--gc-sections
10721072+__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON )
10731073+set( ANDROID_FUNCTION_LEVEL_LINKING ON CACHE BOOL "Allows or disallows undefined symbols in shared libraries" FORCE )
10741074+mark_as_advanced( ANDROID_FUNCTION_LEVEL_LINKING )
10751075+if( ANDROID_FUNCTION_LEVEL_LINKING )
10761076+ set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -fdata-sections -ffunction-sections" )
10771077+ set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" )
10781078+ set( ANDROID_LINKER_FLAGS "-Wl,--gc-sections ${ANDROID_LINKER_FLAGS}" )
10791079+endif()
10801080+10811081+if( ARMEABI_V7A )
10821082+ # this is *required* to use the following linker flags that routes around
10831083+ # a CPU bug in some Cortex-A8 implementations:
10841084+ # set( ANDROID_LINKER_FLAGS "-Wl,--fix-cortex-a8 ${ANDROID_LINKER_FLAGS}" )
10851085+ # Android passes all this stuff by default.
10861086+ set( ANDROID_LINKER_FLAGS "-no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${ANDROID_LINKER_FLAGS} -lc -lm" )
10871087+elseif( ARMEABI )
10881088+ set( ANDROID_LINKER_FLAGS "-no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${ANDROID_LINKER_FLAGS} -lc -lm" )
10891089+elseif ( X86 )
10901090+ set( ANDROID_LINKER_FLAGS "-no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${ANDROID_LINKER_FLAGS} -lc -lm" )
10911091+endif()
10921092+10931093+# cache flags
10941094+set( CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" )
10951095+set( CMAKE_C_FLAGS "${_CMAKE_C_FLAGS}" CACHE STRING "c flags" )
10961096+set( CMAKE_CXX_FLAGS_RELEASE "${_CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c++ Release flags" )
10971097+set( CMAKE_C_FLAGS_RELEASE "${_CMAKE_C_FLAGS_RELEASE}" CACHE STRING "c Release flags" )
10981098+set( CMAKE_CXX_FLAGS_DEBUG "${_CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c++ Debug flags" )
10991099+set( CMAKE_C_FLAGS_DEBUG "${_CMAKE_C_FLAGS_DEBUG}" CACHE STRING "c Debug flags" )
11001100+set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "linker flags" )
11011101+set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "linker flags" )
11021102+set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "linker flags" )
11031103+11041104+include_directories( SYSTEM ${ANDROID_SYSTEM_INCLUDE_DIRS} )
11051105+link_directories( ${ANDROID_SYSTEM_LIB_DIRS} )
11061106+11071107+# finish flags
11081108+set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS}" CACHE INTERNAL "Extra Android C compiler flags")
11091109+set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Extra Android C++ compiler flags")
11101110+set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Extra Android linker flags")
11111111+set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" )
11121112+set( CMAKE_C_FLAGS "${ANDROID_C_FLAGS} ${CMAKE_C_FLAGS}" )
11131113+if( MIPS AND BUILD_WITH_ANDROID_NDK )
11141114+ set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" )
11151115+ set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" )
11161116+ set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.x ${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" )
11171117+else()
11181118+ set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" )
11191119+ set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" )
11201120+ set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" )
11211121+endif()
11221122+11231123+# set these global flags for cmake client scripts to change behavior
11241124+set( ANDROID True )
11251125+set( BUILD_ANDROID True )
11261126+11271127+# where is the target environment
11281128+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" "${CMAKE_FIND_ROOT_PATH}" )
11291129+11301130+# only search for libraries and includes in the ndk toolchain
11311131+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
11321132+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
11331133+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
11341134+11351135+11361136+# macro to find packages on the host OS
11371137+macro( find_host_package )
11381138+ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
11391139+ set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
11401140+ set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
11411141+ if( CMAKE_HOST_WIN32 )
11421142+ SET( WIN32 1 )
11431143+ SET( UNIX )
11441144+ elseif( CMAKE_HOST_APPLE )
11451145+ SET( APPLE 1 )
11461146+ SET( UNIX )
11471147+ endif()
11481148+ find_package( ${ARGN} )
11491149+ SET( WIN32 )
11501150+ SET( APPLE )
11511151+ SET( UNIX 1 )
11521152+ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
11531153+ set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
11541154+ set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
11551155+endmacro()
11561156+11571157+11581158+# macro to find programs on the host OS
11591159+macro( find_host_program )
11601160+ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
11611161+ set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
11621162+ set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
11631163+ if( CMAKE_HOST_WIN32 )
11641164+ SET( WIN32 1 )
11651165+ SET( UNIX )
11661166+ elseif( CMAKE_HOST_APPLE )
11671167+ SET( APPLE 1 )
11681168+ SET( UNIX )
11691169+ endif()
11701170+ find_program( ${ARGN} )
11711171+ SET( WIN32 )
11721172+ SET( APPLE )
11731173+ SET( UNIX 1 )
11741174+ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
11751175+ set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
11761176+ set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
11771177+endmacro()
11781178+11791179+11801180+macro( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR )
11811181+ if( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" )
11821182+ set( ${VAR} "armeabi" )
11831183+ elseif( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" )
11841184+ set( ${VAR} "armeabi-v7a" )
11851185+ elseif( "${TOOLCHAIN_FLAG}" STREQUAL "X86" )
11861186+ set( ${VAR} "x86" )
11871187+ else()
11881188+ set( ${VAR} "unknown" )
11891189+ endif()
11901190+endmacro()
11911191+11921192+11931193+# export toolchain settings for the try_compile() command
11941194+if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" )
11951195+ set( __toolchain_config "")
11961196+ foreach( __var ANDROID_ABI ANDROID_FORCE_ARM_BUILD ANDROID_NATIVE_API_LEVEL ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_SET_OBSOLETE_VARIABLES LIBRARY_OUTPUT_PATH_ROOT ANDROID_USE_STLPORT ANDROID_FORBID_SYGWIN ANDROID_NDK ANDROID_STANDALONE_TOOLCHAIN ANDROID_FUNCTION_LEVEL_LINKING __ndklibspath )
11971197+ if( DEFINED ${__var} )
11981198+ if( "${__var}" MATCHES " ")
11991199+ set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" )
12001200+ else()
12011201+ set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" )
12021202+ endif()
12031203+ endif()
12041204+ endforeach()
12051205+ file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" )
12061206+ unset( __toolchain_config )
12071207+ unset( __ndklibspath )
12081208+endif()
12091209+12101210+12111211+# set some obsolete variables for backward compatibility
12121212+set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" )
12131213+mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES )
12141214+if( ANDROID_SET_OBSOLETE_VARIABLES )
12151215+ set( ANDROID_API_LEVEL ${ANDROID_NATIVE_API_LEVEL} )
12161216+ set( ARM_TARGET "${ANDROID_ABI}" )
12171217+ set( ARMEABI_NDK_NAME "${ANDROID_NDK_ABI_NAME}" )
12181218+endif()
12191219+12201220+12211221+# Variables controlling behavior or set by cmake toolchain:
12221222+# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips"
12231223+# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version)
12241224+# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF
12251225+# ANDROID_USE_STLPORT : OFF/ON - EXPERIMENTAL!!!
12261226+# ANDROID_FORBID_SYGWIN : ON/OFF
12271227+# ANDROID_NO_UNDEFINED : ON/OFF
12281228+# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version)
12291229+# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF
12301230+# Variables that takes effect only at first run:
12311231+# ANDROID_FORCE_ARM_BUILD : ON/OFF
12321232+# LIBRARY_OUTPUT_PATH_ROOT : <any valid path>
12331233+# Can be set only at the first run:
12341234+# ANDROID_NDK
12351235+# ANDROID_STANDALONE_TOOLCHAIN
12361236+# 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"
12371237+# Obsolete:
12381238+# ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL
12391239+# ARM_TARGET : superseded by ANDROID_ABI
12401240+# ARM_TARGETS : superseded by ANDROID_ABI (can be set only)
12411241+# ANDROID_NDK_TOOLCHAIN_ROOT : superseded by ANDROID_STANDALONE_TOOLCHAIN (can be set only)
12421242+# ANDROID_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed)
12431243+#
12441244+# Primary read-only variables:
12451245+# ANDROID : always TRUE
12461246+# ARMEABI : TRUE for arm v6 and older devices
12471247+# ARMEABI_V6 : TRUE for arm v6
12481248+# ARMEABI_V7A : TRUE for arm v7a
12491249+# NEON : TRUE if NEON unit is enabled
12501250+# VFPV3 : TRUE if VFP version 3 is enabled
12511251+# X86 : TRUE if configured for x86
12521252+# BUILD_ANDROID : always TRUE
12531253+# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used
12541254+# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used
12551255+# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform
12561256+# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a" or "x86" depending on ANDROID_ABI
12571257+# ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI
12581258+# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform
12591259+# ANDROID_SYSROOT : path to the compiler sysroot
12601260+# ANDROID_SYSTEM_INCLUDE_DIRS
12611261+# ANDROID_SYSTEM_LIB_DIRS
12621262+# Obsolete:
12631263+# ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME
12641264+#
12651265+# Secondary (less stable) read-only variables:
12661266+# ANDROID_COMPILER_VERSION : GCC version used
12671267+# ANDROID_C_FLAGS : C compiler flags required by Android platform
12681268+# ANDROID_CXX_FLAGS : C++ compiler flags required by Android platform
12691269+# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI
12701270+# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux"
12711271+# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK)
12721272+# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK
12731273+#
12741274+# Defaults:
12751275+# ANDROID_DEFAULT_NDK_API_LEVEL
12761276+# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH}
12771277+# ANDROID_NDK_SEARCH_PATHS
12781278+# ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH
12791279+# ANDROID_SUPPORTED_ABIS_${ARCH}
12801280+# ANDROID_SUPPORTED_NDK_VERSIONS
+10
AndroidCMake/clean_ndk.sh
···11+#!/bin/sh
22+33+(cd cmake_ndk_build
44+ for d in */ ; do
55+ (cd "$d"
66+ make clean
77+ )
88+ done
99+)
1010+
+630
AndroidCMake/genproj_android.pl
···11+#!/usr/bin/env perl -w
22+33+###########################################################
44+#
55+# Convenince script to generate CMake projects for Android
66+# for each architecture and build them.
77+# Copyright (C) PlayControl Software, LLC.
88+# Eric Wing <ewing . public @ playcontrol.net>
99+#
1010+# Convention:
1111+# You have created standalone toolchains and placed them in a directory called standalone under the $ANDROID_NDK_ROOT:
1212+# $ANDROID_NDK_ROOT/standalone/
1313+# arm-linux-androideabi-4.6/
1414+# x86-4.6/
1515+#
1616+##########################################################
1717+1818+1919+#use strict;
2020+use warnings;
2121+2222+# Function to help with command line switches
2323+use Getopt::Long;
2424+# Allows extra "unknown options" to be specified which I will use to pass directly to the cmake executable.
2525+Getopt::Long::Configure("pass_through");
2626+2727+# Function to get the basename of a file
2828+use File::Basename;
2929+# Used for tilde expansion
3030+use File::Glob;
3131+# for make_path (which is mkdir -p)
3232+use File::Path qw(make_path);
3333+3434+# Provides functions to convert relative paths to absolute paths.
3535+use Cwd;
3636+3737+use File::Basename;
3838+3939+# Global constants
4040+4141+my $kCMakeBootStrapCacheFile = "InitialCache_Android.cmake";
4242+4343+my %kArchToDirectoryNameMap =
4444+(
4545+# mips => "mips",
4646+ armeabi => "armeabi",
4747+ "armeabi-v7a" => "armeabi-v7a",
4848+# "armeabi-v7a with NEON" => "armeabi-v7a",
4949+# "armeabi-v7a with VFPV3" => "armeabi-v7a",
5050+# "armeabi-v6 with VFP" => "armeabi",
5151+ x86 => "x86"
5252+);
5353+5454+# Global constants
5555+my %kArchToCompilerNameMap =
5656+(
5757+# mips => "mips",
5858+ armeabi => "arm-linux-androideabi",
5959+ "armeabi-v7a" => "arm-linux-androideabi",
6060+# "armeabi-v7a with NEON" => "armeabi",
6161+# "armeabi-v7a with VFPV3" => "armeabi",
6262+# "armeabi-v6 with VFP" => "armeabi",
6363+ x86 => "x86"
6464+);
6565+6666+6767+my @kSupportedArchitectures =
6868+(
6969+# "mips",
7070+ "armeabi",
7171+ "armeabi-v7a",
7272+# "armeabi-v7a with NEON",
7373+# "armeabi-v7a with VFPV3",
7474+# "armeabi-v6 with VFP",
7575+ "x86",
7676+);
7777+7878+7979+# Function prototypes
8080+8181+# main routine
8282+sub main();
8383+# call main
8484+8585+sub main()
8686+{
8787+8888+ my ($blurrr_sdk_root,
8989+ $blurrr_sdk_path,
9090+ $cmake_source_dir,
9191+ $cmake_binary_dir,
9292+ $libsdir,
9393+ $android_sdk_root,
9494+ $standalone_toolchain_root,
9595+ $targetSdkVersion,
9696+ $minSdkVersion,
9797+ $compilerversion,
9898+ $buildtype,
9999+ $should_build,
100100+ $cmake_toolchain,
101101+ $cmake,
102102+ $architectures,
103103+ @remaining_options
104104+ ) = extract_parameters();
105105+106106+ my @architectures_array;
107107+108108+ if(not defined($architectures))
109109+ {
110110+ @architectures_array = @kSupportedArchitectures;
111111+ }
112112+ else
113113+ {
114114+ @architectures_array = split(/[ ,;]/, $architectures);
115115+ }
116116+117117+118118+119119+120120+ print("blurrr_sdk_root: ", $blurrr_sdk_root, "\n");
121121+ print("blurrr_sdk_path: ", $blurrr_sdk_path, "\n");
122122+ print("cmake_source_dir: ", $cmake_source_dir, "\n");
123123+ print("cmake_binary_dir: ", $cmake_binary_dir, "\n");
124124+ print("libsdir: ", $libsdir, "\n");
125125+126126+127127+ print("android_sdk_root: ", $android_sdk_root, "\n");
128128+ print("standalone_toolchain_root: ", $standalone_toolchain_root, "\n");
129129+ print("targetSdkVersion: ", $targetSdkVersion, "\n");
130130+ print("minSdkVersion: ", $minSdkVersion, "\n");
131131+# print("compilerversion: ", $compilerversion, "\n");
132132+ print("buildtype: ", $buildtype, "\n");
133133+ print("should_build: ", $should_build, "\n");
134134+ print("cmake_toolchain: ", $cmake_toolchain, "\n");
135135+ print("cmake: ", $cmake, "\n");
136136+137137+# print("remaining_options: ", @remaining_options, "\n");
138138+139139+140140+141141+ copy_build_scripts($cmake_source_dir, $cmake_binary_dir);
142142+143143+144144+145145+# my ($targetdir, $standalone, $compilerversion, $should_build, $cmake, $toolchain, $libsdir, $buildtype, $sourcedir, @remaining_options) = extract_parameters();
146146+147147+ # Save in case we need to return to the original current working directory.
148148+ my $original_current_working_directory = Cwd::cwd();
149149+150150+ foreach my $arch(@architectures_array)
151151+ {
152152+ # First choose the correct compiler.
153153+ my $found_compiler;
154154+ my $compiler_base_name = $kArchToCompilerNameMap{$arch};
155155+156156+ opendir(STANDALONEDIR, $standalone_toolchain_root) or die("Could not open standalone_toolchain_root directory: $!\n");
157157+ while(my $file = readdir(STANDALONEDIR))
158158+ {
159159+ my $full_path_and_file = "$standalone_toolchain_root/$file";
160160+161161+ # Go to the next file unless it is a directory
162162+ next unless(-d "$full_path_and_file");
163163+164164+ # if a version was specified, make sure it matches
165165+ if(defined($compilerversion))
166166+ {
167167+ if($file =~ m/$compiler_base_name-$compilerversion/)
168168+ {
169169+ $found_compiler = $full_path_and_file;
170170+ last;
171171+ }
172172+ }
173173+ # otherwise if no version was specified, just go for any match
174174+ else
175175+ {
176176+ if($file =~ m/$compiler_base_name/)
177177+ {
178178+ $found_compiler = $full_path_and_file;
179179+ last;
180180+ }
181181+ }
182182+ }
183183+ closedir(STANDALONEDIR);
184184+185185+ if(not defined $found_compiler)
186186+ {
187187+ die("Could not find compiler in directory:$standalone_toolchain_root for arch:$arch\n");
188188+ }
189189+190190+191191+192192+ chdir($cmake_binary_dir) or die("Could not change directory to $cmake_binary_dir: $!\n");
193193+ # Let's make an intermediate subdirectory for all the CMake NDK stuff we're going to create
194194+ my $cmake_ndk_build = "cmake_ndk_build";
195195+ unless(-e $cmake_ndk_build or mkdir $cmake_ndk_build)
196196+ {
197197+ die("Unable to create $cmake_ndk_build: $!\n");
198198+ }
199199+ chdir($cmake_ndk_build) or die("Could not change directory to $cmake_ndk_build: $!\n");
200200+201201+ my $arch_dir = $kArchToDirectoryNameMap{$arch};
202202+ unless(-e $arch_dir or mkdir $arch_dir)
203203+ {
204204+ die("Unable to create $arch_dir: $!\n");
205205+ }
206206+ chdir($arch_dir) or die("Could not change directory to $arch_dir: $!\n");
207207+208208+ my $android_standalone_toolchain = "$found_compiler";
209209+ print("Generating $arch\n");
210210+211211+ #my $initial_cache = "$blurrr_sdk_root/$kCMakeBootStrapCacheFile";
212212+ my $initial_cache = "$cmake_source_dir/AndroidCMake/$kCMakeBootStrapCacheFile";
213213+ my $suppress_dev_warnings_flags = "-Wno-dev";
214214+215215+ my $blurrr_path_to_use;
216216+ if(defined $blurrr_sdk_path)
217217+ {
218218+ $blurrr_path_to_use = "-DBLURRR_SDK_PATH=$blurrr_sdk_path";
219219+ }
220220+ else
221221+ {
222222+ $blurrr_path_to_use = "-DBLURRR_ROOT=$blurrr_sdk_root";
223223+ }
224224+225225+ # There is something screwing up the call when I do comma separated arguments.
226226+ my $command_string = "$cmake $suppress_dev_warnings_flags -DCMAKE_TOOLCHAIN_FILE=$cmake_toolchain $blurrr_path_to_use -DBLURRR_SDK_PATH=$blurrr_sdk_path -DANDROID_ABI=$arch -DBLURRR_CMAKE_ANDROID_REAL_BINARY_DIR=$cmake_binary_dir -DANDROID_SDK_ROOT=$android_sdk_root -C $initial_cache -DANDROID_STANDALONE_TOOLCHAIN=$android_standalone_toolchain -DANDROID_TARGET_SDK_VERSION=$targetSdkVersion -DANDROID_MIN_SDK_VERSION=$minSdkVersion -DLIBRARY_OUTPUT_PATH_ROOT=$libsdir -DCMAKE_BUILD_TYPE=$buildtype @remaining_options $cmake_source_dir";
227227+ #print("Executing: $cmake $cmake_toolchain $blurrr_root_flag $arch_flag $initial_cache $android_standalone_toolchain $libsdir $buildtype @remaining_options $cmake_source_dir\n");
228228+ print("Executing: $command_string\n\n");
229229+230230+#
231231+# /Volumes/DataPartition/Users/ewing/Source/Blurrr/Templates/DIST/CMake/CMake.app/Contents/bin/cmake -DCMAKE_TOOLCHAIN_FILE=/Volumes/DataPartition/Users/ewing/Source/Blurrr/Templates/DIST/Templates/C/CMakeModules/android.toolchain.cmake -DBLURRR_ROOT=/Volumes/DataPartition/Users/ewing/Source/Blurrr/Templates/DIST -DANDROID_ABI=armeabi -DBLURRR_CMAKE_ANDROID_REAL_BINARY_DIR=/Volumes/DataPartition/Users/ewing/TEMP/GradleCMakeTest -C /Volumes/DataPartition/Users/ewing/Source/Blurrr/Templates/DIST/bootstrap/InitialCache_C_Android.cmake -DANDROID_STANDALONE_TOOLCHAIN=/Library/Frameworks/Android/android-ndk-r9b/standalone/arm-linux-androideabi-4.6 -DLIBRARY_OUTPUT_PATH_ROOT=/Volumes/DataPartition/Users/ewing/TEMP/GradleCMakeTestapp/libs -DCMAKE_BUILD_TYPE=Release /Volumes/DataPartition/Users/ewing/Source/Blurrr/Templates/DIST/Templates/Cloading initial cache file /Volumes/DataPartition/Users/ewing/Source/Blurrr/Templates/DIST/bootstrap/InitialCache_C_Android.cmake
232232+ # Spaces in paths can really system() up, so the comma separated version is better because it is able to distinguish the difference between a space vs. multiple arguments.
233233+ my $error_status = system($cmake,
234234+ $suppress_dev_warnings_flags,
235235+ "-DCMAKE_TOOLCHAIN_FILE=$cmake_toolchain",
236236+ $blurrr_path_to_use,
237237+ "-DBLURRR_SDK_PATH=$blurrr_sdk_path",
238238+ "-DANDROID_ABI=$arch",
239239+ "-DBLURRR_CMAKE_ANDROID_REAL_BINARY_DIR=$cmake_binary_dir",
240240+ "-DANDROID_SDK_ROOT=$android_sdk_root",
241241+ "-C", $initial_cache,
242242+ "-DANDROID_STANDALONE_TOOLCHAIN=$android_standalone_toolchain",
243243+ "-DANDROID_TARGET_SDK_VERSION=$targetSdkVersion",
244244+ "-DANDROID_MIN_SDK_VERSION=$minSdkVersion",
245245+ "-DLIBRARY_OUTPUT_PATH_ROOT=$libsdir",
246246+ "-DCMAKE_BUILD_TYPE=$buildtype",
247247+ @remaining_options,
248248+ $cmake_source_dir
249249+ );
250250+# my $error_status = system($command_string);
251251+ if($error_status != 0)
252252+ {
253253+ die "Invoking CMake failed: $?\n";
254254+ }
255255+256256+ if($should_build)
257257+ {
258258+ print("Building $arch\n");
259259+ $error_status = system("make");
260260+ if($error_status != 0)
261261+ {
262262+ die "Invoking make failed: $?\n";
263263+ }
264264+ }
265265+ }
266266+267267+ return;
268268+269269+}
270270+271271+272272+sub helpmenu()
273273+{
274274+ my $basename = basename($0);
275275+ print "Convenience script for generating and building CMake based projects for Android (multiple architectures).\n\n";
276276+ print "Convention:\n";
277277+ print "You have created standalone toolchains and placed them in a directory called standalone under the \$ANDROID_NDK_ROOT:\n";
278278+ print "\$ANDROID_NDK_ROOT/standalone/\n";
279279+ print "\tarm-linux-androideabi-4.6/\n";
280280+ print "\tx86-4.6/\n";
281281+282282+ #print "Usage: perl $basename [-h | -help] --sourcedir=<path to source> --targetdir=<path to build dir> --toolchain=<CMake toolchain file> [--standalone=<standalone root directory>] [--cmake=<CMake exectuable>] [--buildtype=<None|Debug|Release*|RelWithDebInfo|MinSizeRel>] [<other flags passed to CMake>] <Project Source Directory>\n";
283283+ print "Usage: perl $basename [-h | -help] [<other flags passed to CMake>] <Project Source Directory>\n";
284284+285285+ print "Options:\n";
286286+ print " -h or -help Brings up this help display.\n";
287287+ print "\n";
288288+289289+ print "Required Options:\n";
290290+ print "<Project Source Directory> Path to the source code directory (containing the root CMakeLists.txt)\n";
291291+ print "\n";
292292+293293+ print "Semi-required Options (needed if required environmental variables are not set)\n";
294294+ print " --androidsdkroot=<path to Android SDK> Path to the Android SDK. The environmental variable ANDROID_SDK_ROOT or ANDROID_HOME is used if not provided.\n";
295295+ print " --standalonetoolchainroot=<path> Path to the root of the NDK standalone tool chain you are required to generate. The environmental variable BLURRR_ANDROID_STANDALONE_ANDROID_TOOLCHAIN_ROOT is used if not provided.\n";
296296+ print " --blurrrsdkpath=<path> Path to the SDK to use, e.g. ~/Blurrr/Libraries/Android/SDK/Lua_f32_i32. You may define this in an environmental variable. This acts as an overrride to BLURRR_ROOT.\n";
297297+ print "\n";
298298+299299+ print "Optional Options:\n";
300300+ print " --targetsdkversion=<version> Allows you to override the targetSdkVersion. Default detects the latest availabe in the SDK. (Best to use default.)\n";
301301+ print " --minsdkversion=<version> Allows you to override the minSdkVersion. Default is 14. (Going lower may cause your app to crash on older devices.)\n";
302302+ print " --architectures=<list;of;arches> Allows you to override which architectures to build. Default is \"armeabi;armeabi-v7a;x86\"\n";
303303+ print " --projectsourcedir=<path to source> Overrides the <Project Source Directory> if you need a --switch.\n";
304304+# print " --cmakebinarydir=<path to build dir> Path to where the CMake projects will be generated. Current directory is assumed and is generally better to use than this.\n";
305305+ print " --cmaketoolchain=<toolchain file> Path to and file of the CMake toolchain to use. Default finds the Android toolchain shipped in the Blurrr SDK.\n";
306306+# print " --libsdir=<path where libs are copied> Path where the built libs are placed. \n";
307307+ print " --compilerversion=<version> Allows you to specify the version number (4.6) of the compiler to disambiguate if you have multiple versions.\n";
308308+ print " --cmake=<CMake executable> Allows you to specify the path and file to the CMake executable. Default tries to find it in the Blurrr SDK or your environment.\n";
309309+ print " --buildtype=<build type> The CMake Build Type. Default is MinSizeRel. None|Debug|Release|RelWithDebInfo|MinSizeRel\n";
310310+ print " --[no]build Specifies whether make should be invoked. Default is nobuild.\n";
311311+ print "\n";
312312+ print "Example Usage:\n";
313313+ print "$basename ~/Source/Blurrr/Examples/Oblivion/OblivionC\n";
314314+315315+ return;
316316+}
317317+318318+sub home_dir()
319319+{
320320+ return File::Glob::bsd_glob("~");
321321+}
322322+323323+sub expand_tilde($)
324324+{
325325+ my $path = shift;
326326+ my $home_dir = home_dir();
327327+328328+ $path =~ s/^~/$home_dir/;
329329+ return $path;
330330+}
331331+332332+sub absolute_path($)
333333+{
334334+ my $file = shift;
335335+ return Cwd::abs_path(expand_tilde($file));
336336+}
337337+338338+sub get_path_of_main_script()
339339+{
340340+ my $dirname = dirname(__FILE__);
341341+ return absolute_path($dirname);
342342+# return $dirname;
343343+}
344344+345345+sub copy_build_scripts($$)
346346+{
347347+ my $cmake_source_dir = shift;
348348+ my $cmake_target_dir = shift;
349349+350350+351351+ my $copy = "cp";
352352+# my $flags = "-f";
353353+# my $exclude_flags = ' --exclude ".in"';
354354+ my $flags = '-f';
355355+ my $source_param = $cmake_source_dir . "/AndroidCMake/*_ndk.sh";
356356+ my $target_param = $cmake_target_dir;
357357+ my $command = "$copy $flags $source_param $target_param";
358358+359359+ print("Executing: $copy $flags $source_param $target_param\n");
360360+# my $error_status = system($rsync, $flags, $exclude_flags, $source_param, $target_param);
361361+ my $error_status = system($command);
362362+ if($error_status != 0)
363363+ {
364364+ die "Invoking copy failed: $?\n";
365365+ }
366366+}
367367+368368+sub sort_api_levels
369369+{
370370+ # $a and $b will be automatically defined by sort().
371371+ # Look up the position of the day in the week
372372+ # using the DAYS hash.
373373+ my ($api_level_a) = $a =~ /android-(\d+)/;
374374+ my ($api_level_b) = $b =~ /android-(\d+)/;
375375+376376+ # reverse sort
377377+ return $api_level_b <=> $api_level_a;
378378+379379+ # Now we can just compare $x and $y. Note, it
380380+ # would be simpler in this case to use the <=>
381381+ # operator.
382382+}
383383+384384+sub detect_highest_android_sdk_api_level($)
385385+{
386386+ my $sdk_root = shift;
387387+ my $sdk_platforms = $sdk_root . "/platforms";
388388+389389+ opendir(DIR, $sdk_platforms);
390390+ my @files = grep(/^android-\d+$/, readdir(DIR));
391391+ closedir(DIR);
392392+393393+ # Sort days in order using a sort algorithm
394394+ # contained in a function.
395395+ @files = sort sort_api_levels @files;
396396+397397+398398+# foreach $file(@files)
399399+# {
400400+# print "$file\n";
401401+# }
402402+403403+ my ($api_level) = $files[0] =~ /android-(\d+)/;
404404+ return $api_level;
405405+}
406406+407407+# Subroutine to extract and process command line parameters
408408+sub extract_parameters()
409409+{
410410+ # To follow the convention of the other bootstrap scripts and CMake itself,
411411+ # the last parameter is always the path to the source directory.
412412+ my $cmake_source_dir = $ARGV[$#ARGV];
413413+414414+ # Blurrr assumption: This Perl script is located at the root of the Blurrr SDK.
415415+ my $blurrr_sdk_root = get_path_of_main_script();
416416+417417+ my %params = (
418418+ h => \(my $hflag = 0),
419419+ help => \(my $helpflag = 0),
420420+ blurrrsdkpath => \(my $blurrr_sdk_path), # acts as an override for blurrr_sdk_root
421421+ projectsourcedir => \(my $projectsourcedir), # this is allowed to override $cmake_source_dir
422422+ cmakebinarydir => \(my $cmake_binary_dir), #
423423+ libsdir => \(my $libsdir),
424424+ androidsdkroot => \(my $android_sdk_root),
425425+ standalonetoolchainroot => \(my $standalone_toolchain_root),
426426+ targetsdkversion => \(my $targetSdkVersion),
427427+ minsdkversion => \(my $minSdkVersion = 14),
428428+ architectures => \(my $architectures),
429429+ compilerversion => \(my $compilerversion),
430430+ buildtype => \(my $buildtype = "MinSizeRel"),
431431+ build => \(my $should_build = 0),
432432+ cmaketoolchain => \(my $cmake_toolchain),
433433+ cmake => \(my $cmake)
434434+ );
435435+436436+437437+ # Call Library function which will extract and remove all switches and
438438+ # their corresponding values.
439439+ # These parameters will be removed from @ARGV
440440+ my $errorval = &GetOptions(\%params, "h", "help",
441441+ "blurrrsdkpath=s",
442442+ "projectsourcedir=s",
443443+ "cmakebinarydir=s",
444444+ "libsdir=s",
445445+ "androidsdkroot=s",
446446+ "standalonetoolchainroot=s",
447447+ "targetsdkversion=i",
448448+ "minsdkversion=i",
449449+ "architectures=s",
450450+ "compilerversion=s",
451451+ "buildtype=s",
452452+ "build!",
453453+ "cmaketoolchain=s",
454454+ "cmake=s"
455455+ );
456456+ # the exclaimation point allows for the negation
457457+ # of the switch (i.e. -nobackup/-nobody is a switch)
458458+459459+ # Error value should have returned 1 if nothing went wrong
460460+ # Otherwise, an unlisted parameter was specified.
461461+ if($errorval !=1)
462462+ {
463463+ # Expecting GetOptions to state error.
464464+465465+ print "Exiting Program...\n";
466466+ exit 0;
467467+ }
468468+469469+ if( ($hflag == 1) || ($helpflag == 1) )
470470+ {
471471+ helpmenu();
472472+ exit 0;
473473+ }
474474+475475+ if(not defined($projectsourcedir))
476476+ {
477477+ # $projectsourcedir = $cmake_source_dir;
478478+ }
479479+ else
480480+ {
481481+ $cmake_source_dir = $projectsourcedir;
482482+ }
483483+ # sanitize path
484484+ $cmake_source_dir = absolute_path($cmake_source_dir);
485485+486486+487487+ if(not defined($cmake_binary_dir))
488488+ {
489489+ # This is the current working directory following CMake conventions.
490490+ $cmake_binary_dir = absolute_path(getcwd());
491491+ }
492492+ # sanitize path
493493+ $cmake_binary_dir = absolute_path($cmake_binary_dir);
494494+495495+496496+497497+ if(not defined($libsdir))
498498+ {
499499+ $libsdir = $cmake_binary_dir . "/dist";
500500+ }
501501+502502+503503+ if(not defined($android_sdk_root))
504504+ {
505505+ $android_sdk_root = $ENV{"ANDROID_SDK_ROOT"} or $android_sdk_root = $ENV{"ANDROID_HOME"};
506506+ if(not defined($android_sdk_root))
507507+ {
508508+ print("androidsdkroot directory not specified or environmental variable ANDROID_SDK_ROOT not defined\n");
509509+ helpmenu();
510510+ exit 1;
511511+ }
512512+ }
513513+ # sanitize path
514514+ $android_sdk_root = absolute_path($android_sdk_root);
515515+516516+ if(not defined($blurrr_sdk_path))
517517+ {
518518+ $blurrr_sdk_path = $ENV{"BLURRR_SDK_PATH"};
519519+ if(not defined($blurrr_sdk_path))
520520+ {
521521+ $blurrr_sdk_path = undef;
522522+ }
523523+ }
524524+ else
525525+ {
526526+ $blurrr_sdk_path = absolute_path($blurrr_sdk_path);
527527+ }
528528+529529+530530+ if(not defined($standalone_toolchain_root))
531531+ {
532532+ $standalone_toolchain_root = $ENV{"BLURRR_ANDROID_STANDALONE_ANDROID_TOOLCHAIN_ROOT"};
533533+ if(not defined($standalone_toolchain_root))
534534+ {
535535+ print("standalonetoolchainroot root directory not specified or environmental variable BLURRR_ANDROID_STANDALONE_ANDROID_TOOLCHAIN_ROOT not defined\n");
536536+ helpmenu();
537537+ exit 2;
538538+ }
539539+540540+ }
541541+ # sanitize path
542542+ $standalone_toolchain_root = absolute_path($standalone_toolchain_root);
543543+544544+545545+546546+547547+548548+549549+ if(not defined($targetSdkVersion))
550550+ {
551551+ $targetSdkVersion = detect_highest_android_sdk_api_level($android_sdk_root);
552552+ }
553553+554554+ # test $architectures on return because it is too hard to pass multiple arrays back
555555+556556+ if(not defined($cmake_toolchain))
557557+ {
558558+ # We keep a copy of the toolchain in the PROJECT_SOURCE_DIR/CMakeModules directory
559559+ #$cmake_toolchain = $cmake_source_dir . "/CMakeModules/android.toolchain.cmake";
560560+ $cmake_toolchain = $cmake_source_dir . "/AndroidCMake/android.toolchain.cmake";
561561+ }
562562+563563+ if(not defined($cmake))
564564+ {
565565+ # Grrrr. On Mac & Windows, we ship CMake with the SDK, but on Linux we depend on package management.
566566+ $cmake = $blurrr_sdk_root . "/CMake/CMake.app/Contents/bin/cmake";
567567+ if(!(-f $cmake))
568568+ {
569569+ $cmake = $blurrr_sdk_root . "/CMake/bin/cmake.exe";
570570+ if(!(-f $cmake))
571571+ {
572572+ # assume it is in the path and Unix-y (no .exe)
573573+ $cmake = "cmake";
574574+ }
575575+ }
576576+ }
577577+ else
578578+ {
579579+ $cmake = absolute_path($cmake);
580580+ }
581581+582582+583583+ # Convert to absolute paths because we will be changing directories which will break relative paths.
584584+585585+ # We need to create the directory if it doesn't exist before calling absolute_path() on it.
586586+ unless(-e $libsdir or make_path($libsdir))
587587+ {
588588+ die("Unable to create $libsdir: $!\n");
589589+ }
590590+591591+592592+ $cmake_toolchain = absolute_path($cmake_toolchain);
593593+ $libsdir = absolute_path($libsdir);
594594+595595+596596+ # This can be optimized out, but is left for clarity.
597597+ # We already assumed the last parameter is the source dir and used it, so pop it.
598598+# pop @ARGV;
599599+600600+ # GetOptions has removed all found options so anything left in @ARGV is "remaining".
601601+ my @remaining_options = @ARGV;
602602+ pop @remaining_options;
603603+ # Remember, can't pass back 2 arrays or in the middle because it shifts everything
604604+605605+ my @sorted_options = (
606606+ $blurrr_sdk_root,
607607+ $blurrr_sdk_path,
608608+ $cmake_source_dir,
609609+ $cmake_binary_dir,
610610+ $libsdir,
611611+ $android_sdk_root,
612612+ $standalone_toolchain_root,
613613+ $targetSdkVersion,
614614+ $minSdkVersion,
615615+ $compilerversion,
616616+ $buildtype,
617617+ $should_build,
618618+ $cmake_toolchain,
619619+ $cmake,
620620+ $architectures,
621621+ @remaining_options
622622+ );
623623+ return @sorted_options;
624624+}
625625+626626+627627+print("calling main\n");
628628+main();
629629+630630+
+201
AndroidCMake/make_cmakeandroid.pl
···11+#!/usr/bin/perl -w
22+33+##################################################################
44+#
55+# Convenince script to invoke make on CMake projects for Android
66+# for each architecture and build them.
77+# Copyright (C) PlayControl Software, LLC.
88+# Eric Wing <ewing . public @ playcontrol.net>
99+#
1010+##################################################################
1111+1212+1313+use strict;
1414+use warnings;
1515+1616+# Function to help with command line switches
1717+use Getopt::Long;
1818+# Allows extra "unknown options" to be specified which I will use to pass directly to the cmake executable.
1919+Getopt::Long::Configure("pass_through");
2020+2121+# Function to get the basename of a file
2222+use File::Basename;
2323+# Used for tilde expansion
2424+use File::Glob;
2525+2626+# Provides functions to convert relative paths to absolute paths.
2727+use Cwd;
2828+2929+# Global constants
3030+my %kArchToDirectoryNameMap =
3131+(
3232+# mips => "mips",
3333+ armeabi => "armeabi",
3434+ "armeabi-v7a" => "armeabi-v7a",
3535+# "armeabi-v7a with NEON" => "armeabi-v7a",
3636+# "armeabi-v7a with VFPV3" => "armeabi-v7a",
3737+# "armeabi-v6 with VFP" => "armeabi",
3838+ x86 => "x86"
3939+);
4040+4141+# Global constants
4242+my %kArchToCompilerNameMap =
4343+(
4444+# mips => "mips",
4545+ armeabi => "arm-linux-androideabi",
4646+ "armeabi-v7a" => "arm-linux-androideabi",
4747+# "armeabi-v7a with NEON" => "armeabi",
4848+# "armeabi-v7a with VFPV3" => "armeabi",
4949+# "armeabi-v6 with VFP" => "armeabi",
5050+ x86 => "x86"
5151+);
5252+5353+5454+my @kSupportedArchitectures =
5555+(
5656+# "mips",
5757+ "armeabi",
5858+ "armeabi-v7a",
5959+# "armeabi-v7a with NEON",
6060+# "armeabi-v7a with VFPV3",
6161+# "armeabi-v6 with VFP",
6262+ "x86",
6363+);
6464+6565+6666+# Function prototypes
6767+6868+# main routine
6969+sub main();
7070+# call main
7171+main();
7272+7373+sub main()
7474+{
7575+ my ($targetdir, $make, @remaining_options) = extract_parameters();
7676+ # Save in case we need to return to the original current working directory.
7777+# my $original_current_working_directory = Cwd::cwd();
7878+7979+# print("targetdir: ", $targetdir, "\n");
8080+# print("make: ", $make, "\n");
8181+# print("remaining_options: ", @remaining_options, "\n");
8282+8383+8484+ foreach my $arch(@kSupportedArchitectures)
8585+ {
8686+ chdir($targetdir) or die("Could not change directory to $targetdir: $!\n");
8787+ my $arch_dir = $kArchToDirectoryNameMap{$arch};
8888+ print("Building $arch\n");
8989+ chdir($arch_dir) or die("Could not change directory to $arch_dir: $!\n");
9090+9191+ my $error_status = system($make, @remaining_options);
9292+ if($error_status != 0)
9393+ {
9494+ die "Invoking make failed: $?\n";
9595+ }
9696+9797+ }
9898+9999+ return;
100100+101101+}
102102+103103+104104+sub helpmenu()
105105+{
106106+ my $basename = basename($0);
107107+ print "Convenience script for invoking make on CMake based projects for Android (multiple architectures).\n\n";
108108+109109+ print "Usage: perl $basename [-h | -help] --targetdir=<path to build dir> [--make=<Make exectuable>] [<other flags passed to Make>]\n";
110110+111111+ print "Options:\n";
112112+ print " -h or -help Brings up this help display.\n";
113113+ print " --targetdir=<path to build directory> (Optional) Path to where the root of the build directory is. Default is the current working directory.\n";
114114+ print " --make=<Make executable> (Optional) Allows you to specify the path and file to the Make executable.\n";
115115+ print "\n";
116116+ print "Example Usage:\n";
117117+ print "$basename clean\n";
118118+ print "$basename VERBOSE=1\n";
119119+120120+ return;
121121+}
122122+123123+sub home_dir()
124124+{
125125+ return File::Glob::bsd_glob("~");
126126+}
127127+128128+sub expand_tilde($)
129129+{
130130+ my $path = shift;
131131+ my $home_dir = home_dir();
132132+133133+ $path =~ s/^~/$home_dir/;
134134+ return $path;
135135+}
136136+137137+sub absolute_path($)
138138+{
139139+ my $file = shift;
140140+ return Cwd::abs_path(expand_tilde($file));
141141+}
142142+143143+# Subroutine to extract and process command line parameters
144144+sub extract_parameters()
145145+{
146146+ my %params = (
147147+ h => \(my $hflag = 0),
148148+ help => \(my $helpflag = 0),
149149+ targetdir => \(my $targetdir),
150150+ make => \(my $make)
151151+ );
152152+153153+ # Call Library function which will extract and remove all switches and
154154+ # their corresponding values.
155155+ # These parameters will be removed from @ARGV
156156+ my $errorval = &GetOptions(\%params, "h", "help",
157157+ "targetdir=s",
158158+ "make=s"
159159+ );
160160+ # the exclaimation point allows for the negation
161161+ # of the switch (i.e. -nobackup/-nobody is a switch)
162162+163163+164164+ # Error value should have returned 1 if nothing went wrong
165165+ # Otherwise, an unlisted parameter was specified.
166166+ if($errorval !=1)
167167+ {
168168+ # Expecting GetOptions to state error.
169169+170170+ print "Exiting Program...\n";
171171+ exit 0;
172172+ }
173173+174174+ if( ($hflag == 1) || ($helpflag == 1) )
175175+ {
176176+ helpmenu();
177177+ exit 0;
178178+ }
179179+180180+ if(not defined($targetdir))
181181+ {
182182+ $targetdir = Cwd::cwd();
183183+ }
184184+185185+ if(not defined($make))
186186+ {
187187+ $make = "make";
188188+ }
189189+ else
190190+ {
191191+ $make = absolute_path($make);
192192+ }
193193+ $targetdir = absolute_path($targetdir);
194194+195195+ my @remaining_options = @ARGV;
196196+ my @sorted_options = ($targetdir, $make, @remaining_options);
197197+198198+ return @sorted_options;
199199+}
200200+201201+
+15
AndroidCMake/make_ndk.sh
···11+#!/bin/sh
22+33+(cd cmake_ndk_build
44+ for d in */ ; do
55+ (cd "$d"
66+ make -j2
77+ )
88+ done
99+)
1010+1111+1212+cp -f ../AndroidCMake/Android.mk dist
1313+mkdir -p dist/include
1414+rsync -avz ../SDL_image.h dist/include/
1515+
+6-6
CMakeLists.txt
···2828endif()
29293030option(SDL_gpu_INSTALL "Install SDL_gpu libs, includes, and CMake scripts" ${SDL_gpu_INSTALL_BY_DEFAULT})
3131-option(SDL_gpu_BUILD_DEBUG "Build with debugging symbols" ON)
3131+#option(SDL_gpu_BUILD_DEBUG "Build with debugging symbols" ON)
3232option(SDL_gpu_BUILD_DEMOS "Build SDL_gpu demo programs" ${SDL_gpu_DEFAULT_BUILD_DEMOS})
3333option(SDL_gpu_BUILD_TESTS "Build SDL_gpu test programs" OFF)
3434option(SDL_gpu_BUILD_VIDEO_TEST "Build SDL_gpu video test program (requires FFMPEG)" OFF)
···7373 include(ios-cmake/toolchain/XcodeDefaults)
7474endif()
75757676-if ( SDL_gpu_BUILD_DEBUG )
7777- SET(CMAKE_BUILD_TYPE Debug)
7878-else ( SDL_gpu_BUILD_DEBUG )
7979- SET(CMAKE_BUILD_TYPE Release)
8080-endif ( SDL_gpu_BUILD_DEBUG )
7676+#if ( SDL_gpu_BUILD_DEBUG )
7777+# SET(CMAKE_BUILD_TYPE Debug)
7878+#else ( SDL_gpu_BUILD_DEBUG )
7979+# SET(CMAKE_BUILD_TYPE Release)
8080+#endif ( SDL_gpu_BUILD_DEBUG )
81818282# Find the package for SDL or SDL2
8383if ( SDL_gpu_USE_SDL1 )