libsuperderpy/cmake/android.toolchain

128 lines
5.4 KiB
Text
Raw Normal View History

2016-11-06 03:10:43 +01:00
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
2019-01-20 03:00:01 +01:00
set(ANDROID_HOME "$ENV{ANDROID_HOME}" CACHE PATH "Path to Android SDK" )
2016-11-06 03:10:43 +01:00
#set path for android toolchain -- look
set(ANDROID_ALLEGRO_ROOT "$ENV{ANDROID_ALLEGRO_ROOT}" CACHE PATH "Path to Allegro 5 (>=5.2.2) build directory for Android" )
2016-11-07 01:45:12 +01:00
message( STATUS "Selected Allegro dir: ${ANDROID_ALLEGRO_ROOT}" )
if(NOT EXISTS "${ANDROID_ALLEGRO_ROOT}")
message( FATAL_ERROR "Invalid ANDROID_ALLEGRO_ROOT! Point it to the build directory of Allegro 5 (>=5.2.2) for Android.")
2016-11-07 01:45:12 +01:00
endif()
set(ANDROID_TOOLCHAIN "$ENV{ANDROID_TOOLCHAIN}" CACHE PATH "Path to the Android NDK Standalone Toolchain" )
2016-11-06 03:10:43 +01:00
message( STATUS "Selected Android toolchain: ${ANDROID_TOOLCHAIN}" )
if(NOT EXISTS ${ANDROID_TOOLCHAIN})
set(ANDROID_TOOLCHAIN "/opt/android-toolchain" CACHE PATH "Path to the Android NDK Standalone Toolchain" )
message( STATUS "Using default path for toolchain ${ANDROID_TOOLCHAIN}")
message( STATUS "If you prefer to use a different location, please set the ANDROID_TOOLCHAIN cmake variable.")
2016-11-06 03:10:43 +01:00
endif()
if(NOT EXISTS ${ANDROID_TOOLCHAIN})
2016-11-06 03:10:43 +01:00
message(FATAL_ERROR
"${ANDROID_TOOLCHAIN} does not exist!
2016-11-06 03:10:43 +01:00
You should either set an environment variable:
export ANDROID_TOOLCHAIN=~/my-toolchain
2016-11-06 03:10:43 +01:00
or put the toolchain in the default path:
sudo ln -s ~/android-toolchain /opt/android-toolchain
")
endif()
find_program(CMAKE_MAKE_PROGRAM make)
#setup build targets, mutually exclusive
set(PossibleArmTargets
2017-08-15 13:04:01 +02:00
"x86;x86_64;armeabi;armeabi-v7a;armeabi-v7a with NEON;arm64-v8a;mips;mips64")
2016-11-06 03:10:43 +01:00
set(ARM_TARGETS "armeabi-v7a" CACHE STRING
"the arm targets for android, recommend armeabi-v7a
for floating point support and NEON.")
if(ARM_TARGETS STREQUAL "x86")
set(ANDROID_ARCH "i686-linux-android")
elseif(ARM_TARGETS STREQUAL "x86_64")
set(ANDROID_ARCH "x86_64-linux-android")
2017-08-15 13:04:01 +02:00
elseif(ARM_TARGETS STREQUAL "arm64-v8a")
set(ANDROID_ARCH "aarch64-linux-android")
elseif(ARM_TARGETS STREQUAL "mips")
set(ANDROID_ARCH "mipsel-linux-android")
elseif(ARM_TARGETS STREQUAL "mips64")
set(ANDROID_ARCH "mips64el-linux-android")
elseif(ARM_TARGETS STREQUAL "armeabi")
set(ANDROID_ARCH "arm-linux-androideabi")
set(ARMEABI true)
set(NEON false)
elseif(ARM_TARGETS STREQUAL "armeabi-v7a")
set(ARMEABI true)
set(ANDROID_ARCH "arm-linux-androideabi")
set(NEON false)
elseif(ARM_TARGETS STREQUAL "armeabi-v7a with NEON")
set(ARMEABI true)
2016-11-06 03:10:43 +01:00
set(ANDROID_ARCH "arm-linux-androideabi")
2017-08-15 13:04:01 +02:00
set(NEON true)
else()
message(FATAL_ERROR "Unknown Android target ${ARM_TARGETS}")
2016-11-06 03:10:43 +01:00
endif()
if(WIN32)
set(CMAKE_EXECUTABLE_SUFFIX ".exe")
endif()
# specify the cross compiler
SET(CMAKE_C_COMPILER
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-clang${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "C compiler" FORCE)
2016-11-06 03:10:43 +01:00
SET(CMAKE_CXX_COMPILER
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-clang++${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "C++ compiler" FORCE)
2016-11-06 03:10:43 +01:00
#there may be a way to make cmake deduce these TODO deduce the rest of the tools
set(CMAKE_AR
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-ar${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "archive" FORCE)
2016-11-06 03:10:43 +01:00
set(CMAKE_LINKER
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-ld${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "linker" FORCE)
2016-11-06 03:10:43 +01:00
set(CMAKE_NM
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-nm${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "nm" FORCE)
2016-11-06 03:10:43 +01:00
set(CMAKE_OBJCOPY
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-objcopy${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "objcopy" FORCE)
2016-11-06 03:10:43 +01:00
set(CMAKE_OBJDUMP
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-objdump${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "objdump" FORCE)
2016-11-06 03:10:43 +01:00
set(CMAKE_STRIP
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-strip${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "strip" FORCE)
2016-11-06 03:10:43 +01:00
set(CMAKE_RANLIB
${ANDROID_TOOLCHAIN}/bin/${ANDROID_ARCH}-ranlib${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "ranlib" FORCE)
2016-11-06 03:10:43 +01:00
set_property(CACHE ARM_TARGETS PROPERTY STRINGS ${PossibleArmTargets} )
2019-01-20 03:00:01 +01:00
set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR}/android/app CACHE PATH
2016-11-06 03:10:43 +01:00
"root for library output, set this to change where
android libs are installed to")
#set these flags for client use
2017-08-15 13:04:01 +02:00
set(LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ARM_TARGETS}
CACHE PATH "path for android libs" FORCE)
set(CMAKE_INSTALL_PREFIX ${ANDROID_TOOLCHAIN}/user/${ARM_TARGETS}
2017-08-15 13:04:01 +02:00
CACHE STRING "path for installing" FORCE)
2016-11-06 03:10:43 +01:00
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH ${ANDROID_TOOLCHAIN}/bin ${ANDROID_TOOLCHAIN}/arm-linux-androideabi ${ANDROID_TOOLCHAIN}/sysroot ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_PREFIX}/share)
2016-11-06 03:10:43 +01:00
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
# only search for libraries and includes in the ndk toolchain
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#set these global flags for cmake client scripts to change behavior
set(ANDROID True)
set(BUILD_ANDROID True)
#make use of ANDROID_CFLAGS, ANDROID_LDFLAGS and ANDROID_CXXFLAGS
set(CMAKE_C_FLAGS "$ENV{ANDROID_CFLAGS} $ENV{CFLAGS}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "$ENV{ANDROID_CXXFLAGS} $ENV{CXXFLAGS}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "$ENV{ANDROID_LDFLAGS} $ENV{LDFLAGS}" CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "$ENV{ANDROID_LDFLAGS} $ENV{LDFLAGS}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-pie $ENV{ANDROID_LDFLAGS} $ENV{LDFLAGS}" CACHE STRING "" FORCE)
# Do a no-op access on the CMAKE_TOOLCHAIN_FILE variable so that CMake will not issue a warning on it being unused.
if (CMAKE_TOOLCHAIN_FILE)
endif()