Loading...
Loading...
Meson build system skill for C/C++ projects. Use when setting up a Meson project, configuring build options, managing dependencies with the wrap system, cross-compiling, or integrating Meson with CI. Activates on queries about meson setup, meson compile, meson wrap, meson test, cross-file, meson.build, or migrating from CMake/Autotools to Meson.
npx skill4agent add mohitmishra786/low-level-dev-skills meson# Configure (source-dir, build-dir are positional)
meson setup builddir
# With options
meson setup builddir \
--buildtype=release \
--prefix=/usr/local \
-Db_lto=true \
-Db_sanitize=address
# Reconfigure (change options on existing builddir)
meson configure builddir -Dbuildtype=debug
# Show all available options
meson configure builddir | Equivalent flags |
|---|---|
| |
| |
| |
| |
| No flags added |
# Build (from source directory)
meson compile -C builddir
# Or enter builddir and use ninja directly
cd builddir && ninja
# Run tests
meson test -C builddir
meson test -C builddir --verbose # show test output
meson test -C builddir -t 5 # 5x timeout multiplier
meson test -C builddir --suite unit # run only 'unit' suite
# Install
meson install -C builddir
# Dry run
meson install -C builddir --dry-runproject('myapp', 'c', 'cpp',
version : '1.0.0',
default_options : [
'c_std=c11',
'cpp_std=c++17',
'warning_level=2',
]
)
# Find system dependencies
glib_dep = dependency('glib-2.0', version : '>=2.68')
threads_dep = dependency('threads')
# Include directories
inc = include_directories('include')
# Library
mylib = static_library('mylib',
sources : ['src/lib.c', 'src/util.c'],
include_directories : inc,
)
# Executable
executable('myapp',
sources : ['src/main.c'],
include_directories : inc,
link_with : mylib,
dependencies : [glib_dep, threads_dep],
install : true,
)
# Tests
test('basic', executable('test_basic',
sources : ['tests/test_basic.c'],
link_with : mylib,
))# Search for a wrap
meson wrap search zlib
# Install a wrap (downloads .wrap file from wrapdb)
meson wrap install zlib
meson wrap install gtest
# List installed wraps
meson wrap list
# Update all wraps
meson wrap updatemeson.build# Use wrap as fallback if system lib not found
zlib_dep = dependency('zlib',
fallback : ['zlib', 'zlib_dep'], # [wrap_name, dep_variable]
)
# Force wrap (for reproducible builds)
zlib_dep = dependency('zlib',
fallback : ['zlib', 'zlib_dep'],
default_options : ['default_library=static'],
)subprojects/zlib.wrap[wrap-file]
directory = zlib-1.3
source_url = https://zlib.net/zlib-1.3.tar.gz
source_hash = <sha256>
[provide]
zlib = zlib_depmeson_options.txtmeson.optionsoption('with_tests', type : 'boolean', value : true,
description : 'Build unit tests')
option('backend', type : 'combo',
choices : ['opengl', 'vulkan', 'software'],
value : 'opengl',
description : 'Rendering backend')
option('max_connections', type : 'integer',
min : 1, max : 1024, value : 64)meson.buildif get_option('with_tests')
subdir('tests')
endifcross/arm-linux.ini[binaries]
c = 'arm-linux-gnueabihf-gcc'
cpp = 'arm-linux-gnueabihf-g++'
ar = 'arm-linux-gnueabihf-ar'
strip = 'arm-linux-gnueabihf-strip'
pkgconfig = 'arm-linux-gnueabihf-pkg-config'
[properties]
sys_root = '/path/to/sysroot'
[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'cortex-a9'
endian = 'little'meson setup builddir-arm --cross-file cross/arm-linux.ini
meson compile -C builddir-arm| CMake | Meson equivalent |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
skills/build-systems/cmakeskills/build-systems/ninjaskills/compilers/cross-gccskills/compilers/gccskills/compilers/clang