ci: build simple Android SDL app using gradle

This commit is contained in:
Anonymous Maarten
2024-05-21 20:32:39 +02:00
committed by Anonymous Maarten
parent 8954e42bcb
commit e10666397e
4 changed files with 81 additions and 26 deletions

View File

@@ -1,13 +1,29 @@
cmake_minimum_required(VERSION 3.6)
project(MY_APP)
project(my_app)
find_library(SDL3 SDL3)
if(NOT TARGET SDL3::SDL3)
find_package(SDL3 CONFIG)
endif()
add_library(main SHARED)
if(NOT TARGET SDL3::SDL3)
find_library(SDL3_LIBRARY NAMES "SDL3")
find_path(SDL3_INCLUDE_DIR NAMES "SDL3/SDL.h")
add_library(SDL3::SDL3 UNKNOWN IMPORTED)
set_property(TARGET SDL3::SDL3 PROPERTY IMPORTED_LOCATION "${SDL3_LIBRARY}")
set_property(TARGET SDL3::SDL3 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}")
endif()
target_sources(main PRIVATE YourSourceHere.c)
target_link_libraries(main SDL3)
if(NOT TARGET SDL3::SDL3)
message(FATAL_ERROR "Cannot find SDL3.
Possible ways to fix this:
- Use a SDL3 Android aar archive, and configure gradle to use it: prefab is required.
- Add add_subdirectory(path/to/SDL) to your CMake script, and make sure a vendored SDL is present there.
")
endif()
add_library(main SHARED
YourSourceHere.c
)
target_link_libraries(main PRIVATE SDL3::SDL3)

View File

@@ -0,0 +1,26 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* */
/* Remove this source, and replace with your SDL sources */
/* */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init failed (%s)", SDL_GetError());
return 1;
}
if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Hello World",
"!! Your SDL project successfully runs on Android !!", NULL) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_ShowSimpleMessageBox failed (%s)", SDL_GetError());
return 1;
}
SDL_Quit();
return 0;
}