1# Platform defines. 2set(CMAKE_SYSTEM_NAME Linux) 3set(CMAKE_SYSTEM_PROCESSOR arm-linux-androideabi) 4 5set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) 6 7set(CMAKE_CROSSCOMPILING 1) 8 9# dE defines 10set(DE_CPU "DE_CPU_ARM") 11set(DE_OS "DE_OS_ANDROID") 12set(DE_COMPILER "DE_COMPILER_GCC") 13if (NOT DEFINED DE_ANDROID_API) 14 set(DE_ANDROID_API 5) 15endif () 16 17# NDK installation path 18set(ANDROID_NDK_PATH "/opt/android-ndk-r5b" CACHE STRING "Android NDK installation path") 19set(ANDROID_NDK_HOST_OS "linux-x86" CACHE STRING "Android ndk host os") 20set(ANDROID_ABI "armeabi-v7a" CACHE STRING "Android ABI") 21set(ANDROID_NDK_TARGET "android-${DE_ANDROID_API}") 22 23# \todo [pyry] Detect host type 24set(ANDROID_CC_PATH "${ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/${ANDROID_NDK_HOST_OS}/") 25set(CROSS_COMPILE "${ANDROID_CC_PATH}bin/arm-linux-androideabi-") 26set(ANDROID_SYSROOT "${ANDROID_NDK_PATH}/platforms/${ANDROID_NDK_TARGET}/arch-arm") 27 28include(CMakeForceCompiler) 29 30if (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) 34elseif (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) 37else () 38 message(FATAL_ERROR "Unknown ANDROID_NDK_HOST_OS") 39endif () 40 41set(CMAKE_SHARED_LIBRARY_C_FLAGS "") 42set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") 43 44# crtbegin_so.o & crtend_so.o \todo [pyry] Is there some special CMake variable for these? 45if (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") 48endif () 49 50set(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>") 52set(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. 56set(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 ) 61set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 62set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 63set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 64 65set(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 67if (ANDROID_ABI STREQUAL "armeabi-v7a") 68 # For armeabi-v7a 69 set(NDK_FLAGS "${NDK_FLAGS} -march=armv7-a -mfpu=vfp") 70 71elseif (ANDROID_ABI STREQUAL "armeabi") 72 # For armeabi (ARMv5TE) 73 set(NDK_FLAGS "${NDK_FLAGS} -march=armv5te") 74 75else () 76 message(FATAL_ERROR "Unknown Android ABI \"${ANDROID_ABI}\"") 77endif () 78 79# \note Hacky workaround for flags... 80set(CMAKE_C_FLAGS "${NDK_FLAGS}" CACHE STRING "" FORCE) 81set(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) 82set(CMAKE_SHARED_LINKER_FLAGS "-nostdlib -Wl,-shared,-Bsymbolic -Wl,--no-undefined -Wl,--fix-cortex-a" CACHE STRING "" FORCE) 83