From 6c9af621b52e4d03f3fc11dc72393e18b584dae3 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 28 Jul 2024 23:45:17 +0200 Subject: [PATCH 1/8] Fix some linking issues on MacOS --- CMakeLists.txt | 3 ++- cmake/AppleHelper.cmake | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 583bbfa..5af7803 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,8 @@ if(IOS) set(MACOSX_BUNDLE_BUNDLE_NAME ${APP_BUNDLE_IDENTIFIER}) set(CMAKE_OSX_DEPLOYMENT_TARGET "14.1") # The used ARKit features are only available starting with iOS 14 - +endif() +if(APPLE) LinkAppleFrameworks(openVulkanoCpp) endif () diff --git a/cmake/AppleHelper.cmake b/cmake/AppleHelper.cmake index 7ab0175..c38f88f 100644 --- a/cmake/AppleHelper.cmake +++ b/cmake/AppleHelper.cmake @@ -6,12 +6,14 @@ function(LinkAppleFrameworks TARGET) PUBLIC "-framework CoreVideo" PUBLIC "-framework Metal" PUBLIC "-framework MetalPerformanceShaders" - PUBLIC "-framework ARKit" PUBLIC "-lstdc++" PUBLIC c++ PUBLIC c ) + if(IOS) + target_link_libraries(${TARGET} PUBLIC "-framework ARKit") + endif() # Locate system libraries on iOS find_library(UIKIT UIKit) @@ -19,11 +21,20 @@ function(LinkAppleFrameworks TARGET) find_library(MOBILECORESERVICES MobileCoreServices) find_library(CFNETWORK CFNetwork) find_library(SYSTEMCONFIGURATION SystemConfiguration) + find_library(APPKIT AppKit) + find_library(IOSURFACE IOSurface) + find_library(QUARTZ Quartz) # link the frameworks located above - target_link_libraries(${TARGET} PUBLIC ${UIKIT}) + if(IOS) + target_link_libraries(${TARGET} PUBLIC ${UIKIT}) + target_link_libraries(${TARGET} PUBLIC ${MOBILECORESERVICES}) + else() + target_link_libraries(${TARGET} PUBLIC ${APPKIT}) + target_link_libraries(${TARGET} PUBLIC ${IOSURFACE}) + target_link_libraries(${TARGET} PUBLIC ${QUARTZ}) + endif() target_link_libraries(${TARGET} PUBLIC ${FOUNDATION}) - target_link_libraries(${TARGET} PUBLIC ${MOBILECORESERVICES}) target_link_libraries(${TARGET} PUBLIC ${CFNETWORK}) target_link_libraries(${TARGET} PUBLIC ${SYSTEMCONFIGURATION}) -endfunction() \ No newline at end of file +endfunction() From f46ff780a9f81847d1cacf528d6af0268b55f4e5 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Mon, 29 Jul 2024 00:12:05 +0200 Subject: [PATCH 2/8] Fix libarchive linking on bsd based os --- 3rdParty/libarchive/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/3rdParty/libarchive/CMakeLists.txt b/3rdParty/libarchive/CMakeLists.txt index 8adff1e..44abefa 100644 --- a/3rdParty/libarchive/CMakeLists.txt +++ b/3rdParty/libarchive/CMakeLists.txt @@ -28,6 +28,8 @@ function(LinkLibArchive TARGET) find_package(zstd QUIET) find_package(BZip2 QUIET) find_package(LibLZMA QUIET) + find_package(LibXml2 QUIET) + find_package(EXPAT QUIET) target_include_directories(${TARGET} PRIVATE ${LibArchive_INCLUDE_DIR}) target_link_libraries(${TARGET} PRIVATE ${LibArchive_LIBRARIES} ${ZLIB_LIBRARIES} ${zstd_LIBRARIES} ${LZ4_LIBRARIES}) if (BZIP2_LIBRARIES) @@ -36,4 +38,10 @@ function(LinkLibArchive TARGET) if (LIBLZMA_LIBRARIES) target_link_libraries(${TARGET} PRIVATE ${LIBLZMA_LIBRARIES}) endif() -endfunction() \ No newline at end of file + if (LibXml2_FOUND) + target_link_libraries(${TARGET} PUBLIC ${LIBXML2_LIBRARIES}) + endif() + if (EXPAT_FOUND) + target_link_libraries(${TARGET} PUBLIC ${EXPAT_LIBRARIES}) + endif() +endfunction() From e7ca7dc6bb6ddbdea8862914907e47cb9fee5eeb Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Mon, 29 Jul 2024 00:28:17 +0200 Subject: [PATCH 3/8] Update filters --- cmake/Filter.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/Filter.cmake b/cmake/Filter.cmake index dde772f..2cdf3d2 100644 --- a/cmake/Filter.cmake +++ b/cmake/Filter.cmake @@ -4,6 +4,10 @@ function(FilterPlatformPaths sourcesVar) list(FILTER ${sourcesVar} EXCLUDE REGEX ".*GLFW.*") else () list(FILTER ${sourcesVar} EXCLUDE REGEX ".*[\\/]Host[\\/]iOS[\\/].*") + list(FILTER ${sourcesVar} EXCLUDE REGEX ".*[\\/]AR[\\/]Provider[\\/]ArKit[\\/].*") + endif () + if (NOT APPLE) + list(FILTER ${sourcesVar} EXCLUDE REGEX ".*[\\/]Host[\\/]Apple[\\/].*") endif () if (NOT LINUX) list(FILTER ${sourcesVar} EXCLUDE REGEX ".*[\\/]Host[\\/]Linux[\\/].*") @@ -15,4 +19,4 @@ function(FilterPlatformPaths sourcesVar) list(FILTER ${sourcesVar} EXCLUDE REGEX "main\.(m|mm|c|cpp)") set(${sourcesVar} ${${sourcesVar}} PARENT_SCOPE) -endfunction() \ No newline at end of file +endfunction() From 6e4dd72b3ae0f627551036141746fac65bab0a55 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Mon, 29 Jul 2024 00:40:16 +0200 Subject: [PATCH 4/8] Update for macbuild --- CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5af7803..c86dea3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,13 +41,11 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/TryCompileShaders.cmake.in ${CM execute_process(COMMAND ${BASH_EXECUTABLE} CompileShaders.sh "${SHADER_OUTPUT_DEST}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Scripts) file(GLOB GENERATED_SHADER_SOURCES "${SHADER_OUTPUT_DEST}/*") -if(IOS) +if(APPLE) set(CMAKE_Swift_LANGUAGE_VERSION 5.0) enable_language(Swift) - file(GLOB_RECURSE sources CONFIGURE_DEPENDS "openVulkanoCpp/*.mm" "openVulkanoCpp/*.m" "openVulkanoCpp/*.c" "openVulkanoCpp/*.cpp" "openVulkanoCpp/*.swift") - - file(GLOB_RECURSE resources CONFIGURE_DEPENDS "openVulkanoCpp/*.storyboard" "openVulkanoCpp/*.xib") - add_executable(openVulkanoCpp examples/main.m ${resources}) + file(GLOB_RECURSE sources CONFIGURE_DEPENDS "openVulkanoCpp/*.mm" "openVulkanoCpp/*.m" "openVulkanoCpp/*.c" "openVulkanoCpp/*.cpp" "openVulkanoCpp/*.swift" "examples/*.hpp" "examples/*.cpp") + add_executable(openVulkanoCpp examples/main.cpp ${resources}) else() file(GLOB_RECURSE sources CONFIGURE_DEPENDS "openVulkanoCpp/*.h" "openVulkanoCpp/*.c" "openVulkanoCpp/*.hpp" "openVulkanoCpp/*.cpp" "examples/*.hpp" "examples/*.cpp") file(GLOB SHADER_SRC_FILES ${ROOT_FOLDER}/openVulkanoCpp/Shader/*) From d166f825bb0cccca69ab41047cfc7d21ed47a6e1 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Tue, 30 Jul 2024 08:13:39 +0200 Subject: [PATCH 5/8] Update macos build --- CMakeLists.txt | 2 +- cmake/Filter.cmake | 1 + openVulkanoCpp/AR/ArSession.cpp | 5 + .../{iOS => Apple}/BundledResoureLoaderIos.h | 0 .../{iOS => Apple}/BundledResoureLoaderIos.mm | 0 .../Host/{iOS => Apple}/MetalViewWindow.h | 0 .../Host/{iOS => Apple}/MetalViewWindow.mm | 0 .../Host/{iOS => Apple}/NamedEventProcessor.h | 0 .../{iOS => Apple}/NamedEventProcessor.mm | 0 openVulkanoCpp/Host/MacOS/SystemInfo.mm | 183 ++++++++++++++++++ 10 files changed, 190 insertions(+), 1 deletion(-) rename openVulkanoCpp/Host/{iOS => Apple}/BundledResoureLoaderIos.h (100%) rename openVulkanoCpp/Host/{iOS => Apple}/BundledResoureLoaderIos.mm (100%) rename openVulkanoCpp/Host/{iOS => Apple}/MetalViewWindow.h (100%) rename openVulkanoCpp/Host/{iOS => Apple}/MetalViewWindow.mm (100%) rename openVulkanoCpp/Host/{iOS => Apple}/NamedEventProcessor.h (100%) rename openVulkanoCpp/Host/{iOS => Apple}/NamedEventProcessor.mm (100%) create mode 100644 openVulkanoCpp/Host/MacOS/SystemInfo.mm diff --git a/CMakeLists.txt b/CMakeLists.txt index c86dea3..6cee3d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ if(APPLE) set(CMAKE_Swift_LANGUAGE_VERSION 5.0) enable_language(Swift) file(GLOB_RECURSE sources CONFIGURE_DEPENDS "openVulkanoCpp/*.mm" "openVulkanoCpp/*.m" "openVulkanoCpp/*.c" "openVulkanoCpp/*.cpp" "openVulkanoCpp/*.swift" "examples/*.hpp" "examples/*.cpp") - add_executable(openVulkanoCpp examples/main.cpp ${resources}) + add_executable(openVulkanoCpp examples/main.cpp ${resources} ${GENERATED_SHADER_SOURCES}) else() file(GLOB_RECURSE sources CONFIGURE_DEPENDS "openVulkanoCpp/*.h" "openVulkanoCpp/*.c" "openVulkanoCpp/*.hpp" "openVulkanoCpp/*.cpp" "examples/*.hpp" "examples/*.cpp") file(GLOB SHADER_SRC_FILES ${ROOT_FOLDER}/openVulkanoCpp/Shader/*) diff --git a/cmake/Filter.cmake b/cmake/Filter.cmake index 2cdf3d2..d030112 100644 --- a/cmake/Filter.cmake +++ b/cmake/Filter.cmake @@ -2,6 +2,7 @@ function(FilterPlatformPaths sourcesVar) if (IOS) list(FILTER ${sourcesVar} EXCLUDE REGEX ".*GLFW.*") + list(FILTER ${sourcesVar} EXCLUDE REGEX ".*[\\/]Host[\\/]MacOS[\\/].*") else () list(FILTER ${sourcesVar} EXCLUDE REGEX ".*[\\/]Host[\\/]iOS[\\/].*") list(FILTER ${sourcesVar} EXCLUDE REGEX ".*[\\/]AR[\\/]Provider[\\/]ArKit[\\/].*") diff --git a/openVulkanoCpp/AR/ArSession.cpp b/openVulkanoCpp/AR/ArSession.cpp index cbf3395..cd36b97 100644 --- a/openVulkanoCpp/AR/ArSession.cpp +++ b/openVulkanoCpp/AR/ArSession.cpp @@ -8,7 +8,12 @@ #include "Provider/Playback/ArSessionPlayback.hpp" #include "Provider/Network/ArSessionStream.h" #ifdef __APPLE__ +#include +#if TARGET_OS_MAC +#include "Provider/ArSessionNull.hpp" +#else #include "Provider/ArKit/ArSessionArKit.h" +#endif #else #ifdef ANDROID #include "Provider/ArCore/ArSessionArCore.h" diff --git a/openVulkanoCpp/Host/iOS/BundledResoureLoaderIos.h b/openVulkanoCpp/Host/Apple/BundledResoureLoaderIos.h similarity index 100% rename from openVulkanoCpp/Host/iOS/BundledResoureLoaderIos.h rename to openVulkanoCpp/Host/Apple/BundledResoureLoaderIos.h diff --git a/openVulkanoCpp/Host/iOS/BundledResoureLoaderIos.mm b/openVulkanoCpp/Host/Apple/BundledResoureLoaderIos.mm similarity index 100% rename from openVulkanoCpp/Host/iOS/BundledResoureLoaderIos.mm rename to openVulkanoCpp/Host/Apple/BundledResoureLoaderIos.mm diff --git a/openVulkanoCpp/Host/iOS/MetalViewWindow.h b/openVulkanoCpp/Host/Apple/MetalViewWindow.h similarity index 100% rename from openVulkanoCpp/Host/iOS/MetalViewWindow.h rename to openVulkanoCpp/Host/Apple/MetalViewWindow.h diff --git a/openVulkanoCpp/Host/iOS/MetalViewWindow.mm b/openVulkanoCpp/Host/Apple/MetalViewWindow.mm similarity index 100% rename from openVulkanoCpp/Host/iOS/MetalViewWindow.mm rename to openVulkanoCpp/Host/Apple/MetalViewWindow.mm diff --git a/openVulkanoCpp/Host/iOS/NamedEventProcessor.h b/openVulkanoCpp/Host/Apple/NamedEventProcessor.h similarity index 100% rename from openVulkanoCpp/Host/iOS/NamedEventProcessor.h rename to openVulkanoCpp/Host/Apple/NamedEventProcessor.h diff --git a/openVulkanoCpp/Host/iOS/NamedEventProcessor.mm b/openVulkanoCpp/Host/Apple/NamedEventProcessor.mm similarity index 100% rename from openVulkanoCpp/Host/iOS/NamedEventProcessor.mm rename to openVulkanoCpp/Host/Apple/NamedEventProcessor.mm diff --git a/openVulkanoCpp/Host/MacOS/SystemInfo.mm b/openVulkanoCpp/Host/MacOS/SystemInfo.mm new file mode 100644 index 0000000..4e37d0f --- /dev/null +++ b/openVulkanoCpp/Host/MacOS/SystemInfo.mm @@ -0,0 +1,183 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include "Host/SystemInfo.hpp" +#include "Base/Logger.hpp" +#include + +#include +#include + +#import +#import + +namespace OpenVulkano +{ + Event<> SystemInfo::OnLowPowerModeChanged; + Event<> SystemInfo::OnBatteryStateChanged; + Event<> SystemInfo::OnBatteryLevelChanged; + Event<> SystemInfo::OnDeviceOrientationChanged; + + size_t SystemInfo::GetSystemRam() + { + return [NSProcessInfo processInfo].physicalMemory; + } + + size_t SystemInfo::GetSystemRamAvailable() + { + return 0; //TODO + } + + size_t SystemInfo::GetAppRamMax() + { + return GetAppRamAvailable() + GetAppRamUsed(); + } + + size_t SystemInfo::GetAppVirtualMemoryMax() + { + return INT64_MAX; + } + + size_t SystemInfo::GetAppRamAvailable() + { + return 0; //TODO + } + + size_t SystemInfo::GetAppRamUsed() + { + struct task_basic_info info; + mach_msg_type_number_t size = sizeof(info); + kern_return_t kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size); + if( kerr == KERN_SUCCESS ) + { + return info.resident_size; + } + Logger::PERF->error("Failed to read memory consumption: {}", mach_error_string(kerr)); + return 0; + } + + std::string SystemInfo::GetUserName() + { + return ""; + } + + std::string SystemInfo::GetHostName() + { + return [[NSProcessInfo processInfo].hostName UTF8String]; + } + + std::string SystemInfo::GetDeviceName() + { + return "Mac"; //TODO + } + + std::string SystemInfo::GetDeviceVendorName() + { + return "Apple"; + } + + std::string SystemInfo::GetDeviceModelName() + { + return ""; //TODO + } + + std::string SystemInfo::GetOsName() + { + return ""; //TODO + } + + OsVersion SystemInfo::GetOsVersion() + { + NSOperatingSystemVersion osVersion = [NSProcessInfo processInfo].operatingSystemVersion; + return { static_cast(osVersion.majorVersion), static_cast(osVersion.minorVersion), static_cast(osVersion.patchVersion), 0 }; + } + + std::string SystemInfo::GetOsNameHumanReadable() + { + std::stringstream name; + name << GetOsName() << ' ' << GetOsVersion().major; + return name.str(); + } + + DeviceType SystemInfo::GetDeviceType() + { + return DeviceType::PC; + } + + size_t SystemInfo::GetCpuCoreCount() + { + return [NSProcessInfo processInfo].processorCount; + } + + size_t SystemInfo::GetCpuThreadCount() + { + return [NSProcessInfo processInfo].activeProcessorCount; + } + + int32_t SystemInfo::GetCpuTemperature() + { + switch([NSProcessInfo processInfo].thermalState) + { + case NSProcessInfoThermalStateNominal: return 20; + case NSProcessInfoThermalStateFair: return 50; + case NSProcessInfoThermalStateSerious: return 80; + case NSProcessInfoThermalStateCritical: return 100; + } + return -1; + } + + CpuThermalState SystemInfo::GetCpuThermalState() + { + switch([NSProcessInfo processInfo].thermalState) + { + case NSProcessInfoThermalStateNominal: return CpuThermalState::Normal; + case NSProcessInfoThermalStateFair: return CpuThermalState::Fair; + case NSProcessInfoThermalStateSerious: return CpuThermalState::Serious; + case NSProcessInfoThermalStateCritical: return CpuThermalState::Critical; + } + return CpuThermalState::Normal; + } + + bool SystemInfo::IsDeviceInLowPowerMode() + { + return [NSProcessInfo processInfo].lowPowerModeEnabled; + } + + void SystemInfo::EnableEnergyEvents() + { + //TODO + } + + BatteryState SystemInfo::GetDeviceBatteryState() + { + return BatteryState::Unavailable; //TODO + } + + float SystemInfo::GetDeviceBatteryLevel() + { + return 0; //TODO + } + + bool SystemInfo::IsMultitaskingSupported() + { + return true; + } + + DeviceOrientation SystemInfo::GetDeviceOrientation() + { + return DeviceOrientation::LandscapeRight; + } + + void SystemInfo::EnableDeviceOrientationEvents() + { + //TODO? + } + + InterfaceOrientation SystemInfo::GetInterfaceOrientation() + { + return InterfaceOrientation::Landscape; //TODO? + } +} From a0faae192dae3ccbc39e6a797a766b45c3106199 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Tue, 30 Jul 2024 23:08:38 +0200 Subject: [PATCH 6/8] Fix missing Vulkan loader on MacOS --- 3rdParty/glfw/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/3rdParty/glfw/CMakeLists.txt b/3rdParty/glfw/CMakeLists.txt index 0ff8d20..030c155 100644 --- a/3rdParty/glfw/CMakeLists.txt +++ b/3rdParty/glfw/CMakeLists.txt @@ -13,5 +13,8 @@ FetchContent_Declare( ) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) +if(APPLE) + set(GLFW_VULKAN_STATIC ON CACHE BOOL "" FORCE) +endif() FetchContent_MakeAvailable(glfw) -set(glfw_FOUND ON PARENT_SCOPE) \ No newline at end of file +set(glfw_FOUND ON PARENT_SCOPE) From 6bd6ee8cf50872c7267d601f5350fa92bfd9032f Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Tue, 30 Jul 2024 23:09:38 +0200 Subject: [PATCH 7/8] Engine doesn't need swift --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cee3d4..b7aebc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,9 +42,7 @@ execute_process(COMMAND ${BASH_EXECUTABLE} CompileShaders.sh "${SHADER_OUTPUT_DE file(GLOB GENERATED_SHADER_SOURCES "${SHADER_OUTPUT_DEST}/*") if(APPLE) - set(CMAKE_Swift_LANGUAGE_VERSION 5.0) - enable_language(Swift) - file(GLOB_RECURSE sources CONFIGURE_DEPENDS "openVulkanoCpp/*.mm" "openVulkanoCpp/*.m" "openVulkanoCpp/*.c" "openVulkanoCpp/*.cpp" "openVulkanoCpp/*.swift" "examples/*.hpp" "examples/*.cpp") + file(GLOB_RECURSE sources CONFIGURE_DEPENDS "openVulkanoCpp/*.mm" "openVulkanoCpp/*.m" "openVulkanoCpp/*.c" "openVulkanoCpp/*.cpp" "examples/*.hpp" "examples/*.cpp") add_executable(openVulkanoCpp examples/main.cpp ${resources} ${GENERATED_SHADER_SOURCES}) else() file(GLOB_RECURSE sources CONFIGURE_DEPENDS "openVulkanoCpp/*.h" "openVulkanoCpp/*.c" "openVulkanoCpp/*.hpp" "openVulkanoCpp/*.cpp" "examples/*.hpp" "examples/*.cpp") From 817202137b2d69a76664595b469c87278b4630c4 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Tue, 30 Jul 2024 23:10:02 +0200 Subject: [PATCH 8/8] Build MacOS version --- .gitea/workflows/build_pc.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.gitea/workflows/build_pc.yml b/.gitea/workflows/build_pc.yml index 2da5a0e..69f5f05 100644 --- a/.gitea/workflows/build_pc.yml +++ b/.gitea/workflows/build_pc.yml @@ -16,12 +16,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ windows_x64, ubuntu-latest ] -# - { -# name: "macOS", -# os: macos-latest, -# generator: '-G "xcode"' -# } + os: [ windows_x64, ubuntu-latest, mac_arm ] steps: - name: Checkout