Skip to content

Commit 010107a

Browse files
committed
More movements
1 parent aed2754 commit 010107a

File tree

5 files changed

+99
-113
lines changed

5 files changed

+99
-113
lines changed
Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ==============================================================================
22
#
33
# This file is part of the YUP library.
4-
# Copyright (c) 2025 - [email protected]
4+
# Copyright (c) 2024 - [email protected]
55
#
66
# YUP is an open source library subject to open-source licensing.
77
#
@@ -19,13 +19,93 @@
1919

2020
include_guard (DIRECTORY)
2121

22-
include (${CMAKE_CURRENT_LIST_DIR}/yup_utilities.cmake)
22+
include (${CMAKE_CURRENT_LIST_DIR}/../yup_utilities.cmake)
23+
24+
#==============================================================================
25+
26+
function (_yup_android_prepare_gradle)
27+
set (options "")
28+
set (one_value_args
29+
MIN_SDK_VERSION COMPILE_SDK_VERSION TARGET_SDK_VERSION
30+
TARGET_NAME TARGET_ICON ABI TOOLCHAIN PLATFORM STL CPP_VERSION CMAKE_VERSION
31+
APPLICATION_ID APPLICATION_NAMESPACE APPLICATION_CMAKELISTS_PATH APPLICATION_VERSION)
32+
set (multi_value_args "")
33+
34+
cmake_parse_arguments (YUP_ANDROID "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
35+
36+
# Prepare variables
37+
_yup_set_default (YUP_ANDROID_MIN_SDK_VERSION "21")
38+
_yup_set_default (YUP_ANDROID_COMPILE_SDK_VERSION "34")
39+
_yup_set_default (YUP_ANDROID_TARGET_SDK_VERSION "${YUP_ANDROID_COMPILE_SDK_VERSION}")
40+
_yup_set_default (YUP_ANDROID_TARGET_NAME "default_app")
41+
_yup_set_default (YUP_ANDROID_TOOLCHAIN "clang")
42+
_yup_set_default (YUP_ANDROID_PLATFORM "android-${YUP_ANDROID_MIN_SDK_VERSION}")
43+
_yup_set_default (YUP_ANDROID_STL "c++_shared")
44+
_yup_set_default (YUP_ANDROID_CPP_VERSION "20")
45+
_yup_set_default (YUP_ANDROID_APPLICATION_NAMESPACE "org.yup")
46+
_yup_set_default (YUP_ANDROID_APPLICATION_ID "org.yup.default_app")
47+
_yup_set_default (YUP_ANDROID_APPLICATION_VERSION "1.0")
48+
_yup_set_default (YUP_ANDROID_APPLICATION_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
49+
_yup_set_default (YUP_ANDROID_ABI "arm64-v8a")
50+
_yup_set_default (YUP_ANDROID_CMAKE_VERSION "${CMAKE_VERSION}")
51+
52+
_yup_join_list_with_separator ("${YUP_ANDROID_ABI}" "\n " "abiFilters += \"" "\"" YUP_ANDROID_ABI)
53+
_yup_version_string_to_version_code (${YUP_ANDROID_APPLICATION_VERSION} YUP_ANDROID_APPLICATION_VERSION_CODE)
54+
file (RELATIVE_PATH YUP_ANDROID_APPLICATION_PATH "${CMAKE_CURRENT_BINARY_DIR}/app" "${YUP_ANDROID_APPLICATION_PATH}")
55+
56+
# Prepare files
57+
set (BASE_FILES_PATH "${CMAKE_SOURCE_DIR}/cmake/platforms/android")
58+
configure_file (${BASE_FILES_PATH}/build.gradle.kts.in ${CMAKE_CURRENT_BINARY_DIR}/build.gradle.kts)
59+
configure_file (${BASE_FILES_PATH}/settings.gradle.kts.in ${CMAKE_CURRENT_BINARY_DIR}/settings.gradle.kts)
60+
configure_file (${BASE_FILES_PATH}/app/build.gradle.kts.in ${CMAKE_CURRENT_BINARY_DIR}/app/build.gradle.kts)
61+
configure_file (${BASE_FILES_PATH}/app/proguard-rules.pro.in ${CMAKE_CURRENT_BINARY_DIR}/app/proguard-rules.pro)
62+
configure_file (${BASE_FILES_PATH}/app/src/main/java/org/yup/YupActivity.java.in ${CMAKE_CURRENT_BINARY_DIR}/app/src/main/java/org/yup/YupActivity.java)
63+
configure_file (${BASE_FILES_PATH}/app/src/main/AndroidManifest.xml.in ${CMAKE_CURRENT_BINARY_DIR}/app/src/main/AndroidManifest.xml)
64+
configure_file (${BASE_FILES_PATH}/gradle/libs.versions.toml.in ${CMAKE_CURRENT_BINARY_DIR}/gradle/libs.versions.toml COPYONLY)
65+
configure_file (${BASE_FILES_PATH}/gradle/wrapper/gradle-wrapper.jar.in ${CMAKE_CURRENT_BINARY_DIR}/gradle/wrapper/gradle-wrapper.jar COPYONLY)
66+
configure_file (${BASE_FILES_PATH}/gradle/wrapper/gradle-wrapper.properties.in ${CMAKE_CURRENT_BINARY_DIR}/gradle/wrapper/gradle-wrapper.properties COPYONLY)
67+
configure_file (${BASE_FILES_PATH}/gradlew.in ${CMAKE_CURRENT_BINARY_DIR}/gradlew COPYONLY)
68+
configure_file (${BASE_FILES_PATH}/gradlew.bat.in ${CMAKE_CURRENT_BINARY_DIR}/gradlew.bat COPYONLY)
69+
configure_file (${BASE_FILES_PATH}/gradle.properties.in ${CMAKE_CURRENT_BINARY_DIR}/gradle.properties COPYONLY)
70+
71+
# Copy icons
72+
if (YUP_ANDROID_TARGET_ICON)
73+
set (base_icon_path "${CMAKE_CURRENT_BINARY_DIR}/app/src/main/res")
74+
75+
find_program (sips_program sips)
76+
if (sips_program)
77+
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-ldpi)
78+
_yup_execute_process_or_fail (${sips_program} -z 36 36 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-ldpi/ic_launcher.png")
79+
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-mdpi)
80+
_yup_execute_process_or_fail (${sips_program} -z 48 48 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-mdpi/ic_launcher.png")
81+
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-hdpi)
82+
_yup_execute_process_or_fail (${sips_program} -z 72 72 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-hdpi/ic_launcher.png")
83+
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-xhdpi)
84+
_yup_execute_process_or_fail (${sips_program} -z 96 96 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-xhdpi/ic_launcher.png")
85+
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-xxhdpi)
86+
_yup_execute_process_or_fail (${sips_program} -z 144 144 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-xxhdpi/ic_launcher.png")
87+
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-xxxhdpi)
88+
_yup_execute_process_or_fail (${sips_program} -z 192 192 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-xxxhdpi/ic_launcher.png")
89+
else()
90+
configure_file (${YUP_ANDROID_TARGET_ICON} ${base_icon_path}/mipmap-xxxhdpi/ic_launcher.png COPYONLY)
91+
endif()
92+
endif()
93+
94+
endfunction()
95+
96+
#==============================================================================
97+
98+
function (_yup_android_copy_sdl2_activity)
99+
set (JAVA_SOURCE_RELATIVE_FOLDER app/src/main/java)
100+
set (SOURCE_FOLDER ${CMAKE_BINARY_DIR}/externals/SDL2/android-project/${JAVA_SOURCE_RELATIVE_FOLDER}/org)
101+
file (COPY ${SOURCE_FOLDER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${JAVA_SOURCE_RELATIVE_FOLDER})
102+
endfunction()
23103

24104
#==============================================================================
25105

26106
# Function to add Java bytecode compilation to a YUP module
27-
function (_yup_module_add_java_support module_name)
28-
_yup_message (STATUS "_yup_module_add_java_support called for module: ${module_name}")
107+
function (_yup_android_module_add_java_support module_name)
108+
_yup_message (STATUS "_yup_android_module_add_java_support called for module: ${module_name}")
29109

30110
if (NOT YUP_PLATFORM_ANDROID)
31111
_yup_message (STATUS "Not Android platform, skipping Java support for ${module_name}")
@@ -67,7 +147,7 @@ function (_yup_module_add_java_support module_name)
67147
get_filename_component (class_name "${java_source}" NAME_WE)
68148

69149
# Generate individual class bytecode
70-
_yup_add_single_java_class (
150+
_yup_android_add_single_java_class (
71151
MODULE_NAME ${module_name}
72152
CLASS_NAME ${class_name}
73153
JAVA_SOURCE "${java_source}"
@@ -89,8 +169,8 @@ endfunction()
89169
#==============================================================================
90170

91171
# Function to compile a single Java class to DEX bytecode
92-
function (_yup_add_single_java_class)
93-
_yup_message (STATUS "_yup_add_single_java_class called")
172+
function (_yup_android_add_single_java_class)
173+
_yup_message (STATUS "_yup_android_add_single_java_class called")
94174

95175
cmake_parse_arguments (
96176
JAVA_ARG
@@ -112,7 +192,7 @@ function (_yup_add_single_java_class)
112192
endif()
113193

114194
if (NOT JAVA_ARG_JAVA_SOURCE)
115-
_yup_message (WARNING "_yup_add_single_java_class: No Java source specified for ${JAVA_ARG_CLASS_NAME}")
195+
_yup_message (WARNING "_yup_android_add_single_java_class: No Java source specified for ${JAVA_ARG_CLASS_NAME}")
116196
return()
117197
endif()
118198

cmake/yup.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ endfunction()
8585

8686
#==============================================================================
8787

88+
# Initialize platform settings
89+
_yup_setup_platform()
90+
91+
#==============================================================================
92+
93+
# Common includes
8894
include (${CMAKE_CURRENT_LIST_DIR}/yup_utilities.cmake)
89-
include (${CMAKE_CURRENT_LIST_DIR}/yup_platforms.cmake)
9095
include (${CMAKE_CURRENT_LIST_DIR}/yup_dependencies.cmake)
9196
include (${CMAKE_CURRENT_LIST_DIR}/yup_modules.cmake)
9297
include (${CMAKE_CURRENT_LIST_DIR}/yup_standalone.cmake)
@@ -95,6 +100,5 @@ include (${CMAKE_CURRENT_LIST_DIR}/yup_embed_binary.cmake)
95100
include (${CMAKE_CURRENT_LIST_DIR}/yup_android_java.cmake)
96101
include (${CMAKE_CURRENT_LIST_DIR}/yup_python.cmake)
97102

98-
#==============================================================================
99-
100-
_yup_setup_platform()
103+
# Platform specific includes
104+
include ("${CMAKE_CURRENT_LIST_DIR}/platforms/yup_${YUP_PLATFORM}.cmake")

cmake/yup_modules.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ function (yup_add_module module_path modules_definitions module_group)
586586

587587
# ==== Add Java support for Android if available (after target properties are set)
588588
if (YUP_PLATFORM_ANDROID AND YUP_BUILD_JAVA_SUPPORT)
589-
_yup_module_add_java_support (${module_name})
589+
_yup_android_module_add_java_support (${module_name})
590590
endif()
591591

592592
endfunction()

cmake/yup_platforms.cmake

Lines changed: 0 additions & 98 deletions
This file was deleted.

cmake/yup_standalone.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function (yup_standalone_app)
6262
# ==== Setup Android platform, build gradle stage
6363
if (YUP_TARGET_ANDROID)
6464
_yup_message (STATUS "${target_name} - Creating java gradle project")
65-
_yup_prepare_gradle_android(
65+
_yup_android_prepare_gradle(
6666
TARGET_NAME ${target_name}
6767
TARGET_ICON ${target_icon}
6868
APPLICATION_ID ${target_app_identifier}
@@ -71,7 +71,7 @@ function (yup_standalone_app)
7171

7272
_yup_message (STATUS "${target_name} - Copying SDL2 java activity to application")
7373
_yup_fetch_sdl2()
74-
_yup_copy_sdl2_activity_android()
74+
_yup_android_copy_sdl2_activity()
7575

7676
return()
7777
endif()

0 commit comments

Comments
 (0)