The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Building SDL2 apps with Meson
Jussi Pakkanen
Guest

Hello

I'm working on a build system called Meson, which has several features specifically optimized for game development. Its project page is here:


https://sourceforge.net/projects/meson/


Meson provides, among other things:



- cross-platform support (Linux, OSX, Windows, etc)
- native support for precompiled headers (both GCC and MSVC)
- native support for Unity builds
- embeddable subprojects


The last entry means that you can take any project that is built with Meson and embed it inside any other project and use it as if it was an integral part of the master project. This provides a clean way to use external dependencies (you can still easily use system versions on platforms that provide them if you wish).


As a (heavy duty) proof of concept I rewrote the build system of SDL2 in Meson. The source tree seems to have only 4-5 build systems already so it's about time to get a new one in there. Smile This one is a bit rough and only works on Linux, but on the other hand it is only 512 lines of code. The end result works standalone and is also embeddable.


If you want to try it out yourselves, the steps are simple. The only catch is that you need Meson from Git trunk. First create a top level subdirectory for your project. Then create a "subprojects" subdirectory, cd into it, get the mesonified SDL here and extract the package:


https://drive.google.com/file/d/0BxXyXJtzeIquNHgtUFpmb3F4V2c



Now just write a Meson build definition file called meson.build in the top directory of your project. Put the following in it:


-----


project('gameproj', 'c')


sdl = subproject('SDL')


executable('sdltest', 'prog.c',
link_with : sdl.get_variable('sdl_lib'),
include_dirs : sdl.get_variable('sdl_inc'))



----


Then write a prog.c, I just used a simple helloworld example. That's all there is to it, now you can compile your project with standard Meson steps and it will automatically configure and build a local version of SDL2. If you want to just build SDL2 with Meson, you can do that, too. Get the archive, unzip and build it.


That's about it. If you have any questions that are not related to SDL, feel free to email either me, or (preferably) the Meson mailing list.


Thanks and enjoy,