this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Branch to track Blurrr changes. Current changes are disabling hardcoded debug/release overrides in official CMake, and Android support build scripts.

Eric Wing dd359b1f b623860c

+2318 -6
+87
AndroidCMake/Android.mk
··· 1 + # Copyright (C) PlayControl Software, LLC. 2 + # Eric Wing <ewing . public @ playcontrol.net> 3 + # 4 + # This is a "Prebuilt" Android Makefile provided as an example/template (or direct use if no tweaking is required). 5 + # The idea is that you have already built the lua .so and .a libraries using CMake. 6 + # Now you want to use those prebuilt libraries in your own project. 7 + # 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. 8 + # 9 + # This file assumes you built all your lua libs and put things into a directory structure like so: 10 + # 11 + # Android.mk (this file) 12 + # libs/armeabi/liblua.a 13 + # libs/armeabi/liblua.so 14 + # libs/armeabi-v7a/liblua.a 15 + # libs/armeabi-v7a/liblua.so 16 + # libs/x86/liblua.a 17 + # libs/x86/liblua.so 18 + # 19 + # include/lua/lua.h 20 + # ... (the other header files here) 21 + # 22 + # Note that this file is copied into the directory above libs and include. 23 + # Below is the code you need to make this Makefile export the correct headers, libraries, and flags for both dynamic and static versions. 24 + 25 + # LOCAL_PATH needs to be before include 26 + LOCAL_PATH := $(call my-dir) 27 + 28 + # For the dynamic library 29 + include $(CLEAR_VARS) 30 + # This is the name of module the caller will use in LOCAL_SHARED_LIBRARIES 31 + LOCAL_MODULE := SDL_gpu_shared 32 + LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libSDL2_gpu.so 33 + LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 34 + # 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. 35 + # LOCAL_EXPORT_CFLAGS := 36 + # The .so is already linked so we don't really need to export this. 37 + #LOCAL_EXPORT_LDLIBS := -lm 38 + include $(PREBUILT_SHARED_LIBRARY) 39 + 40 + 41 + ## For the static library 42 + #include $(CLEAR_VARS) 43 + ## This is the name of module the caller will use in LOCAL_STATIC_LIBRARIES 44 + #LOCAL_MODULE := ALmixerLuaBindings_static 45 + #LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libALmixerLuaBindings.a 46 + # 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. 47 + #LOCAL_EXPORT_CFLAGS := 48 + ## Since the .a isn't linked, it's link dependencies must be passed on to the calling project. 49 + # LOCAL_EXPORT_LDLIBS := 50 + #LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/lua 51 + #include $(PREBUILT_STATIC_LIBRARY) 52 + 53 + 54 + 55 + # Two other pieces are needed to make this work which fall outside the scope of this file. 56 + # First, you must have a directory convention for the calling makefile. 57 + # So let's say we put all the above in a directory called lua. The layout looks like this: 58 + # lua/ 59 + # Android.mk (this file) 60 + # libs/armeabi/liblua.a 61 + # libs/armeabi/liblua.so 62 + # libs/armeabi-v7a/liblua.a 63 + # libs/armeabi-v7a/liblua.so 64 + # libs/x86/liblua.a 65 + # libs/x86/liblua.so 66 + # 67 + # include/lua.h 68 + # ... (the other header files here) 69 + 70 + # So the calling makefile looks something like: 71 + # LOCAL_PATH := $(call my-dir) 72 + # include $(CLEAR_VARS) 73 + # LOCAL_MODULE := hello-jni 74 + # LOCAL_SRC_FILES := hello-jni.c 75 + # 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. 76 + # LOCAL_SHARED_LIBRARIES := lua_shared 77 + # #LOCAL_STATIC_LIBRARIES := lua_static 78 + # include $(BUILD_SHARED_LIBRARY) 79 + # Android build system will look for folder `lua` in all import paths: 80 + # $(call import-module,lua) 81 + # ------ end ----- 82 + 83 + # Second, you need to set the environmental variable NDK_MODULE_PATH to list the directory containing lua. 84 + # So if lua is in /Library/Frameworks/Android/PrebuiltModules 85 + # export NDK_MODULE_PATH=/Library/Frameworks/Android/PrebuiltModules 86 + # Note that NDK_MODULE_PATH may contain multiple directories like the PATH environmental variable. 87 +
+80
AndroidCMake/InitialCache_Android.cmake
··· 1 + 2 + # Required BLURRR_SDK_ROOT to be passed in or env 3 + IF(NOT BLURRR_ROOT) 4 + IF(NOT DEFINED ENV{BLURRR_ROOT}) 5 + MESSAGE(AUTHOR_WARNING "BLURRR_SDK_ROOT not passed in") 6 + ELSE() 7 + SET(BLURRR_ROOT $ENV{BLURRR_ROOT}) 8 + ENDIF() 9 + ENDIF() 10 + 11 + # Probably want to use this form 12 + IF(NOT BLURRR_SDK_PATH) 13 + IF(DEFINED ENV{BLURRR_SDK_PATH}) 14 + SET(BLURRR_SDK_PATH $ENV{BLURRR_SDK_PATH}) 15 + ENDIF() 16 + MESSAGE("ENV BLURRR_SDK_PATH $ENV{BLURRR_SDK_PATH}") 17 + 18 + ENDIF() 19 + MESSAGE("BLURRR_SDK_PATH ${BLURRR_SDK_PATH}") 20 + 21 + # CMake doesn't know how to handle multiple architectures. 22 + # So we must manually fake it by running CMake multiple times, each time specifying the architecture. 23 + IF(NOT ANDROID_ABI) 24 + MESSAGE(FATAL_ERROR "ANDROID_ABI not passed in") 25 + ENDIF() 26 + IF(NOT BLURRR_CMAKE_ANDROID_REAL_BINARY_DIR) 27 + MESSAGE(FATAL_ERROR "BLURRR_CMAKE_ANDROID_REAL_BINARY_DIR not passed in") 28 + ENDIF() 29 + 30 + 31 + # Allow for the possibility that the user defined CMAKE_LIBRARY_PATH, etc. and the normal CMake stuff will work without the initial cache. 32 + IF(BLURRR_ROOT OR BLURRR_SDK_PATH) 33 + IF(NOT BLURRR_SDK_PATH) 34 + # Convenience variables 35 + SET(BLURRR_SDK_PATH "${BLURRR_ROOT}/Libraries/Android/SDK/C" CACHE INTERNAL "Blurrr SDK path. (Read-only)") 36 + ENDIF() 37 + 38 + # Note: The layout is a little different than the other platforms. 39 + # This is because I'm trying to conform to the official NDK_MODULE_PATH external module system. 40 + # The Android system has a hard limitation in that it requires environmental variables 41 + # which Android Studio refuses to support, 42 + # and the other hard limitation in that it can't handle any modules in paths with spaces. 43 + # This is one reason I'm not directly using it. 44 + # But for advanced use cases that need to link to my modules that don't use this 45 + # build system, it is really handy to comply with this official mechanism. 46 + 47 + # Because we are generating CMake multiple times in their own little subdirectories, 48 + # we need an anchor back to the real build directory root so the build system can interact with 49 + # shared/common stuff like resources. 50 + SET(BLURRR_CMAKE_ANDROID_REAL_BINARY_DIR "${BLURRR_CMAKE_ANDROID_REAL_BINARY_DIR}" CACHE INTERNAL "Real CMake binary directory. (Read-only)") 51 + 52 + 53 + # SET(BLURRR_INCLUDE_PATH "${BLURRR_SDK_PATH}/include" CACHE STRING "Blurrr SDK include path. (Read-only)") 54 + # SET(BLURRR_LIBRARY_PATH "${BLURRR_SDK_PATH}/libs/${BLURRR_ANDROID_ARCH}" CACHE STRING "Blurrr SDK library path. (Read-only)") 55 + 56 + # SET(ALMIXER_INCLUDE_DIR "${BLURRR_SDK_PATH}/ALmixer/include" CACHE STRING "ALmixer include directory") 57 + # SET(ALMIXER_LIBRARY "${BLURRR_SDK_PATH}/ALmixer/libs/${ANDROID_ABI}/libALmixer.so" CACHE STRING "ALmixer library") 58 + 59 + # SET(OPENAL_INCLUDE_DIR "${BLURRR_SDK_PATH}/openal-soft/jni/OpenAL/include/AL" CACHE STRING "OpenAL include directory") 60 + # SET(OPENAL_LIBRARY "${BLURRR_SDK_PATH}/openal-soft/libs/${ANDROID_ABI}/libopenal.so" CACHE STRING "OpenAL library") 61 + 62 + # SET(CHIPMUNK_INCLUDE_DIR "${BLURRR_SDK_PATH}/chipmunk/include/chipmunk" CACHE STRING "Chipmunk include directory") 63 + # SET(CHIPMUNK_LIBRARY "${BLURRR_SDK_PATH}/chipmunk/libs/${ANDROID_ABI}/libchipmunk.so" CACHE STRING "Chipmunk library") 64 + 65 + SET(SDL_INCLUDE_DIR "${BLURRR_SDK_PATH}/SDL2/include" CACHE STRING "SDL include directory") 66 + SET(SDL_LIBRARY "${BLURRR_SDK_PATH}/SDL2/libs/${ANDROID_ABI}/libSDL2.so" CACHE STRING "SDL library") 67 + SET(SDL_LIBRARY_MAIN "${BLURRR_SDK_PATH}/SDL2/libs/${ANDROID_ABI}/libSDL2main.so" CACHE STRING "SDLmain library") 68 + 69 + SET(SDL2_INCLUDE_DIR "${BLURRR_SDK_PATH}/SDL2/include" CACHE STRING "SDL include directory") 70 + SET(SDL2_LIBRARY "${BLURRR_SDK_PATH}/SDL2/libs/${ANDROID_ABI}/libSDL2.so" CACHE STRING "SDL library") 71 + SET(SDL2_LIBRARY_MAIN "${BLURRR_SDK_PATH}/SDL2/libs/${ANDROID_ABI}/libSDL2main.so" CACHE STRING "SDLmain library") 72 + 73 + 74 + 75 + # SET(LUA_INCLUDE_DIR "${BLURRR_SDK_PATH}/lua/include" CACHE STRING "Lua include directory") 76 + # SET(LUA_LIBRARY "${BLURRR_SDK_PATH}/lua/libs/${ANDROID_ABI}/liblua.so" CACHE STRING "Lua library") 77 + 78 + 79 + 80 + ENDIF(BLURRR_ROOT OR BLURRR_SDK_PATH)
+9
AndroidCMake/README.txt
··· 1 + #!/bin/sh 2 + 3 + mkdir buildandroidcmake 4 + cd buildandroidcmake 5 + rm -rf SDL_image 6 + ../AndroidCMake/genproj_android.pl --blurrrsdkpath=~/Source/Blurrr/Release/Blurrr_Apple_DP1/Libraries/Android/SDK/C --standalonetoolchainroot=$ANDROID_NDK_ROOT/standalone .. 7 + ./make_ndk.sh 8 + mv dist SDL_image 9 +
+1280
AndroidCMake/android.toolchain.cmake
··· 1 + # ------------------------------------------------------------------------------ 2 + # Android CMake toolchain file, for use with the Android NDK r5-r8 3 + # Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). 4 + # See home page: http://code.google.com/p/android-cmake/ 5 + # 6 + # The file is mantained by the OpenCV project. And also can be found at 7 + # http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake 8 + # 9 + # Note: There are now two flavors of this toolchain file: 32-bit toolchain and 64-bit toolchain. 10 + # 11 + # Usage Linux: 12 + # $ export ANDROID_NDK_ROOT=/absolute/path/to/the/android-ndk 13 + # $ mkdir build && cd build 14 + # $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. 15 + # $ make -j8 16 + # 17 + # Usage Linux (using standalone toolchain): 18 + # $ export ANDROID_STANDALONE_TOOLCHAIN=/absolute/path/to/android-toolchain 19 + # $ mkdir build && cd build 20 + # $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. 21 + # $ make -j8 22 + # 23 + # Usage Windows: 24 + # You need native port of make to build your project. 25 + # Android NDK r7 (or newer) already has make.exe on board. 26 + # For older NDK you have to install it separately. 27 + # For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm 28 + # 29 + # $ SET ANDROID_NDK_ROOT=C:\absolute\path\to\the\android-ndk 30 + # $ mkdir build && cd build 31 + # $ cmake.exe -G"MinGW Makefiles" 32 + # -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake 33 + # -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK_ROOT%\prebuilt\windows\bin\make.exe" .. 34 + # $ "%ANDROID_NDK_ROOT%\prebuilt\windows\bin\make.exe" 35 + # 36 + # 37 + # Options (can be set as cmake parameters: -D<option_name>=<value>): 38 + # ANDROID_NDK=/opt/android-ndk - path to the NDK root. 39 + # Can be set as environment variable ANDROID_NDK_ROOT. Can be set only at first cmake run. 40 + # 41 + # ANDROID_STANDALONE_TOOLCHAIN=/opt/android-toolchain - path to the 42 + # standalone toolchain. This option overrides ANDROID_NDK 43 + # (and subsequentally the enviroment variable ANDROID_NDK_ROOT). 44 + # Can be set as environment variable. Can be set only at first cmake run. 45 + # 46 + # ANDROID_ABI=armeabi-v7a - specifies the target Application Binary 47 + # Interface (ABI). This option nearly matches to the APP_ABI variable 48 + # used by ndk-build tool from Android NDK. 49 + # 50 + # Possible targets are: 51 + # "armeabi" - matches to the NDK ABI with the same name. 52 + # See ${ANDROID_NDK_ROOT}/docs/CPU-ARCH-ABIS.html for the documentation. 53 + # "armeabi-v7a" - matches to the NDK ABI with the same name. 54 + # See ${ANDROID_NDK_ROOT}/docs/CPU-ARCH-ABIS.html for the documentation. 55 + # "armeabi-v7a with NEON" - same as armeabi-v7a, but 56 + # sets NEON as floating-point unit 57 + # "armeabi-v7a with VFPV3" - same as armeabi-v7a, but 58 + # sets VFPV3 as floating-point unit (has 32 registers instead of 16). 59 + # "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP. 60 + # "x86" - matches to the NDK ABI with the same name. 61 + # See ${ANDROID_NDK_ROOT}/docs/CPU-ARCH-ABIS.html for the documentation. 62 + # "mips" - matches to the NDK ABI with the same name 63 + # (not testes on real devices) 64 + # 65 + # ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. 66 + # Option is read-only when standalone toolchain used. 67 + # 68 + # ANDROID_FORCE_ARM_BUILD=OFF - set true to generate 32-bit ARM instructions 69 + # instead of Thumb-1. Is not available for "x86" (inapplicable) and 70 + # "armeabi-v6 with VFP" (forced) ABIs. 71 + # 72 + # ANDROID_NO_UNDEFINED=ON - set true to show all undefined symbols as linker 73 + # errors even if they are not used. 74 + # 75 + # ANDROID_SO_UNDEFINED=OFF - set true to allow undefined symbols in shared 76 + # libraries. Automatically turned on for NDK r5x and r6x due to GLESv2 77 + # problems. 78 + # 79 + # LIBRARY_OUTPUT_PATH_ROOT=${CMAKE_SOURCE_DIR} - where to output binary 80 + # files. See additional details below. 81 + # 82 + # ANDROID_SET_OBSOLETE_VARIABLES=ON - it set, then toolchain defines some 83 + # obsolete variables which were set by previous versions of this file for 84 + # backward compatibility. 85 + # 86 + # 87 + # What?: 88 + # android-cmake toolchain searches for NDK/toolchain in the following order: 89 + # ANDROID_NDK - cmake parameter 90 + # ANDROID_NDK_ROOT - environment variable 91 + # (ANDROID_NDK - environment variable as legacy fallback) 92 + # ANDROID_STANDALONE_TOOLCHAIN - cmake parameter 93 + # ANDROID_STANDALONE_TOOLCHAIN - environment variable 94 + # ANDROID_NDK - default locations 95 + # ANDROID_STANDALONE_TOOLCHAIN - default locations 96 + # 97 + # Make sure to do the following in your scripts: 98 + # SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" ) 99 + # SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" ) 100 + # The flags will be prepopulated with critical flags, so don't loose them. 101 + # Also be aware that toolchain also sets configuration-specific compiler 102 + # flags and linker flags. 103 + # 104 + # ANDROID and BUILD_ANDROID will be set to true, you may test any of these 105 + # variables to make necessary Android-specific configuration changes. 106 + # 107 + # Also ARMEABI or ARMEABI_V7A or X86 will be set true, mutually exclusive. 108 + # NEON option will be set true if VFP is set to NEON. 109 + # 110 + # LIBRARY_OUTPUT_PATH_ROOT should be set in cache to determine where Android 111 + # libraries will be installed. 112 + # Default is ${CMAKE_SOURCE_DIR}, and the android libs will always be 113 + # under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME} 114 + # (depending on the target ABI). This is convenient for Android packaging. 115 + # 116 + # Authors: 117 + # Ethan Rublee ethan.ruble@gmail.com 118 + # Andrey Kamaev andrey.kamaev@itseez.com 119 + # Eric Wing <ewing . public |-at-| gmail . com> 120 + # 121 + # Change Log: 122 + # - initial version December 2010 123 + # - modified April 2011 124 + # [+] added possibility to build with NDK (without standalone toolchain) 125 + # [+] support cross-compilation on Windows (native, no cygwin support) 126 + # [+] added compiler option to force "char" type to be signed 127 + # [+] added toolchain option to compile to 32-bit ARM instructions 128 + # [+] added toolchain option to disable SWIG search 129 + # [+] added platform "armeabi-v7a with VFPV3" 130 + # [~] ARM_TARGETS renamed to ARM_TARGET 131 + # [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows) 132 + # [~] Fixed bug with ANDROID_API_LEVEL variable 133 + # [~] turn off SWIG search if it is not found first time 134 + # - modified May 2011 135 + # [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL 136 + # [+] ANDROID_API_LEVEL is detected by toolchain if not specified 137 + # [~] added guard to prevent changing of output directories on the first 138 + # cmake pass 139 + # [~] toolchain exits with error if ARM_TARGET is not recognized 140 + # - modified June 2011 141 + # [~] default NDK path is updated for version r5c 142 + # [+] variable CMAKE_SYSTEM_PROCESSOR is set based on ARM_TARGET 143 + # [~] toolchain install directory is added to linker paths 144 + # [-] removed SWIG-related stuff from toolchain 145 + # [+] added macro find_host_package, find_host_program to search 146 + # packages/programs on the host system 147 + # [~] fixed path to STL library 148 + # - modified July 2011 149 + # [~] fixed options caching 150 + # [~] search for all supported NDK versions 151 + # [~] allowed spaces in NDK path 152 + # - modified September 2011 153 + # [~] updated for NDK r6b 154 + # - modified November 2011 155 + # [*] rewritten for NDK r7 156 + # [+] x86 toolchain support (experimental) 157 + # [+] added "armeabi-v6 with VFP" ABI for ARMv6 processors. 158 + # [~] improved compiler and linker flags management 159 + # [+] support different build flags for Release and Debug configurations 160 + # [~] by default compiler flags the same as used by ndk-build (but only 161 + # where reasonable) 162 + # [~] ANDROID_NDK_TOOLCHAIN_ROOT is splitted to ANDROID_STANDALONE_TOOLCHAIN 163 + # and ANDROID_TOOLCHAIN_ROOT 164 + # [~] ARM_TARGET is renamed to ANDROID_ABI 165 + # [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME 166 + # [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL 167 + # - modified January 2012 168 + # [+] added stlport_static support (experimental) 169 + # [+] added special check for cygwin 170 + # [+] filtered out hidden files (starting with .) while globbing inside NDK 171 + # [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6 172 + # [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags 173 + # - modified February 2012 174 + # [+] updated for NDK r7b 175 + # [~] fixed cmake try_compile() command 176 + # [~] Fix for missing install_name_tool on OS X 177 + # - modified March 2012 178 + # [~] fixed incorrect C compiler flags 179 + # [~] fixed CMAKE_SYSTEM_PROCESSOR change on ANDROID_ABI change 180 + # [+] improved toolchain loading speed 181 + # [+] added assembler language support (.S) 182 + # [+] allowed preset search paths and extra search suffixes 183 + # - modified April 2012 184 + # [+] updated for NDK r7c 185 + # [~] fixed most of problems with compiler/linker flags and caching 186 + # [+] added option ANDROID_FUNCTION_LEVEL_LINKING 187 + # - modified May 2012 188 + # [+] updated for NDK r8 189 + # [+] added mips architecture support 190 + # - modified August 2012 191 + # [+] updated for NDK r8b 192 + # [~] all intermediate files generated by toolchain are moved into CMakeFiles 193 + # [~] libstdc++ and libsupc are removed from explicit link libraries 194 + # - modified August 2013 (EW) 195 + # [+] updated for NDK r9 (standalone) 196 + # [+] Addded Perl helper scripts to make it easier to build multiple architectures in one shot. 197 + # [~] 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. 198 + # [~] 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. 199 + # [~] 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. 200 + # [~] Changed armeabi-v7a to use -mfpu=vfpv3-d16 instead of -mfpu=vfp to conform with stock Android. 201 + # [~] Changed VFPV3 mode to use -mfpu=vfpv3-d32 202 + # [~] Use --sysroot=${ANDROID_SYSROOT} to match stock Android 203 + # [~] Use -fstack-protector -no-canonical-prefixes -Wa,--noexecstack to match stock Android 204 + # [~] Use -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now to match stock Android 205 + # [~] Use -lc -lm to match stock Android 206 + # [~] Removed -fsigned-char and -Wno-psabi because these don't appear in stock Android 207 + # [~] Removed -f[no]exceptions flags from C flags because those are C++ options 208 + # [~] Changed arm debug optimization level to O0 from Os 209 + # [~] Added -funswitch-loops -finline-limit=300 to match stock Android 210 + # [~] Changed arm debug optimization level to O0 from Os 211 + # [~] Separated ANDROID_CXX_FLAGS into ANDROID_CXX_FLAGS and ANDROID_C_FLAGS 212 + # [*] Note: MIPs settings were not changed/tested. 213 + # 214 + # 215 + # (EW) Additional Notes: 216 + # Looking at the switches used by compiling the hello-jni example from ndk-build V=1 in r8d, I see the following compiler flags: 217 + # armeabi 218 + # -MMD -MP -MF /foo/hello-jni.o.d 219 + # -fpic -ffunction-sections -funwind-tables -fstack-protector 220 + # -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -no-canonical-prefixes 221 + # -march=armv5te -mtune=xscale -msoft-float 222 + # -mthumb 223 + # -Os -g -DNDEBUG 224 + # -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 225 + # 226 + # -O0 -UNDEBUG (debug only, not in release) 227 + # -marm -fno-omit-frame-pointer (debug only, not in release) 228 + # 229 + # -DANDROID -Wa,--noexecstack 230 + 231 + 232 + # armeabi-v7a 233 + # -MMD -MP -MF /foo/hello-jni.o.d 234 + # -fpic -ffunction-sections -funwind-tables -fstack-protector 235 + # -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -no-canonical-prefixes 236 + # -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 237 + # -mthumb 238 + # -Os -g -DNDEBUG 239 + # -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 240 + # 241 + # -O0 -UNDEBUG (debug only, not in release) 242 + # -marm -fno-omit-frame-pointer (debug only, not in release) 243 + # 244 + # -DANDROID -Wa,--noexecstack 245 + 246 + # x86 247 + # -MMD -MP -MF /foo/hello-jni.o.d 248 + # -ffunction-sections -funwind-tables -no-canonical-prefixes -fstack-protector 249 + # -O2 -g -DNDEBUG 250 + # -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300 251 + # 252 + # -O0 -UNDEBUG (debug only, not in release) 253 + # -fno-omit-frame-pointer -fno-strict-aliasing (debug only, not in release) 254 + # 255 + # -DANDROID -Wa,--noexecstack 256 + 257 + # The link flags are: 258 + 259 + 260 + # armeabi 261 + # -Wl,-soname,libhello-jni.so -shared 262 + # --sysroot=/fee/android-ndk/platforms/android-14/arch-arm 263 + # /foo/hello-jni.o 264 + # -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -lc -lm 265 + 266 + # armeabi-v7a 267 + # -Wl,-soname,libhello-jni.so -shared 268 + # --sysroot=/fee/android-ndk/platforms/android-14/arch-arm 269 + # /foo/hello-jni.o 270 + # -no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -lc -lm 271 + 272 + # x86 273 + # -Wl,-soname,libhello-jni.so -shared 274 + # --sysroot=/fee/android-ndk/platforms/android-14/arch-x86 275 + # /foo/hello-jni.o 276 + # -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -lc -lm 277 + 278 + 279 + # Some interesting observations are that debug doesn't have different flags, but overrides set flags with additional switches. 280 + 281 + # Differences from Stock Android: 282 + # This toolchain has deviated from the stock flags. 283 + # 284 + # I don't do the override technique as described directly above. 285 + # 286 + # -ffunction-sections has been separated into the option ANDROID_FUNCTION_LEVEL_LINKING. 287 + # But this also brings in -fdata-sections and the linker flags -Wl,--gc-sections which are not in the Android defaults 288 + # 289 + # -funwind-tables has been completely removed for arm by this file. It looks like the author intentionally did this for performance. 290 + # 291 + # 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. 292 + # I am however changing the Os to O0 for debug. 293 + # 294 + # ------------------------------------------------------------------------------ 295 + 296 + cmake_minimum_required( VERSION 2.6.3 ) 297 + 298 + if( DEFINED CMAKE_CROSSCOMPILING ) 299 + # subsequent toolchain loading is not really needed 300 + return() 301 + endif() 302 + 303 + get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) 304 + if( _CMAKE_IN_TRY_COMPILE ) 305 + include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL ) 306 + endif() 307 + 308 + # this one is important 309 + set( CMAKE_SYSTEM_NAME Linux ) 310 + # this one not so much 311 + set( CMAKE_SYSTEM_VERSION 1 ) 312 + 313 + # There was an Android NDK bug with armv7 and vfpv3 in r7b which caused crashes according to 314 + # http://stackoverflow.com/questions/11831648/android-ndk-arm-build-settings-to-run-on-most-devices 315 + # 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. 316 + #set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8d -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) 317 + set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r9 -r8d -r8b -r8 -r7c "" ) 318 + if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) 319 + if( CMAKE_HOST_WIN32 ) 320 + file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) 321 + set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}/android-ndk" "$ENV{SystemDrive}/NVPACK/android-ndk" ) 322 + else() 323 + file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS ) 324 + set( ANDROID_NDK_SEARCH_PATHS /opt/android-ndk "${ANDROID_NDK_SEARCH_PATHS}/NVPACK/android-ndk" ) 325 + endif() 326 + endif() 327 + if(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH) 328 + set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) 329 + endif() 330 + 331 + set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" ) 332 + set( ANDROID_SUPPORTED_ABIS_x86 "x86" ) 333 + set( ANDROID_SUPPORTED_ABIS_mipsel "mips" ) 334 + 335 + set( ANDROID_DEFAULT_NDK_API_LEVEL 8 ) 336 + set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 ) 337 + set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 ) 338 + 339 + 340 + macro( __LIST_FILTER listvar regex ) 341 + if( ${listvar} ) 342 + foreach( __val ${${listvar}} ) 343 + if( __val MATCHES "${regex}" ) 344 + list( REMOVE_ITEM ${listvar} "${__val}" ) 345 + endif() 346 + endforeach() 347 + endif() 348 + endmacro() 349 + 350 + macro( __INIT_VARIABLE var_name ) 351 + set( __test_path 0 ) 352 + foreach( __var ${ARGN} ) 353 + if( __var STREQUAL "PATH" ) 354 + set( __test_path 1 ) 355 + break() 356 + endif() 357 + endforeach() 358 + if( __test_path AND NOT EXISTS "${${var_name}}" ) 359 + unset( ${var_name} CACHE ) 360 + endif() 361 + if( "${${var_name}}" STREQUAL "" ) 362 + set( __values 0 ) 363 + foreach( __var ${ARGN} ) 364 + if( __var STREQUAL "VALUES" ) 365 + set( __values 1 ) 366 + elseif( NOT __var STREQUAL "PATH" ) 367 + set( __obsolete 0 ) 368 + if( __var MATCHES "^OBSOLETE_.*$" ) 369 + string( REPLACE "OBSOLETE_" "" __var "${__var}" ) 370 + set( __obsolete 1 ) 371 + endif() 372 + if( __var MATCHES "^ENV_.*$" ) 373 + string( REPLACE "ENV_" "" __var "${__var}" ) 374 + set( __value "$ENV{${__var}}" ) 375 + elseif( DEFINED ${__var} ) 376 + set( __value "${${__var}}" ) 377 + else() 378 + if( __values ) 379 + set( __value "${__var}" ) 380 + else() 381 + set( __value "" ) 382 + endif() 383 + endif() 384 + if( NOT "${__value}" STREQUAL "" ) 385 + if( __test_path ) 386 + if( EXISTS "${__value}" ) 387 + set( ${var_name} "${__value}" ) 388 + if( __obsolete ) 389 + 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." ) 390 + endif() 391 + break() 392 + endif() 393 + else() 394 + set( ${var_name} "${__value}" ) 395 + if( __obsolete ) 396 + 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." ) 397 + endif() 398 + break() 399 + endif() 400 + endif() 401 + endif() 402 + endforeach() 403 + unset( __value ) 404 + unset( __values ) 405 + unset( __obsolete ) 406 + endif() 407 + unset( __test_path ) 408 + endmacro() 409 + 410 + macro( __DETECT_NATIVE_API_LEVEL _var _path ) 411 + SET( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*$" ) 412 + FILE( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) 413 + if( NOT __apiFileContent ) 414 + 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." ) 415 + endif() 416 + string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) 417 + unset( __apiFileContent ) 418 + unset( __ndkApiLevelRegex ) 419 + endmacro() 420 + 421 + macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) 422 + file( GLOB __gccExePath "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) 423 + __LIST_FILTER( __gccExePath "bin/[.].*-gcc${TOOL_OS_SUFFIX}$" ) 424 + list( LENGTH __gccExePath __gccExePathsCount ) 425 + if( NOT __gccExePathsCount EQUAL 1 ) 426 + message( WARNING "Could not uniquely determine machine name for compiler from ${_root}." ) 427 + set( ${_var} "" ) 428 + else() 429 + get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) 430 + string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" ) 431 + endif() 432 + unset( __gccExePath ) 433 + unset( __gccExePathsCount ) 434 + unset( __gccExeName ) 435 + endmacro() 436 + 437 + macro( __COPY_IF_DIFFERENT _source _destination ) 438 + execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${_source}" "${_destination}" RESULT_VARIABLE __fileCopyProcess ) 439 + if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${_destination}") 440 + message( SEND_ERROR "Failed copying of ${_source} to the ${_destination}" ) 441 + endif() 442 + unset( __fileCopyProcess ) 443 + endmacro() 444 + 445 + 446 + # stl version: by default gnustl_static will be used 447 + set( ANDROID_USE_STLPORT FALSE CACHE BOOL "Experimental: use stlport_static instead of gnustl_static") 448 + mark_as_advanced( ANDROID_USE_STLPORT ) 449 + 450 + # fight against cygwin 451 + set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools") 452 + mark_as_advanced( ANDROID_FORBID_SYGWIN ) 453 + if( ANDROID_FORBID_SYGWIN ) 454 + if( CYGWIN ) 455 + 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." ) 456 + endif() 457 + 458 + if( CMAKE_HOST_WIN32 ) 459 + # remove cygwin from PATH 460 + set( __new_path "$ENV{PATH}") 461 + __LIST_FILTER( __new_path "cygwin" ) 462 + set(ENV{PATH} "${__new_path}") 463 + unset(__new_path) 464 + endif() 465 + endif() 466 + 467 + # detect current host platform 468 + set( TOOL_OS_SUFFIX "" ) 469 + if( CMAKE_HOST_APPLE ) 470 + set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" ) 471 + elseif( CMAKE_HOST_WIN32 ) 472 + set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" ) 473 + set( TOOL_OS_SUFFIX ".exe" ) 474 + elseif( CMAKE_HOST_UNIX ) 475 + set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" ) 476 + else() 477 + message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) 478 + endif() 479 + 480 + # see if we have path to Android NDK 481 + # but only if the user hasn't tried to provide a standalone toolchain as an override. 482 + if( NOT ANDROID_STANDALONE_TOOLCHAIN ) 483 + __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) 484 + # According to a Google engineer on the Android NDK mailing list, the semi-official/blessed environmental variable is ANDROID_NDK_ROOT, not ANDROID_NDK. 485 + if ( NOT ANDROID_NDK ) 486 + __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK_ROOT ) 487 + endif( NOT ANDROID_NDK ) 488 + endif( NOT ANDROID_STANDALONE_TOOLCHAIN ) 489 + 490 + if( NOT ANDROID_NDK ) 491 + # see if we have path to Android standalone toolchain 492 + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN OBSOLETE_ANDROID_NDK_TOOLCHAIN_ROOT OBSOLETE_ENV_ANDROID_NDK_TOOLCHAIN_ROOT ) 493 + 494 + if( NOT ANDROID_STANDALONE_TOOLCHAIN ) 495 + #try to find Android NDK in one of the the default locations 496 + set( __ndkSearchPaths ) 497 + foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} ) 498 + foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) 499 + list( APPEND __ndkSearchPaths "${__ndkSearchPath}${suffix}" ) 500 + endforeach() 501 + endforeach() 502 + __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} ) 503 + unset( __ndkSearchPaths ) 504 + 505 + if( ANDROID_NDK ) 506 + message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" ) 507 + message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" ) 508 + else() 509 + #try to find Android standalone toolchain in one of the the default locations 510 + __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) 511 + 512 + if( ANDROID_STANDALONE_TOOLCHAIN ) 513 + message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" ) 514 + message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" ) 515 + endif( ANDROID_STANDALONE_TOOLCHAIN ) 516 + endif( ANDROID_NDK ) 517 + endif( NOT ANDROID_STANDALONE_TOOLCHAIN ) 518 + endif( NOT ANDROID_NDK ) 519 + 520 + # remember found paths 521 + if( ANDROID_NDK ) 522 + get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE ) 523 + # try to detect change 524 + if( CMAKE_AR ) 525 + string( LENGTH "${ANDROID_NDK}" __length ) 526 + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath ) 527 + if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK ) 528 + message( FATAL_ERROR "It is not possible to change path to the NDK on subsequent run." ) 529 + endif() 530 + unset( __androidNdkPreviousPath ) 531 + unset( __length ) 532 + endif() 533 + set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" ) 534 + set( BUILD_WITH_ANDROID_NDK True ) 535 + elseif( ANDROID_STANDALONE_TOOLCHAIN ) 536 + get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE ) 537 + # try to detect change 538 + if( CMAKE_AR ) 539 + string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length ) 540 + string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath ) 541 + if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN ) 542 + message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." ) 543 + endif() 544 + unset( __androidStandaloneToolchainPreviousPath ) 545 + unset( __length ) 546 + endif() 547 + set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" ) 548 + set( BUILD_WITH_STANDALONE_TOOLCHAIN True ) 549 + else() 550 + list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH) 551 + message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolcahin. 552 + You should either set an environment variable: 553 + export ANDROID_NDK=~/my-android-ndk 554 + or 555 + export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain 556 + or put the toolchain or NDK in the default path: 557 + sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH} 558 + sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) 559 + endif() 560 + 561 + # get all the details about standalone toolchain 562 + if( BUILD_WITH_STANDALONE_TOOLCHAIN ) 563 + __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" ) 564 + set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) 565 + set( __availableToolchains "standalone" ) 566 + __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" ) 567 + if( NOT __availableToolchainMachines ) 568 + message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." ) 569 + endif() 570 + if( __availableToolchainMachines MATCHES i686 ) 571 + set( __availableToolchainArchs "x86" ) 572 + elseif( __availableToolchainMachines MATCHES arm ) 573 + set( __availableToolchainArchs "arm" ) 574 + elseif( __availableToolchainMachines MATCHES mipsel ) 575 + set( __availableToolchainArchs "mipsel" ) 576 + endif() 577 + if( ANDROID_COMPILER_VERSION ) 578 + # do not run gcc every time because it is relatevely expencive 579 + set( __availableToolchainCompilerVersions "${ANDROID_COMPILER_VERSION}" ) 580 + else() 581 + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version 582 + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) 583 + # arm-linux-androideabi-gcc (GCC) 4.6 20120106 (prerelease) 584 + string( REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) 585 + if( NOT __availableToolchainCompilerVersions ) 586 + # arm-linux-androideabi-gcc (GCC) 4.8 587 + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version 588 + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) 589 + string( REGEX MATCH "[0-9]+.[0-9]+" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) 590 + endif() 591 + endif() 592 + endif() 593 + 594 + # get all the details about NDK 595 + if( BUILD_WITH_ANDROID_NDK ) 596 + file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) 597 + string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) 598 + file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) 599 + __LIST_FILTER( __availableToolchains "^[.]" ) 600 + set( __availableToolchainMachines "" ) 601 + set( __availableToolchainArchs "" ) 602 + set( __availableToolchainCompilerVersions "" ) 603 + foreach( __toolchain ${__availableToolchains} ) 604 + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) 605 + if( __machine ) 606 + string( REGEX MATCH "[0-9]+[.][0-9]+[.]*[0-9]*$" __version "${__toolchain}" ) 607 + string( REGEX MATCH "^[^-]+" __arch "${__toolchain}" ) 608 + list( APPEND __availableToolchainMachines "${__machine}" ) 609 + list( APPEND __availableToolchainArchs "${__arch}" ) 610 + list( APPEND __availableToolchainCompilerVersions "${__version}" ) 611 + else() 612 + list( REMOVE_ITEM __availableToolchains "${__toolchain}" ) 613 + endif() 614 + endforeach() 615 + if( NOT __availableToolchains ) 616 + message( FATAL_ERROR "Could not any working toolchain in the NDK. Probably your Android NDK is broken." ) 617 + endif() 618 + endif() 619 + 620 + # build list of available ABIs 621 + if( NOT ANDROID_SUPPORTED_ABIS ) 622 + set( ANDROID_SUPPORTED_ABIS "" ) 623 + set( __uniqToolchainArchNames ${__availableToolchainArchs} ) 624 + list( REMOVE_DUPLICATES __uniqToolchainArchNames ) 625 + list( SORT __uniqToolchainArchNames ) 626 + foreach( __arch ${__uniqToolchainArchNames} ) 627 + list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) 628 + endforeach() 629 + unset( __uniqToolchainArchNames ) 630 + if( NOT ANDROID_SUPPORTED_ABIS ) 631 + message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) 632 + endif() 633 + endif() 634 + 635 + # choose target ABI 636 + __INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${ANDROID_SUPPORTED_ABIS} ) 637 + # verify that target ABI is supported 638 + list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) 639 + if( __androidAbiIdx EQUAL -1 ) 640 + string( REPLACE ";" "\", \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) 641 + message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. 642 + Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" 643 + " ) 644 + endif() 645 + unset( __androidAbiIdx ) 646 + 647 + # remember target ABI 648 + set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) 649 + 650 + # set target ABI options 651 + if( ANDROID_ABI STREQUAL "x86" ) 652 + set( X86 true ) 653 + set( ANDROID_NDK_ABI_NAME "x86" ) 654 + set( ANDROID_ARCH_NAME "x86" ) 655 + set( ANDROID_ARCH_FULLNAME "x86" ) 656 + set( CMAKE_SYSTEM_PROCESSOR "i686" ) 657 + elseif( ANDROID_ABI STREQUAL "mips" ) 658 + set( MIPS true ) 659 + set( ANDROID_NDK_ABI_NAME "mips" ) 660 + set( ANDROID_ARCH_NAME "mips" ) 661 + set( ANDROID_ARCH_FULLNAME "mipsel" ) 662 + set( CMAKE_SYSTEM_PROCESSOR "mips" ) 663 + elseif( ANDROID_ABI STREQUAL "armeabi" ) 664 + set( ARMEABI true ) 665 + set( ANDROID_NDK_ABI_NAME "armeabi" ) 666 + set( ANDROID_ARCH_NAME "arm" ) 667 + set( ANDROID_ARCH_FULLNAME "arm" ) 668 + set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) 669 + elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) 670 + set( ARMEABI_V6 true ) 671 + set( ANDROID_NDK_ABI_NAME "armeabi" ) 672 + set( ANDROID_ARCH_NAME "arm" ) 673 + set( ANDROID_ARCH_FULLNAME "arm" ) 674 + set( CMAKE_SYSTEM_PROCESSOR "armv6" ) 675 + # need always fallback to older platform 676 + set( ARMEABI true ) 677 + elseif( ANDROID_ABI STREQUAL "armeabi-v7a") 678 + set( ARMEABI_V7A true ) 679 + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) 680 + set( ANDROID_ARCH_NAME "arm" ) 681 + set( ANDROID_ARCH_FULLNAME "arm" ) 682 + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) 683 + elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) 684 + set( ARMEABI_V7A true ) 685 + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) 686 + set( ANDROID_ARCH_NAME "arm" ) 687 + set( ANDROID_ARCH_FULLNAME "arm" ) 688 + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) 689 + set( VFPV3 true ) 690 + elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) 691 + set( ARMEABI_V7A true ) 692 + set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) 693 + set( ANDROID_ARCH_NAME "arm" ) 694 + set( ANDROID_ARCH_FULLNAME "arm" ) 695 + set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) 696 + set( VFPV3 true ) 697 + set( NEON true ) 698 + else() 699 + message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." ) 700 + endif() 701 + 702 + if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" ) 703 + # really dirty hack 704 + # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run... 705 + file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) 706 + endif() 707 + 708 + 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." ) 709 + if( CMAKE_VERSION VERSION_GREATER "2.8" ) 710 + list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} ) 711 + set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} ) 712 + endif() 713 + 714 + if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) 715 + __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF ) 716 + set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) 717 + mark_as_advanced( ANDROID_FORCE_ARM_BUILD ) 718 + else() 719 + unset( ANDROID_FORCE_ARM_BUILD CACHE ) 720 + endif() 721 + 722 + # choose toolchain 723 + if( ANDROID_TOOLCHAIN_NAME ) 724 + list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) 725 + if( __toolchainIdx EQUAL -1 ) 726 + 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" ) 727 + endif() 728 + list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) 729 + if( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME ) 730 + message( SEND_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) 731 + endif() 732 + else() 733 + set( __toolchainIdx -1 ) 734 + set( __applicableToolchains "" ) 735 + set( __toolchainMaxVersion "0.0.0" ) 736 + list( LENGTH __availableToolchains __availableToolchainsCount ) 737 + math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" ) 738 + foreach( __idx RANGE ${__availableToolchainsCount} ) 739 + list( GET __availableToolchainArchs ${__idx} __toolchainArch ) 740 + if( __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME ) 741 + list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion ) 742 + if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion ) 743 + set( __toolchainMaxVersion "${__toolchainVersion}" ) 744 + set( __toolchainIdx ${__idx} ) 745 + endif() 746 + endif() 747 + endforeach() 748 + unset( __availableToolchainsCount ) 749 + unset( __toolchainMaxVersion ) 750 + unset( __toolchainVersion ) 751 + endif() 752 + unset( __toolchainArch ) 753 + if( __toolchainIdx EQUAL -1 ) 754 + message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." ) 755 + endif() 756 + list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) 757 + list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) 758 + list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) 759 + set( ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" CACHE INTERNAL "Name of toolchain used" ) 760 + set( ANDROID_COMPILER_VERSION "${ANDROID_COMPILER_VERSION}" CACHE INTERNAL "compiler version from selected toolchain" ) 761 + unset( __toolchainIdx ) 762 + unset( __availableToolchains ) 763 + unset( __availableToolchainMachines ) 764 + unset( __availableToolchainArchs ) 765 + unset( __availableToolchainCompilerVersions ) 766 + 767 + # choose native API level 768 + __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 ) 769 + string( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) 770 + # validate 771 + list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) 772 + if( __levelIdx EQUAL -1 ) 773 + message( SEND_ERROR "Specified Android native API level (${ANDROID_NATIVE_API_LEVEL}) is not supported by your NDK/toolchain." ) 774 + endif() 775 + unset( __levelIdx ) 776 + if( BUILD_WITH_ANDROID_NDK ) 777 + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) 778 + if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL ) 779 + 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." ) 780 + endif() 781 + unset( __realApiLevel ) 782 + endif() 783 + set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) 784 + if( CMAKE_VERSION VERSION_GREATER "2.8" ) 785 + list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) 786 + set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) 787 + endif() 788 + 789 + # setup paths 790 + if( BUILD_WITH_STANDALONE_TOOLCHAIN ) 791 + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) 792 + set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) 793 + set( __stlLibPath "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) 794 + endif() 795 + if( BUILD_WITH_ANDROID_NDK ) 796 + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) 797 + set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) 798 + if( ANDROID_USE_STLPORT ) 799 + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" ) 800 + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}" ) 801 + else() 802 + if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) 803 + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/include" ) 804 + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}" ) 805 + else() 806 + set( __stlIncludePath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/include" ) 807 + set( __stlLibPath "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}" ) 808 + endif() 809 + endif() 810 + endif() 811 + 812 + # specify the cross compiler 813 + set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" ) 814 + set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" ) 815 + set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "Assembler" ) 816 + if( CMAKE_VERSION VERSION_LESS 2.8.5 ) 817 + set( CMAKE_ASM_COMPILER_ARG1 "-c" ) 818 + endif() 819 + # there may be a way to make cmake deduce these TODO deduce the rest of the tools 820 + set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) 821 + set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) 822 + set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) 823 + set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) 824 + set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) 825 + set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" ) 826 + set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" ) 827 + set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" ) 828 + if( APPLE ) 829 + find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) 830 + if( NOT CMAKE_INSTALL_NAME_TOOL ) 831 + message( FATAL_ERROR "Could not find install_name_tool, please check your installation." ) 832 + endif() 833 + mark_as_advanced( CMAKE_INSTALL_NAME_TOOL ) 834 + endif() 835 + 836 + # export directories 837 + set( ANDROID_SYSTEM_INCLUDE_DIRS "" ) 838 + set( ANDROID_SYSTEM_LIB_DIRS "" ) 839 + 840 + # setup output directories 841 + set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) 842 + set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) 843 + 844 + if(NOT _CMAKE_IN_TRY_COMPILE) 845 + if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) 846 + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) 847 + else() 848 + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) 849 + endif() 850 + set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) 851 + endif() 852 + 853 + # includes 854 + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_SYSROOT}/usr/include" ) 855 + if( __stlIncludePath AND EXISTS "${__stlIncludePath}" ) 856 + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${__stlIncludePath}" ) 857 + endif() 858 + 859 + # c++ bits includes 860 + if( __stlLibPath AND EXISTS "${__stlLibPath}/include" ) 861 + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${__stlLibPath}/include" ) 862 + endif() 863 + 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" ) 864 + 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" ) 865 + elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) 866 + 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}" ) 867 + 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" ) 868 + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) 869 + elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/bits" ) 870 + list( APPEND ANDROID_SYSTEM_INCLUDE_DIRS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) 871 + endif() 872 + 873 + # flags and definitions 874 + if(ANDROID_SYSROOT MATCHES "[ ;\"]") 875 + set( ANDROID_C_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) 876 + set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) 877 + # quotes will break try_compile and compiler identification 878 + message(WARNING "Your Android system root has non-alphanumeric symbols. It can break compiler features detection and the whole build.") 879 + else() 880 + set( ANDROID_C_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) 881 + set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) 882 + endif() 883 + 884 + remove_definitions( -DANDROID ) 885 + add_definitions( -DANDROID ) 886 + 887 + # Force set compilers because standard identification works badly for us 888 + include( CMakeForceCompiler ) 889 + CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) 890 + set( CMAKE_C_PLATFORM_ID Linux ) 891 + set( CMAKE_C_SIZEOF_DATA_PTR 4 ) 892 + set( CMAKE_C_HAS_ISYSROOT 1 ) 893 + set( CMAKE_C_COMPILER_ABI ELF ) 894 + CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) 895 + set( CMAKE_CXX_PLATFORM_ID Linux ) 896 + set( CMAKE_CXX_SIZEOF_DATA_PTR 4 ) 897 + set( CMAKE_CXX_HAS_ISYSROOT 1 ) 898 + set( CMAKE_CXX_COMPILER_ABI ELF ) 899 + # force ASM compiler (required for CMake < 2.8.5) 900 + set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) 901 + set( CMAKE_ASM_COMPILER_ID GNU ) 902 + set( CMAKE_ASM_COMPILER_WORKS TRUE ) 903 + set( CMAKE_ASM_COMPILER_FORCED TRUE ) 904 + set( CMAKE_COMPILER_IS_GNUASM 1) 905 + 906 + # NDK flags 907 + if( ARMEABI OR ARMEABI_V7A ) 908 + # NDK also defines -ffunction-sections -funwind-tables but they result in worse OpenCV performance 909 + set( _CMAKE_CXX_FLAGS "-fpic -fstack-protector -no-canonical-prefixes -Wa,--noexecstack" ) 910 + set( _CMAKE_C_FLAGS "-fpic -fstack-protector -no-canonical-prefixes -Wa,--noexecstack" ) 911 + remove_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ) 912 + add_definitions( -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ ) 913 + # extra arm-specific flags 914 + # The default Android build process does not pass -fsigned-char. 915 + # set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -fsigned-char" ) 916 + # set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) 917 + elseif( X86 ) 918 + set( _CMAKE_CXX_FLAGS "-no-canonical-prefixes -funwind-tables -fstack-protector -Wa,--noexecstack" ) 919 + set( _CMAKE_C_FLAGS "-no-canonical-prefixes -funwind-tables -fstack-protector -Wa,--noexecstack" ) 920 + elseif( MIPS ) 921 + 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" ) 922 + 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" ) 923 + # The default Android build process does not pass -fsigned-char. 924 + # set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -fsigned-char" ) 925 + # set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) 926 + else() 927 + set( _CMAKE_CXX_FLAGS "" ) 928 + set( _CMAKE_C_FLAGS "" ) 929 + endif() 930 + 931 + if( ANDROID_USE_STLPORT ) 932 + set( _CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions" ) 933 + # set( _CMAKE_C_FLAGS "${_CMAKE_C_FLAGS}" ) 934 + else() 935 + set( _CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS} -frtti -fexceptions" ) 936 + # set( _CMAKE_C_FLAGS "${_CMAKE_C_FLAGS}" ) 937 + endif() 938 + 939 + # release and debug flags 940 + if( ARMEABI OR ARMEABI_V7A ) 941 + if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 ) 942 + # It is recommended to use the -mthumb compiler flag to force the generation 943 + # of 16-bit Thumb-1 instructions (the default being 32-bit ARM ones). 944 + # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc 945 + # EW: Note that Android's normal build process uses 946 + # -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 947 + # and for debug, appends: -O0 -UNDEBUG -marm -fno-omit-frame-pointer 948 + set( _CMAKE_CXX_FLAGS_RELEASE "-mthumb -O3 -finline-limit=64" ) 949 + set( _CMAKE_C_FLAGS_RELEASE "-mthumb -O3 -finline-limit=64" ) 950 + set( _CMAKE_CXX_FLAGS_DEBUG "-marm -O0 -g -finline-limit=64" ) 951 + set( _CMAKE_C_FLAGS_DEBUG "-marm -O0 -g -finline-limit=64" ) 952 + else() 953 + # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI 954 + # O3 instead of O2/Os in release mode - like cmake sets for desktop gcc 955 + set( _CMAKE_CXX_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" ) 956 + set( _CMAKE_C_FLAGS_RELEASE "-marm -O3 -fstrict-aliasing" ) 957 + set( _CMAKE_CXX_FLAGS_DEBUG "-marm -O0 -finline-limit=300" ) 958 + set( _CMAKE_C_FLAGS_DEBUG "-marm -O0 -finline-limit=300" ) 959 + endif() 960 + elseif( X86 ) 961 + set( _CMAKE_CXX_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" ) 962 + set( _CMAKE_C_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" ) 963 + set( _CMAKE_CXX_FLAGS_DEBUG "-O0 -g -funswitch-loops -finline-limit=300" ) 964 + set( _CMAKE_C_FLAGS_DEBUG "-O0 -g -funswitch-loops -finline-limit=300" ) 965 + elseif( MIPS ) 966 + set( _CMAKE_CXX_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" ) 967 + set( _CMAKE_C_FLAGS_RELEASE "-O3 -funswitch-loops -finline-limit=300" ) 968 + set( _CMAKE_CXX_FLAGS_DEBUG "-O0 -g" ) 969 + set( _CMAKE_C_FLAGS_DEBUG "-O0 -g" ) 970 + endif() 971 + set( _CMAKE_CXX_FLAGS_RELEASE "${_CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" ) 972 + set( _CMAKE_C_FLAGS_RELEASE "${_CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer -DNDEBUG" ) 973 + set( _CMAKE_CXX_FLAGS_DEBUG "${_CMAKE_CXX_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" ) 974 + set( _CMAKE_C_FLAGS_DEBUG "${_CMAKE_C_FLAGS_DEBUG} -fno-strict-aliasing -fno-omit-frame-pointer -DDEBUG -D_DEBUG" ) 975 + 976 + # ABI-specific flags 977 + if( ARMEABI_V7A ) 978 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) 979 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) 980 + if( NEON ) 981 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -mfpu=neon" ) 982 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" ) 983 + elseif( VFPV3 ) 984 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -mfpu=vfpv3-d32" ) 985 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d32" ) 986 + else() 987 + # Default Android armv7 builds with -mfpu=vfpv3-d16. 988 + # According to this: 989 + # http://stackoverflow.com/questions/11831648/android-ndk-arm-build-settings-to-run-on-most-devices 990 + # there was a bug in r7b which caused crashes. 991 + # But r9 is the current as of this writing so developers really need to upgrade their ndk. 992 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -mfpu=vfpv3-d16" ) 993 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" ) 994 + endif() 995 + elseif( ARMEABI_V6 ) 996 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) 997 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) 998 + elseif( ARMEABI ) 999 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) 1000 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) 1001 + elseif( X86 ) 1002 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS}" )#sse? 1003 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" )#sse? 1004 + endif() 1005 + 1006 + # linker flags 1007 + if( NOT DEFINED __ndklibspath ) 1008 + set( __ndklibspath "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ndklibs/${ANDROID_NDK_ABI_NAME}" ) 1009 + endif() 1010 + list( APPEND ANDROID_SYSTEM_LIB_DIRS "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ) 1011 + set( ANDROID_LINKER_FLAGS "" ) 1012 + 1013 + # STL 1014 + if( ANDROID_USE_STLPORT ) 1015 + if( EXISTS "${__stlLibPath}/libstlport_static.a" ) 1016 + 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\"") 1017 + 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\"") 1018 + endif() 1019 + else( ANDROID_USE_STLPORT ) 1020 + if( EXISTS "${__stlLibPath}/libgnustl_static.a" ) 1021 + __COPY_IF_DIFFERENT( "${__stlLibPath}/libgnustl_static.a" "${__ndklibspath}/libstdc++.a" ) 1022 + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) 1023 + __COPY_IF_DIFFERENT( "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) 1024 + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) 1025 + __COPY_IF_DIFFERENT( "${__stlLibPath}/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) 1026 + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${__stlLibPath}/thumb/libstdc++.a" ) 1027 + __COPY_IF_DIFFERENT( "${__stlLibPath}/thumb/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) 1028 + elseif( EXISTS "${__stlLibPath}/libstdc++.a" ) 1029 + __COPY_IF_DIFFERENT( "${__stlLibPath}/libstdc++.a" "${__ndklibspath}/libstdc++.a" ) 1030 + endif() 1031 + if( EXISTS "${__stlLibPath}/libsupc++.a" ) 1032 + __COPY_IF_DIFFERENT( "${__stlLibPath}/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) 1033 + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" ) 1034 + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) 1035 + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" ) 1036 + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) 1037 + elseif( ANDROID_ARCH_NAME STREQUAL "arm" AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" ) 1038 + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) 1039 + elseif( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" ) 1040 + __COPY_IF_DIFFERENT( "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" "${__ndklibspath}/libsupc++.a" ) 1041 + endif() 1042 + list( APPEND ANDROID_SYSTEM_LIB_DIRS "${__ndklibspath}" ) 1043 + endif( ANDROID_USE_STLPORT ) 1044 + 1045 + # cleanup for STL search 1046 + unset( __stlIncludePath ) 1047 + unset( __stlLibPath ) 1048 + 1049 + # other linker flags 1050 + __INIT_VARIABLE( ANDROID_NO_UNDEFINED OBSOLETE_NO_UNDEFINED VALUES ON ) 1051 + set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" FORCE ) 1052 + mark_as_advanced( ANDROID_NO_UNDEFINED ) 1053 + if( ANDROID_NO_UNDEFINED ) 1054 + set( ANDROID_LINKER_FLAGS "-Wl,--no-undefined ${ANDROID_LINKER_FLAGS}" ) 1055 + endif() 1056 + 1057 + if (ANDROID_NDK MATCHES "-r[56].?$") 1058 + # 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. 1059 + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON ) 1060 + else() 1061 + __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF ) 1062 + endif() 1063 + 1064 + set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" FORCE ) 1065 + mark_as_advanced( ANDROID_SO_UNDEFINED ) 1066 + if( ANDROID_SO_UNDEFINED ) 1067 + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" ) 1068 + endif() 1069 + 1070 + # Android by default passes --function-sections for C and C++ but does not pass -fdata-sections. 1071 + # Android also does not pass -Wl,--gc-sections 1072 + __INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON ) 1073 + set( ANDROID_FUNCTION_LEVEL_LINKING ON CACHE BOOL "Allows or disallows undefined symbols in shared libraries" FORCE ) 1074 + mark_as_advanced( ANDROID_FUNCTION_LEVEL_LINKING ) 1075 + if( ANDROID_FUNCTION_LEVEL_LINKING ) 1076 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS} -fdata-sections -ffunction-sections" ) 1077 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) 1078 + set( ANDROID_LINKER_FLAGS "-Wl,--gc-sections ${ANDROID_LINKER_FLAGS}" ) 1079 + endif() 1080 + 1081 + if( ARMEABI_V7A ) 1082 + # this is *required* to use the following linker flags that routes around 1083 + # a CPU bug in some Cortex-A8 implementations: 1084 + # set( ANDROID_LINKER_FLAGS "-Wl,--fix-cortex-a8 ${ANDROID_LINKER_FLAGS}" ) 1085 + # Android passes all this stuff by default. 1086 + 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" ) 1087 + elseif( ARMEABI ) 1088 + set( ANDROID_LINKER_FLAGS "-no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${ANDROID_LINKER_FLAGS} -lc -lm" ) 1089 + elseif ( X86 ) 1090 + set( ANDROID_LINKER_FLAGS "-no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now ${ANDROID_LINKER_FLAGS} -lc -lm" ) 1091 + endif() 1092 + 1093 + # cache flags 1094 + set( CMAKE_CXX_FLAGS "${_CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags" ) 1095 + set( CMAKE_C_FLAGS "${_CMAKE_C_FLAGS}" CACHE STRING "c flags" ) 1096 + set( CMAKE_CXX_FLAGS_RELEASE "${_CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "c++ Release flags" ) 1097 + set( CMAKE_C_FLAGS_RELEASE "${_CMAKE_C_FLAGS_RELEASE}" CACHE STRING "c Release flags" ) 1098 + set( CMAKE_CXX_FLAGS_DEBUG "${_CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING "c++ Debug flags" ) 1099 + set( CMAKE_C_FLAGS_DEBUG "${_CMAKE_C_FLAGS_DEBUG}" CACHE STRING "c Debug flags" ) 1100 + set( CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "linker flags" ) 1101 + set( CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "linker flags" ) 1102 + set( CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc" CACHE STRING "linker flags" ) 1103 + 1104 + include_directories( SYSTEM ${ANDROID_SYSTEM_INCLUDE_DIRS} ) 1105 + link_directories( ${ANDROID_SYSTEM_LIB_DIRS} ) 1106 + 1107 + # finish flags 1108 + set( ANDROID_C_FLAGS "${ANDROID_C_FLAGS}" CACHE INTERNAL "Extra Android C compiler flags") 1109 + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Extra Android C++ compiler flags") 1110 + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Extra Android linker flags") 1111 + set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) 1112 + set( CMAKE_C_FLAGS "${ANDROID_C_FLAGS} ${CMAKE_C_FLAGS}" ) 1113 + if( MIPS AND BUILD_WITH_ANDROID_NDK ) 1114 + set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) 1115 + set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) 1116 + set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.x ${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) 1117 + else() 1118 + set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) 1119 + set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) 1120 + set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) 1121 + endif() 1122 + 1123 + # set these global flags for cmake client scripts to change behavior 1124 + set( ANDROID True ) 1125 + set( BUILD_ANDROID True ) 1126 + 1127 + # where is the target environment 1128 + 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}" ) 1129 + 1130 + # only search for libraries and includes in the ndk toolchain 1131 + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) 1132 + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) 1133 + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) 1134 + 1135 + 1136 + # macro to find packages on the host OS 1137 + macro( find_host_package ) 1138 + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) 1139 + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) 1140 + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) 1141 + if( CMAKE_HOST_WIN32 ) 1142 + SET( WIN32 1 ) 1143 + SET( UNIX ) 1144 + elseif( CMAKE_HOST_APPLE ) 1145 + SET( APPLE 1 ) 1146 + SET( UNIX ) 1147 + endif() 1148 + find_package( ${ARGN} ) 1149 + SET( WIN32 ) 1150 + SET( APPLE ) 1151 + SET( UNIX 1 ) 1152 + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) 1153 + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) 1154 + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) 1155 + endmacro() 1156 + 1157 + 1158 + # macro to find programs on the host OS 1159 + macro( find_host_program ) 1160 + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) 1161 + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) 1162 + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) 1163 + if( CMAKE_HOST_WIN32 ) 1164 + SET( WIN32 1 ) 1165 + SET( UNIX ) 1166 + elseif( CMAKE_HOST_APPLE ) 1167 + SET( APPLE 1 ) 1168 + SET( UNIX ) 1169 + endif() 1170 + find_program( ${ARGN} ) 1171 + SET( WIN32 ) 1172 + SET( APPLE ) 1173 + SET( UNIX 1 ) 1174 + set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) 1175 + set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) 1176 + set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) 1177 + endmacro() 1178 + 1179 + 1180 + macro( ANDROID_GET_ABI_RAWNAME TOOLCHAIN_FLAG VAR ) 1181 + if( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI" ) 1182 + set( ${VAR} "armeabi" ) 1183 + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "ARMEABI_V7A" ) 1184 + set( ${VAR} "armeabi-v7a" ) 1185 + elseif( "${TOOLCHAIN_FLAG}" STREQUAL "X86" ) 1186 + set( ${VAR} "x86" ) 1187 + else() 1188 + set( ${VAR} "unknown" ) 1189 + endif() 1190 + endmacro() 1191 + 1192 + 1193 + # export toolchain settings for the try_compile() command 1194 + if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" ) 1195 + set( __toolchain_config "") 1196 + 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 ) 1197 + if( DEFINED ${__var} ) 1198 + if( "${__var}" MATCHES " ") 1199 + set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" ) 1200 + else() 1201 + set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" ) 1202 + endif() 1203 + endif() 1204 + endforeach() 1205 + file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" ) 1206 + unset( __toolchain_config ) 1207 + unset( __ndklibspath ) 1208 + endif() 1209 + 1210 + 1211 + # set some obsolete variables for backward compatibility 1212 + set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" ) 1213 + mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES ) 1214 + if( ANDROID_SET_OBSOLETE_VARIABLES ) 1215 + set( ANDROID_API_LEVEL ${ANDROID_NATIVE_API_LEVEL} ) 1216 + set( ARM_TARGET "${ANDROID_ABI}" ) 1217 + set( ARMEABI_NDK_NAME "${ANDROID_NDK_ABI_NAME}" ) 1218 + endif() 1219 + 1220 + 1221 + # Variables controlling behavior or set by cmake toolchain: 1222 + # ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips" 1223 + # ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version) 1224 + # ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF 1225 + # ANDROID_USE_STLPORT : OFF/ON - EXPERIMENTAL!!! 1226 + # ANDROID_FORBID_SYGWIN : ON/OFF 1227 + # ANDROID_NO_UNDEFINED : ON/OFF 1228 + # ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) 1229 + # ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF 1230 + # Variables that takes effect only at first run: 1231 + # ANDROID_FORCE_ARM_BUILD : ON/OFF 1232 + # LIBRARY_OUTPUT_PATH_ROOT : <any valid path> 1233 + # Can be set only at the first run: 1234 + # ANDROID_NDK 1235 + # ANDROID_STANDALONE_TOOLCHAIN 1236 + # 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" 1237 + # Obsolete: 1238 + # ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL 1239 + # ARM_TARGET : superseded by ANDROID_ABI 1240 + # ARM_TARGETS : superseded by ANDROID_ABI (can be set only) 1241 + # ANDROID_NDK_TOOLCHAIN_ROOT : superseded by ANDROID_STANDALONE_TOOLCHAIN (can be set only) 1242 + # ANDROID_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL (completely removed) 1243 + # 1244 + # Primary read-only variables: 1245 + # ANDROID : always TRUE 1246 + # ARMEABI : TRUE for arm v6 and older devices 1247 + # ARMEABI_V6 : TRUE for arm v6 1248 + # ARMEABI_V7A : TRUE for arm v7a 1249 + # NEON : TRUE if NEON unit is enabled 1250 + # VFPV3 : TRUE if VFP version 3 is enabled 1251 + # X86 : TRUE if configured for x86 1252 + # BUILD_ANDROID : always TRUE 1253 + # BUILD_WITH_ANDROID_NDK : TRUE if NDK is used 1254 + # BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used 1255 + # ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform 1256 + # ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a" or "x86" depending on ANDROID_ABI 1257 + # ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI 1258 + # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform 1259 + # ANDROID_SYSROOT : path to the compiler sysroot 1260 + # ANDROID_SYSTEM_INCLUDE_DIRS 1261 + # ANDROID_SYSTEM_LIB_DIRS 1262 + # Obsolete: 1263 + # ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME 1264 + # 1265 + # Secondary (less stable) read-only variables: 1266 + # ANDROID_COMPILER_VERSION : GCC version used 1267 + # ANDROID_C_FLAGS : C compiler flags required by Android platform 1268 + # ANDROID_CXX_FLAGS : C++ compiler flags required by Android platform 1269 + # ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI 1270 + # ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" 1271 + # ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) 1272 + # ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK 1273 + # 1274 + # Defaults: 1275 + # ANDROID_DEFAULT_NDK_API_LEVEL 1276 + # ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} 1277 + # ANDROID_NDK_SEARCH_PATHS 1278 + # ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH 1279 + # ANDROID_SUPPORTED_ABIS_${ARCH} 1280 + # ANDROID_SUPPORTED_NDK_VERSIONS
+10
AndroidCMake/clean_ndk.sh
··· 1 + #!/bin/sh 2 + 3 + (cd cmake_ndk_build 4 + for d in */ ; do 5 + (cd "$d" 6 + make clean 7 + ) 8 + done 9 + ) 10 +
+630
AndroidCMake/genproj_android.pl
··· 1 + #!/usr/bin/env perl -w 2 + 3 + ########################################################### 4 + # 5 + # Convenince script to generate CMake projects for Android 6 + # for each architecture and build them. 7 + # Copyright (C) PlayControl Software, LLC. 8 + # Eric Wing <ewing . public @ playcontrol.net> 9 + # 10 + # Convention: 11 + # You have created standalone toolchains and placed them in a directory called standalone under the $ANDROID_NDK_ROOT: 12 + # $ANDROID_NDK_ROOT/standalone/ 13 + # arm-linux-androideabi-4.6/ 14 + # x86-4.6/ 15 + # 16 + ########################################################## 17 + 18 + 19 + #use strict; 20 + use warnings; 21 + 22 + # Function to help with command line switches 23 + use Getopt::Long; 24 + # Allows extra "unknown options" to be specified which I will use to pass directly to the cmake executable. 25 + Getopt::Long::Configure("pass_through"); 26 + 27 + # Function to get the basename of a file 28 + use File::Basename; 29 + # Used for tilde expansion 30 + use File::Glob; 31 + # for make_path (which is mkdir -p) 32 + use File::Path qw(make_path); 33 + 34 + # Provides functions to convert relative paths to absolute paths. 35 + use Cwd; 36 + 37 + use File::Basename; 38 + 39 + # Global constants 40 + 41 + my $kCMakeBootStrapCacheFile = "InitialCache_Android.cmake"; 42 + 43 + my %kArchToDirectoryNameMap = 44 + ( 45 + # mips => "mips", 46 + armeabi => "armeabi", 47 + "armeabi-v7a" => "armeabi-v7a", 48 + # "armeabi-v7a with NEON" => "armeabi-v7a", 49 + # "armeabi-v7a with VFPV3" => "armeabi-v7a", 50 + # "armeabi-v6 with VFP" => "armeabi", 51 + x86 => "x86" 52 + ); 53 + 54 + # Global constants 55 + my %kArchToCompilerNameMap = 56 + ( 57 + # mips => "mips", 58 + armeabi => "arm-linux-androideabi", 59 + "armeabi-v7a" => "arm-linux-androideabi", 60 + # "armeabi-v7a with NEON" => "armeabi", 61 + # "armeabi-v7a with VFPV3" => "armeabi", 62 + # "armeabi-v6 with VFP" => "armeabi", 63 + x86 => "x86" 64 + ); 65 + 66 + 67 + my @kSupportedArchitectures = 68 + ( 69 + # "mips", 70 + "armeabi", 71 + "armeabi-v7a", 72 + # "armeabi-v7a with NEON", 73 + # "armeabi-v7a with VFPV3", 74 + # "armeabi-v6 with VFP", 75 + "x86", 76 + ); 77 + 78 + 79 + # Function prototypes 80 + 81 + # main routine 82 + sub main(); 83 + # call main 84 + 85 + sub main() 86 + { 87 + 88 + my ($blurrr_sdk_root, 89 + $blurrr_sdk_path, 90 + $cmake_source_dir, 91 + $cmake_binary_dir, 92 + $libsdir, 93 + $android_sdk_root, 94 + $standalone_toolchain_root, 95 + $targetSdkVersion, 96 + $minSdkVersion, 97 + $compilerversion, 98 + $buildtype, 99 + $should_build, 100 + $cmake_toolchain, 101 + $cmake, 102 + $architectures, 103 + @remaining_options 104 + ) = extract_parameters(); 105 + 106 + my @architectures_array; 107 + 108 + if(not defined($architectures)) 109 + { 110 + @architectures_array = @kSupportedArchitectures; 111 + } 112 + else 113 + { 114 + @architectures_array = split(/[ ,;]/, $architectures); 115 + } 116 + 117 + 118 + 119 + 120 + print("blurrr_sdk_root: ", $blurrr_sdk_root, "\n"); 121 + print("blurrr_sdk_path: ", $blurrr_sdk_path, "\n"); 122 + print("cmake_source_dir: ", $cmake_source_dir, "\n"); 123 + print("cmake_binary_dir: ", $cmake_binary_dir, "\n"); 124 + print("libsdir: ", $libsdir, "\n"); 125 + 126 + 127 + print("android_sdk_root: ", $android_sdk_root, "\n"); 128 + print("standalone_toolchain_root: ", $standalone_toolchain_root, "\n"); 129 + print("targetSdkVersion: ", $targetSdkVersion, "\n"); 130 + print("minSdkVersion: ", $minSdkVersion, "\n"); 131 + # print("compilerversion: ", $compilerversion, "\n"); 132 + print("buildtype: ", $buildtype, "\n"); 133 + print("should_build: ", $should_build, "\n"); 134 + print("cmake_toolchain: ", $cmake_toolchain, "\n"); 135 + print("cmake: ", $cmake, "\n"); 136 + 137 + # print("remaining_options: ", @remaining_options, "\n"); 138 + 139 + 140 + 141 + copy_build_scripts($cmake_source_dir, $cmake_binary_dir); 142 + 143 + 144 + 145 + # my ($targetdir, $standalone, $compilerversion, $should_build, $cmake, $toolchain, $libsdir, $buildtype, $sourcedir, @remaining_options) = extract_parameters(); 146 + 147 + # Save in case we need to return to the original current working directory. 148 + my $original_current_working_directory = Cwd::cwd(); 149 + 150 + foreach my $arch(@architectures_array) 151 + { 152 + # First choose the correct compiler. 153 + my $found_compiler; 154 + my $compiler_base_name = $kArchToCompilerNameMap{$arch}; 155 + 156 + opendir(STANDALONEDIR, $standalone_toolchain_root) or die("Could not open standalone_toolchain_root directory: $!\n"); 157 + while(my $file = readdir(STANDALONEDIR)) 158 + { 159 + my $full_path_and_file = "$standalone_toolchain_root/$file"; 160 + 161 + # Go to the next file unless it is a directory 162 + next unless(-d "$full_path_and_file"); 163 + 164 + # if a version was specified, make sure it matches 165 + if(defined($compilerversion)) 166 + { 167 + if($file =~ m/$compiler_base_name-$compilerversion/) 168 + { 169 + $found_compiler = $full_path_and_file; 170 + last; 171 + } 172 + } 173 + # otherwise if no version was specified, just go for any match 174 + else 175 + { 176 + if($file =~ m/$compiler_base_name/) 177 + { 178 + $found_compiler = $full_path_and_file; 179 + last; 180 + } 181 + } 182 + } 183 + closedir(STANDALONEDIR); 184 + 185 + if(not defined $found_compiler) 186 + { 187 + die("Could not find compiler in directory:$standalone_toolchain_root for arch:$arch\n"); 188 + } 189 + 190 + 191 + 192 + chdir($cmake_binary_dir) or die("Could not change directory to $cmake_binary_dir: $!\n"); 193 + # Let's make an intermediate subdirectory for all the CMake NDK stuff we're going to create 194 + my $cmake_ndk_build = "cmake_ndk_build"; 195 + unless(-e $cmake_ndk_build or mkdir $cmake_ndk_build) 196 + { 197 + die("Unable to create $cmake_ndk_build: $!\n"); 198 + } 199 + chdir($cmake_ndk_build) or die("Could not change directory to $cmake_ndk_build: $!\n"); 200 + 201 + my $arch_dir = $kArchToDirectoryNameMap{$arch}; 202 + unless(-e $arch_dir or mkdir $arch_dir) 203 + { 204 + die("Unable to create $arch_dir: $!\n"); 205 + } 206 + chdir($arch_dir) or die("Could not change directory to $arch_dir: $!\n"); 207 + 208 + my $android_standalone_toolchain = "$found_compiler"; 209 + print("Generating $arch\n"); 210 + 211 + #my $initial_cache = "$blurrr_sdk_root/$kCMakeBootStrapCacheFile"; 212 + my $initial_cache = "$cmake_source_dir/AndroidCMake/$kCMakeBootStrapCacheFile"; 213 + my $suppress_dev_warnings_flags = "-Wno-dev"; 214 + 215 + my $blurrr_path_to_use; 216 + if(defined $blurrr_sdk_path) 217 + { 218 + $blurrr_path_to_use = "-DBLURRR_SDK_PATH=$blurrr_sdk_path"; 219 + } 220 + else 221 + { 222 + $blurrr_path_to_use = "-DBLURRR_ROOT=$blurrr_sdk_root"; 223 + } 224 + 225 + # There is something screwing up the call when I do comma separated arguments. 226 + 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"; 227 + #print("Executing: $cmake $cmake_toolchain $blurrr_root_flag $arch_flag $initial_cache $android_standalone_toolchain $libsdir $buildtype @remaining_options $cmake_source_dir\n"); 228 + print("Executing: $command_string\n\n"); 229 + 230 + # 231 + # /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 232 + # 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. 233 + my $error_status = system($cmake, 234 + $suppress_dev_warnings_flags, 235 + "-DCMAKE_TOOLCHAIN_FILE=$cmake_toolchain", 236 + $blurrr_path_to_use, 237 + "-DBLURRR_SDK_PATH=$blurrr_sdk_path", 238 + "-DANDROID_ABI=$arch", 239 + "-DBLURRR_CMAKE_ANDROID_REAL_BINARY_DIR=$cmake_binary_dir", 240 + "-DANDROID_SDK_ROOT=$android_sdk_root", 241 + "-C", $initial_cache, 242 + "-DANDROID_STANDALONE_TOOLCHAIN=$android_standalone_toolchain", 243 + "-DANDROID_TARGET_SDK_VERSION=$targetSdkVersion", 244 + "-DANDROID_MIN_SDK_VERSION=$minSdkVersion", 245 + "-DLIBRARY_OUTPUT_PATH_ROOT=$libsdir", 246 + "-DCMAKE_BUILD_TYPE=$buildtype", 247 + @remaining_options, 248 + $cmake_source_dir 249 + ); 250 + # my $error_status = system($command_string); 251 + if($error_status != 0) 252 + { 253 + die "Invoking CMake failed: $?\n"; 254 + } 255 + 256 + if($should_build) 257 + { 258 + print("Building $arch\n"); 259 + $error_status = system("make"); 260 + if($error_status != 0) 261 + { 262 + die "Invoking make failed: $?\n"; 263 + } 264 + } 265 + } 266 + 267 + return; 268 + 269 + } 270 + 271 + 272 + sub helpmenu() 273 + { 274 + my $basename = basename($0); 275 + print "Convenience script for generating and building CMake based projects for Android (multiple architectures).\n\n"; 276 + print "Convention:\n"; 277 + print "You have created standalone toolchains and placed them in a directory called standalone under the \$ANDROID_NDK_ROOT:\n"; 278 + print "\$ANDROID_NDK_ROOT/standalone/\n"; 279 + print "\tarm-linux-androideabi-4.6/\n"; 280 + print "\tx86-4.6/\n"; 281 + 282 + #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"; 283 + print "Usage: perl $basename [-h | -help] [<other flags passed to CMake>] <Project Source Directory>\n"; 284 + 285 + print "Options:\n"; 286 + print " -h or -help Brings up this help display.\n"; 287 + print "\n"; 288 + 289 + print "Required Options:\n"; 290 + print "<Project Source Directory> Path to the source code directory (containing the root CMakeLists.txt)\n"; 291 + print "\n"; 292 + 293 + print "Semi-required Options (needed if required environmental variables are not set)\n"; 294 + 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"; 295 + 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"; 296 + 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"; 297 + print "\n"; 298 + 299 + print "Optional Options:\n"; 300 + print " --targetsdkversion=<version> Allows you to override the targetSdkVersion. Default detects the latest availabe in the SDK. (Best to use default.)\n"; 301 + print " --minsdkversion=<version> Allows you to override the minSdkVersion. Default is 14. (Going lower may cause your app to crash on older devices.)\n"; 302 + print " --architectures=<list;of;arches> Allows you to override which architectures to build. Default is \"armeabi;armeabi-v7a;x86\"\n"; 303 + print " --projectsourcedir=<path to source> Overrides the <Project Source Directory> if you need a --switch.\n"; 304 + # 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"; 305 + 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"; 306 + # print " --libsdir=<path where libs are copied> Path where the built libs are placed. \n"; 307 + print " --compilerversion=<version> Allows you to specify the version number (4.6) of the compiler to disambiguate if you have multiple versions.\n"; 308 + 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"; 309 + print " --buildtype=<build type> The CMake Build Type. Default is MinSizeRel. None|Debug|Release|RelWithDebInfo|MinSizeRel\n"; 310 + print " --[no]build Specifies whether make should be invoked. Default is nobuild.\n"; 311 + print "\n"; 312 + print "Example Usage:\n"; 313 + print "$basename ~/Source/Blurrr/Examples/Oblivion/OblivionC\n"; 314 + 315 + return; 316 + } 317 + 318 + sub home_dir() 319 + { 320 + return File::Glob::bsd_glob("~"); 321 + } 322 + 323 + sub expand_tilde($) 324 + { 325 + my $path = shift; 326 + my $home_dir = home_dir(); 327 + 328 + $path =~ s/^~/$home_dir/; 329 + return $path; 330 + } 331 + 332 + sub absolute_path($) 333 + { 334 + my $file = shift; 335 + return Cwd::abs_path(expand_tilde($file)); 336 + } 337 + 338 + sub get_path_of_main_script() 339 + { 340 + my $dirname = dirname(__FILE__); 341 + return absolute_path($dirname); 342 + # return $dirname; 343 + } 344 + 345 + sub copy_build_scripts($$) 346 + { 347 + my $cmake_source_dir = shift; 348 + my $cmake_target_dir = shift; 349 + 350 + 351 + my $copy = "cp"; 352 + # my $flags = "-f"; 353 + # my $exclude_flags = ' --exclude ".in"'; 354 + my $flags = '-f'; 355 + my $source_param = $cmake_source_dir . "/AndroidCMake/*_ndk.sh"; 356 + my $target_param = $cmake_target_dir; 357 + my $command = "$copy $flags $source_param $target_param"; 358 + 359 + print("Executing: $copy $flags $source_param $target_param\n"); 360 + # my $error_status = system($rsync, $flags, $exclude_flags, $source_param, $target_param); 361 + my $error_status = system($command); 362 + if($error_status != 0) 363 + { 364 + die "Invoking copy failed: $?\n"; 365 + } 366 + } 367 + 368 + sub sort_api_levels 369 + { 370 + # $a and $b will be automatically defined by sort(). 371 + # Look up the position of the day in the week 372 + # using the DAYS hash. 373 + my ($api_level_a) = $a =~ /android-(\d+)/; 374 + my ($api_level_b) = $b =~ /android-(\d+)/; 375 + 376 + # reverse sort 377 + return $api_level_b <=> $api_level_a; 378 + 379 + # Now we can just compare $x and $y. Note, it 380 + # would be simpler in this case to use the <=> 381 + # operator. 382 + } 383 + 384 + sub detect_highest_android_sdk_api_level($) 385 + { 386 + my $sdk_root = shift; 387 + my $sdk_platforms = $sdk_root . "/platforms"; 388 + 389 + opendir(DIR, $sdk_platforms); 390 + my @files = grep(/^android-\d+$/, readdir(DIR)); 391 + closedir(DIR); 392 + 393 + # Sort days in order using a sort algorithm 394 + # contained in a function. 395 + @files = sort sort_api_levels @files; 396 + 397 + 398 + # foreach $file(@files) 399 + # { 400 + # print "$file\n"; 401 + # } 402 + 403 + my ($api_level) = $files[0] =~ /android-(\d+)/; 404 + return $api_level; 405 + } 406 + 407 + # Subroutine to extract and process command line parameters 408 + sub extract_parameters() 409 + { 410 + # To follow the convention of the other bootstrap scripts and CMake itself, 411 + # the last parameter is always the path to the source directory. 412 + my $cmake_source_dir = $ARGV[$#ARGV]; 413 + 414 + # Blurrr assumption: This Perl script is located at the root of the Blurrr SDK. 415 + my $blurrr_sdk_root = get_path_of_main_script(); 416 + 417 + my %params = ( 418 + h => \(my $hflag = 0), 419 + help => \(my $helpflag = 0), 420 + blurrrsdkpath => \(my $blurrr_sdk_path), # acts as an override for blurrr_sdk_root 421 + projectsourcedir => \(my $projectsourcedir), # this is allowed to override $cmake_source_dir 422 + cmakebinarydir => \(my $cmake_binary_dir), # 423 + libsdir => \(my $libsdir), 424 + androidsdkroot => \(my $android_sdk_root), 425 + standalonetoolchainroot => \(my $standalone_toolchain_root), 426 + targetsdkversion => \(my $targetSdkVersion), 427 + minsdkversion => \(my $minSdkVersion = 14), 428 + architectures => \(my $architectures), 429 + compilerversion => \(my $compilerversion), 430 + buildtype => \(my $buildtype = "MinSizeRel"), 431 + build => \(my $should_build = 0), 432 + cmaketoolchain => \(my $cmake_toolchain), 433 + cmake => \(my $cmake) 434 + ); 435 + 436 + 437 + # Call Library function which will extract and remove all switches and 438 + # their corresponding values. 439 + # These parameters will be removed from @ARGV 440 + my $errorval = &GetOptions(\%params, "h", "help", 441 + "blurrrsdkpath=s", 442 + "projectsourcedir=s", 443 + "cmakebinarydir=s", 444 + "libsdir=s", 445 + "androidsdkroot=s", 446 + "standalonetoolchainroot=s", 447 + "targetsdkversion=i", 448 + "minsdkversion=i", 449 + "architectures=s", 450 + "compilerversion=s", 451 + "buildtype=s", 452 + "build!", 453 + "cmaketoolchain=s", 454 + "cmake=s" 455 + ); 456 + # the exclaimation point allows for the negation 457 + # of the switch (i.e. -nobackup/-nobody is a switch) 458 + 459 + # Error value should have returned 1 if nothing went wrong 460 + # Otherwise, an unlisted parameter was specified. 461 + if($errorval !=1) 462 + { 463 + # Expecting GetOptions to state error. 464 + 465 + print "Exiting Program...\n"; 466 + exit 0; 467 + } 468 + 469 + if( ($hflag == 1) || ($helpflag == 1) ) 470 + { 471 + helpmenu(); 472 + exit 0; 473 + } 474 + 475 + if(not defined($projectsourcedir)) 476 + { 477 + # $projectsourcedir = $cmake_source_dir; 478 + } 479 + else 480 + { 481 + $cmake_source_dir = $projectsourcedir; 482 + } 483 + # sanitize path 484 + $cmake_source_dir = absolute_path($cmake_source_dir); 485 + 486 + 487 + if(not defined($cmake_binary_dir)) 488 + { 489 + # This is the current working directory following CMake conventions. 490 + $cmake_binary_dir = absolute_path(getcwd()); 491 + } 492 + # sanitize path 493 + $cmake_binary_dir = absolute_path($cmake_binary_dir); 494 + 495 + 496 + 497 + if(not defined($libsdir)) 498 + { 499 + $libsdir = $cmake_binary_dir . "/dist"; 500 + } 501 + 502 + 503 + if(not defined($android_sdk_root)) 504 + { 505 + $android_sdk_root = $ENV{"ANDROID_SDK_ROOT"} or $android_sdk_root = $ENV{"ANDROID_HOME"}; 506 + if(not defined($android_sdk_root)) 507 + { 508 + print("androidsdkroot directory not specified or environmental variable ANDROID_SDK_ROOT not defined\n"); 509 + helpmenu(); 510 + exit 1; 511 + } 512 + } 513 + # sanitize path 514 + $android_sdk_root = absolute_path($android_sdk_root); 515 + 516 + if(not defined($blurrr_sdk_path)) 517 + { 518 + $blurrr_sdk_path = $ENV{"BLURRR_SDK_PATH"}; 519 + if(not defined($blurrr_sdk_path)) 520 + { 521 + $blurrr_sdk_path = undef; 522 + } 523 + } 524 + else 525 + { 526 + $blurrr_sdk_path = absolute_path($blurrr_sdk_path); 527 + } 528 + 529 + 530 + if(not defined($standalone_toolchain_root)) 531 + { 532 + $standalone_toolchain_root = $ENV{"BLURRR_ANDROID_STANDALONE_ANDROID_TOOLCHAIN_ROOT"}; 533 + if(not defined($standalone_toolchain_root)) 534 + { 535 + print("standalonetoolchainroot root directory not specified or environmental variable BLURRR_ANDROID_STANDALONE_ANDROID_TOOLCHAIN_ROOT not defined\n"); 536 + helpmenu(); 537 + exit 2; 538 + } 539 + 540 + } 541 + # sanitize path 542 + $standalone_toolchain_root = absolute_path($standalone_toolchain_root); 543 + 544 + 545 + 546 + 547 + 548 + 549 + if(not defined($targetSdkVersion)) 550 + { 551 + $targetSdkVersion = detect_highest_android_sdk_api_level($android_sdk_root); 552 + } 553 + 554 + # test $architectures on return because it is too hard to pass multiple arrays back 555 + 556 + if(not defined($cmake_toolchain)) 557 + { 558 + # We keep a copy of the toolchain in the PROJECT_SOURCE_DIR/CMakeModules directory 559 + #$cmake_toolchain = $cmake_source_dir . "/CMakeModules/android.toolchain.cmake"; 560 + $cmake_toolchain = $cmake_source_dir . "/AndroidCMake/android.toolchain.cmake"; 561 + } 562 + 563 + if(not defined($cmake)) 564 + { 565 + # Grrrr. On Mac & Windows, we ship CMake with the SDK, but on Linux we depend on package management. 566 + $cmake = $blurrr_sdk_root . "/CMake/CMake.app/Contents/bin/cmake"; 567 + if(!(-f $cmake)) 568 + { 569 + $cmake = $blurrr_sdk_root . "/CMake/bin/cmake.exe"; 570 + if(!(-f $cmake)) 571 + { 572 + # assume it is in the path and Unix-y (no .exe) 573 + $cmake = "cmake"; 574 + } 575 + } 576 + } 577 + else 578 + { 579 + $cmake = absolute_path($cmake); 580 + } 581 + 582 + 583 + # Convert to absolute paths because we will be changing directories which will break relative paths. 584 + 585 + # We need to create the directory if it doesn't exist before calling absolute_path() on it. 586 + unless(-e $libsdir or make_path($libsdir)) 587 + { 588 + die("Unable to create $libsdir: $!\n"); 589 + } 590 + 591 + 592 + $cmake_toolchain = absolute_path($cmake_toolchain); 593 + $libsdir = absolute_path($libsdir); 594 + 595 + 596 + # This can be optimized out, but is left for clarity. 597 + # We already assumed the last parameter is the source dir and used it, so pop it. 598 + # pop @ARGV; 599 + 600 + # GetOptions has removed all found options so anything left in @ARGV is "remaining". 601 + my @remaining_options = @ARGV; 602 + pop @remaining_options; 603 + # Remember, can't pass back 2 arrays or in the middle because it shifts everything 604 + 605 + my @sorted_options = ( 606 + $blurrr_sdk_root, 607 + $blurrr_sdk_path, 608 + $cmake_source_dir, 609 + $cmake_binary_dir, 610 + $libsdir, 611 + $android_sdk_root, 612 + $standalone_toolchain_root, 613 + $targetSdkVersion, 614 + $minSdkVersion, 615 + $compilerversion, 616 + $buildtype, 617 + $should_build, 618 + $cmake_toolchain, 619 + $cmake, 620 + $architectures, 621 + @remaining_options 622 + ); 623 + return @sorted_options; 624 + } 625 + 626 + 627 + print("calling main\n"); 628 + main(); 629 + 630 +
+201
AndroidCMake/make_cmakeandroid.pl
··· 1 + #!/usr/bin/perl -w 2 + 3 + ################################################################## 4 + # 5 + # Convenince script to invoke make on CMake projects for Android 6 + # for each architecture and build them. 7 + # Copyright (C) PlayControl Software, LLC. 8 + # Eric Wing <ewing . public @ playcontrol.net> 9 + # 10 + ################################################################## 11 + 12 + 13 + use strict; 14 + use warnings; 15 + 16 + # Function to help with command line switches 17 + use Getopt::Long; 18 + # Allows extra "unknown options" to be specified which I will use to pass directly to the cmake executable. 19 + Getopt::Long::Configure("pass_through"); 20 + 21 + # Function to get the basename of a file 22 + use File::Basename; 23 + # Used for tilde expansion 24 + use File::Glob; 25 + 26 + # Provides functions to convert relative paths to absolute paths. 27 + use Cwd; 28 + 29 + # Global constants 30 + my %kArchToDirectoryNameMap = 31 + ( 32 + # mips => "mips", 33 + armeabi => "armeabi", 34 + "armeabi-v7a" => "armeabi-v7a", 35 + # "armeabi-v7a with NEON" => "armeabi-v7a", 36 + # "armeabi-v7a with VFPV3" => "armeabi-v7a", 37 + # "armeabi-v6 with VFP" => "armeabi", 38 + x86 => "x86" 39 + ); 40 + 41 + # Global constants 42 + my %kArchToCompilerNameMap = 43 + ( 44 + # mips => "mips", 45 + armeabi => "arm-linux-androideabi", 46 + "armeabi-v7a" => "arm-linux-androideabi", 47 + # "armeabi-v7a with NEON" => "armeabi", 48 + # "armeabi-v7a with VFPV3" => "armeabi", 49 + # "armeabi-v6 with VFP" => "armeabi", 50 + x86 => "x86" 51 + ); 52 + 53 + 54 + my @kSupportedArchitectures = 55 + ( 56 + # "mips", 57 + "armeabi", 58 + "armeabi-v7a", 59 + # "armeabi-v7a with NEON", 60 + # "armeabi-v7a with VFPV3", 61 + # "armeabi-v6 with VFP", 62 + "x86", 63 + ); 64 + 65 + 66 + # Function prototypes 67 + 68 + # main routine 69 + sub main(); 70 + # call main 71 + main(); 72 + 73 + sub main() 74 + { 75 + my ($targetdir, $make, @remaining_options) = extract_parameters(); 76 + # Save in case we need to return to the original current working directory. 77 + # my $original_current_working_directory = Cwd::cwd(); 78 + 79 + # print("targetdir: ", $targetdir, "\n"); 80 + # print("make: ", $make, "\n"); 81 + # print("remaining_options: ", @remaining_options, "\n"); 82 + 83 + 84 + foreach my $arch(@kSupportedArchitectures) 85 + { 86 + chdir($targetdir) or die("Could not change directory to $targetdir: $!\n"); 87 + my $arch_dir = $kArchToDirectoryNameMap{$arch}; 88 + print("Building $arch\n"); 89 + chdir($arch_dir) or die("Could not change directory to $arch_dir: $!\n"); 90 + 91 + my $error_status = system($make, @remaining_options); 92 + if($error_status != 0) 93 + { 94 + die "Invoking make failed: $?\n"; 95 + } 96 + 97 + } 98 + 99 + return; 100 + 101 + } 102 + 103 + 104 + sub helpmenu() 105 + { 106 + my $basename = basename($0); 107 + print "Convenience script for invoking make on CMake based projects for Android (multiple architectures).\n\n"; 108 + 109 + print "Usage: perl $basename [-h | -help] --targetdir=<path to build dir> [--make=<Make exectuable>] [<other flags passed to Make>]\n"; 110 + 111 + print "Options:\n"; 112 + print " -h or -help Brings up this help display.\n"; 113 + print " --targetdir=<path to build directory> (Optional) Path to where the root of the build directory is. Default is the current working directory.\n"; 114 + print " --make=<Make executable> (Optional) Allows you to specify the path and file to the Make executable.\n"; 115 + print "\n"; 116 + print "Example Usage:\n"; 117 + print "$basename clean\n"; 118 + print "$basename VERBOSE=1\n"; 119 + 120 + return; 121 + } 122 + 123 + sub home_dir() 124 + { 125 + return File::Glob::bsd_glob("~"); 126 + } 127 + 128 + sub expand_tilde($) 129 + { 130 + my $path = shift; 131 + my $home_dir = home_dir(); 132 + 133 + $path =~ s/^~/$home_dir/; 134 + return $path; 135 + } 136 + 137 + sub absolute_path($) 138 + { 139 + my $file = shift; 140 + return Cwd::abs_path(expand_tilde($file)); 141 + } 142 + 143 + # Subroutine to extract and process command line parameters 144 + sub extract_parameters() 145 + { 146 + my %params = ( 147 + h => \(my $hflag = 0), 148 + help => \(my $helpflag = 0), 149 + targetdir => \(my $targetdir), 150 + make => \(my $make) 151 + ); 152 + 153 + # Call Library function which will extract and remove all switches and 154 + # their corresponding values. 155 + # These parameters will be removed from @ARGV 156 + my $errorval = &GetOptions(\%params, "h", "help", 157 + "targetdir=s", 158 + "make=s" 159 + ); 160 + # the exclaimation point allows for the negation 161 + # of the switch (i.e. -nobackup/-nobody is a switch) 162 + 163 + 164 + # Error value should have returned 1 if nothing went wrong 165 + # Otherwise, an unlisted parameter was specified. 166 + if($errorval !=1) 167 + { 168 + # Expecting GetOptions to state error. 169 + 170 + print "Exiting Program...\n"; 171 + exit 0; 172 + } 173 + 174 + if( ($hflag == 1) || ($helpflag == 1) ) 175 + { 176 + helpmenu(); 177 + exit 0; 178 + } 179 + 180 + if(not defined($targetdir)) 181 + { 182 + $targetdir = Cwd::cwd(); 183 + } 184 + 185 + if(not defined($make)) 186 + { 187 + $make = "make"; 188 + } 189 + else 190 + { 191 + $make = absolute_path($make); 192 + } 193 + $targetdir = absolute_path($targetdir); 194 + 195 + my @remaining_options = @ARGV; 196 + my @sorted_options = ($targetdir, $make, @remaining_options); 197 + 198 + return @sorted_options; 199 + } 200 + 201 +
+15
AndroidCMake/make_ndk.sh
··· 1 + #!/bin/sh 2 + 3 + (cd cmake_ndk_build 4 + for d in */ ; do 5 + (cd "$d" 6 + make -j2 7 + ) 8 + done 9 + ) 10 + 11 + 12 + cp -f ../AndroidCMake/Android.mk dist 13 + mkdir -p dist/include 14 + rsync -avz ../SDL_image.h dist/include/ 15 +
+6 -6
CMakeLists.txt
··· 28 28 endif() 29 29 30 30 option(SDL_gpu_INSTALL "Install SDL_gpu libs, includes, and CMake scripts" ${SDL_gpu_INSTALL_BY_DEFAULT}) 31 - option(SDL_gpu_BUILD_DEBUG "Build with debugging symbols" ON) 31 + #option(SDL_gpu_BUILD_DEBUG "Build with debugging symbols" ON) 32 32 option(SDL_gpu_BUILD_DEMOS "Build SDL_gpu demo programs" ${SDL_gpu_DEFAULT_BUILD_DEMOS}) 33 33 option(SDL_gpu_BUILD_TESTS "Build SDL_gpu test programs" OFF) 34 34 option(SDL_gpu_BUILD_VIDEO_TEST "Build SDL_gpu video test program (requires FFMPEG)" OFF) ··· 73 73 include(ios-cmake/toolchain/XcodeDefaults) 74 74 endif() 75 75 76 - if ( SDL_gpu_BUILD_DEBUG ) 77 - SET(CMAKE_BUILD_TYPE Debug) 78 - else ( SDL_gpu_BUILD_DEBUG ) 79 - SET(CMAKE_BUILD_TYPE Release) 80 - endif ( SDL_gpu_BUILD_DEBUG ) 76 + #if ( SDL_gpu_BUILD_DEBUG ) 77 + # SET(CMAKE_BUILD_TYPE Debug) 78 + #else ( SDL_gpu_BUILD_DEBUG ) 79 + # SET(CMAKE_BUILD_TYPE Release) 80 + #endif ( SDL_gpu_BUILD_DEBUG ) 81 81 82 82 # Find the package for SDL or SDL2 83 83 if ( SDL_gpu_USE_SDL1 )