From b374b32419d5cd18a8d5be53099466870c9ec0f5 Mon Sep 17 00:00:00 2001 From: rokuz Date: Sun, 18 Feb 2024 11:25:46 +0000 Subject: [PATCH] Optimize Android builds --- CMakeLists.txt | 28 +++++++++++++++++++--------- android/app/build.gradle.in | 3 +++ samples/CMakeLists.txt | 21 ++++++++++++--------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c3d88340b..10d420b067 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,17 +12,20 @@ project("LVK" CXX C) set_property(GLOBAL PROPERTY USE_FOLDERS ON) # cmake-format: off -option(LVK_CUSTOM_MOLTENVK_PATH "Path to custom MoltenVK" "") -option(LVK_DEPLOY_DEPS "Deploy dependencies via CMake" ON) -option(LVK_WITH_GLFW "Enable GLFW" ON) -option(LVK_WITH_SAMPLES "Enable sample demo apps" ON) -option(LVK_WITH_SAMPLES_ANDROID "Generate Android projects for demo apps" OFF) -option(LVK_WITH_TRACY "Enable Tracy profiler" ON) -option(LVK_WITH_WAYLAND "Enable Wayland" OFF) -option(LVK_WITH_IMPLOT "Enable ImPlot" ON) -option(LVK_WITH_OPENXR "Enable OpenXR" OFF) +option(LVK_DEPLOY_DEPS "Deploy dependencies via CMake" ON) +option(LVK_WITH_GLFW "Enable GLFW" ON) +option(LVK_WITH_SAMPLES "Enable sample demo apps" ON) +option(LVK_WITH_SAMPLES_ANDROID "Generate Android projects for demo apps" OFF) +option(LVK_WITH_TRACY "Enable Tracy profiler" ON) +option(LVK_WITH_WAYLAND "Enable Wayland" OFF) +option(LVK_WITH_IMPLOT "Enable ImPlot" ON) +option(LVK_WITH_OPENXR "Enable OpenXR" OFF) +option(LVK_WITH_ANDROID_VALIDATION "Enable validation layers on Android" ON) cmake_dependent_option(LVK_WITH_VULKAN_PORTABILITY "Enable portability extension" ON "APPLE" OFF) + +set(LVK_ANDROID_ABI "\'arm64-v8a\'" CACHE STRING "Enabled ABI on Android") +set(LVK_CUSTOM_MOLTENVK_PATH "" CACHE STRING "Path to custom MoltenVK") # cmake-format: on if(LVK_WITH_SAMPLES AND NOT LVK_WITH_GLFW) @@ -81,6 +84,13 @@ message(STATUS "LVK_WITH_IMPLOT = ${LVK_WITH_IMPLOT}") message(STATUS "LVK_WITH_OPENXR = ${LVK_WITH_OPENXR}") # cmake-format: on +# cmake-format: off +if(LVK_WITH_SAMPLES_ANDROID) + message(STATUS "LVK_ANDROID_ABI = ${LVK_ANDROID_ABI}") + message(STATUS "LVK_WITH_ANDROID_VALIDATION = ${LVK_WITH_ANDROID_VALIDATION}") +endif() +# cmake-format: on + if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug") endif() diff --git a/android/app/build.gradle.in b/android/app/build.gradle.in index 1e46972bdf..8f563ed0fd 100644 --- a/android/app/build.gradle.in +++ b/android/app/build.gradle.in @@ -12,6 +12,9 @@ android { targetSdk 34 versionCode 1 versionName "1.0" + ndk { + abiFilters @ANDROID_ABI_FILTERS@ + } externalNativeBuild { cmake { targets "lvk_android_native_@APP_NAME@" diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 60f5b1416c..9c75199c51 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -57,6 +57,7 @@ macro(ADD_DEMO app) DESTINATION "${CMAKE_BINARY_DIR}/android/${app}/gradle/wrapper") set(APP_NAME ${app}) + set(ANDROID_ABI_FILTERS ${LVK_ANDROID_ABI}) configure_file("${LVK_ROOT_DIR}/android/settings.gradle.in" "${CMAKE_BINARY_DIR}/android/${app}/settings.gradle") configure_file("${LVK_ROOT_DIR}/android/app/build.gradle.in" @@ -65,15 +66,17 @@ macro(ADD_DEMO app) "${CMAKE_BINARY_DIR}/android/${app}/app/src/main/AndroidManifest.xml") configure_file("${LVK_ROOT_DIR}/android/app/MainActivity.java.in" "${CMAKE_BINARY_DIR}/android/${app}/app/src/main/java/org/lvk/samples/MainActivity.java") - - file(COPY "${LVK_ROOT_DIR}/third-party/deps/src/android-validation-layers/arm64-v8a/libVkLayer_khronos_validation.so" - DESTINATION "${CMAKE_BINARY_DIR}/android/${app}/app/src/main/jniLibs/arm64-v8a") - file(COPY "${LVK_ROOT_DIR}/third-party/deps/src/android-validation-layers/armeabi-v7a/libVkLayer_khronos_validation.so" - DESTINATION "${CMAKE_BINARY_DIR}/android/${app}/app/src/main/jniLibs/armeabi-v7a") - file(COPY "${LVK_ROOT_DIR}/third-party/deps/src/android-validation-layers/x86/libVkLayer_khronos_validation.so" - DESTINATION "${CMAKE_BINARY_DIR}/android/${app}/app/src/main/jniLibs/x86") - file(COPY "${LVK_ROOT_DIR}/third-party/deps/src/android-validation-layers/x86_64/libVkLayer_khronos_validation.so" - DESTINATION "${CMAKE_BINARY_DIR}/android/${app}/app/src/main/jniLibs/x86_64") + + if(LVK_WITH_ANDROID_VALIDATION) + list(APPEND abdroid_abi arm64-v8a armeabi-v7a x86 x86_64) + foreach(abi ${abdroid_abi}) + string(FIND ${LVK_ANDROID_ABI} "${abi}" abi_substr_index) + if(abi_substr_index GREATER -1) + file(COPY "${LVK_ROOT_DIR}/third-party/deps/src/android-validation-layers/${abi}/libVkLayer_khronos_validation.so" + DESTINATION "${CMAKE_BINARY_DIR}/android/${app}/app/src/main/jniLibs/${abi}") + endif() + endforeach() + endif() endif() if(ANDROID)