summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/cmake/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-3.2.20/cmake/android')
-rw-r--r--src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroid.cmake103
-rw-r--r--src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidBuildTools.cmake115
-rw-r--r--src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake124
-rw-r--r--src/contrib/SDL-3.2.20/cmake/android/SdlAndroidFunctions.cmake276
-rw-r--r--src/contrib/SDL-3.2.20/cmake/android/SdlAndroidScript.cmake74
5 files changed, 692 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroid.cmake b/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroid.cmake
new file mode 100644
index 0000000..851848f
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroid.cmake
@@ -0,0 +1,103 @@
1#[=======================================================================[
2
3FindSdlAndroid
4----------------------
5
6Locate various executables that are essential to creating an Android APK archive.
7This find module uses the FindSdlAndroidBuildTools module to locate some Android utils.
8
9
10Imported targets
11^^^^^^^^^^^^^^^^
12
13This module defines the following :prop_tgt:`IMPORTED` target(s):
14
15`` SdlAndroid::aapt2 ``
16 Imported executable for the "android package tool" v2
17
18`` SdlAndroid::apksigner``
19 Imported executable for the APK signer tool
20
21`` SdlAndroid::d8 ``
22 Imported executable for the dex compiler
23
24`` SdlAndroid::zipalign ``
25 Imported executable for the zipalign util
26
27`` SdlAndroid::adb ``
28 Imported executable for the "android debug bridge" tool
29
30`` SdlAndroid::keytool ``
31 Imported executable for the keytool, a key and certificate management utility
32
33`` SdlAndroid::zip ``
34 Imported executable for the zip, for packaging and compressing files
35
36Result variables
37^^^^^^^^^^^^^^^^
38
39This module will set the following variables in your project:
40
41`` AAPT2_BIN ``
42 Path of aapt2
43
44`` APKSIGNER_BIN ``
45 Path of apksigner
46
47`` D8_BIN ``
48 Path of d8
49
50`` ZIPALIGN_BIN ``
51 Path of zipalign
52
53`` ADB_BIN ``
54 Path of adb
55
56`` KEYTOOL_BIN ``
57 Path of keytool
58
59`` ZIP_BIN ``
60 Path of zip
61
62#]=======================================================================]
63
64cmake_minimum_required(VERSION 3.7...3.28)
65
66if(NOT PROJECT_NAME MATCHES "^SDL.*")
67 message(WARNING "This module is internal to SDL and is currently not supported.")
68endif()
69
70find_package(SdlAndroidBuildTools MODULE)
71
72function(_sdl_android_find_create_imported_executable NAME)
73 string(TOUPPER "${NAME}" NAME_UPPER)
74 set(varname "${NAME_UPPER}_BIN")
75 find_program("${varname}" NAMES "${NAME}" PATHS ${SDL_ANDROID_BUILD_TOOLS_ROOT})
76 if(EXISTS "${${varname}}" AND NOT TARGET SdlAndroid::${NAME})
77 add_executable(SdlAndroid::${NAME} IMPORTED)
78 set_property(TARGET SdlAndroid::${NAME} PROPERTY IMPORTED_LOCATION "${${varname}}")
79 endif()
80endfunction()
81
82if(SdlAndroidBuildTools_FOUND)
83 _sdl_android_find_create_imported_executable(aapt2)
84 _sdl_android_find_create_imported_executable(apksigner)
85 _sdl_android_find_create_imported_executable(d8)
86 _sdl_android_find_create_imported_executable(zipalign)
87endif()
88
89_sdl_android_find_create_imported_executable(adb)
90_sdl_android_find_create_imported_executable(keytool)
91_sdl_android_find_create_imported_executable(zip)
92include(FindPackageHandleStandardArgs)
93
94find_package_handle_standard_args(SdlAndroid
95 VERSION_VAR
96 REQUIRED_VARS
97 AAPT2_BIN
98 APKSIGNER_BIN
99 D8_BIN
100 ZIPALIGN_BIN
101 KEYTOOL_BIN
102 ZIP_BIN
103)
diff --git a/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidBuildTools.cmake b/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidBuildTools.cmake
new file mode 100644
index 0000000..999a268
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidBuildTools.cmake
@@ -0,0 +1,115 @@
1#[=======================================================================[
2
3FindSdlAndroidBuildTools
4----------------------
5
6Locate the Android build tools directory.
7
8
9Imported targets
10^^^^^^^^^^^^^^^^
11
12This find module defines the following :prop_tgt:`IMPORTED` target(s):
13
14<none>
15
16Result variables
17^^^^^^^^^^^^^^^^
18
19This module will set the following variables in your project:
20
21`` SdlAndroidBuildTools_FOUND
22 if false, no Android build tools have been found
23
24`` SDL_ANDROID_BUILD_TOOLS_ROOT
25 path of the Android build tools root directory if found
26
27`` SDL_ANDROID_BUILD_TOOLS_VERSION
28 the human-readable string containing the android build tools version if found
29
30Cache variables
31^^^^^^^^^^^^^^^
32
33These variables may optionally be set to help this module find the correct files:
34
35``SDL_ANDROID_BUILD_TOOLS_ROOT``
36 path of the Android build tools root directory
37
38
39Variables for locating Android platform
40^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41
42This module responds to the flags:
43
44``SDL_ANDROID_HOME
45 First, this module will look for platforms in this CMake variable.
46
47``ANDROID_HOME
48 If no platform was found in `SDL_ANDROID_HOME`, then try `ANDROID_HOME`.
49
50``$ENV{ANDROID_HOME}
51 If no platform was found in neither `SDL_ANDROID_HOME` or `ANDROID_HOME`, then try `ANDROID_HOME}`
52
53#]=======================================================================]
54
55cmake_minimum_required(VERSION 3.7...3.28)
56
57if(NOT PROJECT_NAME MATCHES "^SDL.*")
58 message(WARNING "This module is internal to SDL and is currently not supported.")
59endif()
60
61function(_sdl_is_valid_android_build_tools_root RESULT VERSION BUILD_TOOLS_ROOT)
62 set(result TRUE)
63 set(version -1)
64
65 string(REGEX MATCH "/([0-9.]+)$" root_match "${BUILD_TOOLS_ROOT}")
66 if(root_match
67 AND EXISTS "${BUILD_TOOLS_ROOT}/aapt2"
68 AND EXISTS "${BUILD_TOOLS_ROOT}/apksigner"
69 AND EXISTS "${BUILD_TOOLS_ROOT}/d8"
70 AND EXISTS "${BUILD_TOOLS_ROOT}/zipalign")
71 set(result "${BUILD_TOOLS_ROOT}")
72 set(version "${CMAKE_MATCH_1}")
73 endif()
74
75 set(${RESULT} ${result} PARENT_SCOPE)
76 set(${VERSION} ${version} PARENT_SCOPE)
77endfunction()
78
79function(_find_sdl_android_build_tools_root ROOT)
80 cmake_parse_arguments(fsabtr "" "" "" ${ARGN})
81 set(homes ${SDL_ANDROID_HOME} ${ANDROID_HOME} $ENV{ANDROID_HOME})
82 set(root ${ROOT}-NOTFOUND)
83 foreach(home IN LISTS homes)
84 if(NOT IS_DIRECTORY "${home}")
85 continue()
86 endif()
87 file(GLOB build_tools_roots LIST_DIRECTORIES true "${home}/build-tools/*")
88 set(max_build_tools_version -1)
89 set(max_build_tools_root "")
90 foreach(build_tools_root IN LISTS build_tools_roots)
91 _sdl_is_valid_android_build_tools_root(is_valid build_tools_version "${build_tools_root}")
92 if(is_valid AND build_tools_version GREATER max_build_tools_version)
93 set(max_build_tools_version "${build_tools_version}")
94 set(max_build_tools_root "${build_tools_root}")
95 endif()
96 endforeach()
97 if(max_build_tools_version GREATER -1)
98 set(root ${max_build_tools_root})
99 break()
100 endif()
101 endforeach()
102 set(${ROOT} ${root} PARENT_SCOPE)
103endfunction()
104
105if(NOT DEFINED SDL_ANDROID_BUILD_TOOLS_ROOT)
106 _find_sdl_android_build_tools_root(SDL_ANDROID_BUILD_TOOLS_ROOT)
107 set(SDL_ANDROID_BUILD_TOOLS_ROOT "${SDL_ANDROID_BUILD_TOOLS_ROOT}" CACHE PATH "Path of Android build tools")
108endif()
109
110include(FindPackageHandleStandardArgs)
111
112find_package_handle_standard_args(SdlAndroidBuildTools
113 VERSION_VAR SDL_ANDROID_BUILD_TOOLS_VERSION
114 REQUIRED_VARS SDL_ANDROID_BUILD_TOOLS_ROOT
115)
diff --git a/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake b/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake
new file mode 100644
index 0000000..fbe53c3
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake
@@ -0,0 +1,124 @@
1#[=======================================================================[
2
3FindSdlAndroidPlatform
4----------------------
5
6Locate the Android SDK platform.
7
8
9Imported targets
10^^^^^^^^^^^^^^^^
11
12This module defines the following :prop_tgt:`IMPORTED` target(s):
13
14<none>
15
16Result variables
17^^^^^^^^^^^^^^^^
18
19This find module will set the following variables in your project:
20
21`` SdlAndroidPlatform_FOUND
22 if false, no Android platform has been found
23
24`` SDL_ANDROID_PLATFORM_ROOT
25 path of the Android SDK platform root directory if found
26
27`` SDL_ANDROID_PLATFORM_ANDROID_JAR
28 path of the Android SDK platform jar file if found
29
30`` SDL_ANDROID_PLATFORM_VERSION
31 the human-readable string containing the android platform version if found
32
33Cache variables
34^^^^^^^^^^^^^^^
35
36These variables may optionally be set to help this module find the correct files:
37
38``SDL_ANDROID_PLATFORM_ROOT``
39 path of the Android SDK platform root directory
40
41
42Variables for locating Android platform
43^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44
45This module responds to the flags:
46
47``SDL_ANDROID_HOME
48 First, this module will look for platforms in this CMake variable.
49
50``ANDROID_HOME
51 If no platform was found in `SDL_ANDROID_HOME`, then try `ANDROID_HOME`.
52
53``$ENV{ANDROID_HOME}
54 If no platform was found in neither `SDL_ANDROID_HOME` or `ANDROID_HOME`, then try `ANDROID_HOME}`
55
56#]=======================================================================]
57
58cmake_minimum_required(VERSION 3.7...3.28)
59
60if(NOT PROJECT_NAME MATCHES "^SDL.*")
61 message(WARNING "This module is internal to SDL and is currently not supported.")
62endif()
63
64function(_sdl_is_valid_android_platform_root RESULT VERSION PLATFORM_ROOT)
65 set(result FALSE)
66 set(version -1)
67
68 string(REGEX MATCH "/android-([0-9]+)$" root_match "${PLATFORM_ROOT}")
69 if(root_match AND EXISTS "${PLATFORM_ROOT}/android.jar")
70 set(result TRUE)
71 set(version "${CMAKE_MATCH_1}")
72 endif()
73
74 set(${RESULT} ${result} PARENT_SCOPE)
75 set(${VERSION} ${version} PARENT_SCOPE)
76endfunction()
77
78function(_sdl_find_android_platform_root ROOT)
79 cmake_parse_arguments(sfapr "" "" "" ${ARGN})
80 set(homes ${SDL_ANDROID_HOME} ${ANDROID_HOME} $ENV{ANDROID_HOME})
81 set(root ${ROOT}-NOTFOUND)
82 foreach(home IN LISTS homes)
83 if(NOT IS_DIRECTORY "${home}")
84 continue()
85 endif()
86 file(GLOB platform_roots LIST_DIRECTORIES true "${home}/platforms/*")
87 set(max_platform_version -1)
88 set(max_platform_root "")
89 foreach(platform_root IN LISTS platform_roots)
90 _sdl_is_valid_android_platform_root(is_valid platform_version "${platform_root}")
91 if(is_valid AND platform_version GREATER max_platform_version)
92 set(max_platform_version "${platform_version}")
93 set(max_platform_root "${platform_root}")
94 endif()
95 endforeach()
96 if(max_platform_version GREATER -1)
97 set(root ${max_platform_root})
98 break()
99 endif()
100 endforeach()
101 set(${ROOT} ${root} PARENT_SCOPE)
102endfunction()
103
104set(SDL_ANDROID_PLATFORM_ANDROID_JAR "SDL_ANDROID_PLATFORM_ANDROID_JAR-NOTFOUND")
105
106if(NOT DEFINED SDL_ANDROID_PLATFORM_ROOT)
107 _sdl_find_android_platform_root(_new_sdl_android_platform_root)
108 set(SDL_ANDROID_PLATFORM_ROOT "${_new_sdl_android_platform_root}" CACHE PATH "Path of Android platform")
109 unset(_new_sdl_android_platform_root)
110endif()
111if(SDL_ANDROID_PLATFORM_ROOT)
112 _sdl_is_valid_android_platform_root(_valid SDL_ANDROID_PLATFORM_VERSION "${SDL_ANDROID_PLATFORM_ROOT}")
113 if(_valid)
114 set(SDL_ANDROID_PLATFORM_ANDROID_JAR "${SDL_ANDROID_PLATFORM_ROOT}/android.jar")
115 endif()
116 unset(_valid)
117endif()
118
119include(FindPackageHandleStandardArgs)
120
121find_package_handle_standard_args(SdlAndroidPlatform
122 VERSION_VAR SDL_ANDROID_PLATFORM_VERSION
123 REQUIRED_VARS SDL_ANDROID_PLATFORM_ROOT SDL_ANDROID_PLATFORM_ANDROID_JAR
124)
diff --git a/src/contrib/SDL-3.2.20/cmake/android/SdlAndroidFunctions.cmake b/src/contrib/SDL-3.2.20/cmake/android/SdlAndroidFunctions.cmake
new file mode 100644
index 0000000..4acce47
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/android/SdlAndroidFunctions.cmake
@@ -0,0 +1,276 @@
1#[=======================================================================[
2
3This CMake script contains functions to build an Android APK.
4It is (currently) limited to packaging binaries for a single architecture.
5
6#]=======================================================================]
7
8cmake_minimum_required(VERSION 3.7...3.28)
9
10if(NOT PROJECT_NAME MATCHES "^SDL.*")
11 message(WARNING "This module is internal to SDL and is currently not supported.")
12endif()
13
14function(_sdl_create_outdir_for_target OUTDIRECTORY TARGET)
15 set(outdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET}.dir")
16 # Some CMake versions have a slow `cmake -E make_directory` implementation
17 if(NOT IS_DIRECTORY "${outdir}")
18 execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${outdir}")
19 endif()
20 set("${OUTDIRECTORY}" "${outdir}" PARENT_SCOPE)
21endfunction()
22
23function(sdl_create_android_debug_keystore TARGET)
24 set(output "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_debug.keystore")
25 add_custom_command(OUTPUT ${output}
26 COMMAND ${CMAKE_COMMAND} -E rm -f "${output}"
27 COMMAND SdlAndroid::keytool -genkey -keystore "${output}" -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "C=US, O=Android, CN=Android Debug"
28 )
29 add_custom_target(${TARGET} DEPENDS "${output}")
30 set_property(TARGET ${TARGET} PROPERTY OUTPUT "${output}")
31endfunction()
32
33function(sdl_android_compile_resources TARGET)
34 cmake_parse_arguments(arg "" "RESFOLDER" "RESOURCES" ${ARGN})
35
36 if(NOT arg_RESFOLDER AND NOT arg_RESOURCES)
37 message(FATAL_ERROR "Missing RESFOLDER or RESOURCES argument (need one or both)")
38 endif()
39 _sdl_create_outdir_for_target(outdir "${TARGET}")
40 set(out_files "")
41
42 set(res_files "")
43 if(arg_RESFOLDER)
44 get_filename_component(arg_RESFOLDER "${arg_RESFOLDER}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
45 file(GLOB_RECURSE res_folder_files "${arg_RESFOLDER}/*")
46 list(APPEND res_files ${res_folder_files})
47
48 foreach(res_file IN LISTS res_files)
49 file(RELATIVE_PATH rel_res_file "${arg_RESFOLDER}" "${res_file}")
50 string(REPLACE "/" "_" rel_comp_path "${rel_res_file}")
51 if(res_file MATCHES ".*res/values.*\\.xml$")
52 string(REGEX REPLACE "\\.xml" ".arsc" rel_comp_path "${rel_comp_path}")
53 endif()
54 set(comp_path "${outdir}/${rel_comp_path}.flat")
55 add_custom_command(
56 OUTPUT "${comp_path}"
57 COMMAND SdlAndroid::aapt2 compile -o "${outdir}" "${res_file}"
58 DEPENDS ${res_file}
59 )
60 list(APPEND out_files "${comp_path}")
61 endforeach()
62 endif()
63
64 if(arg_RESOURCES)
65 list(APPEND res_files ${arg_RESOURCES})
66 foreach(res_file IN LISTS arg_RESOURCES)
67 string(REGEX REPLACE ".*/res/" "" rel_res_file ${res_file})
68 string(REPLACE "/" "_" rel_comp_path "${rel_res_file}")
69 if(res_file MATCHES ".*res/values.*\\.xml$")
70 string(REGEX REPLACE "\\.xml" ".arsc" rel_comp_path "${rel_comp_path}")
71 endif()
72 set(comp_path "${outdir}/${rel_comp_path}.flat")
73 add_custom_command(
74 OUTPUT "${comp_path}"
75 COMMAND SdlAndroid::aapt2 compile -o "${outdir}" "${res_file}"
76 DEPENDS ${res_file}
77 )
78 list(APPEND out_files "${comp_path}")
79 endforeach()
80 endif()
81
82 add_custom_target(${TARGET} DEPENDS ${out_files})
83 set_property(TARGET "${TARGET}" PROPERTY OUTPUTS "${out_files}")
84 set_property(TARGET "${TARGET}" PROPERTY SOURCES "${res_files}")
85endfunction()
86
87function(sdl_android_link_resources TARGET)
88 cmake_parse_arguments(arg "NO_DEBUG" "MIN_SDK_VERSION;TARGET_SDK_VERSION;ANDROID_JAR;OUTPUT_APK;MANIFEST;PACKAGE" "RES_TARGETS" ${ARGN})
89
90 if(arg_MANIFEST)
91 get_filename_component(arg_MANIFEST "${arg_MANIFEST}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
92 else()
93 message(FATAL_ERROR "sdl_add_android_link_resources_target requires a Android MANIFEST path (${arg_MANIFEST})")
94 endif()
95 if(NOT arg_PACKAGE)
96 file(READ "${arg_MANIFEST}" manifest_contents)
97 string(REGEX MATCH "package=\"([a-zA-Z0-9_.]+)\"" package_match "${manifest_contents}")
98 if(NOT package_match)
99 message(FATAL_ERROR "Could not extract package from Android manifest (${arg_MANIFEST})")
100 endif()
101 set(arg_PACKAGE "${CMAKE_MATCH_1}")
102 endif()
103
104 set(depends "")
105
106 _sdl_create_outdir_for_target(outdir "${TARGET}")
107 string(REPLACE "." "/" java_r_path "${arg_PACKAGE}")
108 get_filename_component(java_r_path "${java_r_path}" ABSOLUTE BASE_DIR "${outdir}")
109 set(java_r_path "${java_r_path}/R.java")
110
111 set(command SdlAndroid::aapt2 link)
112 if(NOT arg_NO_DEBUG)
113 list(APPEND command --debug-mode)
114 endif()
115 if(arg_MIN_SDK_VERSION)
116 list(APPEND command --min-sdk-version ${arg_MIN_SDK_VERSION})
117 endif()
118 if(arg_TARGET_SDK_VERSION)
119 list(APPEND command --target-sdk-version ${arg_TARGET_SDK_VERSION})
120 endif()
121 if(arg_ANDROID_JAR)
122 list(APPEND command -I "${arg_ANDROID_JAR}")
123 else()
124 list(APPEND command -I "${SDL_ANDROID_PLATFORM_ANDROID_JAR}")
125 endif()
126 if(NOT arg_OUTPUT_APK)
127 set(arg_OUTPUT_APK "${TARGET}.apk")
128 endif()
129 get_filename_component(arg_OUTPUT_APK "${arg_OUTPUT_APK}" ABSOLUTE BASE_DIR "${outdir}")
130 list(APPEND command -o "${arg_OUTPUT_APK}")
131 list(APPEND command --java "${outdir}")
132 list(APPEND command --manifest "${arg_MANIFEST}")
133 foreach(res_target IN LISTS arg_RES_TARGETS)
134 list(APPEND command $<TARGET_PROPERTY:${res_target},OUTPUTS>)
135 list(APPEND depends $<TARGET_PROPERTY:${res_target},OUTPUTS>)
136 endforeach()
137 add_custom_command(
138 OUTPUT "${arg_OUTPUT_APK}" "${java_r_path}"
139 COMMAND ${command}
140 DEPENDS ${depends} ${arg_MANIFEST}
141 COMMAND_EXPAND_LISTS
142 VERBATIM
143 )
144 add_custom_target(${TARGET} DEPENDS "${arg_OUTPUT_APK}" "${java_r_path}")
145 set_property(TARGET ${TARGET} PROPERTY OUTPUT "${arg_OUTPUT_APK}")
146 set_property(TARGET ${TARGET} PROPERTY JAVA_R "${java_r_path}")
147 set_property(TARGET ${TARGET} PROPERTY OUTPUTS "${${arg_OUTPUT_APK}};${java_r_path}")
148endfunction()
149
150function(sdl_add_to_apk_unaligned TARGET)
151 cmake_parse_arguments(arg "" "APK_IN;NAME;OUTDIR" "ASSETS;NATIVE_LIBS;DEX" ${ARGN})
152
153 if(NOT arg_APK_IN)
154 message(FATAL_ERROR "Missing APK_IN argument")
155 endif()
156
157 if(NOT TARGET ${arg_APK_IN})
158 message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk")
159 endif()
160
161 _sdl_create_outdir_for_target(workdir ${TARGET})
162
163 if(NOT arg_OUTDIR)
164 set(arg_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}")
165 endif()
166
167 if(NOT arg_NAME)
168 string(REGEX REPLACE "[:-]+" "." arg_NAME "${TARGET}")
169 if(NOT arg_NAME MATCHES "\\.apk")
170 set(arg_NAME "${arg_NAME}.apk")
171 endif()
172 endif()
173 get_filename_component(apk_file "${arg_NAME}" ABSOLUTE BASE_DIR "${arg_OUTDIR}")
174
175 set(apk_libdir "lib/${ANDROID_ABI}")
176
177 set(depends "")
178
179 set(commands
180 COMMAND "${CMAKE_COMMAND}" -E remove_directory -rf "${apk_libdir}" "assets"
181 COMMAND "${CMAKE_COMMAND}" -E make_directory "${apk_libdir}" "assets"
182 COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_PROPERTY:${arg_APK_IN},OUTPUT>" "${apk_file}"
183 )
184
185 set(dex_i "1")
186 foreach(dex IN LISTS arg_DEX)
187 set(suffix "${dex_i}")
188 if(suffix STREQUAL "1")
189 set(suffix "")
190 endif()
191 list(APPEND commands
192 COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_PROPERTY:${dex},OUTPUT>" "classes${suffix}.dex"
193 COMMAND SdlAndroid::zip -u -q -j "${apk_file}" "classes${suffix}.dex"
194 )
195 math(EXPR dex_i "${dex_i}+1")
196 list(APPEND depends "$<TARGET_PROPERTY:${dex},OUTPUT>")
197 endforeach()
198
199 foreach(native_lib IN LISTS arg_NATIVE_LIBS)
200 list(APPEND commands
201 COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_FILE:${native_lib}> "${apk_libdir}/$<TARGET_FILE_NAME:${native_lib}>"
202 COMMAND SdlAndroid::zip -u -q "${apk_file}" "${apk_libdir}/$<TARGET_FILE_NAME:${native_lib}>"
203 )
204 endforeach()
205 if(arg_ASSETS)
206 list(APPEND commands
207 COMMAND "${CMAKE_COMMAND}" -E copy ${arg_ASSETS} "assets"
208 COMMAND SdlAndroid::zip -u -r -q "${apk_file}" "assets"
209 )
210 endif()
211
212 add_custom_command(OUTPUT "${apk_file}"
213 ${commands}
214 DEPENDS ${arg_NATIVE_LIBS} ${depends} "$<TARGET_PROPERTY:${arg_APK_IN},OUTPUT>"
215 WORKING_DIRECTORY "${workdir}"
216 )
217 add_custom_target(${TARGET} DEPENDS "${apk_file}")
218 set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}")
219endfunction()
220
221function(sdl_apk_align TARGET APK_IN)
222 cmake_parse_arguments(arg "" "NAME;OUTDIR" "" ${ARGN})
223
224 if(NOT TARGET ${arg_APK_IN})
225 message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk")
226 endif()
227
228 if(NOT arg_OUTDIR)
229 set(arg_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}")
230 endif()
231
232 if(NOT arg_NAME)
233 string(REGEX REPLACE "[:-]+" "." arg_NAME "${TARGET}")
234 if(NOT arg_NAME MATCHES "\\.apk")
235 set(arg_NAME "${arg_NAME}.apk")
236 endif()
237 endif()
238 get_filename_component(apk_file "${arg_NAME}" ABSOLUTE BASE_DIR "${arg_OUTDIR}")
239
240 add_custom_command(OUTPUT "${apk_file}"
241 COMMAND SdlAndroid::zipalign -f 4 "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" "${apk_file}"
242 DEPENDS "$<TARGET_PROPERTY:${APK_IN},OUTPUT>"
243 )
244 add_custom_target(${TARGET} DEPENDS "${apk_file}")
245 set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}")
246endfunction()
247
248function(sdl_apk_sign TARGET APK_IN)
249 cmake_parse_arguments(arg "" "OUTPUT;KEYSTORE" "" ${ARGN})
250
251 if(NOT TARGET ${arg_APK_IN})
252 message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk")
253 endif()
254
255 if(NOT TARGET ${arg_KEYSTORE})
256 message(FATAL_ERROR "APK_KEYSTORE (${APK_KEYSTORE}) must be a target providing a keystore")
257 endif()
258
259 if(NOT arg_OUTPUT)
260 string(REGEX REPLACE "[:-]+" "." arg_OUTPUT "${TARGET}")
261 if(NOT arg_OUTPUT MATCHES "\\.apk")
262 set(arg_OUTPUT "${arg_OUTPUT}.apk")
263 endif()
264 endif()
265 get_filename_component(apk_file "${arg_OUTPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
266
267 add_custom_command(OUTPUT "${apk_file}"
268 COMMAND SdlAndroid::apksigner sign
269 --ks "$<TARGET_PROPERTY:${arg_KEYSTORE},OUTPUT>"
270 --ks-pass pass:android --in "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" --out "${apk_file}"
271 DEPENDS "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" "$<TARGET_PROPERTY:${arg_KEYSTORE},OUTPUT>"
272 BYPRODUCTS "${apk_file}.idsig"
273 )
274 add_custom_target(${TARGET} DEPENDS "${apk_file}")
275 set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}")
276endfunction()
diff --git a/src/contrib/SDL-3.2.20/cmake/android/SdlAndroidScript.cmake b/src/contrib/SDL-3.2.20/cmake/android/SdlAndroidScript.cmake
new file mode 100644
index 0000000..15dea2d
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/android/SdlAndroidScript.cmake
@@ -0,0 +1,74 @@
1#[=======================================================================[
2
3This CMake script is meant to be used in CMake script mode (cmake -P).
4It wraps commands that communicate with an actual Android device.
5Because
6
7#]=======================================================================]
8
9cmake_minimum_required(VERSION 3.16...3.28)
10
11if(NOT CMAKE_SCRIPT_MODE_FILE)
12 message(FATAL_ERROR "This file can only be used in CMake script mode")
13endif()
14if(NOT ADB)
15 set(ADB "adb")
16endif()
17
18if(NOT ACTION)
19 message(FATAL_ERROR "Missing ACTION argument")
20endif()
21
22if(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()
32elseif(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()
49elseif(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 )
72else()
73 message(FATAL_ERROR "Unknown ACTION=${ACTION}")
74endif()