I guess this is true since I first considered purchasing a Mac laptop. It never seemed as a good price performance investment.
For years I used a Hackintosh to test X-Plane, but since LR moved to pure "metal" programming, I was not able to install a Hackintosh, nor was it worth the invested time, instead I opted in a VMWARE solution but with two big caveats:
- I could only test if the plugin loaded but no way I could test from inside the game, 3D rendering was worse than a slide show, every frame took few seconds to render.
- Only X-Plane 11 can be run from inside the virtual machine.
When Laminar Research announced that XP12 will run on M1 chips, I was worried that I won't be able to build my plugin for both architectures: Intel and Apple Silicon, unfortunately I was right and being without the correct machine just created more questions and confusion.
Fast forward to 2023:
One of the plugins that gave me some hope in building my solution inside a VM was "sparker256" ImGui implementation for X-Plane.
I knew he built his project/plugin using CMake, which I avoided, but now had the opportunity to investigate his implementation for X-Plane and use it as a good reference. Still, I was quite new for the CMake concept, although I used it on other small project I wrote.
My belief was, CMake will allow me to better integrate two architectures, something that XCode fails to do (probably my fault).
So step 1 - Configure the plugin to build with CMake.
The tools I used:
- CMake installation.
- Community build of QT Creator.
- Notepad++
- Visual Studio 2022 - Community addition, my go to editor for C++ programming.
- The internet.
The outcome of this intensive few days of trial and error (and frustration and confusion) was:
One of the benefits of using CMake is that it holds all your project definition in a simple ASCII file (if you so choose), and if you want you could split this file to multiple smaller one to build you libraries first and then link with the main code, I chose the first option, everything in one file.
CMake basically allowed me a better control of my files, nothing was hidden behind graphical nodes and sub nodes, everything is laid out in plain text and you could easily add or remove files or basic settings based on your platform and when using QT Creator as a cross platform editor, it just made my life easier since my work was easily transferred between the Operating Systems and behave just the same.
I started with Windows, then Linux and at the end MacOS, each operating system had its own challenges, but luckily I had the option to check the configuration of the tools I used at the time to correctly construct the CMake file. When I finished doing all the fine tuning, I learned to respect this tool for building a project, really, instead of building a project base on a proprietary format, like Visual Studio, you should use something similar to CMake which is a cross platform solution and also uses Visual Studio own compiler. I'm not saying that the end binary is the exact same, I'm pretty sure Visual Studio does some optimizations that I'm not aware off, but my end goal was to build a "fat" plugin that will hold two architectures for MacOS.
Once I was able to compile all projects in all platforms I had to add the following lines in order to make my end goal work:
When I added the "CMAKE_OSX_ARCHITECTURES" it was enough for CMake with the help of "Ninja" builder to link the correct architecture binaries into one "fat" file.
Now there are some rules to make this happen, and they are quite strait forward:
- Use MacOS frameworks that supports M1 chip (MacOS 11 and up).
- If you use libraries, then make sure they are built for both architectures.
- I think it would be beneficial to also use a newer SDK and compiler (clang) that can handle and optimize for each architecture.
At the end of the day I was able to get this outcome:
I hope this short rant was informative and hopefully assist in building your own universal binary for MacOS, and who knows, maybe I'll be able to buy Apple Silicon machine one day.
Until then,
Blue Skies
Sa'ar