Packaging
The packaging module generates Alpine Linux APK packages from project metadata. Its primary purpose is to produce installable packages in CI pipelines, enabling automated builds that create distributable artifacts from every release. The generated APKBUILD is derived entirely from the CMake project variables, so there is no separate packaging configuration to maintain.
Prerequisites
The module requires abuild to be installed. If it is
not found, the module is silently skipped — this allows the same CMakeLists.txt to work on systems without
Alpine packaging tools. Building APK packages with abuild also requires a
signing key.
Cache variables
| Variable | Default | Description |
|---|---|---|
APK_ARCH | (auto-detected) | Package architecture (all or noarch) |
APK_LICENSE | EUPL-1.2 | Package license (SPDX identifier) |
APK_MAINTAINER | (empty) | Package maintainer in Name <email> format |
APK_PKGREL | 0 | Package release number |
APK_ARCH is auto-detected from the project's enabled languages: all when any compiled language is enabled
(C, CXX, etc.), noarch when no compiled languages are enabled (LANGUAGES NONE). Set it explicitly before
including the module to override the detection.
Build dependencies
The makedepends field is populated automatically. The base set (cmake, ninja) is always included. Additional
packages are registered by the modules that need them:
| Module | Packages |
|---|---|
| (base) | cmake, ninja |
| compiler | gcc, musl-dev (for C) |
| i18n | gettext-dev |
Language-specific compiler packages are added based on the project's ENABLED_LANGUAGES: gcc and musl-dev
for C, g++ and musl-dev for C++.
Variable mapping
CMake project variables are mapped to Alpine packaging fields:
| APKBUILD field | Source |
|---|---|
arch | APK_ARCH |
builddir | $srcdir/PROJECT_NAME-PROJECT_VERSION |
license | APK_LICENSE |
maintainer | APK_MAINTAINER |
makedepends | (auto-detected, see above) |
pkgdesc | PROJECT_DESCRIPTION |
pkgname | PROJECT_NAME |
pkgrel | APK_PKGREL |
pkgver | PROJECT_VERSION (Alpine format) |
source | PROJECT_NAME-PROJECT_VERSION.tar.gz |
url | PROJECT_HOMEPAGE_URL |
Version mapping
The pkgver field is derived from the project version. Alpine's version format differs from
SemVer: pre-release suffixes use an underscore instead of a hyphen. The module
translates between the two formats automatically:
| Project version | pkgver | Notes |
|---|---|---|
1.2.3 | 1.2.3 | Stable release |
1.2.0-rc1 | 1.2.0_rc1 | Release candidate |
1.2.0-rc2 | 1.2.0_rc2 | Release candidate |
Alpine sorts _rc suffixes before the corresponding stable release (1.2.0_rc1 < 1.2.0_rc2 < 1.2.0), so
the version ordering is preserved.
If the project version contains a prerelease identifier that is not a release candidate (for example, a
development version with distance and hash suffixes like 1.2.3-5.gabcdef), no APKBUILD is generated and
the apk target will fail at build time with a descriptive error. Only tagged stable releases and release
candidates produce packages.
The build phase uses Ninja with CMAKE_BUILD_TYPE=Release and CMAKE_INSTALL_PREFIX=/usr.
The APKBUILD generation is deferred to the end of the configure step so that all modules can register their build
dependencies first. The output is written to ${CMAKE_BINARY_DIR}/apk/APKBUILD.
Build targets
| Target | Description |
|---|---|
apk | Builds the APK package from the source tarball |
The module is only loaded for top-level projects; when included from a subdirectory it is silently skipped.
The apk target expects a source tarball — created by make dist — to exist in the project root. It
copies the tarball into the build area and invokes abuild to produce the package.
Usage
The typical workflow is to create a source distribution first, then build the package:
make dist
make apk
The built package is placed under ${CMAKE_BINARY_DIR}/apk/packages/.