1 # Platform defines. 2 set(CMAKE_SYSTEM_NAME Linux) 3 set(CMAKE_SYSTEM_PROCESSOR arm-eabi) 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 14 # NDK installation path 15 set(ANDROID_NDK_PATH "/opt/android-ndk-r4/" CACHE STRING "Android NDK installation path") 16 set(ANDROID_NDK_HOST_OS "linux-x86" CACHE STRING "Android ndk host os") 17 set(ANDROID_NDK_TARGET "android-5" CACHE STRING "Android target") 18 set(ANDROID_ABI "armeabi-v7a" CACHE STRING "Android ABI") 19 20 # \todo [pyry] Detect host type 21 set(ANDROID_CC_PATH "${ANDROID_NDK_PATH}/build/prebuilt/${ANDROID_NDK_HOST_OS}/arm-eabi-4.4.0/") 22 set(CROSS_COMPILE "${ANDROID_CC_PATH}bin/arm-eabi-") 23 24 include(CMakeForceCompiler) 25 26 if (ANDROID_NDK_HOST_OS STREQUAL "linux-x86") 27 cmake_force_c_compiler("${CROSS_COMPILE}gcc" GNU) 28 cmake_force_cxx_compiler("${CROSS_COMPILE}g++" GNU) 29 elseif (ANDROID_NDK_HOST_OS STREQUAL "windows") 30 cmake_force_c_compiler("${CROSS_COMPILE}gcc.exe" GNU) 31 cmake_force_cxx_compiler("${CROSS_COMPILE}g++.exe" GNU) 32 else () 33 message(FATAL_ERROR "Unknown ANDROID_NDK_HOST_OS") 34 endif () 35 36 set(CMAKE_SHARED_LIBRARY_C_FLAGS "") 37 set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") 38 39 set(CMAKE_C_CREATE_SHARED_LIBRARY 40 "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>") 41 set(CMAKE_CXX_CREATE_SHARED_LIBRARY 42 "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>") 43 44 45 # Search libs and include files (but not programs) from toolchain dir. 46 set(CMAKE_FIND_ROOT_PATH 47 "${ANDROID_NDK_PATH}/build/platforms/${ANDROID_NDK_TARGET}/arch-arm" 48 "${ANDROID_CC_PATH}arm-eabi" 49 ) 50 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 51 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 52 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 53 54 include_directories( 55 "${ANDROID_NDK_PATH}/build/platforms/${ANDROID_NDK_TARGET}/arch-arm/usr/include" 56 ) 57 58 link_directories( 59 "${ANDROID_NDK_PATH}/build/platforms/${ANDROID_NDK_TARGET}/arch-arm/usr/lib" 60 ) 61 62 set(NDK_FLAGS "-fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -mfloat-abi=softfp -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -D__ANDROID__ -D__STDC_INT64__") 63 64 if (ANDROID_ABI STREQUAL "armeabi-v7a") 65 # For armeabi-v7a 66 set(NDK_FLAGS "${NDK_FLAGS} -march=armv7-a -mfpu=vfp") 67 68 elseif (ANDROID_ABI STREQUAL "armeabi") 69 # For armeabi (ARMv5TE) 70 set(NDK_FLAGS "${NDK_FLAGS} -march=armv5te") 71 72 else () 73 message(FATAL_ERROR "Unknown Android ABI \"${ANDROID_ABI}\"") 74 endif () 75 76 # \note Hacky workaround for flags... 77 set(CMAKE_C_FLAGS "${NDK_FLAGS}" CACHE STRING "" FORCE) 78 set(CMAKE_CXX_FLAGS "${NDK_FLAGS}" CACHE STRING "" FORCE) 79 set(CMAKE_SHARED_LINKER_FLAGS "-nostdlib -Wl,-shared,-Bsymbolic -Wl,--no-undefined" CACHE STRING "" FORCE) 80