From 40cd585cefcbf2ceb6f9bd3d3f247e94df351807 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Thu, 14 Nov 2024 00:28:40 +0000 Subject: [PATCH] macOS 10.4: Guard non-existing APIs Based on @AJenbo's patch. --- CMake/Definitions.cmake | 2 ++ CMake/Platforms.cmake | 14 ++++++++++++++ Source/platform/locale.cpp | 2 +- Source/utils/file_util.cpp | 4 ++-- Source/utils/stdcompat/filesystem.hpp | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CMake/Definitions.cmake b/CMake/Definitions.cmake index 25ad6d215..7f04742e2 100644 --- a/CMake/Definitions.cmake +++ b/CMake/Definitions.cmake @@ -90,6 +90,8 @@ foreach( REMAP_KEYBOARD_KEYS DEVILUTIONX_DEFAULT_RESAMPLER STREAM_ALL_AUDIO_MIN_FILE_SIZE + DARWIN_MAJOR_VERSION + DARWIN_MINOR_VERSION ) if(DEFINED ${def_name} AND NOT ${def_name} STREQUAL "") list(APPEND DEVILUTIONX_DEFINITIONS ${def_name}=${${def_name}}) diff --git a/CMake/Platforms.cmake b/CMake/Platforms.cmake index 56e138f1b..7cf5d1692 100644 --- a/CMake/Platforms.cmake +++ b/CMake/Platforms.cmake @@ -75,3 +75,17 @@ endif() if(NXDK) include(platforms/xbox_nxdk) endif() + +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + # Some notable Darwin (macOS kernel) versions are: + # 8.x == macOS 10.4 (Tiger) + # 9.x == macOS 10.5 (Leopard) + # + # Importantly, a lot of the APIs first appeared in version 9, including + # the feature availability API (the header). + # + # For Darwin 8 and below, we have to rely on the kernel version + # to detect available APIs. + string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}") + string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}") +endif() diff --git a/Source/platform/locale.cpp b/Source/platform/locale.cpp index c00790e56..c72fa4d00 100644 --- a/Source/platform/locale.cpp +++ b/Source/platform/locale.cpp @@ -161,7 +161,7 @@ std::vector GetLocales() locales.push_back(std::move(locale)); } #endif -#elif defined(__APPLE__) && defined(USE_COREFOUNDATION) +#elif defined(__APPLE__) && defined(USE_COREFOUNDATION) && DARWIN_MAJOR_VERSION >= 9 // Get the user's language list (in order of preference) CFArrayRef languages = CFLocaleCopyPreferredLanguages(); CFIndex numLanguages = CFArrayGetCount(languages); diff --git a/Source/utils/file_util.cpp b/Source/utils/file_util.cpp index 95fe7b58d..4c04d4b77 100644 --- a/Source/utils/file_util.cpp +++ b/Source/utils/file_util.cpp @@ -36,7 +36,7 @@ #include #endif -#ifdef __APPLE__ +#if defined(__APPLE__) && DARWIN_MAJOR_VERSION >= 9 #include #endif @@ -346,7 +346,7 @@ void CopyFileOverwrite(const char *from, const char *to) if (!::CopyFileW(&fromUtf16[0], &toUtf16[0], /*bFailIfExists=*/false)) { LogError("Failed to copy {} to {}", from, to); } -#elif defined(__APPLE__) +#elif defined(__APPLE__) && DARWIN_MAJOR_VERSION >= 9 ::copyfile(from, to, nullptr, COPYFILE_ALL); #elif defined(DVL_HAS_FILESYSTEM) std::error_code error; diff --git a/Source/utils/stdcompat/filesystem.hpp b/Source/utils/stdcompat/filesystem.hpp index 938f029f7..a0e516e3a 100644 --- a/Source/utils/stdcompat/filesystem.hpp +++ b/Source/utils/stdcompat/filesystem.hpp @@ -1,6 +1,6 @@ #pragma once -#if defined(__APPLE__) +#if defined(__APPLE__) && DARWIN_MAJOR_VERSION >= 9 #include #if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500) \ || (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000)