craft_parts.plugins.cmake_plugin module

The cmake plugin.

class craft_parts.plugins.cmake_plugin.CMakePlugin(*, properties, part_info)[source]

Bases: Plugin

The cmake plugin is useful for building cmake based parts.

These are projects that have a CMakeLists.txt that drives the build. The plugin requires a CMakeLists.txt in the root of the source tree.

This plugin uses the common plugin keywords as well as those for “sources”. For more information check the ‘plugins’ topic for the former and the ‘sources’ topic for the latter.

This implementation follows the syntax and behavior used in the Snapcraft cmake plugin for core20. Unlike the cmake plugin used for core18, CMAKE_INSTALL_PREFIX is not automatically set. To retain compatibility with the Snapcraft core18 plugin, define the cmake parameter -DCMAKE_INSTALL_PREFIX= in your project. This also allows libraries built using the cmake plugin and staged by a different part to be automatically recognized without defining additional parameters such as CMAKE_INCLUDE_PATH or CMAKE_INSTALL_PATH.

This plugin uses the following plugin-specific keywords:

  • cmake-parameters (list of strings) parameters to pass to the build using the common cmake semantics.

  • cmake-generator (string; default: “Unix Makefiles”) Determine what native build system is to be used. Can be either Ninja or Unix Makefiles (default).

Parameters:
get_build_commands()[source]

Return a list of commands to run during the build step.

Return type:

list[str]

get_build_environment()[source]

Return a dictionary with the environment to use in the build step.

Return type:

dict[str, str]

get_build_packages()[source]

Return a set of required packages to install in the build environment.

Return type:

set[str]

get_build_snaps()[source]

Return a set of required snaps to install in the build environment.

Return type:

set[str]

classmethod get_out_of_source_build()[source]

Return whether the plugin performs out-of-source-tree builds.

Return type:

bool

properties_class

alias of CMakePluginProperties

class craft_parts.plugins.cmake_plugin.CMakePluginProperties(**data)[source]

Bases: PluginProperties

The part properties used by the cmake plugin.

Parameters:

data (Any)

cmake_generator: str
cmake_parameters: list[str]
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'alias_generator': <function PluginProperties.<lambda>>, 'extra': 'forbid', 'frozen': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'cmake_generator': FieldInfo(annotation=str, required=False, default='Unix Makefiles', alias='cmake-generator', alias_priority=1), 'cmake_parameters': FieldInfo(annotation=list[str], required=False, default=[], alias='cmake-parameters', alias_priority=1), 'plugin': FieldInfo(annotation=Literal['cmake'], required=False, default='cmake', alias='plugin', alias_priority=1), 'source': FieldInfo(annotation=str, required=True, alias='source', alias_priority=1)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

plugin: Literal['cmake']
source: str