Skip to content

Commit

Permalink
Make Luanti buildable for iOS (iPhoneSimulator).
Browse files Browse the repository at this point in the history
  • Loading branch information
sfence committed Nov 18, 2024
1 parent 11837d4 commit 55e95dd
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 16 deletions.
3 changes: 3 additions & 0 deletions cmake/Modules/FindZstd.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
mark_as_advanced(ZSTD_LIBRARY ZSTD_INCLUDE_DIR)

message(STATUS "ZSTD_LIBRARY: ${ZSTD_LIBRARY}")
message(STATUS "ZSTD_INCLUDE_DIR: ${ZSTD_INCLUDE_DIR}")

find_path(ZSTD_INCLUDE_DIR NAMES zstd.h)

find_library(ZSTD_LIBRARY NAMES zstd)
Expand Down
3 changes: 2 additions & 1 deletion irr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ We aim to support these platforms:
* Windows via MinGW
* Linux (GL or GLES)
* macOS
* iOS (GLES)
* Android

This doesn't mean other platforms don't work or won't be supported, if you find something that doesn't work contributions are welcome.
Expand All @@ -51,7 +52,7 @@ Driver (rows) vs Device (columns)

Notes:

* [1] `CIrrDeviceSDL`: supports Android, Linux, macOS, Windows
* [1] `CIrrDeviceSDL`: supports Android, Linux, macOS, iOS, Windows
* [2] `CIrrDeviceLinux`: supports Linux
* [3] `CIrrDeviceOSX`: supports macOS
* [4] `CIrrDeviceWin32`: supports Windows
Expand Down
29 changes: 24 additions & 5 deletions irr/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ else()
option(ENABLE_OPENGL "Enable OpenGL" TRUE)
endif()

