Skip to content

Add support for compiling on macOS#472

Closed
apancik wants to merge 10 commits intoluciusDXL:masterfrom
apancik:master
Closed

Add support for compiling on macOS#472
apancik wants to merge 10 commits intoluciusDXL:masterfrom
apancik:master

Conversation

@apancik
Copy link
Copy Markdown
Contributor

@apancik apancik commented Nov 19, 2024

This pull request introduces changes to enable compiling The Force Engine on macOS.

Hardware: Intel Mac / macOS Sequoia 15.1 / XCode 16.1
SDL2: version 2.30.9, SDL2_image: version 2.8.2, RtMidi: version 6.0.0

  • Further testing on Linux to ensure no regressions were introduced (compiled & launched the first level)
  • Further testing on Windows to ensure no regressions were introduced
  • Verify compilation on ARM-based Macs
  • Somehow VSCode auto formatted some files which makes seeing the diff difficult. I don't know how to fix that quickly

Screenshot 2024-11-19 at 5 57 22 PM
Screenshot 2024-11-19 at 5 57 44 PM
Screenshot 2024-11-19 at 5 58 06 PM

- Updated build scripts and configurations to support macOS
- Resolved compatibility issues specific to macOS
- Verified successful compilation on macOS X environment
@luciusDXL
Copy link
Copy Markdown
Owner

Looks good, other than the formatting. I will wait on pulling the trigger until I can pull it and test locally. But if that goes well, this looks good to merge.

@mlauss2
Copy link
Copy Markdown
Contributor

mlauss2 commented Nov 20, 2024

the unnecessary formatting changes make it hard to review. could you please get rid of them?
Other than that, from a cursory glance, it looks pretty good!

CMakeLists.txt Outdated
if(ENABLE_TFE)
add_executable(tfe)
set_target_properties(tfe PROPERTIES OUTPUT_NAME "theforceengine")
set_target_properties(tfe PROPERTIES OUTPUT_NAME "theforceengine_target") # rename the binary to "theforceengine_target" to avoid conflicts with the directory name on mac os x
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how @luciusDXL feels about this, maybe use "theforceengine_osx" and "theforceengine_linux" but _target sounds just wrong to me.

Copy link
Copy Markdown
Contributor Author

@apancik apancik Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. It was just a quick stopgap solution to avoid the name conflict. What do you think about autoappending CMAKE's platform name:

set(FINAL_OUTPUT_NAME "theforceengine_${CMAKE_SYSTEM_NAME}")
set_target_properties(tfe PROPERTIES OUTPUT_NAME "${FINAL_OUTPUT_NAME}")

@mlauss2
Copy link
Copy Markdown
Contributor

mlauss2 commented Nov 20, 2024

* [x]  Somehow VSCode auto formatted some files which makes seeing the diff difficult. I don't know how to fix that quickly

In these cases I take the full patch file and edit out all the unwanted hunks by hand, apply the edited diff to the tree and fix up the remaining issues. Most of the relevant changes are to fileutil-posix.cpp, renderBackend.cpp, OpenGL_caps.cpp so they should be fairly easy to isolate.

@mlauss2
Copy link
Copy Markdown
Contributor

mlauss2 commented Nov 20, 2024

@apancik: I've cleaned up your patch, against head, attached. Works for me, Please test?
tfe_472_v4.patch.txt

EDIT2: updated the diff to _v4.patch (forgot the crashhandler)
diffstat is much saner now:

CMakeLists.txt                                                 |   15 ++++++++-------
 README.md                                                      |   21 ++++++++++++++++++++-
 TheForceEngine/TFE_FileSystem/fileutil-posix.cpp               |   27 +++++++++++++++++++++++++++
 TheForceEngine/TFE_RenderBackend/Win32OpenGL/openGL_Caps.cpp   |   25 +++++++++++++++++++++++++
 TheForceEngine/TFE_RenderBackend/Win32OpenGL/renderBackend.cpp |   37 +++++++++++++++++++++++++++++++++++--
 TheForceEngine/TFE_RenderBackend/Win32OpenGL/shader.cpp        |   94 ++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------
 TheForceEngine/TFE_RenderBackend/Win32OpenGL/vertexBuffer.cpp  |    3 +++
 TheForceEngine/TFE_System/CMakeLists.txt                       |    4 ++++
 TheForceEngine/TFE_System/CrashHandler/crashHandlerMac.cpp     |  114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 282 insertions(+), 58 deletions(-)

@apancik
Copy link
Copy Markdown
Contributor Author

apancik commented Nov 20, 2024

Your patch tfe_472_v4.patch.txt fails to build on my machine. The issue appears to be related to your refactor of TFE_RenderBackend::bindGlobalVAO(). For context, I originally implemented it with function to avoid declaring s_globalVAO in headers as extern and deal with importing gl.h to have access to GLuint type. It would be more lines of code for the same functionality.

By the way, I tried to do the whitespace mess cleanup in dff0f42 042215b 7558920 4c8d835 – the diff for this PR in Github looks much saner – please have a look. I also removed some uneccesary changes that were just leftovers from my tinkering that ended up in your patch. Maybe this can salvage this PR 😄

@apancik
Copy link
Copy Markdown
Contributor Author

apancik commented Nov 20, 2024

@mlauss2 I could wrap the entire definition and its calls in #ifdef blocks to make it explicitly clear that this is platform-specific. Do you think that approach would be better?

@mlauss2
Copy link
Copy Markdown
Contributor

mlauss2 commented Nov 21, 2024

@apancik : here's a v5, it builds and runs fine on linux; could you please test on osx? Please fix it up and create a new PR.

I would like to keep the executable name "theforceengine" on linux, but you could decide for an osx name and special case that for apple (i.e. something like below on top of your work:)

index cbb9727a..80398f03 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,7 +57,13 @@ option(ENABLE_ADJUSTABLEHUD_MOD "Install the build‑in “AdjustableHud mod”
 
 if(ENABLE_TFE)
        add_executable(tfe)
-       set_target_properties(tfe PROPERTIES OUTPUT_NAME "theforceengine_target") # rename the binary to "theforceengine_target" to avoid conflicts with the directory name on mac os x
+
+       if(APPLE)
+               # cant have executable have the same name as the cmake working dir
+               set_target_properties(tfe PROPERTIES OUTPUT_NAME "theforceengine_osx")
+       else()
+               set_target_properties(tfe PROPERTIES OUTPUT_NAME "theforceengine")
+       endif()
 
        if(UNIX)
                find_package(PkgConfig REQUIRED)

tfe_472_v5.patch.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants