Skip to content

Commit

Permalink
Merge pull request #26 from rokuz/optimize-android-builds
Browse files Browse the repository at this point in the history
Optimize Android builds
  • Loading branch information
corporateshark authored Feb 18, 2024
2 parents de5eb82 + b374b32 commit 798d884
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
28 changes: 19 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions android/app/build.gradle.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
Expand Down
21 changes: 12 additions & 9 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down

0 comments on commit 798d884

Please sign in to comment.