TheCherno / Hazel

Hazel Engine
Apache License 2.0
11.72k stars 1.51k forks source link

Mac OS X support #6

Closed GabrieleInvernizzi closed 3 years ago

GabrieleInvernizzi commented 5 years ago

How can I use the code in Xcode on Mac? If there is a way of course

S-Marais commented 5 years ago

following today's video you should be able to create a an xcode solution. you will need to get premake5 binaries from github and the launch premake5 xcode4 which should generate the xcode project files

RohitAwate commented 5 years ago

You'd also have to add some macOS-specific macros and configuration stuff to premake5.lua. EntryPoint.h would also need some changes since it uses the Windows header guard, which you could just remove since there is no Windows-specific code in there, yet.

ghost commented 5 years ago

you should also be adding macros like HZ_PLATFORM_MACOS

lccatala commented 5 years ago

also, declspec(dllexport) and declspec(dllimport) seem to be Windows-exclusive. I've been looking for an alternative way of exporting and importing symbols on Mac but can't seem to find anything. Is this supposed to work without defining anything?

ghost commented 5 years ago

Mac and Linux, don't use these directives for creating and using shared objects. You can specify them but they will be ignored. Unlike on Windows, you don't need to "export" or "import" symbols.

S-Marais commented 5 years ago

no the std like alternative is

#define HAZEL_API __attribute__((visibility("default")))
lccatala commented 5 years ago

Ok, so I managed to build and run the Sandbox project, however when I click on Xcode's play button with that project selected, it says "Build Succeeded" and nothing happens. Shouldn't a terminal window open?

On Sun, 18 Nov 2018, 21:51 S-Marais <notifications@github.com wrote:

no the std like alternative is

define HAZEL_API attribute((visibility("default")))

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/TheCherno/Hazel/issues/6#issuecomment-439724795, or mute the thread https://github.com/notifications/unsubscribe-auth/Aek9Bsk1n8oI5K1QUQyro9R-ggMRDCWRks5uwchkgaJpZM4Yn84k .

Ali-Sheharyar-Sheikh commented 5 years ago

No it would be using the built in terminal in Xcode. Just change the setting to launch new terminal on application run in Xcode.

GabrieleInvernizzi commented 5 years ago

Iccatala, sorry, can you explain me how did you managed to build this project on xCode, I tried but I can’t do it ahah

lccatala commented 5 years ago

You have to create a new filter for "system:macosx" using the same configurations as for the Windows one, replacing every "windows" word for "mac", so the code you compile is different for each platform. In Core.h, remove the #error macro (there is no need for __declspec(dllexport) in xcode, since every class and function will be accesible throughout the whole solution by default). Then download and install premake for mac and run it with the parameter xcode4. Let me know if there are any errors remaining, it's possible I've forgotten something. Also, I'll try to build it for cmake so it can be edited from VSCode, which I think is far superior to XCode

El lun., 26 nov. 2018 a las 10:16, Gabriele Invernizzi (< notifications@github.com>) escribió:

Iccatala, sorry, can you explain me how did you managed to build this project on xCode, I tried but I can’t do it ahah

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/TheCherno/Hazel/issues/6#issuecomment-441568814, or mute the thread https://github.com/notifications/unsubscribe-auth/Aek9BnURXB1pD3oUfdoDT85Kf3w9gZUOks5uy7FRgaJpZM4Yn84k .

GabrieleInvernizzi commented 5 years ago

Thank you very much, I'll try

You have to create a new filter for "system:macosx" using the same configurations as for the Windows one, replacing every "windows" word for "mac", so the code you compile is different for each platform. In Core.h, remove the #error macro (there is no need for __declspec(dllexport) in xcode, since every class and function will be accesible throughout the whole solution by default). Then download and install premake for mac and run it with the parameter xcode4. Let me know if there are any errors remaining, it's possible I've forgotten something. Also, I'll try to build it for cmake so it can be edited from VSCode, which I think is far superior to XCode El lun., 26 nov. 2018 a las 10:16, Gabriele Invernizzi (< notifications@github.com>) escribió: Iccatala, sorry, can you explain me how did you managed to build this project on xCode, I tried but I can’t do it ahah — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#6 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/Aek9BnURXB1pD3oUfdoDT85Kf3w9gZUOks5uy7FRgaJpZM4Yn84k .

GabrieleInvernizzi commented 5 years ago

I tried but it doesn't work, perhaps is my fault but can you help me with this? This is my premake5.lua file (I know that this is a txt but GitHub do not support .lua): premake5.txt.

