Added the Android port
This commit is contained in:
parent
01b745185e
commit
63bbe2c91e
183 changed files with 40166 additions and 40 deletions
|
@ -37,6 +37,11 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|||
return()
|
||||
endif()
|
||||
endif()
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||
set(SFML_OS_ANDROID 1)
|
||||
|
||||
# use the OpenGL ES implementation on Android
|
||||
set(OPENGL_ES 1)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported operating system")
|
||||
return()
|
||||
|
@ -80,8 +85,8 @@ else()
|
|||
return()
|
||||
endif()
|
||||
|
||||
# define the install directory for miscellaneous files
|
||||
if(SFML_OS_WINDOWS)
|
||||
# define the install directory for miscellaneous files
|
||||
if(SFML_OS_WINDOWS OR SFML_OS_ANDROID)
|
||||
set(INSTALL_MISC_DIR .)
|
||||
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX)
|
||||
set(INSTALL_MISC_DIR share/SFML)
|
||||
|
|
|
@ -10,6 +10,7 @@ macro(sfml_add_library target)
|
|||
# parse the arguments
|
||||
cmake_parse_arguments(THIS "" "" "SOURCES;DEPENDS;EXTERNAL_LIBS" ${ARGN})
|
||||
|
||||
if(NOT ANDROID)
|
||||
# create the target
|
||||
add_library(${target} ${THIS_SOURCES})
|
||||
|
||||
|
@ -105,7 +106,150 @@ macro(sfml_add_library target)
|
|||
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin
|
||||
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel
|
||||
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin)
|
||||
else()
|
||||
# create an empty target added to the default build
|
||||
add_custom_target(${target} ALL)
|
||||
|
||||
# get the module name (extract 'network' from 'sfml-network' for example)
|
||||
string(SUBSTRING ${target} 5 -1 MODULE_NAME)
|
||||
|
||||
# make the first letter a capital letter ('network' -> 'Network')s
|
||||
string(SUBSTRING ${MODULE_NAME} 0 1 FIRST_LETTER)
|
||||
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
|
||||
string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" PROTO_NAME_CAP "${MODULE_NAME}")
|
||||
set(MODULE_NAME ${PROTO_NAME_CAP})
|
||||
|
||||
# create an empty Application.mk ready to be filled
|
||||
set(APPLICATION_MK ${CMAKE_BINARY_DIR}/src/SFML/${MODULE_NAME}/Application.mk)
|
||||
file(WRITE ${APPLICATION_MK})
|
||||
|
||||
# define several path for later use
|
||||
set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
|
||||
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
|
||||
set(EXTLIBS_DIR ${PROJECT_SOURCE_DIR}/extlibs/android/extlibs)
|
||||
|
||||
# add support for Windows under Cygwin (add C:/cygwin64 to path)
|
||||
execute_process(COMMAND uname -o OUTPUT_VARIABLE UNAME_RESULT)
|
||||
if (UNAME_RESULT MATCHES Cygwin)
|
||||
execute_process(COMMAND cygpath --mixed / OUTPUT_VARIABLE CYGPATH)
|
||||
string(STRIP ${CYGPATH} CYGPATH)
|
||||
|
||||
set(INCLUDE_DIR ${CYGPATH}${PROJECT_SOURCE_DIR}/include)
|
||||
set(SRC_DIR ${CYGPATH}${PROJECT_SOURCE_DIR}/src)
|
||||
set(EXTLIBS_DIR ${CYGPATH}${PROJECT_SOURCE_DIR}/extlibs/android/extlibs)
|
||||
endif()
|
||||
|
||||
# write the Application.mk
|
||||
file(APPEND ${APPLICATION_MK} "NDK_APP_OUT := ${CMAKE_BINARY_DIR}/src/SFML/${MODULE_NAME}/obj\n")
|
||||
file(APPEND ${APPLICATION_MK} "APP_PLATFORM := android-${ANDROID_API_LEVEL}\n")
|
||||
file(APPEND ${APPLICATION_MK} "APP_STL := stlport_static\n")
|
||||
file(APPEND ${APPLICATION_MK} "APP_BUILD_SCRIPT := Android.mk\n")
|
||||
file(APPEND ${APPLICATION_MK} "APP_MODULES := ${target}\n")
|
||||
file(APPEND ${APPLICATION_MK} "APP_CPPFLAGS += -I${INCLUDE_DIR}\n")
|
||||
file(APPEND ${APPLICATION_MK} "APP_CPPFLAGS += -I${SRC_DIR}\n")
|
||||
file(APPEND ${APPLICATION_MK} "APP_CPPFLAGS += -I${EXTLIBS_DIR}/include\n")
|
||||
file(APPEND ${APPLICATION_MK} "APP_CPPFLAGS += -DSFML_OPENGL_ES\n")
|
||||
|
||||
if (ANDROID_ABI_ARM)
|
||||
file(APPEND ${APPLICATION_MK} "APP_ABI += armeabi\n")
|
||||
endif()
|
||||
|
||||
if (ANDROID_ABI_ARMv7)
|
||||
file(APPEND ${APPLICATION_MK} "APP_ABI += armeabi-v7a\n")
|
||||
endif()
|
||||
|
||||
if (ANDROID_ABI_MIPS)
|
||||
file(APPEND ${APPLICATION_MK} "APP_ABI += mips\n")
|
||||
endif()
|
||||
|
||||
if (ANDROID_ABI_x86)
|
||||
file(APPEND ${APPLICATION_MK} "APP_ABI += x86\n")
|
||||
endif()
|
||||
|
||||
# define the target build rules
|
||||
set(DIR ${PROJECT_SOURCE_DIR}/src/SFML/${MODULE_NAME})
|
||||
set(NDK_MODULE_PATH ${PROJECT_SOURCE_DIR}/extlibs/android)
|
||||
set(NDK_PROJECT_PATH ${PROJECT_SOURCE_DIR}/src/SFML/${MODULE_NAME})
|
||||
set(NDK_BUILD ${ANDROID_NDK_PATH}/ndk-build)
|
||||
set(NDK_APPLICATION_MK NDK_APPLICATION_MK=${APPLICATION_MK})
|
||||
|
||||
# create the environment for ndk-build
|
||||
set(NDK_ENVIRONMENT NDK_MODULE_PATH=${NDK_MODULE_PATH} NDK_PROJECT_PATH=${NDK_PROJECT_PATH})
|
||||
|
||||
# invoke the ndk-build scripts from the ndk with the right parameters
|
||||
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${NDK_BUILD} -C ${DIR} ${NDK_APPLICATION_MK} ${NDK_ENVIRONMENT})
|
||||
|
||||
# define the target install rules
|
||||
if (ANDROID_ABI_ARM)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/src/SFML/${MODULE_NAME}/obj/local/armeabi DESTINATION ${ANDROID_NDK_PATH}/sources/sfml/lib/ PATTERN "objs" EXCLUDE)
|
||||
endif()
|
||||
if (ANDROID_ABI_ARMv7)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/src/SFML/${MODULE_NAME}/obj/local/armeabi-v7a DESTINATION ${ANDROID_NDK_PATH}/sources/sfml/lib PATTERN "objs" EXCLUDE)
|
||||
endif()
|
||||
if (ANDROID_ABI_MIPS)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/src/SFML/${MODULE_NAME}/obj/local/mips DESTINATION ${ANDROID_NDK_PATH}/sources/sfml/lib PATTERN "objs" EXCLUDE)
|
||||
endif()
|
||||
if (ANDROID_ABI_x86)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/src/SFML/${MODULE_NAME}/obj/local/x86 DESTINATION ${ANDROID_NDK_PATH}/sources/sfml/lib PATTERN "objs" EXCLUDE)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# add a new target which is a SFML example
|
||||
# ex: sfml_add_example(ftp
|
||||
# SOURCES ftp.cpp ...
|
||||
# DEPENDS sfml-network sfml-system)
|
||||
macro(sfml_add_example target)
|
||||
|
||||
# parse the arguments
|
||||
sfml_parse_arguments(THIS "SOURCES;DEPENDS" "GUI_APP" ${ARGN})
|
||||
|
||||
# set a source group for the source files
|
||||
source_group("" FILES ${THIS_SOURCES})
|
||||
|
||||
# create the target
|
||||
if(THIS_GUI_APP AND WINDOWS)
|
||||
add_executable(${target} WIN32 ${THIS_SOURCES})
|
||||
target_link_libraries(${target} sfml-main)
|
||||
else()
|
||||
add_executable(${target} ${THIS_SOURCES})
|
||||
endif()
|
||||
|
||||
# set the debug suffix
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
|
||||
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "Examples")
|
||||
|
||||
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
||||
if(WINDOWS AND COMPILER_GCC AND SFML_USE_STATIC_STD_LIBS)
|
||||
if(NOT GCC_VERSION VERSION_LESS "4")
|
||||
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# link the target to its SFML dependencies
|
||||
if(THIS_DEPENDS)
|
||||
target_link_libraries(${target} ${THIS_DEPENDS})
|
||||
endif()
|
||||
|
||||
# add the install rule
|
||||
install(TARGETS ${target}
|
||||
RUNTIME DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples)
|
||||
|
||||
# install the example's source code
|
||||
install(FILES ${THIS_SOURCES}
|
||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||
COMPONENT examples)
|
||||
|
||||
# install the example's resources as well
|
||||
set(EXAMPLE_RESOURCES "${CMAKE_SOURCE_DIR}/examples/${target}/resources")
|
||||
if(EXISTS ${EXAMPLE_RESOURCES})
|
||||
install(DIRECTORY ${EXAMPLE_RESOURCES}
|
||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||
COMPONENT examples)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# add a new target which is a SFML example
|
||||
|
|
49
cmake/toolchains/Android.cmake
Normal file
49
cmake/toolchains/Android.cmake
Normal file
|
@ -0,0 +1,49 @@
|
|||
# As Android native applications are compiled by the NDK and so, use its build
|
||||
# system (mandatory) which contains many toolchains, we must fool CMake to
|
||||
# obtain the same build interface. Here, we're setting non-existing toolchains
|
||||
# to satisfy CMake. Only CMAKE_SYSTEM_NAME is relevant as it will identify the
|
||||
# targetted platfrom across our CMake scripts.
|
||||
|
||||
include(CMakeForceCompiler)
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Android)
|
||||
set(CMAKE_SYSTEM_VERSION 0)
|
||||
set(CMAKE_SYSTEM_PROCESSOR unknown)
|
||||
|
||||
CMAKE_FORCE_C_COMPILER(/ GNU)
|
||||
CMAKE_FORCE_CXX_COMPILER(/ GNU)
|
||||
|
||||
# We need to know where the NDK is located. We'll define some options to
|
||||
# customize the build process using NDK/ndk-build: a library might be built for
|
||||
# multiple architecture targetting different API level at the same time.
|
||||
|
||||
# See the NDK as an entire filesystem on its own where we would install headers
|
||||
# and libraries in it.
|
||||
|
||||
# attempts to know the NDK path from various environment variable
|
||||
if(NOT $ENV{NDK} STREQUAL "")
|
||||
set(ANDROID_NDK_PATH $ENV{NDK})
|
||||
elseif(NOT $ENV{NDK_PATH} STREQUAL "")
|
||||
set(ANDROID_NDK_PATH $ENV{NDK_PATH})
|
||||
elseif(NOT $ENV{ANDROID_NDK} STREQUAL "")
|
||||
set(ANDROID_NDK_PATH $ENV{ANDROID_NDK})
|
||||
elseif(NOT $ENV{ANDROID_NDK_PATH} STREQUAL "")
|
||||
set(ANDROID_NDK_PATH $ENV{ANDROID_NDK_PATH})
|
||||
else()
|
||||
set(ANDROID_NDK_PATH /path/to/the/NDK)
|
||||
endif()
|
||||
|
||||
# add an option for choosing the NDK
|
||||
sfml_set_option(ANDROID_NDK_PATH ${ANDROID_NDK_PATH} STRING "Where is the NDK located ?")
|
||||
|
||||
# add an option for choosing the API level (by default, it chooses the most widespread and used)
|
||||
sfml_set_option(ANDROID_API_LEVEL 9 STRING "What API level should it target ?")
|
||||
|
||||
# add options for choosing the targetted arches
|
||||
sfml_set_option(ANDROID_ABI_ARM TRUE BOOL "Build for arm architecture ?")
|
||||
sfml_set_option(ANDROID_ABI_ARMv7 FALSE BOOL "Build for armv7 architecture ?")
|
||||
sfml_set_option(ANDROID_ABI_MIPS FALSE BOOL "Build for mipsel architecture ?")
|
||||
sfml_set_option(ANDROID_ABI_x86 FALSE BOOL "Build for x86 architecture ?")
|
||||
|
||||
# where SFML headers and libs need to be installed
|
||||
set(CMAKE_INSTALL_PREFIX ${ANDROID_NDK_PATH}/sources/sfml)
|
Loading…
Add table
Add a link
Reference in a new issue