CommonFuncsObjC: Make function to fetch the current macOS version common
This commit is contained in:
@@ -204,6 +204,7 @@ if (APPLE)
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
${APPKIT_LIBRARY}
|
${APPKIT_LIBRARY}
|
||||||
${COREFOUNDATION_LIBRARY}
|
${COREFOUNDATION_LIBRARY}
|
||||||
|
${FOUNDATION_LIBRARY}
|
||||||
${IOK_LIBRARY}
|
${IOK_LIBRARY}
|
||||||
)
|
)
|
||||||
elseif(WIN32)
|
elseif(WIN32)
|
||||||
@@ -239,6 +240,7 @@ elseif(WIN32)
|
|||||||
)
|
)
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
target_sources(common PRIVATE
|
target_sources(common PRIVATE
|
||||||
|
CommonFuncsObjC.mm
|
||||||
Logging/ConsoleListenerNix.cpp
|
Logging/ConsoleListenerNix.cpp
|
||||||
MemArenaDarwin.cpp
|
MemArenaDarwin.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,6 +8,10 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include "Common/CommonTypes.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
|
||||||
// go to debugger mode
|
// go to debugger mode
|
||||||
@@ -61,4 +65,17 @@ std::string GetWin32ErrorString(unsigned long error_code);
|
|||||||
// Obtains a full path to the specified module.
|
// Obtains a full path to the specified module.
|
||||||
std::optional<std::wstring> GetModuleName(void* hInstance);
|
std::optional<std::wstring> GetModuleName(void* hInstance);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
struct MacOSVersion // NSOperatingSystemVersion
|
||||||
|
{
|
||||||
|
s64 major; // NSInteger majorVersion
|
||||||
|
s64 minor; // NSInteger minorVersion
|
||||||
|
s64 patch; // NSInteger patchVersion
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function to get the current macOS version, which is easy to do with
|
||||||
|
// from Objective-C code, but a little harder from C++.
|
||||||
|
MacOSVersion GetMacOSVersion();
|
||||||
|
#endif
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2026 Dolphin Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "Common/CommonFuncs.h"
|
||||||
|
|
||||||
|
#include <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
namespace Common
|
||||||
|
{
|
||||||
|
MacOSVersion GetMacOSVersion()
|
||||||
|
{
|
||||||
|
const NSOperatingSystemVersion ver = [[NSProcessInfo processInfo] operatingSystemVersion];
|
||||||
|
return {ver.majorVersion, ver.minorVersion, ver.patchVersion};
|
||||||
|
}
|
||||||
|
} // namespace Common
|
||||||
@@ -15,14 +15,16 @@
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include "Common/WindowsRegistry.h"
|
#include "Common/WindowsRegistry.h"
|
||||||
#elif defined(__APPLE__)
|
|
||||||
#include <objc/message.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ANDROID)
|
#if defined(ANDROID)
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "Common/CommonFuncs.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "Common/Analytics.h"
|
#include "Common/Analytics.h"
|
||||||
#include "Common/CPUDetect.h"
|
#include "Common/CPUDetect.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
@@ -300,32 +302,10 @@ void DolphinAnalytics::MakeBaseBuilder()
|
|||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
builder.AddData("os-type", "osx");
|
builder.AddData("os-type", "osx");
|
||||||
|
|
||||||
// id processInfo = [NSProcessInfo processInfo]
|
Common::MacOSVersion version = Common::GetMacOSVersion();
|
||||||
id processInfo = reinterpret_cast<id (*)(Class, SEL)>(objc_msgSend)(
|
builder.AddData("osx-ver-major", version.major);
|
||||||
objc_getClass("NSProcessInfo"), sel_getUid("processInfo"));
|
builder.AddData("osx-ver-minor", version.minor);
|
||||||
if (processInfo)
|
builder.AddData("osx-ver-bugfix", version.patch);
|
||||||
{
|
|
||||||
struct OSVersion // NSOperatingSystemVersion
|
|
||||||
{
|
|
||||||
s64 major_version; // NSInteger majorVersion
|
|
||||||
s64 minor_version; // NSInteger minorVersion
|
|
||||||
s64 patch_version; // NSInteger patchVersion
|
|
||||||
};
|
|
||||||
// Under arm64, we need to call objc_msgSend to receive a struct.
|
|
||||||
// On x86_64, we need to explicitly call objc_msgSend_stret for a struct.
|
|
||||||
#ifdef _M_ARM_64
|
|
||||||
#define msgSend objc_msgSend
|
|
||||||
#else
|
|
||||||
#define msgSend objc_msgSend_stret
|
|
||||||
#endif
|
|
||||||
// NSOperatingSystemVersion version = [processInfo operatingSystemVersion]
|
|
||||||
OSVersion version = reinterpret_cast<OSVersion (*)(id, SEL)>(msgSend)(
|
|
||||||
processInfo, sel_getUid("operatingSystemVersion"));
|
|
||||||
#undef msgSend
|
|
||||||
builder.AddData("osx-ver-major", version.major_version);
|
|
||||||
builder.AddData("osx-ver-minor", version.minor_version);
|
|
||||||
builder.AddData("osx-ver-bugfix", version.patch_version);
|
|
||||||
}
|
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
builder.AddData("os-type", "linux");
|
builder.AddData("os-type", "linux");
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
|
|||||||
Reference in New Issue
Block a user