Add parametrized build script

[ci skip]
This commit is contained in:
Anonymous Maarten
2024-10-05 01:32:27 +02:00
committed by Anonymous Maarten
parent 57f2577c65
commit 45dfdfbb7b
31 changed files with 1820 additions and 927 deletions

View File

@@ -1,58 +1,61 @@
This Android archive allows use of @PROJECT_NAME@ in your Android project, without needing to copy any SDL source.
For integration with CMake/ndk-build, it uses [prefab](https://google.github.io/prefab/).
Copy this archive (@PROJECT_NAME@-@PROJECT_VERSION@.aar) to a `app/libs` directory of your project.
In `app/build.gradle` of your Android project, add:
```
android {
/* ... */
buildFeatures {
prefab true
}
}
dependencies {
implementation files('libs/@PROJECT_NAME@-@PROJECT_VERSION@.aar')
/* ... */
}
```
If you're using CMake, add the following to your CMakeLists.txt:
```
find_package(@PROJECT_NAME@ REQUIRED CONFIG)
target_link_libraries(yourgame PRIVATE @PROJECT_NAME@::@PROJECT_NAME@)
```
If you're using ndk-build, add the following somewhere after `LOCAL_MODULE := yourgame` to your `Android.mk` or `Application.mk`:
```
# https://google.github.io/prefab/build-systems.html
# Add the prefab modules to the import path.
$(call import-add-path,/out)
# Import @PROJECT_NAME@ so we can depend on it.
$(call import-module,prefab/@PROJECT_NAME@)
```
---
For advanced users:
If you want to build a 3rd party library outside Gradle,
running the following command will extract the Android archive into a more common directory structure.
```
python @PROJECT_NAME@-@PROJECT_VERSION@.aar -o android_prefix
```
Add `--help` for a list of all available options.
Look at the example programs in ./test (of the source archive), and check out online documentation:
https://wiki.libsdl.org/SDL3/FrontPage
Join the SDL discourse server if you want to join the community:
https://discourse.libsdl.org/
That's it!
Sam Lantinga <slouken@libsdl.org>
This Android archive allows use of @<@PROJECT_NAME@>@ in your Android project, without needing to copy any SDL source.
For integration with CMake/ndk-build, it uses [prefab](https://google.github.io/prefab/).
Copy this archive (@<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar) to a `app/libs` directory of your project.
In `app/build.gradle` of your Android project, add:
```
android {
/* ... */
buildFeatures {
prefab true
}
}
dependencies {
implementation files('libs/@<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar')
/* ... */
}
```
If you're using CMake, add the following to your CMakeLists.txt:
```
find_package(@<@PROJECT_NAME@>@ REQUIRED CONFIG)
target_link_libraries(yourgame PRIVATE @<@PROJECT_NAME@>@::@<@PROJECT_NAME@>@)
```
If you use ndk-build, add the following before `include $(BUILD_SHARED_LIBRARY)` to your `Android.mk`:
```
LOCAL_SHARED_LIBARARIES := SDL3 SDL3-Headers
```
And add the following at the bottom:
```
# https://google.github.io/prefab/build-systems.html
# Add the prefab modules to the import path.
$(call import-add-path,/out)
# Import @<@PROJECT_NAME@>@ so we can depend on it.
$(call import-module,prefab/@<@PROJECT_NAME@>@)
```
---
For advanced users:
If you want to build a 3rd party library outside Gradle,
running the following command will extract the Android archive into a more common directory structure.
```
python @<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar -o android_prefix
```
Add `--help` for a list of all available options.
Look at the example programs in ./test (of the source archive), and check out online documentation:
https://wiki.libsdl.org/SDL3/FrontPage
Join the SDL discourse server if you want to join the community:
https://discourse.libsdl.org/
That's it!
Sam Lantinga <slouken@libsdl.org>

View File

@@ -1,12 +1,12 @@
#!/usr/bin/env python
"""
Create a @PROJECT_NAME@ SDK prefix from an Android archive
Create a @<@PROJECT_NAME@>@ SDK prefix from an Android archive
This file is meant to be placed in a the root of an android .aar archive
Example usage:
```sh
python @PROJECT_NAME@-@PROJECT_VERSION@.aar -o /usr/opt/android-sdks
python @<@PROJECT_NAME@>@-@<@PROJECT_VERSION@>@.aar -o /usr/opt/android-sdks
cmake -S my-project \
-DCMAKE_PREFIX_PATH=/usr/opt/android-sdks \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
@@ -31,13 +31,14 @@ ANDROID_ARCHS = { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" }
def main():
parser = argparse.ArgumentParser(
description="Convert a @PROJECT_NAME@ Android .aar archive into a SDK",
description="Convert a @<@PROJECT_NAME@>@ Android .aar archive into a SDK",
allow_abbrev=False,
)
parser.add_argument("--version", action="version", version="@<@PROJECT_NAME@>@ @<@PROJECT_VERSION@>@")
parser.add_argument("-o", dest="output", type=pathlib.Path, required=True, help="Folder where to store the SDK")
args = parser.parse_args()
print(f"Creating a @PROJECT_NAME@ SDK at {args.output}...")
print(f"Creating a @<@PROJECT_NAME@>@ SDK at {args.output}...")
prefix = args.output
incdir = prefix / "include"
@@ -92,9 +93,8 @@ def main():
jarpath = javadir / f"{project_name}-{project_version}-sources.jar"
read_zipfile_and_write(jarpath, zippath)
elif zippath == "classes-doc.jar":
data = zf.read(zippath)
with zipfile.ZipFile(io.BytesIO(data)) as doc_zf:
doc_zf.extractall(javadocdir)
jarpath = javadocdir / f"{project_name}-{project_version}-javadoc.jar"
read_zipfile_and_write(jarpath, zippath)
print("... done")
return 0

View File

@@ -1,26 +1,7 @@
# based on the files generated by CMake's write_basic_package_version_file
# @<@PROJECT_NAME@>@ CMake version configuration file:
# This file is meant to be placed in a lib/cmake/@<@PROJECT_NAME@>@ subfolder of a reconstructed Android SDL3 SDK
# SDL CMake version configuration file:
# This file is meant to be placed in a lib/cmake/SDL3 subfolder of a reconstructed Android SDL3 SDK
if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../../include/SDL3/SDL_version.h")
message(AUTHOR_WARNING "Could not find SDL3/SDL_version.h. This script is meant to be placed in the root of SDL3-devel-3.x.y-VC")
return()
endif()
file(READ "${CMAKE_CURRENT_LIST_DIR}/../../../include/SDL3/SDL_version.h" _sdl_version_h)
string(REGEX MATCH "#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_major_re "${_sdl_version_h}")
set(_sdl_major "${CMAKE_MATCH_1}")
string(REGEX MATCH "#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_version_h}")
set(_sdl_minor "${CMAKE_MATCH_1}")
string(REGEX MATCH "#define[ \t]+SDL_MICRO_VERSION[ \t]+([0-9]+)" _sdl_micro_re "${_sdl_version_h}")
set(_sdl_micro "${CMAKE_MATCH_1}")
if(_sdl_major_re AND _sdl_minor_re AND _sdl_micro_re)
set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_micro}")
else()
message(AUTHOR_WARNING "Could not extract version from SDL3/SDL_version.h.")
return()
endif()
set(PACKAGE_VERSION "@<@PROJECT_VERSION@>@")
if(PACKAGE_FIND_VERSION_RANGE)
# Package version must be in the requested version range

View File

@@ -0,0 +1,5 @@
{
"name": "@<@PROJECT_NAME@>@",
"version": "@<@PROJECT_VERSION@>@",
"git-hash": "@<@PROJECT_COMMIT@>@"
}