From a838078341395bf11e7ee71b8c765dafec12629d 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 a63be7ac822..14041b6ce1e 100644 --- a/CMake/Definitions.cmake +++ b/CMake/Definitions.cmake @@ -94,6 +94,8 @@ foreach( STREAM_ALL_AUDIO_MIN_FILE_SIZE DEVILUTIONX_DISPLAY_TEXTURE_FORMAT DEVILUTIONX_SCREENSHOT_FORMAT + 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 1c3d1e927b4..76cd0d98a59 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 dba90787dde..06c68a1b991 100644 --- a/Source/platform/locale.cpp +++ b/Source/platform/locale.cpp @@ -160,7 +160,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 7dd7de82cc9..e7091834814 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 @@ -397,7 +397,7 @@ void CopyFileOverwrite(const char *from, const char *to) LogError("Failed to copy {} to {}", from, to); } #endif // _WIN32 -#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 b3f19a652dc..38c2f7d0bf7 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)