Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Removed custom toolchain + NDK updates #1350

Merged
merged 2 commits into from Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 21 additions & 38 deletions CMakeLists.txt
@@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -133,26 +114,28 @@ 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
set(ANDROID_ABI "armeabi-v7a" CACHE STRING "Look at the NDK docs for currently supported ABIs")

# this is a workaround to compile sfml-activity without the stl library as a dependency
# 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'
Expand Down Expand Up @@ -522,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()

Expand Down
2 changes: 1 addition & 1 deletion cmake/Config.cmake
Expand Up @@ -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()
25 changes: 0 additions & 25 deletions cmake/Macros.cmake
Expand Up @@ -229,28 +229,3 @@ macro(sfml_add_example target)
endif()

endmacro()

# macro to find packages on the host OS
# this is the same as in the toolchain file, which is here for Nsight Tegra VS
# since it won't use the Android toolchain file
if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
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()
endif()
45 changes: 0 additions & 45 deletions cmake/toolchains/android.toolchain.cmake
Expand Up @@ -1555,51 +1555,6 @@ set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )


# 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()


# export toolchain settings for the try_compile() command
if( NOT _CMAKE_IN_TRY_COMPILE )
set( __toolchain_config "")
Expand Down
1 change: 1 addition & 0 deletions include/SFML/OpenGL.hpp
Expand Up @@ -69,6 +69,7 @@
#include <GLES/glext.h>

// We're not using OpenGL ES 2+ yet, but we can use the sRGB extension
#include <GLES2/gl2platform.h>
#include <GLES2/gl2ext.h>

#endif
Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Audio/CMakeLists.txt
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/SFML/CMakeLists.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Graphics/CMakeLists.txt
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/SFML/Main/SFMLActivity.cpp
Expand Up @@ -28,7 +28,9 @@
#include <dlfcn.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <jni.h>
#include <string>

#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sfml-activity", __VA_ARGS__))

Expand Down
2 changes: 1 addition & 1 deletion src/SFML/System/Android/Activity.cpp
Expand Up @@ -43,7 +43,7 @@ std::streambuf::int_type LogcatStream::overflow (std::streambuf::int_type c)
if (c == "\n"[0])
{
m_message.push_back(c);
LOGE(m_message.c_str());
LOGE("%s", m_message.c_str());
m_message.clear();
}

Expand Down
8 changes: 4 additions & 4 deletions src/SFML/Window/EglContext.cpp
Expand Up @@ -243,10 +243,10 @@ EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
{
// Set our video settings constraint
const EGLint attributes[] = {
EGL_BUFFER_SIZE, bitsPerPixel,
EGL_DEPTH_SIZE, settings.depthBits,
EGL_STENCIL_SIZE, settings.stencilBits,
EGL_SAMPLE_BUFFERS, settings.antialiasingLevel,
EGL_BUFFER_SIZE, static_cast<EGLint>(bitsPerPixel),
EGL_DEPTH_SIZE, static_cast<EGLint>(settings.depthBits),
EGL_STENCIL_SIZE, static_cast<EGLint>(settings.stencilBits),
EGL_SAMPLE_BUFFERS, static_cast<EGLint>(settings.antialiasingLevel),
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
EGL_NONE
Expand Down