I think I did some (if not a lot) mistakes, can you help me?

You have to create a new filter for "system:macosx" using the same configurations as for the Windows one, replacing every "windows" word for "mac", so the code you compile is different for each platform. In Core.h, remove the #error macro (there is no need for __declspec(dllexport) in xcode, since every class and function will be accesible throughout the whole solution by default). Then download and install premake for mac and run it with the parameter xcode4. Let me know if there are any errors remaining, it's possible I've forgotten something. Also, I'll try to build it for cmake so it can be edited from VSCode, which I think is far superior to XCode El lun., 26 nov. 2018 a las 10:16, Gabriele Invernizzi (< notifications@github.com>) escribió:

cubedtear commented 5 years ago

On PR #27 we have a working build on Linux, which should contain similar changes to those needed for Mac OS X support. You could maybe try those changes (maybe changing all the system:linux with system:macosx) to see if it works.

thatweirdcoder commented 5 years ago

@GabrieleInvernizzi How about you Use clion (an ide that uses cmake) instead of premake and xcode .. spglog and glfw already use cmake and writing cmake files for glad and imgui wont be hard. I just like that clion is cross platfrom and i can work from my macbook or windows pc. https://www.jetbrains.com/clion/

StevenSavold commented 5 years ago

@not-a-vegetable you can generate cmake files with premake. If you want to use clion you can do that here's the link to the extension

https://github.com/TurkeyMan/premake-cmake

mfdorst commented 5 years ago

@thatweirdcoder I also enjoy CLion for the same reason. However for those who prefer Xcode, it also supports CMake, so there's no reason you have to switch to a new IDE to use it.

cxgslegend commented 5 years ago

@not-a-vegetable you can generate cmake files with premake. If you want to use clion you can do that here's the link to the extension

https://github.com/TurkeyMan/premake-cmake

Unfortunately, it doesn't work with premake5, and the creator isn't updating the project. Issue from 2015. It seems like there are no cmake action extensions. Even the one listed in the premake docs is dead Premake modules.

jviney commented 4 years ago

If anyone is interested, I'm doing this series on macOS using VS Code with CMake instead of premake.

I'm currently up to episode 16. Works fine with Xcode if you want to use that.

https://github.com/jviney/hazel

cxgslegend commented 4 years ago

If anyone is interested, I'm doing this series on macOS using VS Code with CMake instead of premake.

I'm currently up to episode 16. Works fine with Xcode if you want to use that.

https://github.com/jviney/hazel

I assume you are talking about a youtube series. You should probably not promote in Hazel issues. This would be more appropriate for the "game engine series" section in discord.

But regardless, you do not have a link on your github project to the series.

tcaer commented 4 years ago

Hi, I am on MacOS and I have built an engine which is basically Hazel but works on both MacOS and Windows. For Hazel's premake5 file, I added this:

filter "system:macosx"
    defines {
      "CFG_MACOS",
      "__APPLE__"
    }
    kind "SharedLib"

    links {
      "OpenGL.framework",
      "Cocoa.framework",
      "OpenGL.framework",
      "IOKit.framework",
      "CoreFoundation.framework"
    }

configuration to it. I then also added this to the GLFW configuration:

filter "system:macosx"
    systemversion "latest"
    staticruntime "On"

    files {
      "src/cocoa_init.m",
      "src/cocoa_joystick.m",
      "src/cocoa_monitor.m",
      "src/cocoa_time.c",
      "src/posix_thread.c",
      "src/cocoa_window.m",
      "src/egl_context.c",
      "src/nsgl_context.m",
      "src/osmesa_context.c"
    }

    defines {
      "_GLFW_COCOA"
    }

My version of the engine does not require any of the DLL_EXPORT/IMPORT stuff in it. But these settings will build GLFW properly for MacOS. Some of the macros are ones which I changed for my engine but I think you get the gist. I am currently using these configurations in aa VS2019 solution (not surprising as Windows already built fine) and with Make on MacOS. I have not tried this with Xcode.

tcaer commented 4 years ago

Furthermore, the "GLFW_INCLUDE_NONE" macro has to be moved to be a windows-only macro. MacOS requires us to use glfwWindowHints to set the proper context version. Also, the engine has to support version 410 as that is the highest version MacOS supports.

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

This code is required in a Mac window to ensure that the core profile and GL version 410 is being used.

SteveGremory commented 4 years ago

how about just creating a different repo for macOS and linking it in this one?