Almost no application is fully self-contained, rather everyone uses external libraries and frameworks. Meson makes it very easy to find and use external dependencies.
Here is how one would use the zlib compression library.
dep = dependency('zlib', version : '>=1.2.8')
exe = executable('zlibprog', 'prog.cpp', dependencies : dep)
In the above code first Meson is told to find the external library zlib and error out if it is not found. The version keyword is optional and specifies a version requirement for the dependency. Then an executable is built using the specified dependency.
If we have multiple dependencies we can pass them as an array like this
executable('manydeps', 'file.cpp', dependencies : [dep1, dep2, dep3, dep4])
Now we will create a Meson subproject, for this we will use SDL as an example.
All subprojects must be inside the %u2018subprojects%u2019 directory. The subprojects directory must be at the top level of the project. Subproject declaration must be in the top level %u2018meson.build%u2019.
The %u2018meson.build%u2019 file for creating the subproject will look like this
project('SDL test', 'cpp', version: '1.0.0',
default_options : ['default_library=static', 'cpp_std=c++17', 'buildtype=debugoptimized'])
sdl2_dep = dependency('sdl2')
sdl2_image_dep = dependency('sdl2_image')
sdl2_mixer_dep = dependency('sdl2_mixer')
executable('sdltestapp', 'main.cpp',
dependencies : [sdl2_image_dep, sdl2_mixer_dep, sdl2_dep],
win_subsystem: 'windows')
The contents of the .wrap files created consist mostly of download links, hashes and build meta info.
Comments