Files
perfect_dark/cmake/AssetUtils.cmake
izzy2lostandClaude Opus 5 968d582f2f build: modernise the Android toolchain and fix portability breaks
Android:
* compileSdk/targetSdk 34 -> 36, minSdk 21 -> 30, ANDROID_PLATFORM android-30
* pin ndkVersion 27.2.12479018, AGP 8.1.2 -> 9.2.1, Gradle 8.0 -> 9.4.1
  (Gradle 9.x is what runs on the JDK 25 that Android Studio now ships)
* Java 8 -> 17, javac encoding pinned to UTF-8
* drop the x86 ABI: no 32-bit x86 devices exist at minSdk 30, and it was
  a third of the native build time
* refresh AndroidX dependencies

Fixes found while getting the above to build:
* AssetUtils invoked a bare `python` on Windows and Android, which does not
  exist on distros that only ship `python3`. Use the interpreter CMake finds,
  on every platform.
* os_libc.h re-declared bcopy/bcmp/bzero, which clashes with bionic's
  fortified overloadable versions; include <strings.h> on Android instead,
  the same way OSX is already special-cased.
* libultra.c defined those same wrappers, which bionic already provides.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 18:14:09 -04:00

31 lines
1.2 KiB
CMake

# execute a header generator (execcmd) for every json file in jsonpath, collect headers in headerlist
# note that this reads ROMID
macro(generate_asset_headers jsonpath execcmd extraarg headerlist)
set(TMP_JSON "")
if (${jsonpath} MATCHES "\.json")
# is a json file
list(APPEND TMP_JSON "${CMAKE_SOURCE_DIR}/${ASSET_DIR}/${jsonpath}")
else()
# is a directory
file(GLOB TMP_JSON "${CMAKE_SOURCE_DIR}/${ASSET_DIR}/${jsonpath}*.json")
endif()
foreach(JSON ${TMP_JSON})
unset(HEADERNAME)
string(REPLACE ".json" ".h" HEADERNAME ${JSON})
string(REPLACE "${CMAKE_SOURCE_DIR}/${ASSET_DIR}" "${CMAKE_BINARY_DIR}/${GENERATED_DIR}" HEADERNAME ${HEADERNAME})
# Always go through the interpreter CMake found rather than relying on the scripts'
# shebang (no use on Windows) or on a `python` alias existing (many distros only ship
# `python3`, which used to break the Android build).
add_custom_command(
OUTPUT ${HEADERNAME}
DEPENDS ${JSON}
COMMAND ${Python3_EXECUTABLE} ${execcmd} ${JSON} ${extraarg} --headers-only --romid=${ROMID}
)
list(APPEND ${headerlist} "${HEADERNAME}")
endforeach()
unset(TMP_JSON)
endmacro()