Merge pull request #328 from ImperatorS79/nazara-next

Build Nazara on macos (everything compile except NazaraVulkan/OpenGLRenderer)
This commit is contained in:
Jérôme Leclercq 2021-01-26 16:41:16 +01:00 committed by GitHub
commit afe190041f
21 changed files with 192 additions and 33 deletions

View File

@ -159,6 +159,15 @@ function NazaraBuild:Execute()
"../thirdparty/include"
})
if (os.ishost("macosx")) then
includedirs({
"../include",
"../src/",
"../thirdparty/include",
"/usr/local/include/" --brew
})
end
files(moduleTable.Files)
excludes(moduleTable.FilesExcluded)
@ -172,6 +181,14 @@ function NazaraBuild:Execute()
"../lib"
})
if (os.ishost("macosx")) then
libdirs({
"../thirdparty/lib/common",
"../lib",
"/usr/local/lib" --brew
})
end
-- Output to lib/conf/arch
self:FilterLibDirectory("../lib/", targetdir)
@ -928,7 +945,10 @@ end
function NazaraBuild:PostconfigGenericProject()
-- 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("pthread")

View File

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

View File

@ -21,11 +21,15 @@ MODULE.OsDefines.Windows = {
"SDL_VIDEO_DRIVER_WINDOWS=1"
}
MODULE.OsDefines.Posix = {
"SDL_VIDEO_DRIVER_X11=1",
"SDL_VIDEO_DRIVER_WAYLAND=1",
}
MODULE.DynLib = {
"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>
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_IMPORT __attribute__((visibility ("default")))
/*#elif defined(__APPLE__) && defined(__MACH__)
#define NAZARA_PLATFORM_MACOSX
#define NAZARA_PLATFORM_POSIX*/
#elif defined(__APPLE__) && defined(__MACH__)
#define NAZARA_PLATFORM_MACOSX
#define NAZARA_PLATFORM_POSIX
#define NAZARA_EXPORT __attribute__((visibility ("default")))
#define NAZARA_IMPORT __attribute__((visibility ("default")))
#else
#error This operating system is not fully supported by the Nazara Engine

View File

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

View File

@ -31,8 +31,8 @@ namespace Nz
{
if (!m_endOfFileUpdated)
{
struct stat64 fileSize;
if (fstat64(m_fileDescriptor, &fileSize) == -1)
struct Stat fileSize;
if (Fstat(m_fileDescriptor, &fileSize) == -1)
fileSize.st_size = 0;
m_endOfFile = (GetCursorPos() >= static_cast<UInt64>(fileSize.st_size));
@ -50,7 +50,7 @@ namespace Nz
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);
}
@ -77,7 +77,7 @@ namespace Nz
if (mode & OpenMode_Truncate)
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)
{
NazaraError("Failed to open \"" + filePath.generic_u8string() + "\" : " + Error::GetLastSystemError());
@ -166,12 +166,12 @@ namespace Nz
m_endOfFileUpdated = false;
return lseek64(m_fileDescriptor, offset, moveMethod) != -1;
return Lseek(m_fileDescriptor, offset, moveMethod) != -1;
}
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)

View File

