(Android) Added build support to the CMake configuration

This commit is contained in:
Leon Styhre 2023-11-19 17:37:00 +01:00
parent 8c25702fa4
commit 145cd85b0a
3 changed files with 93 additions and 6 deletions

View file

@ -0,0 +1,32 @@
# FindOpenGLES
# ------------
# Finds the OpenGLES3 library
#
# This will define the following variables::
#
# OPENGLES3_FOUND - system has OpenGLES
# OPENGLES3_INCLUDE_DIRS - the OpenGLES include directory
# OPENGLES3_LIBRARIES - the OpenGLES libraries
if(NOT HINT_GLES_LIBNAME)
set(HINT_GLES_LIBNAME GLESv3)
endif()
find_path(OPENGLES3_INCLUDE_DIR GLES3/gl3.h
PATHS "${CMAKE_FIND_ROOT_PATH}/usr/include"
HINTS ${HINT_GLES_INCDIR}
)
find_library(OPENGLES3_gl_LIBRARY
NAMES ${HINT_GLES_LIBNAME}
HINTS ${HINT_GLES_LIBDIR}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenGLES3 REQUIRED_VARS OPENGLES3_gl_LIBRARY OPENGLES3_INCLUDE_DIR)
if(OPENGLES3_FOUND)
set(OPENGLES3_LIBRARIES ${OPENGLES3_gl_LIBRARY})
set(OPENGLES3_INCLUDE_DIRS ${OPENGLES3_INCLUDE_DIR})
mark_as_advanced(OPENGLES3_INCLUDE_DIR OPENGLES3_gl_LIBRARY)
endif()

View file

