mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 14:21:04 +08:00
Android: Removed custom toolchain file
This commit drops the previous custom CMake toolchain file for Android in favor of CMake's new built-in toolchain for this (CMake >3.7.2). This makes building SFML for Android a lot simpler and more straight forward, working almost as smooth as other platforms. To configure your build directory, all you have to do is defining just a few variables the first time you invoke CMake. **Required Variables** * `CMAKE_SYSTEM_NAME` must be `Android`, so CMake knows we actually want to cross-compile. * `CMAKE_ANDROID_NDK` must point to the NDK's installation directory, e.g. `/usr/android/ndk` or `c:/android/ndk`. **Recommended Variables** * `CMAKE_ANDROID_STL_TYPE` defines the STL implementation to be used. You should use `c++_shared`, although others might work. **Optional Variables** * `CMAKE_SYSTEM_VERSION` can be set to pick a specific SDK version other than the latest. * `CMAKE_ANDROID_ARCH_ABI` defines the target architecture and ABI, for example `armeabi` or `armeabi-v7a`. Based on your system, you might want to enforce a specific generator to prevent issues, e.g. using `MinGW Makefiles`.
This commit is contained in:
parent
0da25a0b87
commit
806813e937
@ -1,4 +1,9 @@
|
||||
cmake_minimum_required(VERSION 2.8.3)
|
||||
# CMake's built-in Android support requires 3.7.0
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Android")
|
||||
cmake_minimum_required(VERSION 3.7.2)
|
||||
else()
|
||||
cmake_minimum_required(VERSION 2.8.3)
|
||||
endif()
|
||||
|
||||
# define a macro that helps defining an option
|
||||
macro(sfml_set_option var default type docstring)
|
||||
@ -38,26 +43,6 @@ if(NOT CMAKE_OSX_SYSROOT)
|
||||
ERROR_QUIET)
|
||||
endif()
|
||||
|
||||
# set Android specific options
|
||||
|
||||
# define the minimum API level to be used
|
||||
sfml_set_option(ANDROID_API_MIN 9 STRING "Choose the Android API level to be used (minimum 9)")
|
||||
# mirror the setting for the toolchain file
|
||||
set(ANDROID_NATIVE_API_LEVEL ${ANDROID_API_MIN})
|
||||
|
||||
# define the path to the Android NDK
|
||||
sfml_set_option(ANDROID_NDK "$ENV{ANDROID_NDK}" PATH "Path to the Android NDK")
|
||||
|
||||
# define the STL implementation to be used
|
||||
sfml_set_option(ANDROID_STL c++_shared STRING "Choose the STL implementation to be used (experimental)")
|
||||
|
||||
# default the ABI to ARM v7a for hardware floating point
|
||||
if(NOT ANDROID_ABI)
|
||||
set(ANDROID_ABI armeabi-v7a)
|
||||
endif()
|
||||
|
||||
#end of Android specific options
|
||||
|
||||
# project name
|
||||
project(SFML)
|
||||
|
||||
@ -119,12 +104,8 @@ endif()
|
||||
# Android options
|
||||
if(SFML_OS_ANDROID)
|
||||
# make sure there's the android library available
|
||||
if (${ANDROID_API_MIN} LESS 9)
|
||||
message(FATAL_ERROR "Android API level must be equal or greater than 9. Please adjust the CMake variable 'ANDROID_API_MIN'.")
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID_NDK)
|
||||
message(FATAL_ERROR "The Android NDK couldn't be found. Please adjust the CMake variable 'ANDROID_NDK' to point to the NDK directory.")
|
||||
if (CMAKE_ANDROID_API LESS 9)
|
||||
message(FATAL_ERROR "Android API level (${CMAKE_ANDROID_API}) must be equal or greater than 9.")
|
||||
endif()
|
||||
|
||||
# CMake doesn't support defining the STL to be used with Nsight Tegra, so warn the user
|
||||
@ -133,14 +114,19 @@ if(SFML_OS_ANDROID)
|
||||
endif()
|
||||
|
||||
# install everything in $NDK/sources/ because this path is appended by the NDK (convenient)
|
||||
set(CMAKE_INSTALL_PREFIX ${ANDROID_NDK}/sources/sfml)
|
||||
set(CMAKE_INSTALL_PREFIX ${CMAKE_ANDROID_NDK}/sources/third_party/sfml)
|
||||
|
||||
# we install libs in a subdirectory named after the ABI (lib/mips/*.so)
|
||||
set(LIB_SUFFIX "/${ANDROID_ABI}")
|
||||
set(LIB_SUFFIX "/${CMAKE_ANDROID_ARCH_ABI}")
|
||||
|
||||
# pass shared STL configuration (if any)
|
||||
if (ANDROID_STL MATCHES "_shared")
|
||||
add_definitions("-DSTL_LIBRARY=${ANDROID_STL}")
|
||||
if (CMAKE_ANDROID_STL_TYPE MATCHES "_shared")
|
||||
add_definitions("-DSTL_LIBRARY=${CMAKE_ANDROID_STL_TYPE}")
|
||||
if(NOT CMAKE_ANDROID_STL_TYPE MATCHES "c\\+\\+_shared")
|
||||
message("Android: Using ${CMAKE_ANDROID_STL_TYPE} as STL. Set CMAKE_ANDROID_STL_TYPE to c++_shared, if there are any issues.")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "Android: You're using a static STL (${CMAKE_ANDROID_STL_TYPE}). Set CMAKE_ANDROID_STL_TYPE to c++_shared, if there are any issues.")
|
||||
endif()
|
||||
|
||||
# let the user switch ABIs
|
||||
@ -150,12 +136,6 @@ if(SFML_OS_ANDROID)
|
||||
# we save the original compilation command line to restore it later in Macro.cmake
|
||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITH_STL ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
|
||||
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STL "<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>")
|
||||
else()
|
||||
unset(ANDROID_ABI CACHE)
|
||||
unset(ANDROID_API_MIN CACHE)
|
||||
unset(ANDROID_STL CACHE)
|
||||
unset(ANDROID_NATIVE_API_LEVEL CACHE)
|
||||
unset(ANDROID_NDK CACHE)
|
||||
endif()
|
||||
|
||||
# define SFML_STATIC if the build type is not set to 'shared'
|
||||
@ -525,7 +505,7 @@ elseif(SFML_OS_ANDROID)
|
||||
|
||||
if(NOT SFML_USE_SYSTEM_DEPS)
|
||||
# install extlibs
|
||||
install(DIRECTORY extlibs/libs-android/${ANDROID_ABI} DESTINATION extlibs/lib)
|
||||
install(DIRECTORY extlibs/libs-android/${CMAKE_ANDROID_ARCH_ABI} DESTINATION extlibs/lib)
|
||||
install(FILES extlibs/Android.mk DESTINATION extlibs)
|
||||
endif()
|
||||
|
||||
|
@ -124,5 +124,5 @@ if(SFML_OS_WINDOWS OR SFML_OS_IOS)
|
||||
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX)
|
||||
set(INSTALL_MISC_DIR share/SFML)
|
||||
elseif(SFML_OS_ANDROID)
|
||||
set(INSTALL_MISC_DIR ${ANDROID_NDK}/sources/sfml)
|
||||
set(INSTALL_MISC_DIR ${CMAKE_ANDROID_NDK}/sources/third_party/sfml)
|
||||
endif()
|
||||
|
@ -229,52 +229,3 @@ macro(sfml_add_example target)
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
||||
# macro to find packages on the host OS
|
||||
# We do not use the custom toolchain anymore, so we need to define
|
||||
# the macro here
|
||||
if(SFML_OS_ANDROID)
|
||||
# macro to find packages on the host OS
|
||||
macro( find_host_package )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
|
||||
if( CMAKE_HOST_WIN32 )
|
||||
SET( WIN32 1 )
|
||||
SET( UNIX )
|
||||
elseif( CMAKE_HOST_APPLE )
|
||||
SET( APPLE 1 )
|
||||
SET( UNIX )
|
||||
endif()
|
||||
find_package( ${ARGN} )
|
||||
SET( WIN32 )
|
||||
SET( APPLE )
|
||||
SET( UNIX 1 )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
|
||||
endmacro()
|
||||
|
||||
|
||||
# macro to find programs on the host OS
|
||||
macro( find_host_program )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
|
||||
if( CMAKE_HOST_WIN32 )
|
||||
SET( WIN32 1 )
|
||||
SET( UNIX )
|
||||
elseif( CMAKE_HOST_APPLE )
|
||||
SET( APPLE 1 )
|
||||
SET( UNIX )
|
||||
endif()
|
||||
find_program( ${ARGN} )
|
||||
SET( WIN32 )
|
||||
SET( APPLE )
|
||||
SET( UNIX 1 )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
|
||||
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
|
@ -69,8 +69,6 @@
|
||||
#include <GLES/glext.h>
|
||||
|
||||
// We're not using OpenGL ES 2+ yet, but we can use the sRGB extension
|
||||
// We need to import gl2platform.h, would normally be included by gl2.h
|
||||
// which was included by gl2ext.h in older NDK versions
|
||||
#include <GLES2/gl2platform.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
|
@ -66,7 +66,7 @@ elseif(SFML_OS_ANDROID)
|
||||
endif()
|
||||
|
||||
# find external libraries
|
||||
if(SFML_OS_ANDROID OR SFML_OS_IOS)
|
||||
if(SFML_OS_IOS)
|
||||
if(NOT SFML_OS_IOS)
|
||||
find_host_package(OpenAL REQUIRED)
|
||||
endif()
|
||||
|
@ -36,7 +36,7 @@ elseif(SFML_OS_IOS)
|
||||
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-ios/")
|
||||
elseif(SFML_OS_ANDROID)
|
||||
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers")
|
||||
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-android/${ANDROID_ABI}")
|
||||
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-android/${CMAKE_ANDROID_ARCH_ABI}")
|
||||
endif()
|
||||
|
||||
# add the SFML sources path
|
||||
|
@ -116,7 +116,7 @@ if(SFML_OPENGL_ES AND SFML_OS_LINUX)
|
||||
find_package(GLES REQUIRED)
|
||||
include_directories(${EGL_INCLUDE_DIR} ${GLES_INCLUDE_DIR})
|
||||
endif()
|
||||
if(SFML_OS_ANDROID OR SFML_OS_IOS)
|
||||
if(SFML_OS_IOS)
|
||||
find_host_package(Freetype REQUIRED)
|
||||
else()
|
||||
find_package(Freetype REQUIRED)
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sfml-activity", __VA_ARGS__))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user