From 61518bce6b71caac0e372a9ee59b16a3e3bcca13 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 29 Dec 2015 00:57:24 -0500 Subject: [PATCH] CMake: Changes to get CMake project to work with Android (thanks, Martin!). Fixes Bugzilla #3194. (but note that Bugzilla #3200 still needs to be resolved to get this really going on Android, at a minimum.) --- CMakeLists.txt | 48 +++++++++++++++++++++++++++++++++++++- include/SDL_config.h.cmake | 5 ++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ab53d0b4..db49f6eda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -688,6 +688,52 @@ if(SDL_VIDEO) endif() endif() +if(ANDROID) + file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES}) + file(GLOB ANDROID_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/android/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_MAIN_SOURCES}) + if(SDL_AUDIO) + set(SDL_AUDIO_DRIVER_ANDROID 1) + file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_AUDIO_SOURCES}) + set(HAVE_SDL_AUDIO TRUE) + endif() + if(SDL_FILESYSTEM) + set(SDL_FILESYSTEM_ANDROID 1) + file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/android/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_FILESYSTEM_SOURCES}) + set(HAVE_SDL_FILESYSTEM TRUE) + endif() + if(SDL_JOYSTICK) + set(SDL_JOYSTICK_ANDROID 1) + file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/android/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_JOYSTICK_SOURCES}) + set(HAVE_SDL_JOYSTICK TRUE) + endif() + if(SDL_POWER) + set(SDL_POWER_ANDROID 1) + file(GLOB ANDROID_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/android/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_POWER_SOURCES}) + set(HAVE_SDL_POWER TRUE) + endif() + if(SDL_VIDEO) + set(SDL_VIDEO_DRIVER_ANDROID 1) + file(GLOB ANDROID_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/android/*.c) + set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_VIDEO_SOURCES}) + set(HAVE_SDL_VIDEO TRUE) + + #enable gles + if(VIDEO_OPENGLES) + set(SDL_VIDEO_OPENGL_EGL 1) + set(HAVE_VIDEO_OPENGLES TRUE) + set(SDL_VIDEO_OPENGL_ES2 1) + set(SDL_VIDEO_RENDER_OGL_ES2 1) + endif() + endif() + list(APPEND EXTRA_LDFLAGS "-Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit") +endif() + # Platform-specific options and settings if(EMSCRIPTEN) # Hide noisy warnings that intend to aid mostly during initial stages of porting a new @@ -1090,7 +1136,7 @@ elseif(APPLE) # Requires the darwin file implementation if(SDL_FILE) - file(GLOB EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/file/cocoa/*.m) + file(GLOB EXTRA_SOURCES ${SDL2_SOURCE_DIR}/src/file/cocoa/*.m) set(SOURCE_FILES ${EXTRA_SOURCES} ${SOURCE_FILES}) set_source_files_properties(${EXTRA_SOURCES} PROPERTIES LANGUAGE C) set(HAVE_SDL_FILE TRUE) diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index 3d5e3abf0..7ddfb6048 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -197,6 +197,7 @@ #cmakedefine SDL_FILESYSTEM_DISABLED @SDL_FILESYSTEM_DISABLED@ /* Enable various audio drivers */ +#cmakedefine SDL_AUDIO_DRIVER_ANDROID @SDL_AUDIO_DRIVER_ANDROID@ #cmakedefine SDL_AUDIO_DRIVER_ALSA @SDL_AUDIO_DRIVER_ALSA@ #cmakedefine SDL_AUDIO_DRIVER_ALSA_DYNAMIC @SDL_AUDIO_DRIVER_ALSA_DYNAMIC@ #cmakedefine SDL_AUDIO_DRIVER_ARTS @SDL_AUDIO_DRIVER_ARTS@ @@ -230,6 +231,7 @@ #cmakedefine SDL_INPUT_LINUXEV @SDL_INPUT_LINUXEV@ #cmakedefine SDL_INPUT_LINUXKD @SDL_INPUT_LINUXKD@ #cmakedefine SDL_INPUT_TSLIB @SDL_INPUT_TSLIB@ +#cmakedefine SDL_JOYSTICK_ANDROID @SDL_JOYSTICK_ANDROID@ #cmakedefine SDL_JOYSTICK_HAIKU @SDL_JOYSTICK_HAIKU@ #cmakedefine SDL_JOYSTICK_DINPUT @SDL_JOYSTICK_DINPUT@ #cmakedefine SDL_JOYSTICK_XINPUT @SDL_JOYSTICK_XINPUT@ @@ -268,6 +270,7 @@ #cmakedefine SDL_TIMER_WINCE @SDL_TIMER_WINCE@ /* Enable various video drivers */ +#cmakedefine SDL_VIDEO_DRIVER_ANDROID @SDL_VIDEO_DRIVER_ANDROID@ #cmakedefine SDL_VIDEO_DRIVER_HAIKU @SDL_VIDEO_DRIVER_HAIKU@ #cmakedefine SDL_VIDEO_DRIVER_COCOA @SDL_VIDEO_DRIVER_COCOA@ #cmakedefine SDL_VIDEO_DRIVER_DIRECTFB @SDL_VIDEO_DRIVER_DIRECTFB@ @@ -331,6 +334,7 @@ #cmakedefine SDL_VIDEO_OPENGL_OSMESA_DYNAMIC @SDL_VIDEO_OPENGL_OSMESA_DYNAMIC@ /* Enable system power support */ +#cmakedefine SDL_POWER_ANDROID @SDL_POWER_ANDROID@ #cmakedefine SDL_POWER_LINUX @SDL_POWER_LINUX@ #cmakedefine SDL_POWER_WINDOWS @SDL_POWER_WINDOWS@ #cmakedefine SDL_POWER_MACOSX @SDL_POWER_MACOSX@ @@ -339,6 +343,7 @@ #cmakedefine SDL_POWER_HARDWIRED @SDL_POWER_HARDWIRED@ /* Enable system filesystem support */ +#cmakedefine SDL_FILESYSTEM_ANDROID @SDL_FILESYSTEM_ANDROID@ #cmakedefine SDL_FILESYSTEM_HAIKU @SDL_FILESYSTEM_HAIKU@ #cmakedefine SDL_FILESYSTEM_COCOA @SDL_FILESYSTEM_COCOA@ #cmakedefine SDL_FILESYSTEM_DUMMY @SDL_FILESYSTEM_DUMMY@