@ -114,6 +114,8 @@ set_property(CACHE GLSYSTEM PROPERTY STRINGS "Desktop OpenGL" "Embedded OpenGL")
if(GLSYSTEM MATCHES "Desktop OpenGL") if(GLSYSTEM MATCHES "Desktop OpenGL")
set(OpenGL_GL_PREFERENCE GLVND) set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
elseif(ANDROID)
find_package(OpenGLES3 REQUIRED)
elseif(GLES AND NOT EMSCRIPTEN) elseif(GLES AND NOT EMSCRIPTEN)
find_package(OpenGLES2 REQUIRED) find_package(OpenGLES2 REQUIRED)
endif() endif()
@ -129,7 +131,7 @@ elseif(WIN32)
NOT EXISTS ${PROJECT_SOURCE_DIR}/external/pugixml/pugixml.dll) # MSVC NOT EXISTS ${PROJECT_SOURCE_DIR}/external/pugixml/pugixml.dll) # MSVC
message(FATAL_ERROR "-- You need to build the dependencies in ./external first") message(FATAL_ERROR "-- You need to build the dependencies in ./external first")
endif() endif()
elseif(NOT EMSCRIPTEN) elseif(NOT EMSCRIPTEN AND NOT ANDROID)
find_package(CURL REQUIRED) find_package(CURL REQUIRED)
find_package(FFmpeg REQUIRED) find_package(FFmpeg REQUIRED)
find_package(FreeImage REQUIRED) find_package(FreeImage REQUIRED)
@ -218,6 +220,10 @@ if(APPLE AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 15.0.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-utf8") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-utf8")
endif() endif()
if(ANDROID)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog")
endif()
if(EMSCRIPTEN) if(EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=2 -pthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=2 -pthread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s ASSERTIONS=1 -s EXIT_RUNTIME=1 -s USE_SDL=2 \ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s ASSERTIONS=1 -s EXIT_RUNTIME=1 -s USE_SDL=2 \
@ -379,6 +385,18 @@ if(APPLE)
endif() endif()
endif() endif()
if(ANDROID)
if(ANDROID_ABI MATCHES arm64-v8a)
message("-- Building for Android arm64-v8a")
set(ANDROID_CPU_ARCH arm64-v8a)
elseif(ANDROID_ABI MATCHES x86_64)
message("-- Building for Android x86_64")
set(ANDROID_CPU_ARCH x86_64)
else()
message(FATAL_ERROR "-- Unsupported Android ABI: " ${ANDROID_ABI})
endif()
endif()
# Affects the application updater and is used for displaying version info in the main menu. # Affects the application updater and is used for displaying version info in the main menu.
if(ES_VERSION MATCHES alpha OR ES_VERSION MATCHES beta OR ES_VERSION MATCHES dev) if(ES_VERSION MATCHES alpha OR ES_VERSION MATCHES beta OR ES_VERSION MATCHES dev)
add_compile_definitions(IS_PRERELEASE) add_compile_definitions(IS_PRERELEASE)
@ -446,6 +464,15 @@ elseif(EMSCRIPTEN)
${CMAKE_CURRENT_SOURCE_DIR}/external/FreeImage-CMake/FreeImage/Source ${CMAKE_CURRENT_SOURCE_DIR}/external/FreeImage-CMake/FreeImage/Source
${CMAKE_CURRENT_SOURCE_DIR}/external/freetype/include ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype/include
${CMAKE_CURRENT_SOURCE_DIR}/external/pugixml/src) ${CMAKE_CURRENT_SOURCE_DIR}/external/pugixml/src)
elseif(ANDROID)
set(COMMON_INCLUDE_DIRS ${COMMON_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include
${CMAKE_CURRENT_SOURCE_DIR}/external/ffmpeg-kit/src/ffmpeg
${CMAKE_CURRENT_SOURCE_DIR}/external/freeimage/FreeImage/Source
${CMAKE_CURRENT_SOURCE_DIR}/external/freetype/include
${CMAKE_CURRENT_SOURCE_DIR}/external/libgit2/include
${CMAKE_CURRENT_SOURCE_DIR}/external/pugixml/src
${CMAKE_CURRENT_SOURCE_DIR}/external/SDL_Android)
else() else()
set(COMMON_INCLUDE_DIRS ${COMMON_INCLUDE_DIRS} set(COMMON_INCLUDE_DIRS ${COMMON_INCLUDE_DIRS}
${FFMPEG_INCLUDE_DIRS} ${FFMPEG_INCLUDE_DIRS}
@ -529,6 +556,22 @@ elseif(WIN32)
mingw32 mingw32
Winmm.dll) Winmm.dll)
endif() endif()
elseif(ANDROID)
set(COMMON_LIBRARIES ${COMMON_LIBRARIES}
# FFmpeg libraries.
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libavcodec.so
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libavfilter.so
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libavformat.so
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libavutil.so
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libswresample.so
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libswscale.so
# Other dependencies.
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libcurl.so
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libfreeimage.a
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libfreetype.so
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libgit2.so
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libpugixml.a
${PROJECT_SOURCE_DIR}/android/libs/${ANDROID_CPU_ARCH}/libSDL2.so)
elseif(EMSCRIPTEN) elseif(EMSCRIPTEN)
set(COMMON_LIBRARIES ${COMMON_LIBRARIES} set(COMMON_LIBRARIES ${COMMON_LIBRARIES}
# FFmpeg core libraries. # FFmpeg core libraries.
@ -611,6 +654,8 @@ endif()
# OpenGL. # OpenGL.
if(GLSYSTEM MATCHES "Desktop OpenGL") if(GLSYSTEM MATCHES "Desktop OpenGL")
list(APPEND COMMON_LIBRARIES ${OPENGL_LIBRARIES}) list(APPEND COMMON_LIBRARIES ${OPENGL_LIBRARIES})
elseif(GLES AND ANDROID)
list(APPEND COMMON_LIBRARIES ${OPENGLES3_LIBRARIES})
elseif(GLES) elseif(GLES)
list(APPEND COMMON_LIBRARIES ${OPENGLES2_LIBRARIES}) list(APPEND COMMON_LIBRARIES ${OPENGLES2_LIBRARIES})
endif() endif()
@ -623,13 +668,18 @@ set(EXECUTABLE_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
set(LIBRARY_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE) set(LIBRARY_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
# Add each component. # Add each component.
if(NOT ANDROID)
add_subdirectory(es-pdf-converter) add_subdirectory(es-pdf-converter)
endif()
add_subdirectory(external) add_subdirectory(external)
add_subdirectory(es-core) add_subdirectory(es-core)
add_subdirectory(es-app) add_subdirectory(es-app)
if(NOT ANDROID)
# Make sure that es-pdf-convert is built first, and then that rlottie is built before es-core. # Make sure that es-pdf-convert is built first, and then that rlottie is built before es-core.
# Also set lottie2gif to not be built. # Also set lottie2gif to not be built.
add_dependencies(lunasvg es-pdf-convert) add_dependencies(lunasvg es-pdf-convert)
endif()
add_dependencies(es-core rlottie) add_dependencies(es-core rlottie)
set_target_properties(lottie2gif PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) set_target_properties(lottie2gif PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)

View file

@ -132,6 +132,11 @@ elseif(WIN32)
add_executable(EmulationStation WIN32 ${ES_SOURCES} ${ES_HEADERS}) add_executable(EmulationStation WIN32 ${ES_SOURCES} ${ES_HEADERS})
target_link_libraries(EmulationStation ${COMMON_LIBRARIES} es-core) target_link_libraries(EmulationStation ${COMMON_LIBRARIES} es-core)
set_target_properties(EmulationStation PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) set_target_properties(EmulationStation PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
elseif(ANDROID)
include_directories(${COMMON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_library(main SHARED ${ES_SOURCES} ${ES_HEADERS})
target_link_libraries(main ${COMMON_LIBRARIES} ${CMAKE_DL_LIBS} es-core)
set_target_properties(main PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
else() else()
include_directories(${COMMON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src) include_directories(${COMMON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src)
add_executable(emulationstation ${ES_SOURCES} ${ES_HEADERS}) add_executable(emulationstation ${ES_SOURCES} ${ES_HEADERS})
@ -325,7 +330,7 @@ elseif(APPLE)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/themes/modern-es-de DESTINATION ../Resources/themes) install(DIRECTORY ${CMAKE_SOURCE_DIR}/themes/modern-es-de DESTINATION ../Resources/themes)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/themes/slate-es-de DESTINATION ../Resources/themes) install(DIRECTORY ${CMAKE_SOURCE_DIR}/themes/slate-es-de DESTINATION ../Resources/themes)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses DESTINATION ../Resources) install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses DESTINATION ../Resources)
else() elseif(NOT ANDROID)
install(TARGETS emulationstation RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) install(TARGETS emulationstation RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS es-pdf-convert RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) install(TARGETS es-pdf-convert RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
if(CMAKE_SYSTEM_NAME MATCHES Linux) if(CMAKE_SYSTEM_NAME MATCHES Linux)