Files
kaizen/external/SDL/cmake/android/SdlAndroidFunctions.cmake
T
iris 00cc9309cb Squashed 'external/ircolib/' changes from ce3cd726c..de6e324bd
de6e324bd separate emu thread
10d3daf86 Roms List improvements
95d202f37 Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.
fc306967f Wow the ROM Header was just completely busted. Game list view works now
bad1691ee fuck this shit
2b59e5f46 game list in progress
d26417b83 remappable inputs in progress
ac4af8106 input
e72abc240 update readme
430139dc9 Qt6 frontend
3080d4d45 Fix this small bug too
08cd13b85 Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.
61bb4fb44 make idle loop detection a little more specific with where the load goes
b037de4c3 SAZDFsdff
12e81e73e need to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)
204f0e13b idle skipping seems to work!
cb8bb634a sdkfjlasdf
58e5c89c1 Fix compilation issue on my machine (no idea)
24fb2898e attempting more serious idle skipping
214719577 Place rsp.Step inside cached interpreter. Gains about 3 more fps
bb97dcc23 mmmmm
920b77d38 wjkhasdfjhkasdf
430ccdab4 it's a start...
4f42a673a Cached interpreter plays Mario 64. Start looking into RSP as well
c9a030787 idle skipping works!
5fbda03ce new idea
366637aba Idle skipping... maybe?
609fa2fb0 Cache instructions implemented but broken lmao. Commented out for now
e140a6d12 - Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work
68e613057 prep cache impl
811b4d809 fix clang format
fda755f7d idk
d5024ebbf small MI refactor in preparation of (eventually) implementing the RDRAM interface properly
694b45341 Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'
206dcdedf Squashed 'external/SDL/' content from commit 4d17b99d0a
4d16e1cb4 need to update sdl
848b19920 Fix compilation error
db61b5299 Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'
e94a94559 Squashed 'external/imgui/' content from commit 02e9b8cac
52edb3757 need to update imgui
c1a705e86 Emulate weird JALR behaviour
4b4c32f4b Fix exception for "unusable COP1" in 4 instructions i missed accidentally (again)
df5828142 Bug putting 0s in the log everywhere
f8b580048 Make isviewer a sink to file
8241e9735 Fix exception for "unusable COP1" in 4 instructions i missed accidentally
b29715f20 small changes
d9a620bc1 make use of my new small utility library
0d1aa938e Add 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'
e64eb40b3 Fuck git

git-subtree-dir: external/ircolib
git-subtree-split: de6e324bde
2026-06-15 11:56:38 +02:00

277 lines
10 KiB
CMake

#[=======================================================================[
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 $<TARGET_PROPERTY:${res_target},OUTPUTS>)
list(APPEND depends $<TARGET_PROPERTY:${res_target},OUTPUTS>)
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 "$<TARGET_PROPERTY:${arg_APK_IN},OUTPUT>" "${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 "$<TARGET_PROPERTY:${dex},OUTPUT>" "classes${suffix}.dex"
COMMAND SdlAndroid::zip -u -q -j "${apk_file}" "classes${suffix}.dex"
)
math(EXPR dex_i "${dex_i}+1")
list(APPEND depends "$<TARGET_PROPERTY:${dex},OUTPUT>")
endforeach()
foreach(native_lib IN LISTS arg_NATIVE_LIBS)
list(APPEND commands
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_FILE:${native_lib}> "${apk_libdir}/$<TARGET_FILE_NAME:${native_lib}>"
COMMAND SdlAndroid::zip -u -q "${apk_file}" "${apk_libdir}/$<TARGET_FILE_NAME:${native_lib}>"
)
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} "$<TARGET_PROPERTY:${arg_APK_IN},OUTPUT>"
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 "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" "${apk_file}"
DEPENDS "$<TARGET_PROPERTY:${APK_IN},OUTPUT>"
)
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 "$<TARGET_PROPERTY:${arg_KEYSTORE},OUTPUT>"
--ks-pass pass:android --in "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" --out "${apk_file}"
DEPENDS "$<TARGET_PROPERTY:${APK_IN},OUTPUT>" "$<TARGET_PROPERTY:${arg_KEYSTORE},OUTPUT>"
BYPRODUCTS "${apk_file}.idsig"
)
add_custom_target(${TARGET} DEPENDS "${apk_file}")
set_property(TARGET ${TARGET} PROPERTY OUTPUT "${apk_file}")
endfunction()