diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/cmake/android/SdlAndroidScript.cmake | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/cmake/android/SdlAndroidScript.cmake')
| -rw-r--r-- | contrib/SDL-3.2.8/cmake/android/SdlAndroidScript.cmake | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/cmake/android/SdlAndroidScript.cmake b/contrib/SDL-3.2.8/cmake/android/SdlAndroidScript.cmake new file mode 100644 index 0000000..15dea2d --- /dev/null +++ b/contrib/SDL-3.2.8/cmake/android/SdlAndroidScript.cmake | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | #[=======================================================================[ | ||
| 2 | |||
| 3 | This CMake script is meant to be used in CMake script mode (cmake -P). | ||
| 4 | It wraps commands that communicate with an actual Android device. | ||
| 5 | Because | ||
| 6 | |||
| 7 | #]=======================================================================] | ||
| 8 | |||
| 9 | cmake_minimum_required(VERSION 3.16...3.28) | ||
| 10 | |||
| 11 | if(NOT CMAKE_SCRIPT_MODE_FILE) | ||
| 12 | message(FATAL_ERROR "This file can only be used in CMake script mode") | ||
| 13 | endif() | ||
| 14 | if(NOT ADB) | ||
| 15 | set(ADB "adb") | ||
| 16 | endif() | ||
| 17 | |||
| 18 | if(NOT ACTION) | ||
| 19 | message(FATAL_ERROR "Missing ACTION argument") | ||
| 20 | endif() | ||
| 21 | |||
| 22 | if(ACTION STREQUAL "uninstall") | ||
| 23 | # The uninstall action attempts to uninstall all packages. All failures are ignored. | ||
| 24 | foreach(package IN LISTS PACKAGES) | ||
| 25 | message("Uninstalling ${package} ...") | ||
| 26 | execute_process( | ||
| 27 | COMMAND ${ADB} uninstall ${package} | ||
| 28 | RESULT_VARIABLE res | ||
| 29 | ) | ||
| 30 | message("... result=${res}") | ||
| 31 | endforeach() | ||
| 32 | elseif(ACTION STREQUAL "install") | ||
| 33 | # The install actions attempts to install APK's to an Android device using adb. Failures are ignored. | ||
| 34 | set(failed_apks "") | ||
| 35 | foreach(apk IN LISTS APKS) | ||
| 36 | message("Installing ${apk} ...") | ||
| 37 | execute_process( | ||
| 38 | COMMAND ${ADB} install -d -r --streaming ${apk} | ||
| 39 | RESULT_VARIABLE res | ||
| 40 | ) | ||
| 41 | message("... result=${res}") | ||
| 42 | if(NOT res EQUAL 0) | ||
| 43 | list(APPEND failed_apks ${apk}) | ||
| 44 | endif() | ||
| 45 | endforeach() | ||
| 46 | if(failed_apks) | ||
| 47 | message(FATAL_ERROR "Failed to install ${failed_apks}") | ||
| 48 | endif() | ||
| 49 | elseif(ACTION STREQUAL "build-install-run") | ||
| 50 | if(NOT EXECUTABLES) | ||
| 51 | message(FATAL_ERROR "Missing EXECUTABLES (don't know what executables to build/install and start") | ||
| 52 | endif() | ||
| 53 | if(NOT BUILD_FOLDER) | ||
| 54 | message(FATAL_ERROR "Missing BUILD_FOLDER (don't know where to build the APK's") | ||
| 55 | endif() | ||
| 56 | set(install_targets "") | ||
| 57 | foreach(executable IN LISTS EXECUTABLES) | ||
| 58 | list(APPEND install_targets "install-${executable}") | ||
| 59 | endforeach() | ||
| 60 | execute_process( | ||
| 61 | COMMAND ${CMAKE_COMMAND} --build "${BUILD_FOLDER}" --target ${install_targets} | ||
| 62 | RESULT_VARIABLE res | ||
| 63 | ) | ||
| 64 | if(NOT res EQUAL 0) | ||
| 65 | message(FATAL_ERROR "Failed to install APK(s) for ${EXECUTABLES}") | ||
| 66 | endif() | ||
| 67 | list(GET EXECUTABLES 0 start_executable) | ||
| 68 | execute_process( | ||
| 69 | COMMAND ${CMAKE_COMMAND} --build "${BUILD_FOLDER}" --target start-${start_executable} | ||
| 70 | RESULT_VARIABLE res | ||
| 71 | ) | ||
| 72 | else() | ||
| 73 | message(FATAL_ERROR "Unknown ACTION=${ACTION}") | ||
| 74 | endif() | ||
