CMake plugin

The CMake plugin configures projects using CMake and builds them either using GNU Make or Ninja as the build system.

After a successful build, this plugin will install the generated binaries in $CRAFT_PART_INSTALL.

Keys

This plugin provides the following unique keys.

cmake-generator

Type

str

Description

The build system to use.

Values

Value

Description

Unix Makefiles

Default. Runs GNU Make.

Ninja

Runs Ninja

cmake-parameters

Type

list[str]

Description

The parameters to pass to the build system.

Environment variables

The plugin sets the CMAKE_PREFIX_PATH to the stage directory.

Dependencies

The CMake plugin needs the cmake executable to configure, and make or ninja executable to build. make and ninja are dependent on the selected cmake-generator. These dependencies are provided by the plugin as a build-packages entry.

The plugin also sets up gcc. Other compiler or library dependencies the source requires to build are to be provided.

How it works

During the build step the plugin performs the following actions:

  1. Run cmake in the build directory referring to the pulled source directory (this plugin runs an out of tree build). The preferred generator is set at this stage, and the project is configured with any cmake-parameters that might have been set.

  2. cmake --build is run to build the source, cmake itself takes care of calling make or ninja.

  3. cmake calls the install target with DESTDIR set to $CRAFT_PART_INSTALL.

Example

The following snippet declares a part using the cmake plugin. It sets the CMAKE_BUILD_TYPE to RelWithDebInfo to generate debug symbols from the build:

parts:
  hello:
    source: .
    plugin: cmake
    cmake-parameters:
      - -DCMAKE_BUILD_TYPE=RelWithDebInfo