Merge pull request #3595 from Sonicadvance1/Android_headless

[Android] Headless support
This commit is contained in:
Ryan Houdek
2016-02-06 20:08:58 -05:00
8 changed files with 179 additions and 159 deletions

View File

@ -375,10 +375,24 @@ endif(VTUNE)
if(ANDROID) if(ANDROID)
message("Building for Android") message("Building for Android")
if(NOT ENABLE_HEADLESS)
add_definitions(-DANDROID) add_definitions(-DANDROID)
else()
# Lie to cmake a bit. We are cross compiling to Android
# but not as a shared library. We want an executable.
set(ANDROID 0)
endif()
set(USE_X11 0) set(USE_X11 0)
set(USE_UPNP 0) set(USE_UPNP 0)
set(USE_EGL 1) set(USE_EGL 1)
set(DISABLE_WX 1)
set(ENABLE_QT2 0)
# We are cross compiling, search only the toolchain for libraries and includes
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
elseif(NOT APPLE)
list(APPEND LIBS rt)
endif() endif()
if(ENABLE_HEADLESS) if(ENABLE_HEADLESS)
@ -390,8 +404,6 @@ if(ENABLE_HEADLESS)
add_definitions(-DUSE_HEADLESS) add_definitions(-DUSE_HEADLESS)
endif() endif()
include_directories(Externals/GL)
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE) add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
######################################## ########################################
@ -403,10 +415,10 @@ add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
include(CheckLib) include(CheckLib)
include(CheckCXXSourceRuns) include(CheckCXXSourceRuns)
if(NOT ANDROID)
include(FindOpenGL) include(FindOpenGL)
if (OPENGL_GL)
include_directories(${OPENGL_INCLUDE_DIR}) include_directories(${OPENGL_INCLUDE_DIR})
endif()
include(FindALSA OPTIONAL) include(FindALSA OPTIONAL)
if(ALSA_FOUND) if(ALSA_FOUND)
@ -467,7 +479,7 @@ if(NOT ANDROID)
set(USE_X11 0) set(USE_X11 0)
if(UNIX AND NOT APPLE AND NOT ENABLE_HEADLESS) if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT ENABLE_HEADLESS)
include(FindX11) include(FindX11)
if(TRY_X11 AND X11_FOUND) if(TRY_X11 AND X11_FOUND)
set(USE_X11 1) set(USE_X11 1)
@ -538,7 +550,6 @@ if(NOT ANDROID)
message(FATAL_ERROR "OProfile not found. Can't build profiling support.") message(FATAL_ERROR "OProfile not found. Can't build profiling support.")
endif() endif()
endif() endif()
endif()
if(USE_EGL) if(USE_EGL)
message("EGL OpenGL interface enabled") message("EGL OpenGL interface enabled")
@ -586,7 +597,7 @@ endif()
add_subdirectory(Externals/Bochs_disasm) add_subdirectory(Externals/Bochs_disasm)
include_directories(Externals/Bochs_disasm) include_directories(Externals/Bochs_disasm)
if(NOT ANDROID AND USE_SHARED_ENET) if(USE_SHARED_ENET)
check_lib(ENET libenet enet enet/enet.h QUIET) check_lib(ENET libenet enet enet/enet.h QUIET)
include(CheckSymbolExists) include(CheckSymbolExists)
if (ENET_FOUND) if (ENET_FOUND)
@ -636,7 +647,7 @@ else(ZLIB_FOUND)
include_directories(Externals/zlib) include_directories(Externals/zlib)
endif(ZLIB_FOUND) endif(ZLIB_FOUND)
if(NOT APPLE AND NOT ANDROID) if(NOT APPLE)
check_lib(LZO "(no .pc for lzo2)" lzo2 lzo/lzo1x.h QUIET) check_lib(LZO "(no .pc for lzo2)" lzo2 lzo/lzo1x.h QUIET)
endif() endif()
if(LZO_FOUND) if(LZO_FOUND)
@ -649,7 +660,7 @@ else()
endif() endif()
list(APPEND LIBS ${LZO}) list(APPEND LIBS ${LZO})
if(NOT APPLE AND NOT ANDROID) if(NOT APPLE)
check_lib(PNG libpng png png.h QUIET) check_lib(PNG libpng png png.h QUIET)
endif() endif()
if (PNG_FOUND) if (PNG_FOUND)
@ -701,7 +712,7 @@ if(LIBUSB_FOUND)
endif(LIBUSB_FOUND) endif(LIBUSB_FOUND)
set(SFML_REQD_VERSION 2.1) set(SFML_REQD_VERSION 2.1)
if(NOT APPLE AND NOT ANDROID) if(NOT APPLE)
find_package(SFML ${SFML_REQD_VERSION} COMPONENTS network system) find_package(SFML ${SFML_REQD_VERSION} COMPONENTS network system)
endif() endif()
if(SFML_FOUND) if(SFML_FOUND)
@ -714,7 +725,7 @@ else()
endif() endif()
if(USE_UPNP) if(USE_UPNP)
if(NOT APPLE AND NOT ANDROID) if(NOT APPLE)
include(FindMiniupnpc) include(FindMiniupnpc)
endif() endif()
if(MINIUPNPC_FOUND AND MINIUPNPC_API_VERSION GREATER 8) if(MINIUPNPC_FOUND AND MINIUPNPC_API_VERSION GREATER 8)
@ -730,7 +741,7 @@ if(USE_UPNP)
list(APPEND LIBS ${MINIUPNPC_LIBRARIES}) list(APPEND LIBS ${MINIUPNPC_LIBRARIES})
endif() endif()
if(NOT APPLE AND NOT ANDROID) if(NOT APPLE)
include(FindMbedTLS) include(FindMbedTLS)
endif() endif()
if(MBEDTLS_FOUND) if(MBEDTLS_FOUND)
@ -743,7 +754,7 @@ else()
include_directories(Externals/mbedtls/include) include_directories(Externals/mbedtls/include)
endif() endif()
if(NOT APPLE AND NOT ANDROID) if(NOT APPLE)
check_lib(SOIL "(no .pc for SOIL)" SOIL SOIL/SOIL.h QUIET) check_lib(SOIL "(no .pc for SOIL)" SOIL SOIL/SOIL.h QUIET)
endif() endif()
if(SOIL_FOUND) if(SOIL_FOUND)
@ -754,16 +765,27 @@ else()
include_directories(Externals/SOIL) include_directories(Externals/SOIL)
endif() endif()
if (ANDROID) find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c)
find_path(ICONV_INCLUDE_DIR NAMES iconv.h)
if (ICONV_LIBRARIES AND ICONV_INCLUDE_DIR)
mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARIES)
else()
message("Using static iconv from Externals") message("Using static iconv from Externals")
include_directories(Externals/libiconv-1.14/include) include_directories(Externals/libiconv-1.14/include)
add_subdirectory(Externals/libiconv-1.14) add_subdirectory(Externals/libiconv-1.14)
list(APPEND LIBS iconv) set(ICONV_LIBRARIES iconv)
else() endif()
find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c)
find_path(ICONV_INCLUDE_DIR NAMES iconv.h)
list(APPEND LIBS ${ICONV_LIBRARIES}) list(APPEND LIBS ${ICONV_LIBRARIES})
mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARIES)
find_library(OPENSLES_LIBRARIES NAMES OpenSLES)
find_path(OPENSLES_INCLUDE_DIR NAMES SLES/OpenSLES.h)
if (OPENSLES_LIBRARIES AND OPENSLES_INCLUDE_DIR)
set(OPENSLES_FOUND 1)
add_definitions(-DHAVE_OPENSLES=1)
include_directories(${OPENSLES_INCLUDE_DIR})
message("OpenSLES found, enabling OpenSLES sound backend")
endif() endif()
if(ENABLE_QT2) if(ENABLE_QT2)
@ -771,7 +793,7 @@ if(ENABLE_QT2)
message("Found Qt version ${Qt5Core_VERSION}, enabling the Qt backend") message("Found Qt version ${Qt5Core_VERSION}, enabling the Qt backend")
endif() endif()
if(NOT DISABLE_WX AND NOT ANDROID) if(NOT DISABLE_WX)
include(FindwxWidgets OPTIONAL) include(FindwxWidgets OPTIONAL)
FIND_PACKAGE(wxWidgets COMPONENTS core aui adv) FIND_PACKAGE(wxWidgets COMPONENTS core aui adv)
@ -845,7 +867,7 @@ if(NOT DISABLE_WX AND NOT ANDROID)
set(wxWidgets_LIBRARIES "wx") set(wxWidgets_LIBRARIES "wx")
endif(wxWidgets_FOUND) endif(wxWidgets_FOUND)
add_definitions(-DHAVE_WX=1) add_definitions(-DHAVE_WX=1)
endif(NOT DISABLE_WX AND NOT ANDROID) endif(NOT DISABLE_WX)
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD") if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD")
set(LIBS ${LIBS} usbhid) set(LIBS ${LIBS} usbhid)

