Skip to main content

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

VariableDefaultDescription
APK_ARCH(auto-detected)Package architecture (all or noarch)
APK_LICENSEEUPL-1.2Package license (SPDX identifier)
APK_MAINTAINER(empty)Package maintainer in Name <email> format
APK_PKGREL0Package 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:

ModulePackages
(base)cmake, ninja
compilergcc, musl-dev (for C)
i18ngettext-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 fieldSource
archAPK_ARCH
builddir$srcdir/PROJECT_NAME-PROJECT_VERSION
licenseAPK_LICENSE
maintainerAPK_MAINTAINER
makedepends(auto-detected, see above)
pkgdescPROJECT_DESCRIPTION
pkgnamePROJECT_NAME
pkgrelAPK_PKGREL
pkgverPROJECT_VERSION (Alpine format)
sourcePROJECT_NAME-PROJECT_VERSION.tar.gz
urlPROJECT_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 versionpkgverNotes
1.2.31.2.3Stable release
1.2.0-rc11.2.0_rc1Release candidate
1.2.0-rc21.2.0_rc2Release 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

TargetDescription
apkBuilds 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/.