From 565fdafbebb74f93ca88ab788396cbd12013e9ff Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 10 Oct 2024 21:11:26 +0200 Subject: [PATCH 1/2] Add ResourceLoaderAppDirMacOS --- .../Host/MacOS/ResourceLoaderAppDirMacOS.cpp | 57 +++++++++++++++++++ .../Host/MacOS/ResourceLoaderAppDirMacOS.hpp | 19 +++++++ 2 files changed, 76 insertions(+) create mode 100644 openVulkanoCpp/Host/MacOS/ResourceLoaderAppDirMacOS.cpp create mode 100644 openVulkanoCpp/Host/MacOS/ResourceLoaderAppDirMacOS.hpp diff --git a/openVulkanoCpp/Host/MacOS/ResourceLoaderAppDirMacOS.cpp b/openVulkanoCpp/Host/MacOS/ResourceLoaderAppDirMacOS.cpp new file mode 100644 index 0000000..c9973dc --- /dev/null +++ b/openVulkanoCpp/Host/MacOS/ResourceLoaderAppDirMacOS.cpp @@ -0,0 +1,57 @@ +/* + * 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 "ResourceLoaderAppDirMacOS.hpp" +#include "Base/Utils.hpp" +#include +#include +#include +#include +#include + +namespace OpenVulkano +{ + namespace + { + void* HANDLE = ResourceLoader::RegisterResourceLoader(std::make_unique()); + + std::string FindAppDir() + { + char pathBuffer[PATH_MAX]; + uint32_t bufferSize = sizeof(pathBuffer); + + if (_NSGetExecutablePath(pathBuffer, &bufferSize) == 0) + { + char resolvedPath[PATH_MAX]; + if (realpath(pathBuffer, resolvedPath) != nullptr) + { + std::string_view appDirPath(resolvedPath); + appDirPath = appDirPath.substr(0, appDirPath.find_last_of('/') + 1); + return std::string(appDirPath); + } + } + + std::cerr << "Failed to find real path to application!"; + return ""; + } + + const std::string& GetAppDir() + { + static const std::string appDirPath = FindAppDir(); + return appDirPath; + } + } + + std::string ResourceLoaderAppDirMacOS::GetResourcePath(const std::string& resourceName) + { + return GetAppDir() + resourceName; + } + + Array ResourceLoaderAppDirMacOS::GetResource(const std::string& resourceName) + { + return Utils::ReadFile(GetAppDir() + resourceName, true); + } +} \ No newline at end of file diff --git a/openVulkanoCpp/Host/MacOS/ResourceLoaderAppDirMacOS.hpp b/openVulkanoCpp/Host/MacOS/ResourceLoaderAppDirMacOS.hpp new file mode 100644 index 0000000..2e65340 --- /dev/null +++ b/openVulkanoCpp/Host/MacOS/ResourceLoaderAppDirMacOS.hpp @@ -0,0 +1,19 @@ +/* + * 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/. + */ + +#pragma once + +#include "Host/ResourceLoader.hpp" + +namespace OpenVulkano +{ + class ResourceLoaderAppDirMacOS final : public ResourceLoader + { + public: + std::string GetResourcePath(const std::string& resourceName) override; + Array GetResource(const std::string& resourceName) override; + }; +} \ No newline at end of file From 552cbd3925e26f372c61eac7773cd333b19dd770 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Thu, 10 Oct 2024 21:11:43 +0200 Subject: [PATCH 2/2] Fix system freetype detection --- 3rdParty/msdf/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/3rdParty/msdf/CMakeLists.txt b/3rdParty/msdf/CMakeLists.txt index c43c63b..a8e3600 100644 --- a/3rdParty/msdf/CMakeLists.txt +++ b/3rdParty/msdf/CMakeLists.txt @@ -13,11 +13,11 @@ if (ENABLE_MSDF) set(FREETYPE_REPO https://github.com/freetype/freetype.git) endif() - unset(Freetype_FOUND) - if (NOT APPLE) - find_package(Freetype QUIET) + unset(freetype_FOUND) + if (NOT IOS) + find_package(freetype QUIET) endif () - if (NOT Freetype_FOUND OR NOT EXISTS "${CMAKE_BINARY_DIR}/_deps/freetype-src/build") + if (NOT freetype_FOUND OR NOT EXISTS "${CMAKE_BINARY_DIR}/_deps/freetype-src/build") message("Installing freetype from sources") FetchContent_Declare( freetype