Skip to content

Commit

Permalink
Added ios support (Kenix3#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv authored Apr 28, 2024
1 parent 54a387a commit a245aaf
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 74 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ jobs:
name: soh-mac
path: build-cmake/src/*.a
if-no-files-found: error
build-ios:
runs-on: macos-12
steps:
- uses: actions/checkout@v2
- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ runner.os }}-ccache
- name: Build libultraship
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 -DCMAKE_BUILD_TYPE:STRING=Release
cmake --build build-cmake --config Release --parallel 10
- name: Upload build
uses: actions/upload-artifact@v3
with:
name: soh-ios
path: build-cmake/src/*/*.a
if-no-files-found: error
build-linux:
runs-on: ubuntu-latest
steps:
Expand Down
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,22 @@ ZAPDUtils.lib
.vs/
.idea/
cmake-build-**
cmake_install.cmake
*.a
*.o
*.pc
*.vcxproj
*.sln
*.filters
*.stamp
*.depend
*.lib
*.tlog
*.recipe
src/install_config.h
# Removed jsonConfig and jsonConfigVersion
extern/nlohmann-json/*_jsonConfig*
*.pbxproj
*.xcworkspace
*.xcsettings
build*
33 changes: 29 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ cmake_minimum_required(VERSION 3.24.0)

option(NON_PORTABLE "Build a non-portable version" OFF)

if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
option(SIGN_LIBRARY "Enable xcode signing" OFF)
option(BUNDLE_ID "Bundle ID for xcode signing" "com.example.libultraship")
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
endif()

project(libultraship LANGUAGES C CXX)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
enable_language(OBJCXX)
set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -fobjc-arc")
set(CMAKE_OBJCXX_FLAGS "${CMAKE_OBJCXX_FLAGS} -fobjc-arc")
Expand All @@ -14,15 +20,34 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
endif()

include(cmake/Utils.cmake)
set(ADDITIONAL_LIB_INCLUDES "")

include(cmake/dependencies/common.cmake)
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
include(cmake/dependencies/android.cmake)
elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS")
include(cmake/dependencies/ios.cmake)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
include(cmake/dependencies/windows.cmake)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
include(cmake/dependencies/windows.cmake)

if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(PLATFORM "OS64COMBINED")
include(FetchContent)
FetchContent_Declare(iostoolchain
GIT_REPOSITORY https://github.com/leetal/ios-cmake
GIT_TAG 06465b27698424cf4a04a5ca4904d50a3c966c45
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)
FetchContent_GetProperties(iostoolchain)
if(NOT iostoolchain_POPULATED)
FetchContent_Populate(iostoolchain)
endif()
set(CMAKE_IOS_TOOLCHAIN_FILE ${iostoolchain_SOURCE_DIR}/ios.toolchain.cmake)
set_property(GLOBAL PROPERTY IOS_TOOLCHAIN_FILE ${CMAKE_IOS_TOOLCHAIN_FILE})
include(${CMAKE_IOS_TOOLCHAIN_FILE})
endif()

add_subdirectory("extern")
add_subdirectory("src")

44 changes: 44 additions & 0 deletions cmake/dependencies/ios.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#=================== SDL2 ===================
find_package(SDL2 QUIET)
if (NOT ${SDL2_FOUND})
include(FetchContent)
FetchContent_Declare(
SDL2
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG release-2.28.1
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(SDL2)
endif()

#=================== nlohmann-json ===================
find_package(nlohmann_json QUIET)
if (NOT ${nlohmann_json_FOUND})
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(nlohmann_json)
endif()

#=================== libzip ===================
find_package(libzip QUIET)
if (NOT ${libzip_FOUND})
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(BUILD_TOOLS OFF)
set(BUILD_REGRESS OFF)
set(BUILD_EXAMPLES OFF)
set(BUILD_DOC OFF)
set(BUILD_OSSFUZZ OFF)
set(BUILD_SHARED_LIBS OFF)
FetchContent_Declare(
libzip
GIT_REPOSITORY https://github.com/nih-at/libzip.git
GIT_TAG v1.10.1
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(libzip)
list(APPEND ADDITIONAL_LIB_INCLUDES ${libzip_SOURCE_DIR}/lib ${libzip_BINARY_DIR})
endif()
8 changes: 5 additions & 3 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
${IMGUI_DIR}/backends/imgui_impl_dx11.cpp
${IMGUI_DIR}/backends/imgui_impl_win32.cpp
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
target_sources(ImGui
PRIVATE
${IMGUI_DIR}/backends/imgui_impl_metal.mm
Expand All @@ -77,13 +77,15 @@ endif()

target_include_directories(ImGui PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends PRIVATE ${SDL2_INCLUDE_DIRS})

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
target_include_directories(ImGui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/metal-cpp)
target_compile_definitions(ImGui PUBLIC IMGUI_IMPL_METAL_CPP)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(ImGui PUBLIC SDL2::SDL2 SDL2::SDL2main)
elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS")
target_link_libraries(ImGui PUBLIC SDL2::SDL2-static SDL2::SDL2main)
elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
target_link_libraries(ImGui PUBLIC SDL2::SDL2-static)
else()
Expand All @@ -97,7 +99,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_package(GLEW REQUIRED)
target_link_libraries(ImGui PUBLIC ${OPENGL_opengl_LIBRARY} GLEW::GLEW)
set_target_properties(ImGui PROPERTIES
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
if (USE_OPENGLES)
Expand Down
2 changes: 1 addition & 1 deletion include/libultraship/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#endif
#include "audio/SDLAudioPlayer.h"
#ifdef __APPLE__
#include "utils/OSXFolderManager.h"
#include "utils/AppleFolderManager.h"
#endif
#ifdef __SWITCH__
#include "port/switch/SwitchImpl.h"
Expand Down
74 changes: 53 additions & 21 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ target_sources(libultraship PRIVATE ${Source_Files__Window__Gui})

file(GLOB Source_Files__Utils RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "utils/*.h" "utils/*.cpp" "utils/*.c")

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND Source_Files__Utils ${CMAKE_CURRENT_SOURCE_DIR}/utils/OSXFolderManager.mm)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/utils/OSXFolderManager.mm PROPERTIES COMPILE_FLAGS -fno-objc-arc)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND Source_Files__Utils ${CMAKE_CURRENT_SOURCE_DIR}/utils/AppleFolderManager.mm)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/utils/AppleFolderManager.mm PROPERTIES COMPILE_FLAGS -fno-objc-arc)
else()
list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/utils/OSXFolderManager.h)
list(REMOVE_ITEM Header_Files__include ${CMAKE_CURRENT_SOURCE_DIR}/utils/AppleFolderManager.h)
endif()

source_group("utils" FILES ${Source_Files__Utils})
Expand All @@ -131,10 +131,10 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchImpl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/port/switch/SwitchPerformanceProfiles.h
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Android")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(Source_Files__Port
${CMAKE_CURRENT_SOURCE_DIR}/port/android/AndroidImpl.h
${CMAKE_CURRENT_SOURCE_DIR}/port/android/AndroidImpl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/port/mobile/MobileImpl.h
${CMAKE_CURRENT_SOURCE_DIR}/port/mobile/MobileImpl.cpp
)
endif()

Expand Down Expand Up @@ -167,10 +167,14 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/dxsdk/*")
endif()

if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_metal*")
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_opengl*")
endif()

if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gfx_wiiu*")
list(FILTER Source_Files__Graphic EXCLUDE REGEX "graphic/Fast3D/gx2*")
Expand All @@ -184,7 +188,7 @@ target_sources(libultraship PRIVATE ${Source_Files__Graphic})

#=================== metal-cpp ===================

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
target_include_directories(libultraship PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern/metal-cpp)
endif()

Expand All @@ -205,7 +209,7 @@ endif()

target_include_directories(libultraship
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern ${CMAKE_CURRENT_BINARY_DIR} $<$<BOOL:${GFX_DEBUG_DISASSEMBLER}>:${CMAKE_CURRENT_SOURCE_DIR}/../../ZAPDTR/lib/libgfxd>
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../extern/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../extern/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb ${ADDITIONAL_LIB_INCLUDES}
)

if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
Expand Down Expand Up @@ -248,7 +252,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "NintendoS
target_link_libraries(libultraship PRIVATE Threads::Threads)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
find_Library(OSX_FOUNDATION Foundation)
find_Library(OSX_AVFOUNDATION AVFoundation)
find_library(METAL Metal)
Expand Down Expand Up @@ -277,30 +281,57 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
)
endif()

if (NOT CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
target_compile_definitions(libultraship PRIVATE
$<$<CONFIG:Debug>:_DEBUG>
$<$<NOT:$<CONFIG:Debug>>:NDEBUG>
SPDLOG_NO_THREAD_ID
SPDLOG_NO_TLS
STBI_NO_THREAD_LOCALS
SPDLOG_ACTIVE_LEVEL=3
)
elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS")
target_compile_definitions(libultraship PRIVATE
ENABLE_OPENGL
$<$<CONFIG:Debug>:_DEBUG>
$<$<NOT:$<CONFIG:Debug>>:NDEBUG>
$<$<CONFIG:Debug>:SPDLOG_ACTIVE_LEVEL=0>
$<$<NOT:$<CONFIG:Debug>>:SPDLOG_ACTIVE_LEVEL=1>
$<$<BOOL:${USE_OPENGLES}>:USE_OPENGLES>
$<$<BOOL:${GFX_DEBUG_DISASSEMBLER}>:GFX_DEBUG_DISASSEMBLER>
__IOS__
)
else ()

set_xcode_property(${PROJECT_NAME} PRODUCT_BUNDLE_IDENTIFIER ${BUNDLE_ID} All)

if(NOT SIGN_LIBRARY)
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
)

set_target_properties(SDL2 PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
)

set_target_properties(zip PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
)
endif()
else()
target_compile_definitions(libultraship PRIVATE
ENABLE_OPENGL
$<$<CONFIG:Debug>:_DEBUG>
$<$<NOT:$<CONFIG:Debug>>:NDEBUG>
SPDLOG_NO_THREAD_ID
SPDLOG_NO_TLS
STBI_NO_THREAD_LOCALS
SPDLOG_ACTIVE_LEVEL=3
$<$<CONFIG:Debug>:SPDLOG_ACTIVE_LEVEL=0>
$<$<NOT:$<CONFIG:Debug>>:SPDLOG_ACTIVE_LEVEL=1>
$<$<BOOL:${USE_OPENGLES}>:USE_OPENGLES>
$<$<BOOL:${GFX_DEBUG_DISASSEMBLER}>:GFX_DEBUG_DISASSEMBLER>
)
endif()

Expand Down Expand Up @@ -341,6 +372,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang")
-Wno-parentheses
-Wno-narrowing
-Wno-missing-field-initializers
-Wno-implicit-function-declaration
$<$<COMPILE_LANGUAGE:C,OBJC>:-Wno-int-conversion>
)
endif()
17 changes: 16 additions & 1 deletion src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#endif

#ifdef __APPLE__
#include "utils/OSXFolderManager.h"
#include "utils/AppleFolderManager.h"
#elif defined(__SWITCH__)
#include "port/switch/SwitchImpl.h"
#elif defined(__WIIU__)
Expand Down Expand Up @@ -216,6 +216,10 @@ void Context::InitResourceManager(const std::vector<std::string>& otrFiles,
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OTR file not found",
"Main OTR file not found. Please generate one", nullptr);
SPDLOG_ERROR("Main OTR file not found!");
#ifdef __IOS__
// We need this exit to close the app when we dismiss the dialog
exit(0);
#endif
#endif
return;
}
Expand Down Expand Up @@ -334,6 +338,12 @@ std::string Context::GetAppBundlePath() {
return externaldir;
}
#endif

#ifdef __IOS__
const char* home = getenv("HOME");
return std::string(home) + "/Documents";
#endif

#ifdef NON_PORTABLE
return CMAKE_INSTALL_PREFIX;
#else
Expand Down Expand Up @@ -370,6 +380,11 @@ std::string Context::GetAppDirectoryPath(std::string appName) {
}
#endif

#ifdef __IOS__
const char* home = getenv("HOME");
return std::string(home) + "/Documents";
#endif

#if defined(__linux__) || defined(__APPLE__)
char* fpath = std::getenv("SHIP_HOME");
if (fpath != NULL) {
Expand Down
Loading

0 comments on commit a245aaf

Please sign in to comment.