From 9d6404d130456c5c09bc4784ec3d3c56ba8878ef Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 6 Jun 2024 09:47:32 +0200 Subject: [PATCH] move cmake stuff to android subdir --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 96 +------------------------------------ android/CMakeLists.txt | 100 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 96 deletions(-) create mode 100644 android/CMakeLists.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f927b7d..b97664a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,7 @@ jobs: name: ${{ github.event.repository.name }}-android-arm64 # TODO: do propper packing path: | - ${{github.workspace}}/build/tomato.apk + ${{github.workspace}}/build/android/tomato.apk macos: timeout-minutes: 10 diff --git a/CMakeLists.txt b/CMakeLists.txt index e56307b..468ff51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,100 +74,6 @@ add_subdirectory(./src) if (ANDROID AND TARGET SDL3::Jar) message("II building for ANDROID!!!") - list(APPEND CMAKE_MODULE_PATH "${SDL3_SOURCE_DIR}/cmake/android") - - # here be dragons - - find_package(SdlAndroid MODULE) - find_package(Java) - find_package(SdlAndroidPlatform MODULE) - # the existence of SDL3::Jar usually implies platform - if(SdlAndroid_FOUND) - include(SdlAndroidFunctions) - sdl_create_android_debug_keystore(tomato-debug-keystore) - sdl_android_compile_resources(tomato-resources RESFOLDER android/app/res) - - - set(ANDROID_MANIFEST_PACKAGE "org.libsdl.app.tomato") - #set(generated_manifest_path "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src/AndroidManifest.xml") - string(REPLACE "." "/" JAVA_PACKAGE_DIR "${ANDROID_MANIFEST_PACKAGE}") - #set(GENERATED_SRC_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src") - #set(GENERATED_RES_FOLDER "${GENERATED_SRC_FOLDER}/res") - #set(JAVA_PACKAGE_DIR "${GENERATED_SRC_FOLDER}/${JAVA_PACKAGE_DIR}") - set(JAVA_PACKAGE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android/app/java/${JAVA_PACKAGE_DIR}") - - sdl_android_link_resources(tomato-apk-linked - MANIFEST "android/app/AndroidManifest.xml" - PACKAGE ${ANDROID_MANIFEST_PACKAGE} - RES_TARGETS tomato-resources - TARGET_SDK_VERSION 31 - ) - - set(CMAKE_JAVA_COMPILE_FLAGS "-encoding;utf-8") - set(classes_path "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/tomato-java.dir/classes") - # Some CMake versions have a slow `cmake -E make_directory` implementation - if(NOT IS_DIRECTORY "${classes_path}") - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}") - endif() - set(OUT_JAR "${CMAKE_CURRENT_BINARY_DIR}/tomato.jar") - add_custom_command( - OUTPUT "${OUT_JAR}" - COMMAND ${CMAKE_COMMAND} -E rm -rf "${classes_path}" - COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}" - COMMAND ${Java_JAVAC_EXECUTABLE} - -source 1.8 -target 1.8 - -bootclasspath "$" - "${JAVA_PACKAGE_DIR}/TomatoActivity.java" - $ - -cp "$:${SDL_ANDROID_PLATFORM_ANDROID_JAR}" - -d "${classes_path}" - COMMAND ${Java_JAR_EXECUTABLE} cf "${OUT_JAR}" -C "${classes_path}" . - DEPENDS $ "$" - ) - add_custom_target(tomato-jar DEPENDS "${OUT_JAR}") - add_dependencies(tomato-jar SDL3::Jar) # HACK: somehow their jar is not registered as an output - set_property(TARGET tomato-jar PROPERTY OUTPUT "${OUT_JAR}") - - set(dexworkdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/tomato-dex.dir") - # Some CMake versions have a slow `cmake -E make_directory` implementation - if(NOT IS_DIRECTORY "${dexworkdir}") - execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${dexworkdir}") - endif() - set(classes_dex_base_name "classes.dex") - set(classes_dex "${dexworkdir}/${classes_dex_base_name}") - add_custom_command( - OUTPUT "${classes_dex}" - COMMAND SdlAndroid::d8 - $ - $ - --lib "${SDL_ANDROID_PLATFORM_ANDROID_JAR}" - --output "${dexworkdir}" - DEPENDS $ $ - ) - add_custom_target(tomato-dex DEPENDS "${classes_dex}") - set_property(TARGET tomato-dex PROPERTY OUTPUT "${classes_dex}") - set_property(TARGET tomato-dex PROPERTY OUTPUT_BASE_NAME "${classes_dex_base_name}") - - # file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt) - - sdl_add_to_apk_unaligned(tomato-unaligned-apk - APK_IN tomato-apk-linked - OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/intermediates" - #ASSETS ${RESOURCE_FILES} - #NATIVE_LIBS SDL3::SDL3-shared tomato - NATIVE_LIBS tomato - DEX tomato-dex - ) - - sdl_apk_align(tomato-aligned-apk tomato-unaligned-apk - OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/intermediates" - ) - sdl_apk_sign(tomato-apk tomato-aligned-apk - KEYSTORE tomato-debug-keystore - ) - - else() - message("FF SdlAndroid module not found") - endif() + add_subdirectory(android) endif() diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt new file mode 100644 index 0000000..e6f92ed --- /dev/null +++ b/android/CMakeLists.txt @@ -0,0 +1,100 @@ +cmake_minimum_required(VERSION 3.14...3.24 FATAL_ERROR) + +project(tomato_android) + +# here be dragons + +list(APPEND CMAKE_MODULE_PATH "${SDL3_SOURCE_DIR}/cmake/android") + +find_package(SdlAndroid MODULE) +find_package(Java) +find_package(SdlAndroidPlatform MODULE) +# the existence of SDL3::Jar usually implies platform +if(SdlAndroid_FOUND) + include(SdlAndroidFunctions) + sdl_create_android_debug_keystore(tomato-debug-keystore) + sdl_android_compile_resources(tomato-resources RESFOLDER app/res) + + + set(ANDROID_MANIFEST_PACKAGE "org.libsdl.app.tomato") + #set(generated_manifest_path "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src/AndroidManifest.xml") + string(REPLACE "." "/" JAVA_PACKAGE_DIR "${ANDROID_MANIFEST_PACKAGE}") + #set(GENERATED_SRC_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/android/${TEST}-src") + #set(GENERATED_RES_FOLDER "${GENERATED_SRC_FOLDER}/res") + #set(JAVA_PACKAGE_DIR "${GENERATED_SRC_FOLDER}/${JAVA_PACKAGE_DIR}") + set(JAVA_PACKAGE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/app/java/${JAVA_PACKAGE_DIR}") + + sdl_android_link_resources(tomato-apk-linked + MANIFEST "app/AndroidManifest.xml" + PACKAGE ${ANDROID_MANIFEST_PACKAGE} + RES_TARGETS tomato-resources + TARGET_SDK_VERSION 31 + ) + + set(CMAKE_JAVA_COMPILE_FLAGS "-encoding;utf-8") + set(classes_path "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/tomato-java.dir/classes") + # Some CMake versions have a slow `cmake -E make_directory` implementation + if(NOT IS_DIRECTORY "${classes_path}") + execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}") + endif() + set(OUT_JAR "${CMAKE_CURRENT_BINARY_DIR}/tomato.jar") + # TODO: convert to cmake's add_jar + add_custom_command( + OUTPUT "${OUT_JAR}" + COMMAND ${CMAKE_COMMAND} -E rm -rf "${classes_path}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}" + COMMAND ${Java_JAVAC_EXECUTABLE} + -source 1.8 -target 1.8 + -bootclasspath "$" + "${JAVA_PACKAGE_DIR}/TomatoActivity.java" + $ + -cp "$:${SDL_ANDROID_PLATFORM_ANDROID_JAR}" + -d "${classes_path}" + COMMAND ${Java_JAR_EXECUTABLE} cf "${OUT_JAR}" -C "${classes_path}" . + DEPENDS $ "$" + ) + add_custom_target(tomato-jar DEPENDS "${OUT_JAR}") + add_dependencies(tomato-jar SDL3::Jar) # HACK: somehow their jar is not registered as an output + set_property(TARGET tomato-jar PROPERTY OUTPUT "${OUT_JAR}") + + set(dexworkdir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/tomato-dex.dir") + # Some CMake versions have a slow `cmake -E make_directory` implementation + if(NOT IS_DIRECTORY "${dexworkdir}") + execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${dexworkdir}") + endif() + set(classes_dex_base_name "classes.dex") + set(classes_dex "${dexworkdir}/${classes_dex_base_name}") + add_custom_command( + OUTPUT "${classes_dex}" + COMMAND SdlAndroid::d8 + $ + $ + --lib "${SDL_ANDROID_PLATFORM_ANDROID_JAR}" + --output "${dexworkdir}" + DEPENDS $ $ + ) + add_custom_target(tomato-dex DEPENDS "${classes_dex}") + set_property(TARGET tomato-dex PROPERTY OUTPUT "${classes_dex}") + set_property(TARGET tomato-dex PROPERTY OUTPUT_BASE_NAME "${classes_dex_base_name}") + + # file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt) + + sdl_add_to_apk_unaligned(tomato-unaligned-apk + APK_IN tomato-apk-linked + OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/intermediates" + #ASSETS ${RESOURCE_FILES} + #NATIVE_LIBS SDL3::SDL3-shared tomato + NATIVE_LIBS tomato + DEX tomato-dex + ) + + sdl_apk_align(tomato-aligned-apk tomato-unaligned-apk + OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/intermediates" + ) + sdl_apk_sign(tomato-apk tomato-aligned-apk + KEYSTORE tomato-debug-keystore + ) +else() + message("EE SdlAndroid module not found") +endif() +