@ -16,6 +16,24 @@
#include <ctime>
#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
{
class File;

View File

@ -6,6 +6,10 @@
#include <Nazara/Core/Functor.hpp>
#include <Nazara/Core/Debug.hpp>
#if defined(NAZARA_PLATFORM_MACOSX)
#include <errno.h>
#endif
namespace Nz
{
bool TaskSchedulerImpl::Initialize(unsigned int workerCount)
@ -191,4 +195,55 @@ namespace Nz
pthread_cond_t TaskSchedulerImpl::s_cvEmpty;
pthread_cond_t TaskSchedulerImpl::s_cvNotEmpty;
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 <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
{
struct Functor;
@ -45,6 +56,12 @@ namespace Nz
static pthread_cond_t s_cvEmpty;
static pthread_cond_t s_cvNotEmpty;
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)
std::string_view temp(string);
// Nothing to do
#elif defined(NAZARA_PLATFORM_MACOS)
#elif defined(NAZARA_PLATFORM_MACOSX)
std::string temp(string);
ReplaceStr(temp, "\n", "\r");
#endif

View File

@ -17,6 +17,10 @@
#include <cstring>
#include <Nazara/Network/Debug.hpp>
#if !defined(TCP_KEEPIDLE) && defined(TCP_KEEPALIVE)
#define TCP_KEEPIDLE TCP_KEEPALIVE // see -> https://gitlab.freedesktop.org/spice/usbredir/-/issues/9
#endif
namespace Nz
{
constexpr int SOCKET_ERROR = -1;
@ -269,6 +273,9 @@ namespace Nz
unsigned int code;
socklen_t codeLength = sizeof(code);
#if defined(NAZARA_PLATFORM_MACOSX)
return 0; //No IP_MTU on macosx
#else
if (getsockopt(handle, IPPROTO_IP, IP_MTU, &code, &codeLength) == SOCKET_ERROR)
{
if (error)
@ -276,6 +283,7 @@ namespace Nz
return 0;
}
#endif
if (error)
*error = SocketError_NoError;
@ -597,8 +605,11 @@ namespace Nz
}
IpAddress senderIp;
#if defined(MSG_NOSIGNAL)
int byteRead = recvmsg(handle, &msgHdr, MSG_NOSIGNAL);
#else
int byteRead = recvmsg(handle, &msgHdr, 0);
#endif
if (byteRead == -1)
{
int errorCode = GetLastErrorCode();
@ -714,7 +725,12 @@ namespace Nz
msgHdr.msg_iov = sysBuffers.data();
msgHdr.msg_iovlen = static_cast<int>(bufferCount);
#if defined(MSG_NOSIGNAL)
int byteSent = sendmsg(handle, &msgHdr, MSG_NOSIGNAL);
#else
int byteSent = sendmsg(handle, &msgHdr, 0);
#endif
if (byteSent == SOCKET_ERROR)
{
int errorCode = GetLastErrorCode();
@ -897,6 +913,18 @@ namespace Nz
if (error)
*error = SocketError_NoError;
#if not defined(MSG_NOSIGNAL) // -> https://github.com/intel/parameter-framework/pull/133/files
//There is no MSG_NOSIGNAL on macos
const int set = 1;
if (setsockopt(handle, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(set)) == SOCKET_ERROR)
{
if (error)
*error = TranslateErrnoToSocketError(GetLastErrorCode());
return false; //< Error
}
#endif
return true;
}

View File

@ -258,7 +258,7 @@ namespace Nz
void ShaderAstSerializerBase::Serialize(ShaderNodes::SwizzleOp& node)
{
Value(node.componentCount);
SizeT(node.componentCount);
Node(node.expression);
for (std::size_t i = 0; i < node.componentCount; ++i)

View File

@ -332,7 +332,7 @@ void BufferField::PopulateFieldList(std::size_t structIndex, const std::string&
else if constexpr (std::is_same_v<T, std::size_t>)
PopulateFieldList(arg, prefix + member.name + ".");
else
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
static_assert(Nz::AlwaysFalse<T>::value, "non-exhaustive visitor");
},
member.type);
}

View File

@ -2,6 +2,7 @@
#include <Nazara/Shader/ShaderBuilder.hpp>
#include <QtWidgets/QDoubleSpinBox>
#include <QtWidgets/QFormLayout>
#include <QtCore/QJsonArray>
#include <stdexcept>
template<std::size_t ToComponentCount>

View File

@ -48,7 +48,7 @@ struct VecExpressionTypeHelper<4>
static constexpr Nz::ShaderNodes::BasicType ExpressionType = Nz::ShaderNodes::BasicType::Float4;
};
template<std::size_t N> constexpr Nz::ShaderNodes::BasicType VecExpressionType = VecExpressionTypeHelper<N>::template ExpressionType;
template<std::size_t N> constexpr Nz::ShaderNodes::BasicType VecExpressionType = VecExpressionTypeHelper<N>::ExpressionType;
struct VecTypeDummy {};
@ -86,7 +86,7 @@ struct VecTypeHelper<4>
using Type = Nz::Vector4f;
};
template<std::size_t N> using VecType = typename VecTypeHelper<N>::template Type;
template<std::size_t N> using VecType = typename VecTypeHelper<N>::Type;
constexpr std::array<char, 4> s_vectorComponents = { 'X', 'Y', 'Z', 'W' };

View File

@ -64,7 +64,7 @@ m_type(ShaderType::NotSet)
{ "position", PrimitiveType::Float3 },
{ "normal", PrimitiveType::Float3 },
{ "uv", PrimitiveType::Float2 },
{ "inner", 2 }
{ "inner", 2u }
}
});
AddStruct("InnerStruct", {
@ -74,7 +74,7 @@ m_type(ShaderType::NotSet)
});
AddStruct("OuterStruct", {
{
{ "a", 1 },
{ "a", 1u },
{ "b", PrimitiveType::Float1 }
}
});
@ -266,7 +266,7 @@ void ShaderGraph::Load(const QJsonObject& data)
if (typeDocRef.isString())
memberInfo.type = DecodeEnum<PrimitiveType>(typeDocRef.toString().toStdString()).value();
else
memberInfo.type = typeDocRef.toInt();
memberInfo.type = static_cast<std::size_t>(typeDocRef.toInt());
}
}
@ -363,7 +363,7 @@ QJsonObject ShaderGraph::Save()
else if constexpr (std::is_same_v<T, std::size_t>)
memberDoc["type"] = int(arg);
else
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
static_assert(Nz::AlwaysFalse<T>::value, "non-exhaustive visitor");
}, member.type);
memberArray.append(std::move(memberDoc));
@ -535,7 +535,7 @@ Nz::ShaderExpressionType ShaderGraph::ToShaderExpressionType(const std::variant<
return s.name;
}
else
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
static_assert(Nz::AlwaysFalse<T>::value, "non-exhaustive visitor");
}, type);
};

View File

@ -269,7 +269,7 @@ Nz::ShaderAst MainWindow::ToShader()
else if constexpr (std::is_same_v<T, std::size_t>)
member.type = m_shaderGraph.GetStruct(arg).name;
else
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
static_assert(Nz::AlwaysFalse<T>::value, "non-exhaustive visitor");
}, sMember.type);
}

View File

@ -97,7 +97,7 @@ QString StructEditDialog::GetMemberName(const StructInfo::Member& member)
else if constexpr (std::is_same_v<T, std::size_t>)
name += QString::fromStdString(m_shaderGraph.GetStruct(arg).name);
else
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
static_assert(Nz::AlwaysFalse<T>::value, "non-exhaustive visitor");
},
member.type);

View File

@ -50,7 +50,7 @@ StructMemberEditDialog(shaderGraph, parent)
else if constexpr (std::is_same_v<T, std::size_t>)
m_typeList->setCurrentIndex(static_cast<int>(PrimitiveTypeCount + arg));
else
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
static_assert(Nz::AlwaysFalse<T>::value, "non-exhaustive visitor");
},
member.type);
}

View File

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