[macOS] Build infrastructure and portability fixes
Build system: - Enable ObjC++, macOS deployment target, framework linking - Fix AppleClang detection - macOS platform name for output directories - Skip Vulkan on macOS, null graphics without Vulkan dependency - macOS SDL2 framework detection and discord-rpc macOS sources Portability fixes: - mach_absolute_time for macOS tick counting - _NSGetExecutablePath for macOS - guard MAP_FIXED_NOREPLACE, ftruncate64->ftruncate - guard Vulkan include/usage, fix data root for all POSIX
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#ifdef __APPLE__
|
||||
#include <mach/mach_time.h>
|
||||
#endif
|
||||
|
||||
#include "xenia/base/assert.h"
|
||||
#include "xenia/base/clock.h"
|
||||
@@ -15,6 +18,12 @@
|
||||
namespace xe {
|
||||
|
||||
uint64_t Clock::host_tick_frequency_platform() {
|
||||
#ifdef __APPLE__
|
||||
mach_timebase_info_data_t info;
|
||||
mach_timebase_info(&info);
|
||||
return (uint64_t)((1000000000ull * (uint64_t)info.denom) /
|
||||
(uint64_t)info.numer);
|
||||
#else
|
||||
timespec res;
|
||||
int error = clock_getres(CLOCK_MONOTONIC_RAW, &res);
|
||||
assert_zero(error);
|
||||
@@ -22,14 +31,19 @@ uint64_t Clock::host_tick_frequency_platform() {
|
||||
|
||||
// Convert nano seconds to hertz. Resolution is 1ns on most systems.
|
||||
return 1000000000ull / res.tv_nsec;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t Clock::host_tick_count_platform() {
|
||||
#ifdef __APPLE__
|
||||
return mach_absolute_time();
|
||||
#else
|
||||
timespec tp;
|
||||
int error = clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
|
||||
assert_zero(error);
|
||||
|
||||
return tp.tv_nsec + tp.tv_sec * 1000000000ull;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t Clock::QueryHostSystemTime() {
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#if XE_PLATFORM_MAC
|
||||
#include <limits.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
namespace xe {
|
||||
|
||||
@@ -43,10 +47,26 @@ std::filesystem::path to_path(const std::u16string_view source) {
|
||||
namespace filesystem {
|
||||
|
||||
std::filesystem::path GetExecutablePath() {
|
||||
#if XE_PLATFORM_MAC
|
||||
char path[PATH_MAX];
|
||||
uint32_t size = sizeof(path);
|
||||
if (_NSGetExecutablePath(path, &size) == 0) {
|
||||
char real_path[PATH_MAX];
|
||||
if (realpath(path, real_path)) {
|
||||
return std::string(real_path);
|
||||
}
|
||||
return std::string(path);
|
||||
}
|
||||
return std::string();
|
||||
#else
|
||||
char buff[FILENAME_MAX] = "";
|
||||
readlink("/proc/self/exe", buff, FILENAME_MAX);
|
||||
std::string s(buff);
|
||||
return s;
|
||||
ssize_t len = readlink("/proc/self/exe", buff, sizeof(buff) - 1);
|
||||
if (len != -1) {
|
||||
buff[len] = '\0';
|
||||
return std::string(buff);
|
||||
}
|
||||
return std::string();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path GetExecutableFolder() {
|
||||
|
||||
@@ -146,7 +146,9 @@ void* AllocFixed(void* base_address, size_t length,
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
#ifdef MAP_FIXED_NOREPLACE
|
||||
flags |= MAP_FIXED_NOREPLACE;
|
||||
#endif
|
||||
}
|
||||
|
||||
void* result = mmap(base_address, length, prot, flags, -1, 0);
|
||||
@@ -296,7 +298,7 @@ FileMappingHandle CreateFileMappingHandle(const std::filesystem::path& path,
|
||||
if (ret < 0) {
|
||||
return kFileMappingHandleInvalid;
|
||||
}
|
||||
if (ftruncate64(ret, length) < 0) {
|
||||
if (ftruncate(ret, length) < 0) {
|
||||
close(ret);
|
||||
shm_unlink(full_path.c_str());
|
||||
return kFileMappingHandleInvalid;
|
||||
@@ -335,7 +337,9 @@ void* MapFileView(FileMappingHandle handle, void* base_address, size_t length,
|
||||
|
||||
int flags = MAP_SHARED;
|
||||
if (base_address != nullptr) {
|
||||
#ifdef MAP_FIXED_NOREPLACE
|
||||
flags |= MAP_FIXED_NOREPLACE;
|
||||
#endif
|
||||
}
|
||||
|
||||
void* result = mmap(base_address, length, prot, flags, handle, file_offset);
|
||||
|
||||
Reference in New Issue
Block a user