View File

@ -6,10 +6,10 @@ set(SRCS AudioCommon.cpp
set(LIBS "") set(LIBS "")
if(ANDROID) if(OPENSLES_FOUND)
set(SRCS ${SRCS} OpenSLESStream.cpp) set(SRCS ${SRCS} OpenSLESStream.cpp)
set(LIBS ${LIBS} OpenSLES) set(LIBS ${LIBS} ${OPENSLES_LIBRARIES})
endif(ANDROID) endif(OPENSLES_FOUND)
if(ALSA_FOUND) if(ALSA_FOUND)
set(SRCS ${SRCS} AlsaSoundStream.cpp) set(SRCS ${SRCS} AlsaSoundStream.cpp)

View File

@ -42,7 +42,7 @@ else()
Logging/ConsoleListenerNix.cpp) Logging/ConsoleListenerNix.cpp)
endif() endif()
set(LIBS enet) list(APPEND LIBS enet)
if(_M_ARM_64) if(_M_ARM_64)
set(SRCS ${SRCS} set(SRCS ${SRCS}
Arm64Emitter.cpp Arm64Emitter.cpp
@ -60,10 +60,7 @@ else()
endif() endif()
endif() endif()
set(LIBS "${CMAKE_THREAD_LIBS_INIT}" ${VTUNE_LIBRARIES}) list(APPEND LIBS "${CMAKE_THREAD_LIBS_INIT}" ${VTUNE_LIBRARIES})
if(NOT APPLE AND NOT ANDROID)
set(LIBS ${LIBS} rt)
endif()
# OpenGL Interface # OpenGL Interface
set(SRCS ${SRCS} set(SRCS ${SRCS}

View File

@ -4,6 +4,8 @@
#include <array> #include <array>
#include <cstdlib> #include <cstdlib>
#include <sstream>
#include <vector>
#include "Common/GL/GLInterface/EGL.h" #include "Common/GL/GLInterface/EGL.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"

View File

@ -6,9 +6,7 @@
#include "Common/GL/GLInterfaceBase.h" #include "Common/GL/GLInterfaceBase.h"
#ifdef ANDROID #if defined(__APPLE__)
#include "Common/GL/GLInterface/EGLAndroid.h"
#elif defined(__APPLE__)
#include "Common/GL/GLInterface/AGL.h" #include "Common/GL/GLInterface/AGL.h"
#elif defined(_WIN32) #elif defined(_WIN32)
#include "Common/GL/GLInterface/WGL.h" #include "Common/GL/GLInterface/WGL.h"
@ -20,15 +18,15 @@
#endif #endif
#elif defined(USE_EGL) && USE_EGL && defined(USE_HEADLESS) #elif defined(USE_EGL) && USE_EGL && defined(USE_HEADLESS)
#include "Common/GL/GLInterface/EGL.h" #include "Common/GL/GLInterface/EGL.h"
#elif ANDROID
#include "Common/GL/GLInterface/EGLAndroid.h"
#else #else
#error Platform doesnt have a GLInterface #error Platform doesnt have a GLInterface
#endif #endif
std::unique_ptr<cInterfaceBase> HostGL_CreateGLInterface() std::unique_ptr<cInterfaceBase> HostGL_CreateGLInterface()
{ {
#ifdef ANDROID #if defined(__APPLE__)
return std::make_unique<cInterfaceEGLAndroid>();
#elif defined(__APPLE__)
return std::make_unique<cInterfaceAGL>(); return std::make_unique<cInterfaceAGL>();
#elif defined(_WIN32) #elif defined(_WIN32)
return std::make_unique<cInterfaceWGL>(); return std::make_unique<cInterfaceWGL>();
@ -40,6 +38,8 @@ std::unique_ptr<cInterfaceBase> HostGL_CreateGLInterface()
#else #else
return std::make_unique<cInterfaceGLX>(); return std::make_unique<cInterfaceGLX>();
#endif #endif
#elif ANDROID
return std::make_unique<cInterfaceEGLAndroid>();
#else #else
return nullptr; return nullptr;
#endif #endif

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include <vector> #include <vector>
#include "Common/Arm64Emitter.h" #include "Common/Arm64Emitter.h"

View File

@ -31,6 +31,7 @@ elseif(X11_FOUND)
endif() endif()
set(LIBS ${LIBS} ${X11_LIBRARIES} ${XINPUT2_LIBRARIES}) set(LIBS ${LIBS} ${X11_LIBRARIES} ${XINPUT2_LIBRARIES})
elseif(ANDROID) elseif(ANDROID)
add_definitions(-DCIFACE_USE_ANDROID)
set(SRCS ${SRCS} set(SRCS ${SRCS}
ControllerInterface/Android/Android.cpp) ControllerInterface/Android/Android.cpp)
endif() endif()

View File

@ -29,9 +29,6 @@
#if defined(__APPLE__) #if defined(__APPLE__)
#define CIFACE_USE_OSX #define CIFACE_USE_OSX
#endif #endif
#ifdef ANDROID
#define CIFACE_USE_ANDROID
#endif
#if defined(HAVE_SDL) && HAVE_SDL #if defined(HAVE_SDL) && HAVE_SDL
#define CIFACE_USE_SDL #define CIFACE_USE_SDL
#endif #endif