Build Nazara on macos up to Nazara_network (not included

This commit is contained in:
ImperatorS79 2020-11-21 20:05:19 +01:00
parent d243e7bcd2
commit 4bf49876c6
13 changed files with 158 additions and 18 deletions

View File

@ -159,6 +159,15 @@ function NazaraBuild:Execute()
"../thirdparty/include" "../thirdparty/include"
}) })
if (os.ishost("macosx")) then
includedirs({
"../include",
"../src/",
"../thirdparty/include",
"/usr/local/include/" --brew
})
end
files(moduleTable.Files) files(moduleTable.Files)
excludes(moduleTable.FilesExcluded) excludes(moduleTable.FilesExcluded)
@ -172,6 +181,14 @@ function NazaraBuild:Execute()
"../lib" "../lib"
}) })
if (os.ishost("macosx")) then
libdirs({
"../thirdparty/lib/common",
"../lib",
"/usr/local/lib" --brew
})
end
-- Output to lib/conf/arch -- Output to lib/conf/arch
self:FilterLibDirectory("../lib/", targetdir) self:FilterLibDirectory("../lib/", targetdir)
@ -928,7 +945,10 @@ end
function NazaraBuild:PostconfigGenericProject() function NazaraBuild:PostconfigGenericProject()
-- Add options required for C++17 thread and filesystem (have to be linked last) -- Add options required for C++17 thread and filesystem (have to be linked last)
filter("action:gmake*") filter({"action:gmake*", "system:macosx"})
links("pthread")
filter({"action:gmake*", "system:not macosx"})
links("stdc++fs") links("stdc++fs")
links("pthread") links("pthread")

View File

@ -21,11 +21,15 @@ MODULE.OsDefines.Windows = {
"SDL_VIDEO_DRIVER_WINDOWS=1" "SDL_VIDEO_DRIVER_WINDOWS=1"
} }
MODULE.OsDefines.Posix = {
"SDL_VIDEO_DRIVER_X11=1",
"SDL_VIDEO_DRIVER_WAYLAND=1",
}
MODULE.DynLib = { MODULE.DynLib = {
"SDL2" "SDL2"
} }
MODULE.Custom = function()
filter("system:linux")
defines("SDL_VIDEO_DRIVER_X11=1")
defines("SDL_VIDEO_DRIVER_WAYLAND=1")
filter("system:macosx")
defines("SDL_VIDEO_DRIVER_COCOA=1")
end

View File

@ -97,7 +97,7 @@ namespace Nz
} }
}; };
#ifdef NAZARA_PLATFORM_POSIX #ifdef NAZARA_PLATFORM_LINUX
template<typename T> template<typename T>
void SinCos(std::enable_if_t<!std::is_same<T, float>::value && !std::is_same<T, long double>::value, double> x, T* sin, T* cos) void SinCos(std::enable_if_t<!std::is_same<T, float>::value && !std::is_same<T, long double>::value, double> x, T* sin, T* cos)
{ {

View File

@ -121,9 +121,12 @@
#define NAZARA_EXPORT __attribute__((visibility ("default"))) #define NAZARA_EXPORT __attribute__((visibility ("default")))
#define NAZARA_IMPORT __attribute__((visibility ("default"))) #define NAZARA_IMPORT __attribute__((visibility ("default")))
/*#elif defined(__APPLE__) && defined(__MACH__) #elif defined(__APPLE__) && defined(__MACH__)
#define NAZARA_PLATFORM_MACOSX #define NAZARA_PLATFORM_MACOSX
#define NAZARA_PLATFORM_POSIX*/ #define NAZARA_PLATFORM_POSIX
#define NAZARA_EXPORT __attribute__((visibility ("default")))
#define NAZARA_IMPORT __attribute__((visibility ("default")))
#else #else
#error This operating system is not fully supported by the Nazara Engine #error This operating system is not fully supported by the Nazara Engine

View File

@ -68,6 +68,7 @@ namespace Nz
virtual void Value(UInt16& val) = 0; virtual void Value(UInt16& val) = 0;
virtual void Value(UInt32& val) = 0; virtual void Value(UInt32& val) = 0;
virtual void Value(UInt64& val) = 0; virtual void Value(UInt64& val) = 0;
virtual void Value(std::size_t& val) = 0;
inline void SizeT(std::size_t& val); inline void SizeT(std::size_t& val);
virtual void Variable(ShaderNodes::VariablePtr& var) = 0; virtual void Variable(ShaderNodes::VariablePtr& var) = 0;
@ -101,6 +102,7 @@ namespace Nz
void Value(UInt16& val) override; void Value(UInt16& val) override;
void Value(UInt32& val) override; void Value(UInt32& val) override;
void Value(UInt64& val) override; void Value(UInt64& val) override;
void Value(std::size_t& val) override;
void Variable(ShaderNodes::VariablePtr& var) override; void Variable(ShaderNodes::VariablePtr& var) override;
ByteStream& m_stream; ByteStream& m_stream;
@ -132,6 +134,7 @@ namespace Nz
void Value(UInt16& val) override; void Value(UInt16& val) override;
void Value(UInt32& val) override; void Value(UInt32& val) override;
void Value(UInt64& val) override; void Value(UInt64& val) override;
void Value(std::size_t& val) override;
void Variable(ShaderNodes::VariablePtr& var) override; void Variable(ShaderNodes::VariablePtr& var) override;
ByteStream& m_stream; ByteStream& m_stream;

View File

@ -132,7 +132,11 @@ namespace Nz
"libopenal.so.0", "libopenal.so.0",
"libopenal.so" "libopenal.so"
}; };
//#elif defined(NAZARA_PLATFORM_MACOSX) #elif defined(NAZARA_PLATFORM_MACOSX)
const char* libs[] = {
"libopenal.dylib",
"libopenal.1.dylib",
};
#else #else
NazaraError("Unknown OS"); NazaraError("Unknown OS");
return false; return false;

