.. _build-system: Build system ============ |Dock| uses `the Meson build system `__. Rationale --------- `Meson `__ is a fast and user-friendly build system, and therefore building and testing of |Dock| is now straightforward. But it was not always so simple. rDock built using tmake ^^^^^^^^^^^^^^^^^^^^^^^ When we stumbled upon rDock back in April 2019, the first thing we noticed was its build process that required ``tmake`` command. As you might know, `tmake `__ was developed by Trolltech (now `Qt Company `__) during the 1990s as a build system for cross-platform applications, specifically `Qt Toolkit `__ and applications using it. It was still somewhat popular in the early 2000s, but afterward, it got superseded by `qmake `__ and later `Qbs `__. Well, as you might observe, rDock never migrated away from tmake. Luckily, tmake could still run on modern Linux distributions so building rDock was possible. Once we got rDock to build, albeit, with thousands of lines of warnings (more on that in the future posts), we decided that the first step is replacing tmake. The replacement should be some actively maintained build system, but we also wanted it to be cross-platform just like tmake as we intended to expand the number of :ref:`supported platforms `. rDock as we found it ran only on Linux, but after forking as RxDock we ported it to FreeBSD, Solaris, and Windows over a few months. Aside from portability, we also wanted our build system to be easy to use; one wants to spend time developing software, not writing build scripts. In the process of choosing the replacement for tmake, we evaluated `CMake `__, `Waf `__, and `Meson `__. Choosing the build system ^^^^^^^^^^^^^^^^^^^^^^^^^ There is the old saying that `Linux is user friendly, but picky who its friends are `__. CMake is similar, and unless you can sing precisely quoted passages from `CGold `__ when woken up in the middle of the night, you are not in that circle of friends (sorry to disappoint). To be fair, the syntax of the `CMakeLists.txt` build configuration files has gotten simpler over time, but CMake is still a lot more painful to use compared to Waf and Meson. Furthermore, guides like `An Introduction to Modern CMake `__ are a great resource if, for whatever reason, CMake is the way you want to go. `Waf `__ is a mature build system, but it's nowhere near as big and popular as CMake. Vedran Miletić worked with it quite a bit while developing `ns-3 `__ during his Ph.D. days so it was an attractive option for |Dock| as well. Waf's build scripts are Python scripts so it's very flexible in terms of what it can do while being easy to use. In summary, we would likely have picked Waf over CMake if Meson didn't exist. Despite being somewhat niche, Waf is still used by important projects such as `mpv `__ and `Samba `__. Finally, `Meson `__, a build system originally developed by `Jussi Pakkanen `__ `as a hobby since 2012 `__. Jussi carefully evaluated the existing solutions and concluded that building software can be done better (`xkcd about standards `__ comes to our mind and `critics of Meson agree in that regard `__). A good overview of Meson is `the presentation at Linux.conf.au in 2015 `__, where the author credits `SCons `__, `GYP `__, and qmake/Qbs for inspiration. The usage of Meson started to grow steadily after that presentation: `it started building GStreamer in 2016 `__ and `it was adopted by GNOME in 2017 `__. It's no longer a niche tool as `it's used by 100+ other projects today `__, including some big names such as `Mesa `__, `Linux Vendor Firmware Service `__, `systemd `__, and `DXVK `__. DOSBox is `switching to Meson at the time of writing `__ in the staging branch. The joy of working with Meson ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The reason why we picked Meson among the three build systems was the ease of use. It took just a few hours and 120 lines of the ``meson.build`` build configuration file (more than a third of that being the names of the source files) to get |Dock| building and running, and tests came soon afterward. `This tweet from Vedran Miletić `__ captures some of the initial excitement coming from replacing tmake and custom ``Makefile``\ s with Meson. Unlike Waf, the `syntax isn't Python `__ (there's `a good reason for that `__), but it's very much Python-like and therefore easy to get started. At `CppCon 2018 `__, Jussi told the audience to just `look at the build configuration file for 10 seconds `__ without any prior knowledge of the Meson syntax; it's just so obvious what it does. The documentation is very good, especially its coverage of `common use cases `__. You get `reproducible builds for free `__. IDE integration is getting there, e.g. `Qt Creator `__ `added Meson support in summer 2020 `__ and `Visual Studio Code had it for a while `__. It has been almost two years at the time of writing since we switched to Meson and we are very happy with how it builds |Dock|. `The Meson community is very active `__ and therefore we expect to continue using Meson to build |Dock| for the foreseeable future.