Skip to content

Commit

Permalink
macOS 10.4: Guard non-existing APIs
Browse files Browse the repository at this point in the history
Based on @AJenbo's patch.
  • Loading branch information
glebm authored and AJenbo committed Nov 15, 2024
1 parent cfac786 commit a838078
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMake/Definitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand Down
14 changes: 14 additions & 0 deletions CMake/Platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Availability.h> 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()
2 changes: 1 addition & 1 deletion Source/platform/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ std::vector<std::string> 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);
Expand Down
4 changes: 2 additions & 2 deletions Source/utils/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <unistd.h>
#endif

#ifdef __APPLE__
#if defined(__APPLE__) && DARWIN_MAJOR_VERSION >= 9
#include <copyfile.h>
#endif

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/utils/stdcompat/filesystem.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#if defined(__APPLE__)
#if defined(__APPLE__) && DARWIN_MAJOR_VERSION >= 9
#include <Availability.h>
#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)
Expand Down

0 comments on commit a838078

Please sign in to comment.