summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-3.2.20/build-scripts/pkg-support/android')
-rw-r--r--src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/INSTALL.md.in91
-rwxr-xr-xsrc/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/__main__.py.in104
-rw-r--r--src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/cmake/SDL3ConfigVersion.cmake.in38
-rw-r--r--src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/description.json.in5
4 files changed, 238 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/INSTALL.md.in b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/INSTALL.md.in
new file mode 100644
index 0000000..80321c2
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/INSTALL.md.in
@@ -0,0 +1,91 @@
1
2# Using this package
3
4This package contains @<@PROJECT_NAME@>@ built for the Android platform.
5
6## Gradle integration
7
8For integration with CMake/ndk-build, it uses [prefab](https://google.github.io/prefab/).
9
10Copy the aar archive (@<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar) to a `app/libs` directory of your project.
11
12In `app/build.gradle` of your Android project, add:
13```
14android {
15 /* ... */
16 buildFeatures {
17 prefab true
18 }
19}
20dependencies {
21 implementation files('libs/@<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar')
22 /* ... */
23}
24```
25
26If you're using CMake, add the following to your CMakeLists.txt:
27```
28find_package(@<@PROJECT_NAME@>@ REQUIRED CONFIG)
29target_link_libraries(yourgame PRIVATE @<@PROJECT_NAME@>@::@<@PROJECT_NAME@>@)
30```
31
32If you use ndk-build, add the following before `include $(BUILD_SHARED_LIBRARY)` to your `Android.mk`:
33```
34LOCAL_SHARED_LIBARARIES := SDL3 SDL3-Headers
35```
36And add the following at the bottom:
37```
38# https://google.github.io/prefab/build-systems.html
39
40# Add the prefab modules to the import path.
41$(call import-add-path,/out)
42
43# Import @<@PROJECT_NAME@>@ so we can depend on it.
44$(call import-module,prefab/@<@PROJECT_NAME@>@)
45```
46
47---
48
49## Other build systems (advanced)
50
51If you want to build a project without Gradle,
52running the following command will extract the Android archive into a more common directory structure.
53```
54python @<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar -o android_prefix
55```
56Add `--help` for a list of all available options.
57
58# Documentation
59
60An API reference, tutorials, and additional documentation is available at:
61
62https://wiki.libsdl.org/@<@PROJECT_NAME@>@
63
64# Example code
65
66There are simple example programs available at:
67
68https://examples.libsdl.org/SDL3
69
70# Discussions
71
72## Discord
73
74You can join the official Discord server at:
75
76https://discord.com/invite/BwpFGBWsv8
77
78## Forums/mailing lists
79
80You can join SDL development discussions at:
81
82https://discourse.libsdl.org/
83
84Once you sign up, you can use the forum through the website or as a mailing list from your email client.
85
86## Announcement list
87
88You can sign up for the low traffic announcement list at:
89
90https://www.libsdl.org/mailing-list.php
91
diff --git a/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/__main__.py.in b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/__main__.py.in
new file mode 100755
index 0000000..344cf71
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/__main__.py.in
@@ -0,0 +1,104 @@
1#!/usr/bin/env python
2
3"""
4Create a @<@PROJECT_NAME@>@ SDK prefix from an Android archive
5This file is meant to be placed in a the root of an android .aar archive
6
7Example usage:
8```sh
9python @<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar -o /usr/opt/android-sdks
10cmake -S my-project \
11 -DCMAKE_PREFIX_PATH=/usr/opt/android-sdks \
12 -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
13 -B build-arm64 -DANDROID_ABI=arm64-v8a \
14 -DCMAKE_BUILD_TYPE=Releaase
15cmake --build build-arm64
16```
17"""
18import argparse
19import io
20import json
21import os
22import pathlib
23import re
24import stat
25import zipfile
26
27
28AAR_PATH = pathlib.Path(__file__).resolve().parent
29ANDROID_ARCHS = { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" }
30
31
32def main():
33 parser = argparse.ArgumentParser(
34 description="Convert a @<@PROJECT_NAME@>@ Android .aar archive into a SDK",
35 allow_abbrev=False,
36 )
37 parser.add_argument("--version", action="version", version="@<@PROJECT_NAME@>@ @<@PROJECT_VERSION@>@")
38 parser.add_argument("-o", dest="output", type=pathlib.Path, required=True, help="Folder where to store the SDK")
39 args = parser.parse_args()
40
41 print(f"Creating a @<@PROJECT_NAME@>@ SDK at {args.output}...")
42
43 prefix = args.output
44 incdir = prefix / "include"
45 libdir = prefix / "lib"
46
47 RE_LIB_MODULE_ARCH = re.compile(r"prefab/modules/(?P<module>[A-Za-z0-9_-]+)/libs/android\.(?P<arch>[a-zA-Z0-9_-]+)/(?P<filename>lib[A-Za-z0-9_]+\.(?:so|a))")
48 RE_INC_MODULE_ARCH = re.compile(r"prefab/modules/(?P<module>[A-Za-z0-9_-]+)/include/(?P<header>[a-zA-Z0-9_./-]+)")
49 RE_LICENSE = re.compile(r"(?:.*/)?(?P<filename>(?:license|copying)(?:\.md|\.txt)?)", flags=re.I)
50 RE_PROGUARD = re.compile(r"(?:.*/)?(?P<filename>proguard.*\.(?:pro|txt))", flags=re.I)
51 RE_CMAKE = re.compile(r"(?:.*/)?(?P<filename>.*\.cmake)", flags=re.I)
52
53 with zipfile.ZipFile(AAR_PATH) as zf:
54 project_description = json.loads(zf.read("description.json"))
55 project_name = project_description["name"]
56 project_version = project_description["version"]
57 licensedir = prefix / "share/licenses" / project_name
58 cmakedir = libdir / "cmake" / project_name
59 javadir = prefix / "share/java" / project_name
60 javadocdir = prefix / "share/javadoc" / project_name
61
62 def read_zipfile_and_write(path: pathlib.Path, zippath: str):
63 data = zf.read(zippath)
64 path.parent.mkdir(parents=True, exist_ok=True)
65 path.write_bytes(data)
66
67 for zip_info in zf.infolist():
68 zippath = zip_info.filename
69 if m := RE_LIB_MODULE_ARCH.match(zippath):
70 lib_path = libdir / m["arch"] / m["filename"]
71 read_zipfile_and_write(lib_path, zippath)
72 if m["filename"].endswith(".so"):
73 os.chmod(lib_path, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
74
75 elif m := RE_INC_MODULE_ARCH.match(zippath):
76 header_path = incdir / m["header"]
77 read_zipfile_and_write(header_path, zippath)
78 elif m:= RE_LICENSE.match(zippath):
79 license_path = licensedir / m["filename"]
80 read_zipfile_and_write(license_path, zippath)
81 elif m:= RE_PROGUARD.match(zippath):
82 proguard_path = javadir / m["filename"]
83 read_zipfile_and_write(proguard_path, zippath)
84 elif m:= RE_CMAKE.match(zippath):
85 cmake_path = cmakedir / m["filename"]
86 read_zipfile_and_write(cmake_path, zippath)
87 elif zippath == "classes.jar":
88 versioned_jar_path = javadir / f"{project_name}-{project_version}.jar"
89 unversioned_jar_path = javadir / f"{project_name}.jar"
90 read_zipfile_and_write(versioned_jar_path, zippath)
91 os.symlink(src=versioned_jar_path.name, dst=unversioned_jar_path)
92 elif zippath == "classes-sources.jar":
93 jarpath = javadir / f"{project_name}-{project_version}-sources.jar"
94 read_zipfile_and_write(jarpath, zippath)
95 elif zippath == "classes-doc.jar":
96 jarpath = javadocdir / f"{project_name}-{project_version}-javadoc.jar"
97 read_zipfile_and_write(jarpath, zippath)
98
99 print("... done")
100 return 0
101
102
103if __name__ == "__main__":
104 raise SystemExit(main())
diff --git a/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/cmake/SDL3ConfigVersion.cmake.in b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/cmake/SDL3ConfigVersion.cmake.in
new file mode 100644
index 0000000..3268da7
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/cmake/SDL3ConfigVersion.cmake.in
@@ -0,0 +1,38 @@
1# @<@PROJECT_NAME@>@ CMake version configuration file:
2# This file is meant to be placed in a lib/cmake/@<@PROJECT_NAME@>@ subfolder of a reconstructed Android SDL3 SDK
3
4set(PACKAGE_VERSION "@<@PROJECT_VERSION@>@")
5
6if(PACKAGE_FIND_VERSION_RANGE)
7 # Package version must be in the requested version range
8 if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN)
9 OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX)
10 OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX)))
11 set(PACKAGE_VERSION_COMPATIBLE FALSE)
12 else()
13 set(PACKAGE_VERSION_COMPATIBLE TRUE)
14 endif()
15else()
16 if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
17 set(PACKAGE_VERSION_COMPATIBLE FALSE)
18 else()
19 set(PACKAGE_VERSION_COMPATIBLE TRUE)
20 if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
21 set(PACKAGE_VERSION_EXACT TRUE)
22 endif()
23 endif()
24endif()
25
26# if the using project doesn't have CMAKE_SIZEOF_VOID_P set, fail.
27if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "")
28 set(PACKAGE_VERSION_UNSUITABLE TRUE)
29endif()
30
31include("${CMAKE_CURRENT_LIST_DIR}/sdlcpu.cmake")
32SDL_DetectTargetCPUArchitectures(_detected_archs)
33
34# check that the installed version has a compatible architecture as the one which is currently searching:
35if(NOT(SDL_CPU_X86 OR SDL_CPU_X64 OR SDL_CPU_ARM32 OR SDL_CPU_ARM64))
36 set(PACKAGE_VERSION "${PACKAGE_VERSION} (X86,X64,ARM32,ARM64)")
37 set(PACKAGE_VERSION_UNSUITABLE TRUE)
38endif()
diff --git a/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/description.json.in b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/description.json.in
new file mode 100644
index 0000000..e75ef38
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/build-scripts/pkg-support/android/aar/description.json.in
@@ -0,0 +1,5 @@
1{
2 "name": "@<@PROJECT_NAME@>@",
3 "version": "@<@PROJECT_VERSION@>@",
4 "git-hash": "@<@PROJECT_COMMIT@>@"
5}