Skip to content

Commit

Permalink
Moved from GLFW to SDL2 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki authored Dec 14, 2024
1 parent bcf087f commit df37d6e
Show file tree
Hide file tree
Showing 56 changed files with 1,148 additions and 734 deletions.
6 changes: 6 additions & 0 deletions cmake/platforms/android/app/build.gradle.kts.in
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ dependencies {
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)*/
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
20 changes: 9 additions & 11 deletions cmake/platforms/android/app/src/main/AndroidManifest.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,29 @@
<!--
android:dataExtractionRules="@xml/data_extraction_rules"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.Application"
android:fullBackupContent="@xml/backup_rules"
android:screenOrientation="portrait"
-->

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:hasCode="true"
android:label="@YUP_ANDROID_TARGET_NAME@"
android:extractNativeLibs="true"
android:isGame="true">
android:icon="@mipmap/ic_launcher"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleInstance"
android:hardwareAccelerated="true"
android:configChanges="keyboard|keyboardHidden|orientation|density|screenSize|screenLayout">
<activity
android:name="android.app.NativeActivity"
android:name="org.yup.YupActivity"
android:exported="true">
<meta-data
android:name="android.app.lib_name"
android:value="@YUP_ANDROID_TARGET_NAME@" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.yup;

import org.libsdl.app.SDLActivity;

public class YupActivity extends SDLActivity
{
/**
* This method is called by SDL before loading the native shared libraries.
* It can be overridden to provide names of shared libraries to be loaded.
* The default implementation returns the defaults. It never returns null.
* An array returned by a new implementation must at least contain "SDL2".
* Also keep in mind that the order the libraries are loaded may matter.
*
* @return names of shared libraries to be loaded (e.g. "SDL2", "main").
*/
@Override
protected String[] getLibraries()
{
return new String[]
{
"@YUP_ANDROID_TARGET_NAME@"
};
}
}
2 changes: 1 addition & 1 deletion cmake/yup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function (_yup_setup_platform)
if (CMAKE_SYSTEM_NAME MATCHES "WindowsStore")
set (yup_platform "uwp")
else()
set (yup_platform "win32")
set (yup_platform "windows")
endif()

else()
Expand Down
4 changes: 2 additions & 2 deletions cmake/yup_audio_plugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function (yup_audio_plugin)
include (FetchContent)

if (NOT "${yup_platform}" MATCHES "^(emscripten)$")
_yup_fetch_glfw3()
list (APPEND additional_libraries glfw)
_yup_fetch_sdl2()
list (APPEND additional_libraries sdl2::sdl2)

# ==== Fetch plugins SDKS
if (YUP_ARG_PLUGIN_CREATE_CLAP)
Expand Down
38 changes: 26 additions & 12 deletions cmake/yup_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,44 @@

#==============================================================================

