Skip to content

Commit

Permalink
Mac build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Dec 6, 2024
1 parent 670022f commit edcfd6f
Show file tree
Hide file tree
Showing 71 changed files with 1,129 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "Submodules/vcpkg"]
path = Submodules/vcpkg
url = https://github.com/microsoft/vcpkg.git
[submodule "Submodules/SDL"]
path = Submodules/SDL
url = https://github.com/XITRIX/SDL.git
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,22 @@ add_executable(${PROJECT_NAME}
app/main.cpp
)

target_link_libraries(${PROJECT_NAME} PUBLIC
target_link_libraries(${PROJECT_NAME} PRIVATE
UIKit
)

setup_project()
setup_project()

#list(APPEND google_angle_libs
# ${EXTERN_PATH}/angle/mac/libEGL.dylib
# ${EXTERN_PATH}/angle/mac/libGLESv2.dylib
#)
#
#set_property(
# SOURCE ${google_angle_libs}
# PROPERTY MACOSX_PACKAGE_LOCATION "Frameworks"
#)
#
#target_sources(${PROJECT_NAME} PRIVATE
# ${google_angle_libs}
#)
1 change: 1 addition & 0 deletions Submodules/SDL
Submodule SDL added at d98f18
32 changes: 12 additions & 20 deletions Submodules/UIKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,23 @@ if (APPLE)

# MAC
if (PLATFORM_DESKTOP)
list(APPEND google_angle_libs
${EXTERN_PATH}/angle/mac/libEGL.dylib
${EXTERN_PATH}/angle/mac/libGLESv2.dylib
)
find_library(SDL2 NAMES SDL2-static SDL2main)

list(APPEND platform_libs
${google_angle_libs}
SDL2-static SDL2main
${EXTERN_PATH}/skia/out/mac-arm64-angle/libskia.a
${EXTERN_PATH}/skia/out/mac-arm64-angle/libwindow.a
)
# IOS
elseif (PLATFORM_IOS)
list(APPEND FRAMEWORKS ${EXTERN_PATH}/angle/ios/MetalANGLE.framework)
find_library(SDL2 NAMES SDL2-static SDL2main)

list(APPEND platform_libs
${google_angle_libs}
SDL2-static SDL2main
${EXTERN_PATH}/skia/out/ios-arm64-angle/libskia.a
${EXTERN_PATH}/skia/out/ios-arm64-angle/libwindow.a
)
endif ()

set_property(
SOURCE ${google_angle_libs}
PROPERTY MACOSX_PACKAGE_LOCATION "Frameworks"
)
endif ()

add_library(UIKit
Expand All @@ -45,18 +37,18 @@ add_library(UIKit
)

target_include_directories(UIKit PUBLIC
${EXTERN_PATH}/SDL/include
${EXTERN_PATH}/skia
include
lib
)

find_package(SDL2 REQUIRED)
target_link_libraries(UIKit PUBLIC
${platform_libs}
SDL2::SDL2
)
if (PLATFORM_IOS)
target_include_directories(SDL2-static PRIVATE ${EXTERN_PATH}/angle/ios/MetalANGLE.framework/Headers)
endif ()

if (APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_EMBED_FRAMEWORKS "${FRAMEWORKS}")
endif ()
list(APPEND platform_libs "-framework Foundation" "-framework VideoToolbox" "-framework AVKit" "-framework MetalKit")
endif ()

target_link_libraries(UIKit PRIVATE ${platform_libs})
2 changes: 1 addition & 1 deletion Submodules/UIKit/include/platforms/SkiaInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

std::unique_ptr<skwindow::WindowContext> skiaMakeWindow(SDL_Window* window);

bool platformRunLoop(const std::function<bool()>& runLoop);
bool platformRunLoop(const std::function<bool()>& runLoop);
2 changes: 1 addition & 1 deletion Submodules/UIKit/lib/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Application.h"

#include <SDL2/SDL_syswm.h>
#include <SDL_syswm.h>

#include <include/core/SkGraphics.h>
#include <include/core/SkSurface.h>
Expand Down
13 changes: 13 additions & 0 deletions Submodules/UIKit/lib/platforms/apple/SkiaInit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
#endif

#ifdef PLATFORM_IOS
#include "tools/window/ios/WindowContextFactory_ios.h"
#import "UIKit/UIKit.h"

std::unique_ptr<skwindow::WindowContext> skiaMakeWindow(SDL_Window* window) {
auto metalView = SDL_Metal_CreateView(window);

auto appWindow = UIApplication.sharedApplication.keyWindow;
skwindow::IOSWindowInfo info{};
info.fWindow = appWindow;
info.fViewController = appWindow.rootViewController;
return skwindow::MakeMetalForIOS(info, std::make_unique<skwindow::DisplayParams>());
}

#endif

bool platformRunLoop(const std::function<bool()>& runLoop) {
Expand Down
108 changes: 96 additions & 12 deletions Submodules/cmake/toolchain.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")

# Setup Sunmodules directory
set(CMAKE_TOOLCHAIN_FILE ${EXTERN_PATH}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE PATH "vcpkg toolchain file")

# Include Submodules
function(check_libromfs_generator)
if (NOT DEFINED LIBROMFS_PREBUILT_GENERATOR OR NOT EXISTS "${LIBROMFS_PREBUILT_GENERATOR}")
Expand All @@ -22,18 +19,62 @@ function(add_libromfs app res)
set(LIBROMFS_RESOURCE_LOCATION "${res}" PARENT_SCOPE)
endfunction()

function(ios_bundle iosStoryBoard assets plist)
set(IOS_CODE_SIGN_IDENTITY "" CACHE STRING "The code sign identity to use when building the IPA.")
set(IOS_GUI_IDENTIFIER "" CACHE STRING "The package name")
if(IOS_CODE_SIGN_IDENTITY STREQUAL "")
set(IOS_CODE_SIGNING_ENABLED NO)
else()
set(IOS_CODE_SIGNING_ENABLED YES)
endif()
if (IOS_GUI_IDENTIFIER STREQUAL "")
set(IOS_GUI_IDENTIFIER "${PACKAGE_NAME}")
message(WARNING "Using default package name: ${PACKAGE_NAME}")
endif ()

set(IOS_SPLASH_STORYBOARD "${iosStoryBoard}")

set(IOS_ASSETS ${assets})
set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${IOS_CODE_SIGN_IDENTITY}"
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED YES
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "${IOS_CODE_SIGNING_ENABLED}"
BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${plist}
XCODE_ATTRIBUTE_ENABLE_BITCODE NO
XCODE_ATTRIBUTE_SKIP_INSTALL NO
)
set_property(
SOURCE ${IOS_ASSETS}
PROPERTY MACOSX_PACKAGE_LOCATION "Resources"
)
set_property(
SOURCE ${IOS_SPLASH_STORYBOARD}
PROPERTY MACOSX_PACKAGE_LOCATION "Resources"
)
target_sources(${PROJECT_NAME} PRIVATE
${IOS_ASSETS}
${IOS_SPLASH_STORYBOARD}
)
endfunction()

# Platform specific configs
if (PLATFORM_DESKTOP)
message("Building for Desktop")
add_definitions( -DPLATFORM_DESKTOP )
if (APPLE)
set(PLATFORM_MAC ON)
add_definitions( -DPLATFORM_MAC )
endif ()

set(CMAKE_TOOLCHAIN_FILE ${EXTERN_PATH}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE PATH "vcpkg toolchain file")
elseif (PLATFORM_IOS)
message("Building for iOS")
add_definitions( -DPLATFORM_IOS )

set(BUILD_SHARED_LIBS OFF)
set(PLATFORM OS64)
set(CMAKE_TOOLCHAIN_FILE ${EXTERN_PATH}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE PATH "vcpkg toolchain file")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${EXTERN_PATH}/cmake/ios.toolchain.cmake CACHE PATH "ios toolchain file")
set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2") # iphone, ipad
endif ()
Expand All @@ -42,14 +83,9 @@ endif ()
check_libromfs_generator()

function(setup_project)
# Include Submodules
add_subdirectory(${EXTERN_PATH})
add_subdirectory(${EXTERN_PATH}/UIKit)

add_libromfs(${PROJECT_NAME} ${PROJECT_RESOURCES})
add_subdirectory(${EXTERN_PATH}/libromfs EXCLUDE_FROM_ALL)

if (APPLE)
add_subdirectory(${EXTERN_PATH}/SDL)

set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
Expand All @@ -65,11 +101,59 @@ function(setup_project)
XCODE_ATTRIBUTE_INSTALL_PATH $(LOCAL_APPS_DIR)
XCODE_EMBED_RESOURCES_CODE_SIGN_ON_COPY ON # Not work
XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY ON # Not work
XCODE_EMBED_FRAMEWORKS "${IOS_FRAMEWORKS}"
XCODE_EMBED_FRAMEWORKS "${FRAMEWORKS}"
INSTALL_RPATH "@executable_path/../Frameworks"
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks"
)
endif ()

