Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Malkierian/libultraship into cvar-r…
Browse files Browse the repository at this point in the history
…edefines
  • Loading branch information
Malkierian committed Apr 29, 2024
2 parents 902d89c + 6f978e0 commit 4a9dc24
Show file tree
Hide file tree
Showing 241 changed files with 1,947 additions and 1,746 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,9 +2,15 @@ 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 @@ -15,15 +21,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
78 changes: 55 additions & 23 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ file(GLOB_RECURSE Source_Files__Controller RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
if (CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/controldevice/controller/mapping/keyboard/*")
list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/controldevice/controller/mapping/sdl/*")
list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/deviceindex/LUSDeviceIndexToSDLDeviceIndexMapping.*")
list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.*")
else()
list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/controldevice/controller/mapping/wiiu/*")
list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/deviceindex/LUSDeviceIndexToWiiUDeviceIndexMapping.*")
list(FILTER Source_Files__Controller EXCLUDE REGEX "controller/deviceindex/ShipDeviceIndexToWiiUDeviceIndexMapping.*")
endif()

source_group("controller" FILES ${Source_Files__Controller})
Expand Down Expand Up @@ -103,11 +103,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 @@ -133,10 +133,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 @@ -169,10 +169,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 @@ -186,7 +190,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 @@ -207,7 +211,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 @@ -250,7 +254,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 @@ -279,30 +283,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 @@ -343,6 +374,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()
Loading

0 comments on commit 4a9dc24

Please sign in to comment.