function (_yup_fetch_glfw3)
FetchContent_Declare (glfw
GIT_REPOSITORY https://github.com/kunitoki/glfw.git
GIT_TAG dev/android_support
function (_yup_fetch_sdl2)
if (TARGET sdl2::sdl2)
return()
endif()

FetchContent_Declare (SDL2
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG release-2.30.10
SOURCE_DIR ${CMAKE_BINARY_DIR}/externals/SDL2
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)

set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set (GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
set (GLFW_INSTALL OFF CACHE STRING "" FORCE)
set (BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set (SDL_SHARED OFF CACHE BOOL "" FORCE)
set (SDL_STATIC ON CACHE BOOL "" FORCE)
set (SDL_STATIC_PIC ON CACHE BOOL "" FORCE)
set (SDL_AUDIO_ENABLED_BY_DEFAULT OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable (SDL2)

FetchContent_MakeAvailable (glfw)
set_target_properties (SDL2-static PROPERTIES
POSITION_INDEPENDENT_CODE ON
FOLDER "Thirdparty")

set_target_properties (glfw PROPERTIES FOLDER "Thirdparty")
add_library (sdl2::sdl2 ALIAS SDL2-static)
endfunction()

#==============================================================================

function (_yup_fetch_perfetto)
if (TARGET perfetto::perfetto)
return()
endif()

FetchContent_Declare (Perfetto
GIT_REPOSITORY https://android.googlesource.com/platform/external/perfetto
GIT_TAG v42.0
SOURCE_DIR ${CMAKE_BINARY_DIR}/externals/Perfetto
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)

Expand All @@ -59,7 +73,7 @@ function (_yup_fetch_perfetto)
"$<BUILD_INTERFACE:${perfetto_SOURCE_DIR}/sdk>")

set_target_properties (perfetto PROPERTIES
POSITION_INDEPENDENT_CODE TRUE
POSITION_INDEPENDENT_CODE ON
FOLDER "Thirdparty")

if (WIN32)
Expand Down
3 changes: 2 additions & 1 deletion cmake/yup_embed_binary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function (yup_add_embedded_binary_resources library_name)
target_include_directories (${library_name} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
target_compile_features (${library_name} PUBLIC cxx_std_17)

set_target_properties (${library_name} PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties (${library_name} PROPERTIES
POSITION_INDEPENDENT_CODE ON)

file (WRITE "${binary_header_path}"
"#pragma once\n"
Expand Down
42 changes: 25 additions & 17 deletions cmake/yup_modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ function (_yup_module_collect_sources folder output_variable)
foreach (extension ${source_extensions})
file (GLOB found_source_files "${base_path}*${extension}")

if (NOT "${yup_platform}" MATCHES "^(win32|uwp)$")
list (FILTER found_source_files EXCLUDE REGEX "${base_path}*_windows${extension}")
if (NOT "${yup_platform}" MATCHES "^(windows|uwp)$")
list (FILTER found_source_files EXCLUDE REGEX "${base_path}*_microsoft${extension}")
endif()

if (NOT "${yup_platform}" MATCHES "^(win32)$")
list (FILTER found_source_files EXCLUDE REGEX "${base_path}*_win32${extension}")
if (NOT "${yup_platform}" MATCHES "^(windows)$")
list (FILTER found_source_files EXCLUDE REGEX "${base_path}*_windows${extension}")
endif()

if (NOT "${yup_platform}" MATCHES "^(uwp)$")
Expand Down Expand Up @@ -115,9 +115,7 @@ function (_yup_module_collect_sources folder output_variable)
list (FILTER found_source_files EXCLUDE REGEX "${base_path}*_posix${extension}")
endif()

foreach (source ${found_source_files})
list (APPEND all_module_sources ${source})
endforeach()
list (APPEND all_module_sources ${found_source_files})
endforeach()

set (module_sources "")
Expand Down Expand Up @@ -173,7 +171,7 @@ function (_yup_module_setup_target module_name
module_frameworks
module_dependencies
module_arc_enabled)
if ("${yup_platform}" MATCHES "^(win32|uwp)$")
if ("${yup_platform}" MATCHES "^(windows|uwp)$")
list (APPEND module_defines NOMINMAX=1 WIN32_LEAN_AND_MEAN=1)
endif()

Expand Down Expand Up @@ -221,7 +219,7 @@ endfunction()
#==============================================================================

function (_yup_module_setup_plugin_client_clap target_name plugin_client_target folder_name)
if (NOT "${yup_platform}" MATCHES "^(osx|linux|win32)$")
if (NOT "${yup_platform}" MATCHES "^(osx|linux|windows)$")
return()
endif()

Expand Down Expand Up @@ -345,13 +343,23 @@ function (yup_add_module module_path)

# ==== Setup Platform-Specific Configurations
if ("${yup_platform}" MATCHES "^(ios)$")
list (APPEND module_dependencies ${module_iosDeps})
list (APPEND module_defines ${module_iosDefines})
list (APPEND module_options ${module_iosOptions})
list (APPEND module_libs ${module_iosLibs})
_yup_resolve_variable_paths ("${module_iosSearchpaths}" module_iosSearchpaths)
list (APPEND module_searchpaths ${module_iosSearchpaths})
_yup_module_prepare_frameworks ("${module_iosFrameworks}" "${module_iosWeakFrameworks}" module_frameworks)
if (PLATFORM MATCHES "^(SIMULATOR.*)$")
list (APPEND module_dependencies ${module_iosSimDeps})
list (APPEND module_defines ${module_iosSimDefines})
list (APPEND module_options ${module_iosSimOptions})
list (APPEND module_libs ${module_iosSimLibs})
_yup_resolve_variable_paths ("${module_iosSimSearchpaths}" module_iosSimSearchpaths)
list (APPEND module_searchpaths ${module_iosSimSearchpaths})
_yup_module_prepare_frameworks ("${module_iosSimFrameworks}" "${module_iosSimWeakFrameworks}" module_frameworks)
else()
list (APPEND module_dependencies ${module_iosDeps})
list (APPEND module_defines ${module_iosDefines})
list (APPEND module_options ${module_iosOptions})
list (APPEND module_libs ${module_iosLibs})
_yup_resolve_variable_paths ("${module_iosSearchpaths}" module_iosSearchpaths)
list (APPEND module_searchpaths ${module_iosSearchpaths})
_yup_module_prepare_frameworks ("${module_iosFrameworks}" "${module_iosWeakFrameworks}" module_frameworks)
endif()

elseif ("${yup_platform}" MATCHES "^(osx)$")
list (APPEND module_dependencies ${module_osxDeps})
Expand Down Expand Up @@ -390,7 +398,7 @@ function (yup_add_module module_path)
_yup_resolve_variable_paths ("${module_androidSearchpaths}" module_androidSearchpaths)
list (APPEND module_searchpaths ${module_androidSearchpaths})

elseif ("${yup_platform}" MATCHES "^(win32|uwp)$")
elseif ("${yup_platform}" MATCHES "^(windows|uwp)$")
list (APPEND module_dependencies ${module_windowsDeps})
list (APPEND module_defines ${module_windowsDefines})
list (APPEND module_options ${module_windowsOptions})
Expand Down
37 changes: 34 additions & 3 deletions cmake/yup_platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function (_yup_prepare_gradle_android)
set (options "")
set (one_value_args
MIN_SDK_VERSION COMPILE_SDK_VERSION TARGET_SDK_VERSION
TARGET_NAME ABI TOOLCHAIN PLATFORM STL CPP_VERSION CMAKE_VERSION
TARGET_NAME TARGET_ICON ABI TOOLCHAIN PLATFORM STL CPP_VERSION CMAKE_VERSION
APPLICATION_ID APPLICATION_NAMESPACE APPLICATION_CMAKELISTS_PATH APPLICATION_VERSION)
set (multi_value_args "")

Expand All @@ -38,8 +38,8 @@ function (_yup_prepare_gradle_android)
_yup_set_default (YUP_ANDROID_PLATFORM "android-${YUP_ANDROID_MIN_SDK_VERSION}")
_yup_set_default (YUP_ANDROID_STL "c++_shared")
_yup_set_default (YUP_ANDROID_CPP_VERSION "17")
_yup_set_default (YUP_ANDROID_APPLICATION_ID "com.yup.default_app")
_yup_set_default (YUP_ANDROID_APPLICATION_NAMESPACE "${YUP_ANDROID_APPLICATION_ID}")
_yup_set_default (YUP_ANDROID_APPLICATION_NAMESPACE "org.yup")
_yup_set_default (YUP_ANDROID_APPLICATION_ID "org.yup.default_app")
_yup_set_default (YUP_ANDROID_APPLICATION_VERSION "1.0")
_yup_set_default (YUP_ANDROID_APPLICATION_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
_yup_set_default (YUP_ANDROID_ABI "arm64-v8a")
Expand All @@ -55,13 +55,44 @@ function (_yup_prepare_gradle_android)
configure_file (${BASE_FILES_PATH}/settings.gradle.kts.in ${CMAKE_CURRENT_BINARY_DIR}/settings.gradle.kts)
configure_file (${BASE_FILES_PATH}/app/build.gradle.kts.in ${CMAKE_CURRENT_BINARY_DIR}/app/build.gradle.kts)
configure_file (${BASE_FILES_PATH}/app/proguard-rules.pro.in ${CMAKE_CURRENT_BINARY_DIR}/app/proguard-rules.pro)
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)
configure_file (${BASE_FILES_PATH}/app/src/main/AndroidManifest.xml.in ${CMAKE_CURRENT_BINARY_DIR}/app/src/main/AndroidManifest.xml)
configure_file (${BASE_FILES_PATH}/gradle/libs.versions.toml.in ${CMAKE_CURRENT_BINARY_DIR}/gradle/libs.versions.toml COPYONLY)
configure_file (${BASE_FILES_PATH}/gradle/wrapper/gradle-wrapper.jar.in ${CMAKE_CURRENT_BINARY_DIR}/gradle/wrapper/gradle-wrapper.jar COPYONLY)
configure_file (${BASE_FILES_PATH}/gradle/wrapper/gradle-wrapper.properties.in ${CMAKE_CURRENT_BINARY_DIR}/gradle/wrapper/gradle-wrapper.properties COPYONLY)
configure_file (${BASE_FILES_PATH}/gradlew.in ${CMAKE_CURRENT_BINARY_DIR}/gradlew COPYONLY)
configure_file (${BASE_FILES_PATH}/gradlew.bat.in ${CMAKE_CURRENT_BINARY_DIR}/gradlew.bat COPYONLY)
configure_file (${BASE_FILES_PATH}/gradle.properties.in ${CMAKE_CURRENT_BINARY_DIR}/gradle.properties COPYONLY)

# Copy icons
if (YUP_ANDROID_TARGET_ICON)
set (base_icon_path "${CMAKE_CURRENT_BINARY_DIR}/app/src/main/res")

find_program (sips_program sips)
if (sips_program)
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-ldpi RESULT result)
_yup_execute_process_or_fail (${sips_program} -z 36 36 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-ldpi/ic_launcher.png")
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-mdpi RESULT result)
_yup_execute_process_or_fail (${sips_program} -z 48 48 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-mdpi/ic_launcher.png")
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-hdpi RESULT result)
_yup_execute_process_or_fail (${sips_program} -z 72 72 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-hdpi/ic_launcher.png")
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-xhdpi RESULT result)
_yup_execute_process_or_fail (${sips_program} -z 96 96 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-xhdpi/ic_launcher.png")
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-xxhdpi RESULT result)
_yup_execute_process_or_fail (${sips_program} -z 144 144 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-xxhdpi/ic_launcher.png")
file (MAKE_DIRECTORY ${base_icon_path}/mipmap-xxxhdpi RESULT result)
_yup_execute_process_or_fail (${sips_program} -z 192 192 "${YUP_ANDROID_TARGET_ICON}" --out "${base_icon_path}/mipmap-xxxhdpi/ic_launcher.png")
else()
configure_file (${YUP_ANDROID_TARGET_ICON} ${base_icon_path}/mipmap-xxxhdpi/ic_launcher.png COPYONLY)
endif()
endif()

endfunction()

#==============================================================================

function (_yup_copy_sdl2_activity_android)
set (JAVA_SOURCE_RELATIVE_FOLDER app/src/main/java)
set (SOURCE_FOLDER ${CMAKE_BINARY_DIR}/externals/SDL2/android-project/${JAVA_SOURCE_RELATIVE_FOLDER}/org)
file (COPY ${SOURCE_FOLDER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${JAVA_SOURCE_RELATIVE_FOLDER})
endfunction()
Loading

0 comments on commit df37d6e

Please sign in to comment.