CMake vs Meson vs Autotools vs xmake
You have now used all four. This lesson puts them side by side: the same small project in each, then the differences that matter when you choose one or inherit one.
The same project, four times
A static library shape with a header in include/, a program area that uses it, and one test. Each build description is complete; the session builds and tests all four from the same sources.
mkdir -p same/include same/src && cd same
echo 'double square(double side);' > include/shape.h
echo '#include "shape.h"
double square(double s) { return s * s; }' > src/shape.c
echo '#include <stdio.h>
#include "shape.h"
int main(void) { printf("%.1f\n", square(1.5)); return 0; }' > src/area.c
cat > CMakeLists.txt <<'X'
cmake_minimum_required(VERSION 3.25)
project(same LANGUAGES C)
add_library(shape STATIC src/shape.c)
target_include_directories(shape PUBLIC include)
add_executable(area src/area.c)
target_link_libraries(area PRIVATE shape)
enable_testing()
add_test(NAME area COMMAND area)
X
cat > meson.build <<'X'
project('same', 'c')
shape = static_library('shape', 'src/shape.c', include_directories: 'include')
shape_dep = declare_dependency(link_with: shape, include_directories: 'include')
area = executable('area', 'src/area.c', dependencies: shape_dep)
test('area', area)
X
cat > configure.ac <<'X'
AC_INIT([same], [1.0])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AM_PROG_AR
AC_PROG_CC
AC_PROG_RANLIB
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
X
cat > Makefile.am <<'X'
ARFLAGS = cr
noinst_LIBRARIES = libshape.a
libshape_a_SOURCES = src/shape.c include/shape.h
libshape_a_CPPFLAGS = -I$(srcdir)/include
bin_PROGRAMS = area
area_SOURCES = src/area.c
area_CPPFLAGS = -I$(srcdir)/include
area_LDADD = libshape.a
TESTS = area
X
cat > xmake.lua <<'X'
target("shape")
set_kind("static")
add_files("src/shape.c")
add_includedirs("include", {public = true})
target("area")
set_kind("binary")
add_deps("shape")
add_files("src/area.c")
add_tests("default")
X
echo "--- size of each build description (non-empty lines)"
for f in CMakeLists.txt meson.build "configure.ac Makefile.am" xmake.lua; do printf '%-26s %s\n' "$f" "$(cat $f | grep -c .)"; done
echo "--- CMake"; cmake -S . -B b-cmake -G Ninja > /dev/null && cmake --build b-cmake > /dev/null && ctest --test-dir b-cmake | grep 'tests passed'
echo "--- Meson"; meson setup b-meson > /dev/null && meson compile -C b-meson -j 1 > /dev/null && meson test -C b-meson --num-processes 1 | grep '^Ok'
echo "--- Autotools"; autoreconf -i 2> /dev/null && mkdir b-auto && cd b-auto && ../configure --quiet && make -j1 -s && make -j1 -s check | grep '^# PASS'; cd ..
echo "--- xmake"; xmake -j1 > /dev/null 2>&1 && xmake test 2>&1 | grep 'tests passed' | sed 's/, spent .*//'--- size of each build description (non-empty lines)
CMakeLists.txt 8
meson.build 5
configure.ac Makefile.am 16
xmake.lua 9
--- CMake
100% tests passed out of 1
--- Meson
Ok: 1
--- Autotools
# PASS: 1
--- xmake
100% tests passed, 0 test(s) failed out of 1
Each tool ran its own test runner (CTest, meson test, automake's harness, xmake test), and Autotools built out of tree in b-auto/ this time, which is why its Makefile.am uses $(srcdir)/include.
Side by side
| CMake | Meson | Autotools | xmake | |
|---|---|---|---|---|
| Kind | generator | generator | generator (shell script + Makefiles) | build tool |
| Language | CMake script | Meson DSL (not Turing-complete) | M4 + shell + make | Lua |
| Backends | Ninja, Make, VS, Xcode, … | Ninja (VS, Xcode) | make | itself (exports Make, Ninja, CMake, VS) |
| Needed to build a release | CMake | Python 3 + Meson + Ninja (or muon + samurai) | sh + make | xmake |
| Configure speed | medium | fast | slow (one process per check) | fast |
| Out-of-tree builds | yes (-B) |
mandatory | optional (VPATH) | build/ + .xmake/ in the tree |
| Source globbing | possible, discouraged | not allowed | not allowed | normal (src/*.c) |
| Find dependencies | find_package (config/module) |
dependency() (pkg-config, CMake, system) |
PKG_CHECK_MODULES, AC_CHECK_LIB |
add_requires (xrepo, system, Conan, vcpkg) |
| Fetch dependencies | FetchContent, or Conan/vcpkg | subprojects + wraps (WrapDB) | no (system packages) | built in (xrepo) |
| Cross-compiling | toolchain file | cross file (build/host/target) | --host=triplet + cross tools |
-p/-a/--toolchain/--sdk |
| Shared libraries | add_library(SHARED), VERSION/SOVERSION |
library(), version/soversion |
libtool, -version-info c:r:a |
set_kind("shared"), set_version(…, {soname = true}) |
| Tests | CTest | meson test |
make check |
xmake test |
| Install + pkg-config | install(), .pc by hand or via template |
install: true, pkgconfig.generate() |
make install, .pc.in template |
xmake install, utils.install.pkgconfig_importfiles |
| Release tarball | CPack (TGZ) |
meson dist (from git, self-tested) |
make distcheck (self-tested) |
xmake pack |
| IDE support | everywhere | good (introspection, VS Code, Qt Creator, CLion) | via compile_commands (bear) |
VS Code plugin, exported projects |
| Typical users | most C++ projects, KDE, LLVM | GNOME, systemd, Mesa, GStreamer, QEMU, PostgreSQL | GNU, classic Unix libraries | games, embedded, many Chinese OSS projects |
How to choose
- A new C++ project that others will consume: CMake. Not because it is the nicest, but because every IDE, package manager (Conan, vcpkg) and downstream user expects a CMake package. If you pick something else, still install a CMake config file or at least a
.pcfile. - A new C project, a Linux system component, or anything joining the GNOME/freedesktop/systemd world: Meson. It is faster, stricter and easier to read, and cross-compiling is excellent.
- An existing Autotools project: keep Autotools, unless there is a real reason to migrate (Windows/MSVC support, build speed, nobody understands the M4). Learn to read
configure.acand runmake distcheckin CI. Migrations of large projects (systemd, GStreamer, Mesa, PostgreSQL) to Meson took months and kept both systems in parallel for a while. - A small application where you want packages with almost no setup, or an embedded/game project with many toolchains: xmake is very productive. Check that your team (and your users, if it is a library) can live with a less common tool.
- Huge polyglot monorepos with remote caching: none of these; look at Bazel.
Test yourself
Which tool lets a user build a release tarball with only a POSIX shell, make and a compiler installed?
- CMake
- Meson
- Autotools
- xmake
You are writing a new C++ library that many other projects will consume. Why is CMake usually the pragmatic choice?
- It is the fastest build tool
- Consumers, IDEs and package managers (Conan, vcpkg) expect a CMake package; whatever you choose, you should install CMake config and/or pkg-config files
- Meson can't build C++
- xmake can't install libraries
Which statement about source globbing is correct?
- Meson allows
files('*.c') - xmake's
add_files("src/*.c")is normal usage, while Meson doesn't allow globbing at all - Automake supports
*_SOURCES = *.c - CMake forbids
file(GLOB)