if(APPLE)
if(APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
set(ENABLE_GLES2 FALSE)
set(ENABLE_WEBGL1 FALSE)
else()
Expand Down Expand Up @@ -271,7 +271,7 @@ endif()

if(ANDROID)
enable_language(C)
elseif(APPLE)
elseif(APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
find_library(COCOA_LIB Cocoa REQUIRED)
find_library(IOKIT_LIB IOKit REQUIRED)

Expand Down Expand Up @@ -356,14 +356,14 @@ endif()
if(ENABLE_OPENGL3)
set(IRRDRVROBJ
${IRRDRVROBJ}
OpenGL3/Driver.cpp
OpenGL3/DriverGL3.cpp
)
endif()

if(ENABLE_GLES2)
set(IRRDRVROBJ
${IRRDRVROBJ}
OpenGLES2/Driver.cpp
OpenGLES2/DriverGLES2.cpp
)
endif()

Expand Down Expand Up @@ -497,7 +497,6 @@ target_link_libraries(IrrlichtMt PRIVATE
${ZLIB_LIBRARY}
${JPEG_LIBRARY}
${PNG_LIBRARY}
"$<$<BOOL:${USE_SDL2}>:SDL2::SDL2>"

"$<$<BOOL:${OPENGL_DIRECT_LINK}>:${OPENGL_LIBRARIES}>"
${EGL_LIBRARY}
Expand All @@ -512,6 +511,26 @@ target_link_libraries(IrrlichtMt PRIVATE
"$<$<BOOL:${USE_X11}>:${X11_Xi_LIB}>"
)

if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
target_link_libraries(IrrlichtMt PRIVATE
"-framework UIKit"
"-framework Foundation"
"-framework CoreGraphics"
"-framework QuartzCore"
"-framework OpenGLES"
"-framework AudioToolbox"
"-framework AVFoundation"
"-framework CoreAudio"
"-framework CoreMotion"
SDL2::SDL2-static
SDL2::SDL2main
)
else()
target_link_libraries(IrrlichtMt PRIVATE
"$<$<BOOL:${USE_SDL2}>:SDL2::SDL2>"
)
endif()

if(WIN32)
target_compile_definitions(IrrlichtMt INTERFACE _IRR_WINDOWS_API_) # used in _IRR_DEBUG_BREAK_IF definition in a public header
endif()
Expand Down
5 changes: 5 additions & 0 deletions irr/src/OpenGL/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
#include <SDL_video.h>
#include <SDL_opengl.h>
#ifdef __IPHONEOS__
//#include <OpenGLES/ES3/gl.h>
//#include <OpenGLES/ES3/glext.h>
#include "vendor/gl.h"
#endif
#else
#include "vendor/gl.h"
#endif
Expand Down
4 changes: 2 additions & 2 deletions irr/src/OpenGL/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters &params
ContextManager->activateContext(ExposedData, false);
GL.LoadAllProcedures(ContextManager);
if (EnableErrorTest) {
GL.Enable(GL_DEBUG_OUTPUT);
GL.DebugMessageCallback(debugCb, this);
//GL.Enable(GL_DEBUG_OUTPUT);
//GL.DebugMessageCallback(debugCb, this);
}
initQuadsIndices();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h

#include "Driver.h"
#include "DriverGL3.h"
#include <cassert>
#include "mt_opengl.h"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h

#include "Driver.h"
#include "DriverGLES2.h"
#include <cassert>
#include <CColorConverter.h>

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/sha256/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@
#endif
#endif

#if defined(__APPLE__) && !defined(HAVE_ENDIAN_H)
#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define be16toh(x) OSSwapBigToHostInt16((x))
#define htobe16(x) OSSwapHostToBigInt16((x))
#define le32toh(x) OSSwapLittleToHostInt32((x))
#define be32toh(x) OSSwapBigToHostInt32((x))
#define htole32(x) OSSwapHostToLittleInt32(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#endif /* __APPLE__ && !HAVE_ENDIAN_H */
#endif /* __APPLE__ */

#if defined(_WIN32) && !defined(HAVE_ENDIAN_H)
#include <winsock2.h>
Expand Down
28 changes: 28 additions & 0 deletions misc/ios/Info.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>luanti</string>
<key>CFBundleIconFile</key>
<string>luanti-icon.icns</string>
<key>CFBundleName</key>
<string>@PROJECT_NAME_CAPITALIZED@</string>
<key>CFBundleDisplayName</key>
<string>@PROJECT_NAME_CAPITALIZED@</string>
<key>CFBundleIdentifier</key>
<string>org.luanti.luanti</string>
<key>CFBundleVersion</key>
<string>@VERSION_STRING@</string>
<key>CFBundleShortVersionString</key>
<string>@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>NSHighResolutionCapable</key>
<false/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
6 changes: 6 additions & 0 deletions misc/ios/entitlements/release.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
2 changes: 2 additions & 0 deletions misc/macos/Info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<string>org.luanti.luanti</string>
<key>CFBundleVersion</key>
<string>@VERSION_STRING@</string>
<key>CFBundleShortVersionString</key>
<string>@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>NSHighResolutionCapable</key>
Expand Down
17 changes: 13 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,17 @@ endif()

if(APPLE)
# Configure the Info.plist file
configure_file(
"${CMAKE_SOURCE_DIR}/misc/macos/Info.plist.in"
"${CMAKE_BINARY_DIR}/Info.plist"
)
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
configure_file(
"${CMAKE_SOURCE_DIR}/misc/macos/Info.plist.in"
"${CMAKE_BINARY_DIR}/Info.plist"
)
else()
configure_file(
"${CMAKE_SOURCE_DIR}/misc/ios/Info.plist.in"
"${CMAKE_BINARY_DIR}/Info.plist"
)
endif()
endif()

if(BUILD_CLIENT)
Expand Down Expand Up @@ -678,6 +685,8 @@ if(BUILD_CLIENT)
# on Android, Luanti depends on SDL2 directly
# on other platforms, only IrrlichtMt depends on SDL2
"$<$<PLATFORM_ID:Android>:${SDL2_LIBRARIES}>"
#"$<$<PLATFORM_ID:iOS>:-framework UIKit -framework Foundation -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework AudioToolbox -framework AVFoundation -framework CoreAudio -framework CoreMotion -framework Security>"
"$<$<PLATFORM_ID:iOS>:-framework Security -framework CoreHaptics -framework CoreBluetooth -framework GameController -framework Metal -framework Foundation>"
)
target_compile_definitions(${PROJECT_NAME} PRIVATE "MT_BUILDTARGET=1")
if(NOT USE_LUAJIT)
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ extern "C" {
#endif
}

#if TARGET_OS_IPHONE
#include <SDL2/SDL.h>
#endif

#if !defined(__cpp_rtti) || !defined(__cpp_exceptions)
#error Luanti cannot be built without exceptions or RTTI
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/util/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#elif !defined(BYTE_ORDER) && defined(__BYTE_ORDER)
#define BYTE_ORDER __BYTE_ORDER
#endif
#ifndef TARGET_OS_IPHONE

#endif
#undef HAVE_ENDIAN_H

#define FIXEDPOINT_FACTOR 1000.0f

Expand Down

0 comments on commit 55e95dd

Please sign in to comment.