Devlog #11: Switching to Meson (Commits: c65e483c45, c1bdb7eb50)
4 changed files with 305 additions and 233 deletions
Switching to Meson from a Makefile was quite an easy decision. Considering I want a cross-platform build system that is fast, Meson+Ninja stood out as the best possible candidate. On top of that, Meson easily supports cross-compilation, which fits my use case even more!
Switch to Meson (Commit c65e483c45)
The first commit that this devlog details contains the initial implementation of meson.build, and of a Makefile shim.
meson.build
I decided to write meson.build as idiomatically as possible. I followed the mesonbuild.com documentation for this purpose.
Because of my project’s reliance on ISO C23, I had to make sure that Meson supports setting c23 as an option. That means ensuring Meson is above or equal to v1.4.0.
The compilation flags and linking flags stay the exact same as in my previous Makefile, and on top of that, Meson checks whether a flag is supported and prints it right out while compiling!
Makefile shim
The only drawback I encountered while toying with Meson is that the commands can get quite lengthy. For example, to compile and run my project from nothing via meson looks something like this:
meson setup build-debug --buildtype=debug -Db_ndebug=if-release && meson compile -C build-debug && ./build-debug/zinn
While via my previous Makefile it looked like this:
make debug && make run
Of course, this has a lot to do with the fact that Meson saves a bunch of metadata, but nevertheless the flow is slower when trying to remember all the meson options.
That’s why I created a Makefile shim. The term comes from Embedded Artistry, and it refers to a Makefile that acts as a front-end for Meson (in this case).
I wrapped all the meson commands in neat Makefile targets, so I can just run make debug && make run all the same while still getting the valuable Meson features.
Windows & cross-compilation support (Commit c1bdb7eb50)
With Meson now working in my codebase, it was time for cross-platform support. Adding it was really easy.
meson.build changes
The only change in meson.build besides the Windows linker-flag section is that is_windows and is_mingw detection.
cross folder & .ini file
Cross-compilation is simply compiling code for a different computer on your own computer. In my case, I wanted to compile for Windows while staying on Linux. In my old Makefile this would be a huge hassle, but Meson only needs this little file to know the target and which cross-compiler binaries to use:
[binaries]
c = 'x86_64-w64-mingw32-gcc'
ar = 'x86_64-w64-mingw32-ar'
strip = 'x86_64-w64-mingw32-strip'
windres = 'x86_64-w64-mingw32-windres'
exe_wrapper = ['wine']
...
The last row is where the magic happens: exe_wrapper tells Meson to run any produced Windows binary through Wine, so I can test the cross-compiled output directly from Linux.
What’s next?
If you checked the attachment out, you can see a bunch of compilation errors; those are there on purpose. I have yet to update my actual code to support Windows.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.