1 # Platform defines. 2 set(CMAKE_SYSTEM_NAME Linux) 3 set(CMAKE_SYSTEM_PROCESSOR arm-linux-androideabi) 4 5 set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) 6 7 set(CMAKE_CROSSCOMPILING 1) 8 9 # dE defines 10 set(DE_CPU "DE_CPU_ARM") 11 set(DE_OS "DE_OS_ANDROID") 12 set(DE_COMPILER "DE_COMPILER_GCC") 13 if (NOT DEFINED DE_ANDROID_API) 14 set(DE_ANDROID_API 5) 15 endif () 16 17 # NDK installation path 18 set(ANDROID_NDK_PATH "/opt/android-ndk-r5b" CACHE STRING "Android NDK installation path") 19 set(ANDROID_NDK_HOST_OS "linux-x86" CACHE STRING "Android ndk host os") 20 set(ANDROID_ABI "armeabi-v7a" CACHE STRING "Android ABI") 21 set(ANDROID_NDK_TARGET "android-${DE_ANDROID_API}") 22 23 # \todo [pyry] Detect host type 24 set(ANDROID_CC_PATH "${ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/${ANDROID_NDK_HOST_OS}/") 25 set(CROSS_COMPILE "${ANDROID_CC_PATH}bin/arm-linux-androideabi-") 26 set(ANDROID_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-arm") 27 28 include(CMakeForceCompiler) 29 30 if (ANDROID_NDK_HOST_OS STREQUAL "linux-x86" OR 31 ANDROID_NDK_HOST_OS STREQUAL "darwin-x86") 32 cmake_force_c_compiler("${CROSS_COMPILE}gcc" GNU) 33 cmake_force_cxx_compiler("${CROSS_COMPILE}g++" GNU) 34 elseif (ANDROID_NDK_HOST_OS STREQUAL "windows") 35 cmake_force_c_compiler("${CROSS_COMPILE}gcc.exe" GNU) 36 cmake_force_cxx_compiler("${CROSS_COMPILE}g++.exe" GNU) 37 else () 38 message(FATAL_ERROR "Unknown ANDROID_NDK_HOST_OS") 39 endif () 40 41 set(CMAKE_SHARED_LIBRARY_C_FLAGS "") 42 set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") 43 44 # crtbegin_so.o & crtend_so.o \todo [pyry] Is there some special CMake variable for these? 45 if (DE_ANDROID_API GREATER 8) 46 set(CRTBEGIN_SO "${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o") 47 set(CRTEND_SO "${ANDROID_SYSROOT}/usr/lib/crtend_so.o") 48 endif () 49 50 set(CMAKE_C_CREATE_SHARED_LIBRARY 51 "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>") 52 set(CMAKE_CXX_CREATE_SHARED_LIBRARY 53 "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> ${CRTBEGIN_SO} <OBJECTS> <LINK_LIBRARIES> ${CRTEND_SO}") 54 55 # Search libs and include files (but not programs) from toolchain dir. 56 set(CMAKE_FIND_ROOT_PATH 57 "${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_ABI}" 58 "${ANDROID_CC_PATH}arm-linux-androideabi" 59 ${ANDROID_SYSROOT} 60 ) 61 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 62 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 63 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 64 65 set(NDK_FLAGS "--sysroot=${ANDROID_SYSROOT} -fpic -mfloat-abi=softfp -Os -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -D__ANDROID__ -D__STDC_INT64__") 66 67 if (ANDROID_ABI STREQUAL "armeabi-v7a") 68 # For armeabi-v7a 69 set(NDK_FLAGS "${NDK_FLAGS} -march=armv7-a -mfpu=vfp") 70 71 elseif (ANDROID_ABI STREQUAL "armeabi") 72 # For armeabi (ARMv5TE) 73 set(NDK_FLAGS "${NDK_FLAGS} -march=armv5te") 74 75 else () 76 message(FATAL_ERROR "Unknown Android ABI \"${ANDROID_ABI}\"") 77 endif () 78 79 # \note Hacky workaround for flags... 80 set(CMAKE_C_FLAGS "${NDK_FLAGS}" CACHE STRING "" FORCE) 81 set(CMAKE_CXX_FLAGS "${NDK_FLAGS} -I${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/include -I${ANDROID_NDK_PATH}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_ABI}/include" CACHE STRING "" FORCE) 82 set(CMAKE_SHARED_LINKER_FLAGS "-nostdlib -Wl,-shared,-Bsymbolic -Wl,--no-undefined -Wl,--fix-cortex-a" CACHE STRING "" FORCE) 83