File: SdlAndroidScript.cmake

package info (click to toggle)
libsdl3 3.2.10%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 42,240 kB
  • sloc: ansic: 389,254; objc: 12,241; xml: 9,084; cpp: 5,728; perl: 4,547; python: 3,370; sh: 947; makefile: 265; cs: 56
file content (74 lines) | stat: -rw-r--r-- 2,383 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#[=======================================================================[

This CMake script is meant to be used in CMake script mode (cmake -P).
It wraps commands that communicate with an actual Android device.
Because

#]=======================================================================]

cmake_minimum_required(VERSION 3.16...3.28)

if(NOT CMAKE_SCRIPT_MODE_FILE)
  message(FATAL_ERROR "This file can only be used in CMake script mode")
endif()
if(NOT ADB)
  set(ADB "adb")
endif()

if(NOT ACTION)
  message(FATAL_ERROR "Missing ACTION argument")
endif()

if(ACTION STREQUAL "uninstall")
  # The uninstall action attempts to uninstall all packages. All failures are ignored.
  foreach(package IN LISTS PACKAGES)
    message("Uninstalling ${package} ...")
    execute_process(
        COMMAND ${ADB} uninstall ${package}
        RESULT_VARIABLE res
    )
    message("... result=${res}")
  endforeach()
elseif(ACTION STREQUAL "install")
  # The install actions attempts to install APK's to an Android device using adb. Failures are ignored.
  set(failed_apks "")
  foreach(apk IN LISTS APKS)
    message("Installing ${apk} ...")
    execute_process(
        COMMAND ${ADB} install -d -r --streaming ${apk}
        RESULT_VARIABLE res
    )
    message("... result=${res}")
    if(NOT res EQUAL 0)
      list(APPEND failed_apks ${apk})
    endif()
  endforeach()
  if(failed_apks)
    message(FATAL_ERROR "Failed to install ${failed_apks}")
  endif()
elseif(ACTION STREQUAL "build-install-run")
  if(NOT EXECUTABLES)
    message(FATAL_ERROR "Missing EXECUTABLES (don't know what executables to build/install and start")
  endif()
  if(NOT BUILD_FOLDER)
    message(FATAL_ERROR "Missing BUILD_FOLDER (don't know where to build the APK's")
  endif()
  set(install_targets "")
  foreach(executable IN LISTS EXECUTABLES)
    list(APPEND install_targets "install-${executable}")
  endforeach()
  execute_process(
      COMMAND ${CMAKE_COMMAND} --build "${BUILD_FOLDER}" --target ${install_targets}
      RESULT_VARIABLE res
  )
  if(NOT res EQUAL 0)
    message(FATAL_ERROR "Failed to install APK(s) for ${EXECUTABLES}")
  endif()
  list(GET EXECUTABLES 0 start_executable)
  execute_process(
      COMMAND ${CMAKE_COMMAND} --build "${BUILD_FOLDER}" --target start-${start_executable}
      RESULT_VARIABLE res
  )
else()
  message(FATAL_ERROR "Unknown ACTION=${ACTION}")
endif()