Friday, April 1, 2022

The C++ best practices game jam sample project Meson conversion

Today is April Fool's day and also when the C++ best practices game jam begins. This is interesting because the Jam provides a modern multiplatform C++ starter project setup using multiple dependencies. I though it would be illuminating to convert it to build with Meson and compare the results with a modern build setup as opposed to one that has gathered unfortunate cruft for years. The original project can be found in this repo whereas my Meson conversion is here (I only tested it on Linux, though it "should work" on all platforms).

The original project builds with CMake and interestingly uses two different methods of obtaining external dependencies. Catch2, spdlog and docopt are obtained via Conan whereas FTXUI is downloaded with CMake's FetchContent. The relevant lines for the latter are the following:

include(FetchContent)

set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
FetchContent_Declare(ftxui
  GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
  GIT_TAG v2.0.0
)

FetchContent_GetProperties(ftxui)
if(NOT ftxui_POPULATED)
  FetchContent_Populate(ftxui)
  add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

The Meson version gets all the dependencies directly from WrapDB. The main advantage is that you don't need any third party dependency manager or provider, everything happens directly within Meson. The build definitions needed to get all these deps is just this:

docopt_dep = dependency('docopt')
ftxui_dep = dependency('ftxui-component')
spdlog_dep = dependency('spdlog')
catch2_dep = dependency('catch2')

All the nitty gritty details needed to download the dependencies are stored in the wrap files, which are created automatically with commands like following:

meson wrap install catch2

Thus for this project we find at least that Meson setup is both simpler and does not require external tooling.

No comments:

Post a Comment