View File

@ -31,8 +31,8 @@ namespace Nz
{ {
if (!m_endOfFileUpdated) if (!m_endOfFileUpdated)
{ {
struct stat64 fileSize; struct Stat fileSize;
if (fstat64(m_fileDescriptor, &fileSize) == -1) if (Fstat(m_fileDescriptor, &fileSize) == -1)
fileSize.st_size = 0; fileSize.st_size = 0;
m_endOfFile = (GetCursorPos() >= static_cast<UInt64>(fileSize.st_size)); m_endOfFile = (GetCursorPos() >= static_cast<UInt64>(fileSize.st_size));
@ -50,7 +50,7 @@ namespace Nz
UInt64 FileImpl::GetCursorPos() const UInt64 FileImpl::GetCursorPos() const
{ {
off64_t position = lseek64(m_fileDescriptor, 0, SEEK_CUR); Off_t position = Lseek(m_fileDescriptor, 0, SEEK_CUR);
return static_cast<UInt64>(position); return static_cast<UInt64>(position);
} }
@ -77,7 +77,7 @@ namespace Nz
if (mode & OpenMode_Truncate) if (mode & OpenMode_Truncate)
flags |= O_TRUNC; flags |= O_TRUNC;
int fileDescriptor = open64(filePath.generic_u8string().data(), flags, permissions); int fileDescriptor = Open_def(filePath.generic_u8string().data(), flags, permissions);
if (fileDescriptor == -1) if (fileDescriptor == -1)
{ {
NazaraError("Failed to open \"" + filePath.generic_u8string() + "\" : " + Error::GetLastSystemError()); NazaraError("Failed to open \"" + filePath.generic_u8string() + "\" : " + Error::GetLastSystemError());
@ -166,12 +166,12 @@ namespace Nz
m_endOfFileUpdated = false; m_endOfFileUpdated = false;
return lseek64(m_fileDescriptor, offset, moveMethod) != -1; return Lseek(m_fileDescriptor, offset, moveMethod) != -1;
} }
bool FileImpl::SetSize(UInt64 size) bool FileImpl::SetSize(UInt64 size)
{ {
return ftruncate64(m_fileDescriptor, size) != 0; return Ftruncate(m_fileDescriptor, size) != 0;
} }
std::size_t FileImpl::Write(const void* buffer, std::size_t size) std::size_t FileImpl::Write(const void* buffer, std::size_t size)

View File

@ -16,6 +16,24 @@
#include <ctime> #include <ctime>
#include <filesystem> #include <filesystem>
#if defined(NAZARA_PLATFORM_MACOSX)
#define Stat stat
#define Fstat fstat
#define Off_t off_t
#define Lseek lseek
#define Open_def open
#define Ftruncate ftruncate
#elif defined(NAZARA_PLATFORM_LINUX)
#define Stat stat64
#define Fstat fstat64
#define Off_t off64_t
#define Lseek lseek64
#define Open_def open64
#define Ftruncate ftruncate64
#else
#error This operating system is not fully supported by the Nazara Engine
#endif
namespace Nz namespace Nz
{ {
class File; class File;

View File

@ -6,6 +6,10 @@
#include <Nazara/Core/Functor.hpp> #include <Nazara/Core/Functor.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
#if defined(NAZARA_PLATFORM_MACOSX)
#include <errno.h>
#endif
namespace Nz namespace Nz
{ {
bool TaskSchedulerImpl::Initialize(unsigned int workerCount) bool TaskSchedulerImpl::Initialize(unsigned int workerCount)
@ -191,4 +195,55 @@ namespace Nz
pthread_cond_t TaskSchedulerImpl::s_cvEmpty; pthread_cond_t TaskSchedulerImpl::s_cvEmpty;
pthread_cond_t TaskSchedulerImpl::s_cvNotEmpty; pthread_cond_t TaskSchedulerImpl::s_cvNotEmpty;
pthread_barrier_t TaskSchedulerImpl::s_barrier; pthread_barrier_t TaskSchedulerImpl::s_barrier;
#if defined(NAZARA_PLATFORM_MACOSX)
//Code from https://blog.albertarmea.com/post/47089939939/using-pthreadbarrier-on-mac-os-x
int TaskSchedulerImpl::pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
{
if(count == 0)
{
errno = EINVAL;
return -1;
}
if(pthread_mutex_init(&barrier->mutex, 0) < 0)
{
return -1;
}
if(pthread_cond_init(&barrier->cond, 0) < 0)
{
pthread_mutex_destroy(&barrier->mutex);
return -1;
}
barrier->tripCount = count;
barrier->count = 0;
return 0;
}
int TaskSchedulerImpl::pthread_barrier_destroy(pthread_barrier_t *barrier)
{
pthread_cond_destroy(&barrier->cond);
pthread_mutex_destroy(&barrier->mutex);
return 0;
}
int TaskSchedulerImpl::pthread_barrier_wait(pthread_barrier_t *barrier)
{
pthread_mutex_lock(&barrier->mutex);
++(barrier->count);
if(barrier->count >= barrier->tripCount)
{
barrier->count = 0;
pthread_cond_broadcast(&barrier->cond);
pthread_mutex_unlock(&barrier->mutex);
return 1;
}
else
{
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
pthread_mutex_unlock(&barrier->mutex);
return 0;
}
}
#endif
} }

View File

@ -13,6 +13,17 @@
#include <pthread.h> #include <pthread.h>
#include <queue> #include <queue>
#if defined(NAZARA_PLATFORM_MACOSX)
typedef int pthread_barrierattr_t;
typedef struct
{
pthread_mutex_t mutex;
pthread_cond_t cond;
int count;
int tripCount;
} pthread_barrier_t;
#endif
namespace Nz namespace Nz
{ {
struct Functor; struct Functor;
@ -45,6 +56,12 @@ namespace Nz
static pthread_cond_t s_cvEmpty; static pthread_cond_t s_cvEmpty;
static pthread_cond_t s_cvNotEmpty; static pthread_cond_t s_cvNotEmpty;
static pthread_barrier_t s_barrier; static pthread_barrier_t s_barrier;
#if defined(NAZARA_PLATFORM_MACOSX)
static int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count);
static int pthread_barrier_destroy(pthread_barrier_t *barrier);
static int pthread_barrier_wait(pthread_barrier_t *barrier);
#endif
}; };
} }

View File

@ -157,7 +157,7 @@ namespace Nz
#elif defined(NAZARA_PLATFORM_LINUX) #elif defined(NAZARA_PLATFORM_LINUX)
std::string_view temp(string); std::string_view temp(string);
// Nothing to do // Nothing to do
#elif defined(NAZARA_PLATFORM_MACOS) #elif defined(NAZARA_PLATFORM_MACOSX)
std::string temp(string); std::string temp(string);
ReplaceStr(temp, "\n", "\r"); ReplaceStr(temp, "\n", "\r");
#endif #endif

View File

@ -466,6 +466,11 @@ namespace Nz
m_stream << val; m_stream << val;
} }
void ShaderAstSerializer::Value(std::size_t& val)
{
m_stream << val;
}
void ShaderAstSerializer::Variable(ShaderNodes::VariablePtr& var) void ShaderAstSerializer::Variable(ShaderNodes::VariablePtr& var)
{ {
ShaderNodes::VariableType nodeType = (var) ? var->GetType() : ShaderNodes::VariableType::None; ShaderNodes::VariableType nodeType = (var) ? var->GetType() : ShaderNodes::VariableType::None;
@ -732,6 +737,11 @@ namespace Nz
m_stream >> val; m_stream >> val;
} }
void ShaderAstUnserializer::Value(std::size_t& val)
{
m_stream >> val;
}
void ShaderAstUnserializer::Variable(ShaderNodes::VariablePtr& var) void ShaderAstUnserializer::Variable(ShaderNodes::VariablePtr& var)
{ {
Int32 nodeTypeInt; Int32 nodeTypeInt;

View File

@ -36,4 +36,10 @@ LIBRARY.Custom = function()
filter({"architecture:x86", "system:linux"}) filter({"architecture:x86", "system:linux"})
defines("_POSIX_VER") defines("_POSIX_VER")
filter({"architecture:x86_64", "system:macosx"})
defines("_POSIX_VER_64")
filter({"architecture:x86", "system:macosx"})
defines("_POSIX_VER")
end end