From 6aaedb813fa11ba0679c3051bc2eb28646b9506c Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 30 Aug 2025 16:53:58 -0700 Subject: Update to SDL3 --- .../SDL-3.2.20/cmake/android/FindSdlAndroid.cmake | 103 ++++++++ .../cmake/android/FindSdlAndroidBuildTools.cmake | 115 +++++++++ .../cmake/android/FindSdlAndroidPlatform.cmake | 124 +++++++++ .../cmake/android/SdlAndroidFunctions.cmake | 276 +++++++++++++++++++++ .../cmake/android/SdlAndroidScript.cmake | 74 ++++++ 5 files changed, 692 insertions(+) create mode 100644 src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroid.cmake create mode 100644 src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidBuildTools.cmake create mode 100644 src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake create mode 100644 src/contrib/SDL-3.2.20/cmake/android/SdlAndroidFunctions.cmake create mode 100644 src/contrib/SDL-3.2.20/cmake/android/SdlAndroidScript.cmake (limited to 'src/contrib/SDL-3.2.20/cmake/android') 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 @@ +#[=======================================================================[ + +FindSdlAndroid +---------------------- + +Locate various executables that are essential to creating an Android APK archive. +This find module uses the FindSdlAndroidBuildTools module to locate some Android utils. + + +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target(s): + +`` SdlAndroid::aapt2 `` + Imported executable for the "android package tool" v2 + +`` SdlAndroid::apksigner`` + Imported executable for the APK signer tool + +`` SdlAndroid::d8 `` + Imported executable for the dex compiler + +`` SdlAndroid::zipalign `` + Imported executable for the zipalign util + +`` SdlAndroid::adb `` + Imported executable for the "android debug bridge" tool + +`` SdlAndroid::keytool `` + Imported executable for the keytool, a key and certificate management utility + +`` SdlAndroid::zip `` + Imported executable for the zip, for packaging and compressing files + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +`` AAPT2_BIN `` + Path of aapt2 + +`` APKSIGNER_BIN `` + Path of apksigner + +`` D8_BIN `` + Path of d8 + +`` ZIPALIGN_BIN `` + Path of zipalign + +`` ADB_BIN `` + Path of adb + +`` KEYTOOL_BIN `` + Path of keytool + +`` ZIP_BIN `` + Path of zip + +#]=======================================================================] + +cmake_minimum_required(VERSION 3.7...3.28) + +if(NOT PROJECT_NAME MATCHES "^SDL.*") + message(WARNING "This module is internal to SDL and is currently not supported.") +endif() + +find_package(SdlAndroidBuildTools MODULE) + +function(_sdl_android_find_create_imported_executable NAME) + string(TOUPPER "${NAME}" NAME_UPPER) + set(varname "${NAME_UPPER}_BIN") + find_program("${varname}" NAMES "${NAME}" PATHS ${SDL_ANDROID_BUILD_TOOLS_ROOT}) + if(EXISTS "${${varname}}" AND NOT TARGET SdlAndroid::${NAME}) + add_executable(SdlAndroid::${NAME} IMPORTED) + set_property(TARGET SdlAndroid::${NAME} PROPERTY IMPORTED_LOCATION "${${varname}}") + endif() +endfunction() + +if(SdlAndroidBuildTools_FOUND) + _sdl_android_find_create_imported_executable(aapt2) + _sdl_android_find_create_imported_executable(apksigner) + _sdl_android_find_create_imported_executable(d8) + _sdl_android_find_create_imported_executable(zipalign) +endif() + +_sdl_android_find_create_imported_executable(adb) +_sdl_android_find_create_imported_executable(keytool) +_sdl_android_find_create_imported_executable(zip) +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(SdlAndroid + VERSION_VAR + REQUIRED_VARS + AAPT2_BIN + APKSIGNER_BIN + D8_BIN + ZIPALIGN_BIN + KEYTOOL_BIN + ZIP_BIN +) 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 @@ +#[=======================================================================[ + +FindSdlAndroidBuildTools +---------------------- + +Locate the Android build tools directory. + + +Imported targets +^^^^^^^^^^^^^^^^ + +This find module defines the following :prop_tgt:`IMPORTED` target(s): + + + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +`` SdlAndroidBuildTools_FOUND + if false, no Android build tools have been found + +`` SDL_ANDROID_BUILD_TOOLS_ROOT + path of the Android build tools root directory if found + +`` SDL_ANDROID_BUILD_TOOLS_VERSION + the human-readable string containing the android build tools version if found + +Cache variables +^^^^^^^^^^^^^^^ + +These variables may optionally be set to help this module find the correct files: + +``SDL_ANDROID_BUILD_TOOLS_ROOT`` + path of the Android build tools root directory + + +Variables for locating Android platform +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This module responds to the flags: + +``SDL_ANDROID_HOME + First, this module will look for platforms in this CMake variable. + +``ANDROID_HOME + If no platform was found in `SDL_ANDROID_HOME`, then try `ANDROID_HOME`. + +``$ENV{ANDROID_HOME} + If no platform was found in neither `SDL_ANDROID_HOME` or `ANDROID_HOME`, then try `ANDROID_HOME}` + +#]=======================================================================] + +cmake_minimum_required(VERSION 3.7...3.28) + +if(NOT PROJECT_NAME MATCHES "^SDL.*") + message(WARNING "This module is internal to SDL and is currently not supported.") +endif() + +function(_sdl_is_valid_android_build_tools_root RESULT VERSION BUILD_TOOLS_ROOT) + set(result TRUE) + set(version -1) + + string(REGEX MATCH "/([0-9.]+)$" root_match "${BUILD_TOOLS_ROOT}") + if(root_match + AND EXISTS "${BUILD_TOOLS_ROOT}/aapt2" + AND EXISTS "${BUILD_TOOLS_ROOT}/apksigner" + AND EXISTS "${BUILD_TOOLS_ROOT}/d8" + AND EXISTS "${BUILD_TOOLS_ROOT}/zipalign") + set(result "${BUILD_TOOLS_ROOT}") + set(version "${CMAKE_MATCH_1}") + endif() + + set(${RESULT} ${result} PARENT_SCOPE) + set(${VERSION} ${version} PARENT_SCOPE) +endfunction() + +function(_find_sdl_android_build_tools_root ROOT) + cmake_parse_arguments(fsabtr "" "" "" ${ARGN}) + set(homes ${SDL_ANDROID_HOME} ${ANDROID_HOME} $ENV{ANDROID_HOME}) + set(root ${ROOT}-NOTFOUND) + foreach(home IN LISTS homes) + if(NOT IS_DIRECTORY "${home}") + continue() + endif() + file(GLOB build_tools_roots LIST_DIRECTORIES true "${home}/build-tools/*") + set(max_build_tools_version -1) + set(max_build_tools_root "") + foreach(build_tools_root IN LISTS build_tools_roots) + _sdl_is_valid_android_build_tools_root(is_valid build_tools_version "${build_tools_root}") + if(is_valid AND build_tools_version GREATER max_build_tools_version) + set(max_build_tools_version "${build_tools_version}") + set(max_build_tools_root "${build_tools_root}") + endif() + endforeach() + if(max_build_tools_version GREATER -1) + set(root ${max_build_tools_root}) + break() + endif() + endforeach() + set(${ROOT} ${root} PARENT_SCOPE) +endfunction() + +if(NOT DEFINED SDL_ANDROID_BUILD_TOOLS_ROOT) + _find_sdl_android_build_tools_root(SDL_ANDROID_BUILD_TOOLS_ROOT) + set(SDL_ANDROID_BUILD_TOOLS_ROOT "${SDL_ANDROID_BUILD_TOOLS_ROOT}" CACHE PATH "Path of Android build tools") +endif() + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(SdlAndroidBuildTools + VERSION_VAR SDL_ANDROID_BUILD_TOOLS_VERSION + REQUIRED_VARS SDL_ANDROID_BUILD_TOOLS_ROOT +) 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 @@ +#[=======================================================================[ + +FindSdlAndroidPlatform +---------------------- + +Locate the Android SDK platform. + + +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target(s): + + + +Result variables +^^^^^^^^^^^^^^^^ + +This find module will set the following variables in your project: + +`` SdlAndroidPlatform_FOUND + if false, no Android platform has been found + +`` SDL_ANDROID_PLATFORM_ROOT + path of the Android SDK platform root directory if found + +`` SDL_ANDROID_PLATFORM_ANDROID_JAR + path of the Android SDK platform jar file if found + +`` SDL_ANDROID_PLATFORM_VERSION + the human-readable string containing the android platform version if found + +Cache variables +^^^^^^^^^^^^^^^ + +These variables may optionally be set to help this module find the correct files: + +``SDL_ANDROID_PLATFORM_ROOT`` + path of the Android SDK platform root directory + + +Variables for locating Android platform +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +This module responds to the flags: + +``SDL_ANDROID_HOME + First, this module will look for platforms in this CMake variable. + +``ANDROID_HOME + If no platform was found in `SDL_ANDROID_HOME`, then try `ANDROID_HOME`. + +``$ENV{ANDROID_HOME} + If no platform was found in neither `SDL_ANDROID_HOME` or `ANDROID_HOME`, then try `ANDROID_HOME}` + +#]=======================================================================] + +cmake_minimum_required(VERSION 3.7...3.28) + +if(NOT PROJECT_NAME MATCHES "^SDL.*") + message(WARNING "This module is internal to SDL and is currently not supported.") +endif() + +function(_sdl_is_valid_android_platform_root RESULT VERSION PLATFORM_ROOT) + set(result FALSE) + set(version -1) + + string(REGEX MATCH "/android-([0-9]+)$" root_match "${PLATFORM_ROOT}") + if(root_match AND EXISTS "${PLATFORM_ROOT}/android.jar") + set(result TRUE) + set(version "${CMAKE_MATCH_1}") + endif() + + set(${RESULT} ${result} PARENT_SCOPE) + set(${VERSION} ${version} PARENT_SCOPE) +endfunction() + +function(_sdl_find_android_platform_root ROOT) + cmake_parse_arguments(sfapr "" "" "" ${ARGN}) + set(homes ${SDL_ANDROID_HOME} ${ANDROID_HOME} $ENV{ANDROID_HOME}) + set(root ${ROOT}-NOTFOUND) + foreach(home IN LISTS homes) + if(NOT IS_DIRECTORY "${home}") + continue() + endif() + file(GLOB platform_roots LIST_DIRECTORIES true "${home}/platforms/*") + set(max_platform_version -1) + set(max_platform_root "") + foreach(platform_root IN LISTS platform_roots) + _sdl_is_valid_android_platform_root(is_valid platform_version "${platform_root}") + if(is_valid AND platform_version GREATER max_platform_version) + set(max_platform_version "${platform_version}") + set(max_platform_root "${platform_root}") + endif() + endforeach() + if(max_platform_version GREATER -1) + set(root ${max_platform_root}) + break() + endif() + endforeach() + set(${ROOT} ${root} PARENT_SCOPE) +endfunction() + +set(SDL_ANDROID_PLATFORM_ANDROID_JAR "SDL_ANDROID_PLATFORM_ANDROID_JAR-NOTFOUND") + +if(NOT DEFINED SDL_ANDROID_PLATFORM_ROOT) + _sdl_find_android_platform_root(_new_sdl_android_platform_root) + set(SDL_ANDROID_PLATFORM_ROOT "${_new_sdl_android_platform_root}" CACHE PATH "Path of Android platform") + unset(_new_sdl_android_platform_root) +endif() +if(SDL_ANDROID_PLATFORM_ROOT) + _sdl_is_valid_android_platform_root(_valid SDL_ANDROID_PLATFORM_VERSION "${SDL_ANDROID_PLATFORM_ROOT}") + if(_valid) + set(SDL_ANDROID_PLATFORM_ANDROID_JAR "${SDL_ANDROID_PLATFORM_ROOT}/android.jar") + endif() + unset(_valid) +endif() + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(SdlAndroidPlatform + VERSION_VAR SDL_ANDROID_PLATFORM_VERSION + REQUIRED_VARS SDL_ANDROID_PLATFORM_ROOT SDL_ANDROID_PLATFORM_ANDROID_JAR +) 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 @@ +#[=======================================================================[ + +This CMake script contains functions to build an Android APK. +It is (currently) limited to packaging binaries for a single architecture. + +#]=======================================================================] + +cmake_minimum_required(VERSION 3.7...3.28) + +if(NOT PROJECT_NAME MATCHES "^SDL.*") + message(WARNING "This module is internal to SDL and is currently not supported.") +endif() + +function(_sdl_create_outdir_for_target OUTDIRECTORY TARGET) + set(outdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET}.dir") + # Some CMake versions have a slow `cmake -E make_directory` implementation + if(NOT IS_DIRECTORY "${outdir}") + execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${outdir}") + endif() + set("${OUTDIRECTORY}" "${outdir}" PARENT_SCOPE) +endfunction() + +function(sdl_create_android_debug_keystore TARGET) + set(output "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_debug.keystore") + add_custom_command(OUTPUT ${output} + COMMAND ${CMAKE_COMMAND} -E rm -f "${output}" + 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" + ) + add_custom_target(${TARGET} DEPENDS "${output}") + set_property(TARGET ${TARGET} PROPERTY OUTPUT "${output}") +endfunction() + +function(sdl_android_compile_resources TARGET) + cmake_parse_arguments(arg "" "RESFOLDER" "RESOURCES" ${ARGN}) + + if(NOT arg_RESFOLDER AND NOT arg_RESOURCES) + message(FATAL_ERROR "Missing RESFOLDER or RESOURCES argument (need one or both)") + endif() + _sdl_create_outdir_for_target(outdir "${TARGET}") + set(out_files "") + + set(res_files "") + if(arg_RESFOLDER) + get_filename_component(arg_RESFOLDER "${arg_RESFOLDER}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + file(GLOB_RECURSE res_folder_files "${arg_RESFOLDER}/*") + list(APPEND res_files ${res_folder_files}) + + foreach(res_file IN LISTS res_files) + file(RELATIVE_PATH rel_res_file "${arg_RESFOLDER}" "${res_file}") + string(REPLACE "/" "_" rel_comp_path "${rel_res_file}") + if(res_file MATCHES ".*res/values.*\\.xml$") + string(REGEX REPLACE "\\.xml" ".arsc" rel_comp_path "${rel_comp_path}") + endif() + set(comp_path "${outdir}/${rel_comp_path}.flat") + add_custom_command( + OUTPUT "${comp_path}" + COMMAND SdlAndroid::aapt2 compile -o "${outdir}" "${res_file}" + DEPENDS ${res_file} + ) + list(APPEND out_files "${comp_path}") + endforeach() + endif() + + if(arg_RESOURCES) + list(APPEND res_files ${arg_RESOURCES}) + foreach(res_file IN LISTS arg_RESOURCES) + string(REGEX REPLACE ".*/res/" "" rel_res_file ${res_file}) + string(REPLACE "/" "_" rel_comp_path "${rel_res_file}") + if(res_file MATCHES ".*res/values.*\\.xml$") + string(REGEX REPLACE "\\.xml" ".arsc" rel_comp_path "${rel_comp_path}") + endif() + set(comp_path "${outdir}/${rel_comp_path}.flat") + add_custom_command( + OUTPUT "${comp_path}" + COMMAND SdlAndroid::aapt2 compile -o "${outdir}" "${res_file}" + DEPENDS ${res_file} + ) + list(APPEND out_files "${comp_path}") + endforeach() + endif() + + add_custom_target(${TARGET} DEPENDS ${out_files}) + set_property(TARGET "${TARGET}" PROPERTY OUTPUTS "${out_files}") + set_property(TARGET "${TARGET}" PROPERTY SOURCES "${res_files}") +endfunction() + +function(sdl_android_link_resources TARGET) + cmake_parse_arguments(arg "NO_DEBUG" "MIN_SDK_VERSION;TARGET_SDK_VERSION;ANDROID_JAR;OUTPUT_APK;MANIFEST;PACKAGE" "RES_TARGETS" ${ARGN}) + + if(arg_MANIFEST) + get_filename_component(arg_MANIFEST "${arg_MANIFEST}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + else() + message(FATAL_ERROR "sdl_add_android_link_resources_target requires a Android MANIFEST path (${arg_MANIFEST})") + endif() + if(NOT arg_PACKAGE) + file(READ "${arg_MANIFEST}" manifest_contents) + string(REGEX MATCH "package=\"([a-zA-Z0-9_.]+)\"" package_match "${manifest_contents}") + if(NOT package_match) + message(FATAL_ERROR "Could not extract package from Android manifest (${arg_MANIFEST})") + endif() + set(arg_PACKAGE "${CMAKE_MATCH_1}") + endif() + + set(depends "") + + _sdl_create_outdir_for_target(outdir "${TARGET}") + string(REPLACE "." "/" java_r_path "${arg_PACKAGE}") + get_filename_component(java_r_path "${java_r_path}" ABSOLUTE BASE_DIR "${outdir}") + set(java_r_path "${java_r_path}/R.java") + + set(command SdlAndroid::aapt2 link) + if(NOT arg_NO_DEBUG) + list(APPEND command --debug-mode) + endif() + if(arg_MIN_SDK_VERSION) + list(APPEND command --min-sdk-version ${arg_MIN_SDK_VERSION}) + endif() + if(arg_TARGET_SDK_VERSION) + list(APPEND command --target-sdk-version ${arg_TARGET_SDK_VERSION}) + endif() + if(arg_ANDROID_JAR) + list(APPEND command -I "${arg_ANDROID_JAR}") + else() + list(APPEND command -I "${SDL_ANDROID_PLATFORM_ANDROID_JAR}") + endif() + if(NOT arg_OUTPUT_APK) + set(arg_OUTPUT_APK "${TARGET}.apk") + endif() + get_filename_component(arg_OUTPUT_APK "${arg_OUTPUT_APK}" ABSOLUTE BASE_DIR "${outdir}") + list(APPEND command -o "${arg_OUTPUT_APK}") + list(APPEND command --java "${outdir}") + list(APPEND command --manifest "${arg_MANIFEST}") + foreach(res_target IN LISTS arg_RES_TARGETS) + list(APPEND command $) + list(APPEND depends $) + endforeach() + add_custom_command( + OUTPUT "${arg_OUTPUT_APK}" "${java_r_path}" + COMMAND ${command} + DEPENDS ${depends} ${arg_MANIFEST} + COMMAND_EXPAND_LISTS + VERBATIM + ) + add_custom_target(${TARGET} DEPENDS "${arg_OUTPUT_APK}" "${java_r_path}") + set_property(TARGET ${TARGET} PROPERTY OUTPUT "${arg_OUTPUT_APK}") + set_property(TARGET ${TARGET} PROPERTY JAVA_R "${java_r_path}") + set_property(TARGET ${TARGET} PROPERTY OUTPUTS "${${arg_OUTPUT_APK}};${java_r_path}") +endfunction() + +function(sdl_add_to_apk_unaligned TARGET) + cmake_parse_arguments(arg "" "APK_IN;NAME;OUTDIR" "ASSETS;NATIVE_LIBS;DEX" ${ARGN}) + + if(NOT arg_APK_IN) + message(FATAL_ERROR "Missing APK_IN argument") + endif() + + if(NOT TARGET ${arg_APK_IN}) + message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk") + endif() + + _sdl_create_outdir_for_target(workdir ${TARGET}) + + if(NOT arg_OUTDIR) + set(arg_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}") + endif() + + if(NOT arg_NAME) + string(REGEX REPLACE "[:-]+" "." arg_NAME "${TARGET}") + if(NOT arg_NAME MATCHES "\\.apk") + set(arg_NAME "${arg_NAME}.apk") + endif() + endif() + get_filename_component(apk_file "${arg_NAME}" ABSOLUTE BASE_DIR "${arg_OUTDIR}") + + set(apk_libdir "lib/${ANDROID_ABI}") + + set(depends "") + + set(commands + COMMAND "${CMAKE_COMMAND}" -E remove_directory -rf "${apk_libdir}" "assets" + COMMAND "${CMAKE_COMMAND}" -E make_directory "${apk_libdir}" "assets" + COMMAND "${CMAKE_COMMAND}" -E copy "$" "${apk_file}" + ) + + set(dex_i "1") + foreach(dex IN LISTS arg_DEX) + set(suffix "${dex_i}") + if(suffix STREQUAL "1") + set(suffix "") + endif() + list(APPEND commands + COMMAND "${CMAKE_COMMAND}" -E copy "$" "classes${suffix}.dex" + COMMAND SdlAndroid::zip -u -q -j "${apk_file}" "classes${suffix}.dex" + ) + math(EXPR dex_i "${dex_i}+1") + list(APPEND depends "$") + endforeach() + + foreach(native_lib IN LISTS arg_NATIVE_LIBS) + list(APPEND commands + COMMAND "${CMAKE_COMMAND}" -E copy $ "${apk_libdir}/$" + COMMAND SdlAndroid::zip -u -q "${apk_file}" "${apk_libdir}/$" + ) + endforeach() + if(arg_ASSETS) + list(APPEND commands + COMMAND "${CMAKE_COMMAND}" -E copy ${arg_ASSETS} "assets" + COMMAND SdlAndroid::zip -u -r -q "${apk_file}" "assets" + ) + endif() + + add_custom_command(OUTPUT "${apk_file}" + ${commands} + DEPENDS ${arg_NATIVE_LIBS} ${depends} "$" + WORKING_DIRECTORY "${workdir}" + ) + add_custom_target(${TARGET} DEPENDS "${apk_file}") + set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}") +endfunction() + +function(sdl_apk_align TARGET APK_IN) + cmake_parse_arguments(arg "" "NAME;OUTDIR" "" ${ARGN}) + + if(NOT TARGET ${arg_APK_IN}) + message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk") + endif() + + if(NOT arg_OUTDIR) + set(arg_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}") + endif() + + if(NOT arg_NAME) + string(REGEX REPLACE "[:-]+" "." arg_NAME "${TARGET}") + if(NOT arg_NAME MATCHES "\\.apk") + set(arg_NAME "${arg_NAME}.apk") + endif() + endif() + get_filename_component(apk_file "${arg_NAME}" ABSOLUTE BASE_DIR "${arg_OUTDIR}") + + add_custom_command(OUTPUT "${apk_file}" + COMMAND SdlAndroid::zipalign -f 4 "$" "${apk_file}" + DEPENDS "$" + ) + add_custom_target(${TARGET} DEPENDS "${apk_file}") + set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}") +endfunction() + +function(sdl_apk_sign TARGET APK_IN) + cmake_parse_arguments(arg "" "OUTPUT;KEYSTORE" "" ${ARGN}) + + if(NOT TARGET ${arg_APK_IN}) + message(FATAL_ERROR "APK_IN (${arg_APK_IN}) must be a target providing an apk") + endif() + + if(NOT TARGET ${arg_KEYSTORE}) + message(FATAL_ERROR "APK_KEYSTORE (${APK_KEYSTORE}) must be a target providing a keystore") + endif() + + if(NOT arg_OUTPUT) + string(REGEX REPLACE "[:-]+" "." arg_OUTPUT "${TARGET}") + if(NOT arg_OUTPUT MATCHES "\\.apk") + set(arg_OUTPUT "${arg_OUTPUT}.apk") + endif() + endif() + get_filename_component(apk_file "${arg_OUTPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}") + + add_custom_command(OUTPUT "${apk_file}" + COMMAND SdlAndroid::apksigner sign + --ks "$" + --ks-pass pass:android --in "$" --out "${apk_file}" + DEPENDS "$" "$" + BYPRODUCTS "${apk_file}.idsig" + ) + add_custom_target(${TARGET} DEPENDS "${apk_file}") + set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}") +endfunction() 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 @@ +#[=======================================================================[ + +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() -- cgit v1.2.3