On this page
Make / CMake / Meson Build Systems
Coverage: GNU Make (pattern rules) → CMake (target-based) → Meson (declarative) → pkg-config → Build system selection Applicable to: C/C++ project builds
GNU Make
Core Syntax
# Basic rule: target: prerequisites → recipe
: : # pattern rule# Variables:
CC := gcc
CFLAGS := -O2 -Wall
LDFLAGS := -lm
# Automatic dependency generation:
:
CMake: Target-Based
# CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(myproj C)
add_library(mylib STATIC lib.c lib.h)
target_compile_features(mylib PRIVATE c_std_11)
add_executable(prog main.c)
target_link_libraries(prog PRIVATE mylib)
# Find external dependencies:
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZLIB REQUIRED zlib)
target_link_libraries(prog PRIVATE ${ZLIB_LIBRARIES})
target_include_directories(prog PRIVATE ${ZLIB_INCLUDE_DIRS})
Meson: Declarative
# meson.build
project('myproj', 'c', version: '1.0')
zlib_dep = dependency('zlib')
mylib = static_library('mylib', 'lib.c', 'lib.h')
executable('prog', 'main.c',
link_with: mylib,
dependencies: zlib_dep,
c_args: ['-O2', '-Wall'])
Comparison of the Three
| GNU Make | CMake | Meson | |
|---|---|---|---|
| Model | imperative (how to do it) | target-based | declarative (what is needed) |
| Dependency Management | Manual | find_package + pkg-config | Built-in dependency() |
| Compilation Speed | Baseline | Slow (configure phase) | Fast (ninja + caching) |
| Learning Curve | Medium | Medium-High | Low |
| IDE Integration | Weak | Strong (CLion, VSCode) | Medium |
| Gentoo ebuild | Common | Common | Increasing |
pkg-config
# Query installed libraries:
# .pc file locations:
# Custom .pc file:
prefix=/usr/local
References
- Documentation:
info make, cmake.org/documentation, mesonbuild.com - Gentoo:
man 5 ebuild(Make integration)
Keywords: Make, CMake, Meson, pattern rule, target-based, pkg-config, ninja