if (PLATFORM_MAC)
list(APPEND google_angle_libs
${EXTERN_PATH}/angle/mac/libEGL.dylib
${EXTERN_PATH}/angle/mac/libGLESv2.dylib
)

target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Foundation" "-framework VideoToolbox" "-framework AVKit" "-framework MetalKit")
list(APPEND platform_libs
${google_angle_libs}
)

set_property(
SOURCE ${google_angle_libs}
PROPERTY MACOSX_PACKAGE_LOCATION "Frameworks"
)

target_sources(${PROJECT_NAME} PRIVATE
${google_angle_libs}
)
elseif (PLATFORM_IOS)
ios_bundle("${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/iphoneos/Splash.storyboard"
"${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/Images.xcassets"
"${CMAKE_CURRENT_SOURCE_DIR}/app/platforms/ios/iOSBundleInfo.plist.in")

set_target_properties(${PROJECT_NAME} PROPERTIES
INSTALL_RPATH @executable_path/Frameworks
XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY ON
MACOSX_BUNDLE_COPYRIGHT "Copyright 2024 ${PROJECT_AUTHOR}"
XCODE_ATTRIBUTE_CURRENT_PROJECT_VERSION "${VERSION_BUILD}"
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCSupportsGameMode YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCSupportsControllerUserInteraction YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_GCRequiresControllerUserInteraction YES
XCODE_ATTRIBUTE_INFOPLIST_KEY_LSApplicationCategoryType "public.app-category.games"
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/Frameworks"
XCODE_ATTRIBUTE_FRAMEWORK_SEARCH_PATHS "${EXTERN_PATH}/angle/ios/"
XCODE_ATTRIBUTE_INSTALL_PATH $(LOCAL_APPS_DIR))

