mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-20 22:21:15 +00:00
Wrap gradle under cmake & build SDL3.aar
run cmake with -DANDROID_NDK_PATH=/path/to/ndk to generate the .aar & run the gradle build if using Android Studio you will have to run the aar script manually(or do the cmake cmd) then put the normal cmake args inside '-PcmakeArgs="-DCMAKE_BUILD_TYPE=Release ...."' at `Settings > Build, Execution, Deployment > Gradle-Android Compiler > Command-line Options` Check CMakeLists.txt Android build block for more info
This commit is contained in:
parent
40e3193213
commit
0836f5fd35
@ -55,6 +55,7 @@ cmake_dependent_option(ISLE_COMPILE_SHADERS "Compile shaders" ON "SDL_SHADERCROS
|
|||||||
option(CMAKE_POSITION_INDEPENDENT_CODE "Build with -fPIC" ON)
|
option(CMAKE_POSITION_INDEPENDENT_CODE "Build with -fPIC" ON)
|
||||||
option(ENABLE_CLANG_TIDY "Enable clang-tidy")
|
option(ENABLE_CLANG_TIDY "Enable clang-tidy")
|
||||||
option(DOWNLOAD_DEPENDENCIES "Download dependencies" ON)
|
option(DOWNLOAD_DEPENDENCIES "Download dependencies" ON)
|
||||||
|
set(ANDROID_NDK_PATH "" CACHE PATH "Path to Android NDK")
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" CACHE PATH "Directory where to put executables and dll")
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" CACHE PATH "Directory where to put executables and dll")
|
||||||
set(ISLE_EMSCRIPTEN_HOST "" CACHE STRING "Host URL for Emscripten streaming (e.g., https://test.com)")
|
set(ISLE_EMSCRIPTEN_HOST "" CACHE STRING "Host URL for Emscripten streaming (e.g., https://test.com)")
|
||||||
cmake_dependent_option(BUILD_SHARED_LIBS "Build lego1 as a shared library" ON "NOT EMSCRIPTEN" OFF)
|
cmake_dependent_option(BUILD_SHARED_LIBS "Build lego1 as a shared library" ON "NOT EMSCRIPTEN" OFF)
|
||||||
@ -74,47 +75,22 @@ if (DOWNLOAD_DEPENDENCIES)
|
|||||||
message(STATUS "Fetching SDL3 and iniparser. This might take a while...")
|
message(STATUS "Fetching SDL3 and iniparser. This might take a while...")
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
# FIXME: properly build and source the .aar
|
# FIXME: properly build and source the .aar
|
||||||
if (NOT ANDROID)
|
if (WINDOWS_STORE)
|
||||||
if (WINDOWS_STORE)
|
FetchContent_Declare(
|
||||||
FetchContent_Declare(
|
SDL3
|
||||||
SDL3
|
GIT_REPOSITORY "https://github.com/Helloyunho/SDL3-uwp.git"
|
||||||
GIT_REPOSITORY "https://github.com/Helloyunho/SDL3-uwp.git"
|
GIT_TAG "main"
|
||||||
GIT_TAG "main"
|
EXCLUDE_FROM_ALL
|
||||||
EXCLUDE_FROM_ALL
|
)
|
||||||
)
|
|
||||||
else()
|
|
||||||
FetchContent_Declare(
|
|
||||||
SDL3
|
|
||||||
GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git"
|
|
||||||
GIT_TAG "main"
|
|
||||||
EXCLUDE_FROM_ALL
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
FetchContent_MakeAvailable(SDL3)
|
|
||||||
else()
|
else()
|
||||||
find_package(SDL3 CONFIG REQUIRED)
|
FetchContent_Declare(
|
||||||
|
SDL3
|
||||||
|
GIT_REPOSITORY "https://github.com/libsdl-org/SDL.git"
|
||||||
|
GIT_TAG "main"
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
FetchContent_MakeAvailable(SDL3)
|
||||||
# if(ANDROID)
|
|
||||||
# FetchContent_GetProperties(SDL3)
|
|
||||||
# set(SDL3_ANDROID_DIR "${sdl3_SOURCE_DIR}/android-project")
|
|
||||||
#
|
|
||||||
# add_custom_command(
|
|
||||||
# OUTPUT ${SDL3_ANDROID_DIR}/SDL/build/outputs/aar/SDL-release.aar
|
|
||||||
# COMMAND ${CMAKE_COMMAND} -E echo "Building SDL3.aar via Gradle..."
|
|
||||||
# COMMAND ./gradlew :SDL:assembleRelease
|
|
||||||
# WORKING_DIRECTORY ${SDL3_ANDROID_DIR}
|
|
||||||
# DEPENDS ${SDL3_ANDROID_DIR}/SDL/build.gradle
|
|
||||||
# COMMENT "Generating SDL3.aar from SDL3 android-project"
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# add_custom_target(build_sdl3_aar ALL
|
|
||||||
# DEPENDS ${SDL3_ANDROID_DIR}/SDL/build/outputs/aar/SDL-release.aar
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# # Make your native targets depend on the aar build, e.g.
|
|
||||||
# # add_dependencies(your_native_target build_sdl3_aar)
|
|
||||||
# endif()
|
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
iniparser
|
iniparser
|
||||||
@ -132,12 +108,49 @@ else()
|
|||||||
# find_package looks for already-installed system packages.
|
# find_package looks for already-installed system packages.
|
||||||
# Configure with `-DCMAKE_PREFIX_PATH="/path/to/package1;/path/to/package2"`
|
# Configure with `-DCMAKE_PREFIX_PATH="/path/to/package1;/path/to/package2"`
|
||||||
# to add search paths.
|
# to add search paths.
|
||||||
|
if (ANDROID)
|
||||||
|
message(STATUS "Please place the version-appropriate SDL3.aar in android-project/app/libs")
|
||||||
|
endif()
|
||||||
find_package(SDL3 CONFIG REQUIRED)
|
find_package(SDL3 CONFIG REQUIRED)
|
||||||
|
|
||||||
find_package(iniparser REQUIRED CONFIG COMPONENTS shared)
|
find_package(iniparser REQUIRED CONFIG COMPONENTS shared)
|
||||||
target_link_libraries(Isle::iniparser INTERFACE iniparser-shared)
|
target_link_libraries(Isle::iniparser INTERFACE iniparser-shared)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Effectively use as a gate for running the Android build
|
||||||
|
if (ANDROID_NDK_PATH)
|
||||||
|
|
||||||
|
FetchContent_GetProperties(SDL3)
|
||||||
|
|
||||||
|
set(SDL_ANDROID_ARCHIVE "${CMAKE_SOURCE_DIR}/android-project/app/libs/SDL3.aar")
|
||||||
|
add_custom_command(OUTPUT "${SDL_ANDROID_ARCHIVE}"
|
||||||
|
COMMAND ${Python3_EXECUTABLE} "${SDL3_SOURCE_DIR}/build-scripts/build-release.py"
|
||||||
|
--actions android
|
||||||
|
--fast
|
||||||
|
--android-ndk-home=${ANDROID_NDK_PATH}
|
||||||
|
--force
|
||||||
|
--root="${SDL3_SOURCE_DIR}"
|
||||||
|
COMMAND sh -c "cp ${sdl3_SOURCE_DIR}/build-android/SDL3-*.aar ${SDL_ANDROID_ARCHIVE}"
|
||||||
|
COMMENT "Generating SDL3.aar for android-project"
|
||||||
|
)
|
||||||
|
|
||||||
|
set(GRADLEW "${CMAKE_SOURCE_DIR}/android-project/gradlew")
|
||||||
|
if(CMAKE_BUILD_TYPE MATCHES "^Rel")
|
||||||
|
set(GRADLE_TASK "assembleRelease")
|
||||||
|
else()
|
||||||
|
set(GRADLE_TASK "assembleDebug")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_custom_target(ANDROID_GRADLE_BUILD ALL
|
||||||
|
DEPENDS "${SDL_ANDROID_ARCHIVE}"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/android-project"
|
||||||
|
COMMAND "${GRADLEW}" -i ${GRADLE_TASK} -PcmakeArgs=" -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DISLE_USE_DX5=${ISLE_USE_DX5} -DISLE_BUILD_CONFIG=${ISLE_BUILD_CONFIG} -DENABLE_CLANG_TIDY=${ENABLE_CLANG_TIDY} -DISLE_WERROR=${ISLE_WERROR} -DISLE_DEBUG=${ISLE_DEBUG} -Werror=dev"
|
||||||
|
COMMENT "Building Android APK with Gradle"
|
||||||
|
)
|
||||||
|
message(STATUS "SDL AAR")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
if (ENABLE_CLANG_TIDY)
|
if (ENABLE_CLANG_TIDY)
|
||||||
find_program(CLANG_TIDY_BIN NAMES "clang-tidy" ENV "LLVM_ROOT" REQUIRED)
|
find_program(CLANG_TIDY_BIN NAMES "clang-tidy" ENV "LLVM_ROOT" REQUIRED)
|
||||||
|
|||||||
@ -15,7 +15,12 @@ android {
|
|||||||
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
arguments '-DANDROID_STL=c++_shared', '-DCMAKE_BUILD_TYPE=Release', '-DISLE_USE_DX5=false', '-DISLE_BUILD_CONFIG=false', '-DENABLE_CLANG_TIDY=false', '-DISLE_WERROR=true', '-DISLE_DEBUG=false', '-Werror=dev', '-DCMAKE_MESSAGE_LOG_LEVEL=STATUS'
|
arguments '-DANDROID_STL=c++_shared'
|
||||||
|
if (project.hasProperty('cmakeArgs')) {
|
||||||
|
project.cmakeArgs.split(" ").each {arg -> arguments arg}
|
||||||
|
}
|
||||||
|
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
||||||
|
// abiFilters 'x86_64', 'arm64-v8a'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,9 @@
|
|||||||
android:name="org.legoisland.isle.IsleActivity"
|
android:name="org.legoisland.isle.IsleActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
|
android:configChanges="layoutDirection|locale|orientation|uiMode|screenLayout|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
|
||||||
android:preferMinimalPostProcessing="true">
|
android:preferMinimalPostProcessing="true"
|
||||||
|
android:screenOrientation="landscape"
|
||||||
|
android:launchMode="singleInstance">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user