AgentSkillsCN

archlinux-pkgbuild/build-systems

适用于使用 CMake 或 Meson 构建系统打包软件时使用——上游源码中存在 CMakeLists.txt 或 meson.build 文件。

SKILL.md
--- frontmatter
name: archlinux-pkgbuild/build-systems
description: Use when packaging software using CMake or Meson build systems - CMakeLists.txt or meson.build present in upstream source

Build System Packages (CMake & Meson)

For core PKGBUILD workflow, use archlinux-pkgbuild

This sub-skill covers CMake and Meson build systems with Arch-specific configuration requirements.

Quick Reference

Build SystemKey ToolPrefix FlagBuild TypeCommon Issues
CMakecmakeCMAKE_INSTALL_PREFIX=/usrCMAKE_BUILD_TYPE=Nonelib64, RPATH, /usr/local
Mesonmeson/arch-meson--prefix=/usr--buildtype=plainWrong prefix

CMake Packages

CMake is a cross-platform build system. Common for C/C++ projects.

CMake Key Rules

RuleDescription
CMAKE_BUILD_TYPEUse None (not Release) to avoid automatic -O3 flag override
CMAKE_INSTALL_PREFIXMust be /usr (not /usr/local)
CMAKE_INSTALL_LIBDIRMust be lib if project defaults to lib64
Verbose buildsUse VERBOSE=1 to verify compiler flags
RPATH securityUse CMAKE_SKIP_INSTALL_RPATH=YES or CMAKE_SKIP_RPATH=YES
cmake in makedependsAlways required

CMake Template

bash
pkgname=example
pkgver=1.0.0
pkgrel=1
pkgdesc="CMake-based package"
arch=('x86_64')
url="https://example.com"
license=('GPL')
depends=('lib1' 'lib2')
makedepends=('cmake')
source=("https://example.com/$pkgname-$pkgver.tar.gz")
sha256sums=('...')

build() {
    local cmake_options=(
        -B build
        -S "$pkgname-$pkgver"
        -W no-dev
        -D CMAKE_BUILD_TYPE=None
        -D CMAKE_INSTALL_PREFIX=/usr
        -D CMAKE_INSTALL_LIBDIR=lib
        -D CMAKE_SKIP_INSTALL_RPATH=YES
    )
    cmake "${cmake_options[@]}"
    cmake --build build
}

check() {
    ctest --test-dir build --output-on-failure
}

package() {
    DESTDIR="$pkgdir" cmake --install build
    install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

CMake Common Issues

IssueErrorFix
Wrong prefixFiles in /usr/local-DCMAKE_INSTALL_PREFIX=/usr
lib64 directorynamcap: file-in-non-standard-dir-DCMAKE_INSTALL_LIBDIR=lib
Insecure RPATHnamcap: insecure-rpath-DCMAKE_SKIP_INSTALL_RPATH=YES
-O3 overrideWrong optimization level-DCMAKE_BUILD_TYPE=None

Meson Packages

Meson is a fast, user-friendly build system that generates build files for backends like Ninja.

Meson Key Rules

RuleDescription
meson in makedependsAlways required
Build methodDirect: meson setup + meson compile, or arch-meson wrapper
Build directoryOut-of-source: commonly named build or _build
PrefixAlways --prefix=/usr (MANDATORY)
Build typeUse --buildtype=plain or omit with arch-meson

Meson Template

bash
pkgname=example
pkgver=1.0.0
pkgrel=1
pkgdesc="Example Meson-based application"
arch=('x86_64')
url="https://example.com"
license=('GPL')
depends=('lib1' 'lib2')
makedepends=('meson')
source=("https://example.com/$pkgname-$pkgver.tar.xz")
sha256sums=('...')

build() {
    arch-meson $pkgname-$pkgver build
    meson compile -C build
}

check() {
    meson test -C build --print-errorlogs
}

package() {
    meson install -C build --destdir "$pkgdir"
    install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

Meson Common Issues

IssueCauseFix
Files in /usr/localWrong prefixUse --prefix=/usr or arch-meson
Build type overrideOptimization flags not honoredUse --buildtype=plain
In-source buildBuild artifacts in sourceUse out-of-source build directory
Missing testsTests not runAdd check() with meson test