set_target_properties(${PROJECT_NAME} PROPERTIES
XCODE_EMBED_FRAMEWORKS ${EXTERN_PATH}/angle/ios/MetalANGLE.framework
)
endif ()

# Include Submodules
add_subdirectory(${EXTERN_PATH})
add_subdirectory(${EXTERN_PATH}/UIKit)

add_libromfs(${PROJECT_NAME} ${PROJECT_RESOURCES})
add_subdirectory(${EXTERN_PATH}/libromfs EXCLUDE_FROM_ALL)

# target_link_libraries(${PROJECT_NAME} fmt tweeny yogacore ${PLATFORM_LIBS})
endfunction()
28 changes: 28 additions & 0 deletions app/platforms/ios/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"images" : [
{
"filename" : "moonlight 1.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"filename" : "moonlight 2.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024",
"unassigned" : true
},
{
"filename" : "moonlight.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024",
"unassigned" : true
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Frame [email protected]",
"idiom" : "tv"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"author" : "xcode",
"version" : 1
},
"layers" : [
{
"filename" : "Front.imagestacklayer"
},
{
"filename" : "Middle.imagestacklayer"
},
{
"filename" : "Back.imagestacklayer"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Frame [email protected]",
"idiom" : "tv"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Frame [email protected]",
"idiom" : "tv"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit edcfd6f

Please sign in to comment.