cmakemeson-buildfetchcontent

What is the meson equivalent of cmake's `FetchContent`?


How would I fetch a dependency from GitHub in meson? I am trying to convert the following cmake snippet into meson

FetchContent_Declare(
  some_dep
  GIT_REPOSITORY https://github.com/some/repo
  GIT_TAG        sometag
  SOURCE_SUBDIR  src
)

FetchContent_MakeAvailable(some_dep)

Note that this dependency may not be using meson as its build system.


Solution

  • The meson equivalent is subprojects and the wrap dependency system. Here a simple example:

    This will search libfmt on your system and fallback to downloading it as specified in the wrap file. The subproject() function requires a meson.build file in the root directory, similar to how FetchContent expects a CMakeLists.txt. If the respective project does not have meson build files, you can provide patches through the patch_* or diff_files properties in the wrap file. This is e.g. the case for libfmt does not have meson build files. You can also use [wrap-git] instead of [wrap-file] to specify a git repository instead of a release tarball. Please refer to the documentation.

    Tip: The meson developers maintain the Wrap DB, where you can find wrap files for some common libraries/projects.