# CPackRPM

The built in (binary) CPack RPM generator (Unix only)

## Variables specific to CPack RPM generator

CPackRPM may be used to create RPM packages using `CPack`. CPackRPM is a `CPack` generator thus it uses the `CPACK_XXX` variables used by `CPack`.

CPackRPM has specific features which are controlled by the specifics `CPACK_RPM_XXX` variables.

`CPACK_RPM_<COMPONENT>_XXXX` variables may be used in order to have component specific values. Note however that `<COMPONENT>` refers to the grouping name written in upper case. It may be either a component name or a component GROUP name. Usually those variables correspond to RPM spec file entities. One may find information about spec files here http://www.rpm.org/wiki/Docs

Note

<COMPONENT> part of variables is preferred to be in upper case (for e.g. if component is named foo then use CPACK_RPM_FOO_XXXX variable name format) as is with other CPACK_<COMPONENT>_XXXX variables. For the purposes of back compatibility (CMake/CPack version 3.5 and lower) support for same cased component (e.g. fOo would be used as CPACK_RPM_fOo_XXXX) is still supported for variables defined in older versions of CMake/CPack but is not guaranteed for variables that will be added in the future. For the sake of back compatibility same cased component variables also override upper cased versions where both are present.

Here are some CPackRPM wiki resources that are here for historic reasons and are no longer maintained but may still prove useful:

> - https://cmake.org/Wiki/CMake:CPackConfiguration
> - https://cmake.org/Wiki/CMake:CPackPackageGenerators#RPM_.28Unix_Only.29

List of CPackRPM specific variables:

`CPACK_RPM_PACKAGE_COMPONENT`

  Enable component packaging for CPackRPM

  - Mandatory : NO
  - Default : OFF

  If enabled (ON) multiple packages are generated. By default a single package containing files of all components is generated.

`CPACK_RPM_PACKAGE_SUMMARY`
`CPACK_RPM_<component>_PACKAGE_SUMMARY`

  The RPM package summary.

  - Mandatory : YES
  - Default : `CPACK_PACKAGE_DESCRIPTION_SUMMARY`

`CPACK_RPM_PACKAGE_NAME`
`CPACK_RPM_<component>_PACKAGE_NAME`

  The RPM package name.

  - Mandatory : YES
  - Default : `CPACK_PACKAGE_NAME`

`CPACK_RPM_FILE_NAME`
`CPACK_RPM_<component>_FILE_NAME`

  Package file name.

  - Mandatory : YES

  - Default : `<CPACK_PACKAGE_FILE_NAME>[-<component>].rpm` with spaces

      replaced by ‘-‘

  This may be set to `RPM-DEFAULT` to allow rpmbuild tool to generate package file name by itself. Alternatively provided package file name must end with `.rpm` suffix.

  Note

  By using user provided spec file, rpm macro extensions such as for generating debuginfo packages or by simply using multiple components more than one rpm file may be generated, either from a single spec file or from multiple spec files (each component execution produces it’s own spec file). In such cases duplicate file names may occur as a result of this variable setting or spec file content structure. Duplicate files get overwritten and it is up to the packager to set the variables in a manner that will prevent such errors.

`CPACK_RPM_PACKAGE_VERSION`

  The RPM package version.

  - Mandatory : YES
  - Default : `CPACK_PACKAGE_VERSION`

`CPACK_RPM_PACKAGE_ARCHITECTURE`
`CPACK_RPM_<component>_PACKAGE_ARCHITECTURE`

  The RPM package architecture.

  - Mandatory : YES
  - Default : Native architecture output by `uname -m`

  This may be set to `noarch` if you know you are building a noarch package.

`CPACK_RPM_PACKAGE_RELEASE`

  The RPM package release.

  - Mandatory : YES
  - Default : 1

  This is the numbering of the RPM package itself, i.e. the version of the packaging and not the version of the content (see `CPACK_RPM_PACKAGE_VERSION`). One may change the default value if the previous packaging was buggy and/or you want to put here a fancy Linux distro specific numbering.

Note

This is the string that goes into the RPM `Release:` field. Some distros (e.g. Fedora, CentOS) require `1%{?dist}` format and not just a number. `%{?dist}` part can be added by setting `CPACK_RPM_PACKAGE_RELEASE_DIST`.

`CPACK_RPM_PACKAGE_RELEASE_DIST`

  The dist tag that is added RPM `Release:` field.

  - Mandatory : NO
  - Default : OFF

  This is the reported `%{dist}` tag from the current distribution or empty `%{dist}` if RPM macro is not set. If this variable is set then RPM `Release:` field value is set to `${CPACK_RPM_PACKAGE_RELEASE}%{?dist}`.

`CPACK_RPM_PACKAGE_LICENSE`

  The RPM package license policy.

  - Mandatory : YES
  - Default : “unknown”

`CPACK_RPM_PACKAGE_GROUP`
`CPACK_RPM_<component>_PACKAGE_GROUP`

  The RPM package group.

  - Mandatory : YES
  - Default : “unknown”

`CPACK_RPM_PACKAGE_VENDOR`

  The RPM package vendor.

  - Mandatory : YES
  - Default : CPACK_PACKAGE_VENDOR if set or “unknown”

`CPACK_RPM_PACKAGE_URL`
`CPACK_RPM_<component>_PACKAGE_URL`

  The projects URL.

  - Mandatory : NO
  - Default : -

`CPACK_RPM_PACKAGE_DESCRIPTION`
`CPACK_RPM_<component>_PACKAGE_DESCRIPTION`

  RPM package description.

  - Mandatory : YES
  - Default : `CPACK_COMPONENT_<compName>_DESCRIPTION` (component based installers only) if set, `CPACK_PACKAGE_DESCRIPTION_FILE` if set or “no package description available”

`CPACK_RPM_COMPRESSION_TYPE`

  RPM compression type.

  - Mandatory : NO
  - Default : -

  May be used to override RPM compression type to be used to build the RPM. For example some Linux distribution now default to lzma or xz compression whereas older cannot use such RPM. Using this one can enforce compression type to be used.

  Possible values are:

  - lzma
  - xz
  - bzip2
  - gzip

`CPACK_RPM_PACKAGE_AUTOREQ`
`CPACK_RPM_<component>_PACKAGE_AUTOREQ`

  RPM spec autoreq field.

  - Mandatory : NO
  - Default : -

  May be used to enable (1, yes) or disable (0, no) automatic shared libraries dependency detection. Dependencies are added to requires list.

  Note

  By default automatic dependency detection is enabled by rpm generator.

`CPACK_RPM_PACKAGE_AUTOPROV`
`CPACK_RPM_<component>_PACKAGE_AUTOPROV`

  RPM spec autoprov field.

  - Mandatory : NO
  - Default : -

  May be used to enable (1, yes) or disable (0, no) automatic listing of shared libraries that are provided by the package. Shared libraries are added to provides list.

  Note

  By default automatic provides detection is enabled by rpm generator.

`CPACK_RPM_PACKAGE_AUTOREQPROV`
`CPACK_RPM_<component>_PACKAGE_AUTOREQPROV`

  RPM spec autoreqprov field.

  - Mandatory : NO
  - Default : -

  Variable enables/disables autoreq and autoprov at the same time. See `CPACK_RPM_PACKAGE_AUTOREQ` and `CPACK_RPM_PACKAGE_AUTOPROV` for more details.

  Note

  By default automatic detection feature is enabled by rpm.

`CPACK_RPM_PACKAGE_REQUIRES`
`CPACK_RPM_<component>_PACKAGE_REQUIRES`

  RPM spec requires field.

  - Mandatory : NO
  - Default : -

  May be used to set RPM dependencies (requires). Note that you must enclose the complete requires string between quotes, for example:

      set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.5.0, cmake >= 2.8")

  The required package list of an RPM file could be printed with:

      rpm -qp --requires file.rpm

`CPACK_RPM_PACKAGE_CONFLICTS`
`CPACK_RPM_<component>_PACKAGE_CONFLICTS`

  RPM spec conflicts field.

  - Mandatory : NO
  - Default : -

  May be used to set negative RPM dependencies (conflicts). Note that you must enclose the complete requires string between quotes, for example:

      set(CPACK_RPM_PACKAGE_CONFLICTS "libxml2")

  The conflicting package list of an RPM file could be printed with:

      rpm -qp --conflicts file.rpm

`CPACK_RPM_PACKAGE_REQUIRES_PRE`
`CPACK_RPM_<component>_PACKAGE_REQUIRES_PRE`

  RPM spec requires(pre) field.

  - Mandatory : NO
  - Default : -

  May be used to set RPM preinstall dependencies (requires(pre)). Note that you must enclose the complete requires string between quotes, for example:

      set(CPACK_RPM_PACKAGE_REQUIRES_PRE "shadow-utils, initscripts")

`CPACK_RPM_PACKAGE_REQUIRES_POST`
`CPACK_RPM_<component>_PACKAGE_REQUIRES_POST`

  RPM spec requires(post) field.

  - Mandatory : NO
  - Default : -

  May be used to set RPM postinstall dependencies (requires(post)). Note that you must enclose the complete requires string between quotes, for example:

      set(CPACK_RPM_PACKAGE_REQUIRES_POST "shadow-utils, initscripts")

`CPACK_RPM_PACKAGE_REQUIRES_POSTUN`
`CPACK_RPM_<component>_PACKAGE_REQUIRES_POSTUN`

  RPM spec requires(postun) field.

  - Mandatory : NO
  - Default : -

  May be used to set RPM postuninstall dependencies (requires(postun)). Note that you must enclose the complete requires string between quotes, for example:

      set(CPACK_RPM_PACKAGE_REQUIRES_POSTUN "shadow-utils, initscripts")

`CPACK_RPM_PACKAGE_REQUIRES_PREUN`
`CPACK_RPM_<component>_PACKAGE_REQUIRES_PREUN`

  RPM spec requires(preun) field.

  - Mandatory : NO
  - Default : -

  May be used to set RPM preuninstall dependencies (requires(preun)). Note that you must enclose the complete requires string between quotes, for example:

      set(CPACK_RPM_PACKAGE_REQUIRES_PREUN "shadow-utils, initscripts")

`CPACK_RPM_PACKAGE_SUGGESTS`
`CPACK_RPM_<component>_PACKAGE_SUGGESTS`

  RPM spec suggest field.

  - Mandatory : NO
  - Default : -

  May be used to set weak RPM dependencies (suggests). Note that you must enclose the complete requires string between quotes.

`CPACK_RPM_PACKAGE_PROVIDES`
`CPACK_RPM_<component>_PACKAGE_PROVIDES`

  RPM spec provides field.

  - Mandatory : NO
  - Default : -

  May be used to set RPM dependencies (provides). The provided package list of an RPM file could be printed with:

      rpm -qp --provides file.rpm

`CPACK_RPM_PACKAGE_OBSOLETES`
`CPACK_RPM_<component>_PACKAGE_OBSOLETES`

  RPM spec obsoletes field.

  - Mandatory : NO
  - Default : -

  May be used to set RPM packages that are obsoleted by this one.

`CPACK_RPM_PACKAGE_RELOCATABLE`

  build a relocatable RPM.

  - Mandatory : NO
  - Default : CPACK_PACKAGE_RELOCATABLE

  If this variable is set to TRUE or ON CPackRPM will try to build a relocatable RPM package. A relocatable RPM may be installed using:

      rpm --prefix or --relocate

  in order to install it at an alternate place see rpm(8). Note that currently this may fail if `CPACK_SET_DESTDIR` is set to `ON`. If `CPACK_SET_DESTDIR` is set then you will get a warning message but if there is file installed with absolute path you’ll get unexpected behavior.

`CPACK_RPM_SPEC_INSTALL_POST`

  Deprecated - use `CPACK_RPM_POST_INSTALL_SCRIPT_FILE` instead.

  - Mandatory : NO
  - Default : -
  - Deprecated: YES

  This way of specifying post-install script is deprecated, use `CPACK_RPM_POST_INSTALL_SCRIPT_FILE`. May be used to set an RPM post-install command inside the spec file. For example setting it to `/bin/true` may be used to prevent rpmbuild to strip binaries.

`CPACK_RPM_SPEC_MORE_DEFINE`

  RPM extended spec definitions lines.

  - Mandatory : NO
  - Default : -

  May be used to add any `%define` lines to the generated spec file.

`CPACK_RPM_PACKAGE_DEBUG`

  Toggle CPackRPM debug output.

  - Mandatory : NO
  - Default : -

  May be set when invoking cpack in order to trace debug information during CPack RPM run. For example you may launch CPack like this:

      cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM

`CPACK_RPM_USER_BINARY_SPECFILE`
`CPACK_RPM_<componentName>_USER_BINARY_SPECFILE`

  A user provided spec file.

  - Mandatory : NO
  - Default : -

  May be set by the user in order to specify a USER binary spec file to be used by CPackRPM instead of generating the file. The specified file will be processed by configure_file( @ONLY).

`CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE`

  Spec file template.

  - Mandatory : NO
  - Default : -

  If set CPack will generate a template for USER specified binary spec file and stop with an error. For example launch CPack like this:

      cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM

  The user may then use this file in order to hand-craft is own binary spec file which may be used with `CPACK_RPM_USER_BINARY_SPECFILE`.

`CPACK_RPM_PRE_INSTALL_SCRIPT_FILE`
`CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE`

  Path to file containing pre (un)install script.

  - Mandatory : NO
  - Default : -

  May be used to embed a pre (un)installation script in the spec file. The referred script file (or both) will be read and directly put after the `%pre` or `%preun` section If `CPACK_RPM_PACKAGE_COMPONENT` is set to ON the (un)install script for each component can be overridden with `CPACK_RPM_<COMPONENT>_PRE_INSTALL_SCRIPT_FILE` and `CPACK_RPM_<COMPONENT>_PRE_UNINSTALL_SCRIPT_FILE`. One may verify which scriptlet has been included with:

      rpm -qp --scripts  package.rpm

`CPACK_RPM_POST_INSTALL_SCRIPT_FILE`
`CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE`

  Path to file containing post (un)install script.

  - Mandatory : NO
  - Default : -

  May be used to embed a post (un)installation script in the spec file. The referred script file (or both) will be read and directly put after the `%post` or `%postun` section. If `CPACK_RPM_PACKAGE_COMPONENT` is set to ON the (un)install script for each component can be overridden with `CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE` and `CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE`. One may verify which scriptlet has been included with:

      rpm -qp --scripts  package.rpm

`CPACK_RPM_USER_FILELIST`
`CPACK_RPM_<COMPONENT>_USER_FILELIST`
  - Mandatory : NO
  - Default : -

  May be used to explicitly specify `%(<directive>)` file line in the spec file. Like `%config(noreplace)` or any other directive that be found in the `%files` section. Since CPackRPM is generating the list of files (and directories) the user specified files of the `CPACK_RPM_<COMPONENT>_USER_FILELIST` list will be removed from the generated list.

`CPACK_RPM_CHANGELOG_FILE`

  RPM changelog file.

  - Mandatory : NO
  - Default : -

  May be used to embed a changelog in the spec file. The referred file will be read and directly put after the `%changelog` section.

`CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST`

  list of path to be excluded.

  - Mandatory : NO
  - Default : /etc /etc/init.d /usr /usr/share /usr/share/doc /usr/bin /usr/lib /usr/lib64 /usr/include

  May be used to exclude path (directories or files) from the auto-generated list of paths discovered by CPack RPM. The defaut value contains a reasonable set of values if the variable is not defined by the user. If the variable is defined by the user then CPackRPM will NOT any of the default path. If you want to add some path to the default list then you can use `CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION` variable.

`CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION`

  additional list of path to be excluded.

  - Mandatory : NO
  - Default : -

  May be used to add more exclude path (directories or files) from the initial default list of excluded paths. See `CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST`.

`CPACK_RPM_RELOCATION_PATHS`

  Packages relocation paths list.

  - Mandatory : NO
  - Default : -

  May be used to specify more than one relocation path per relocatable RPM. Variable contains a list of relocation paths that if relative are prefixed by the value of `CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX` or by the value of `CPACK_PACKAGING_INSTALL_PREFIX` if the component version is not provided. Variable is not component based as its content can be used to set a different path prefix for e.g. binary dir and documentation dir at the same time. Only prefixes that are required by a certain component are added to that component - component must contain at least one file/directory/symbolic link with `CPACK_RPM_RELOCATION_PATHS` prefix for a certain relocation path to be added. Package will not contain any relocation paths if there are no files/directories/symbolic links on any of the provided prefix locations. Packages that either do not contain any relocation paths or contain files/directories/symbolic links that are outside relocation paths print out an `AUTHOR_WARNING` that RPM will be partially relocatable.

`CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX`

  Per component relocation path install prefix.

  - Mandatory : NO
  - Default : CPACK_PACKAGING_INSTALL_PREFIX

  May be used to set per component `CPACK_PACKAGING_INSTALL_PREFIX` for relocatable RPM packages.

`CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION`
`CPACK_RPM_NO_<COMPONENT>_INSTALL_PREFIX_RELOCATION`

  Removal of default install prefix from relocation paths list.

  - Mandatory : NO

  - Default : CPACK_PACKAGING_INSTALL_PREFIX or CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX

      are treated as one of relocation paths

  May be used to remove CPACK_PACKAGING_INSTALL_PREFIX and CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX from relocatable RPM prefix paths.

`CPACK_RPM_ADDITIONAL_MAN_DIRS`
  - Mandatory : NO
  - Default : -

  May be used to set additional man dirs that could potentially be compressed by brp-compress RPM macro. Variable content must be a list of regular expressions that point to directories containing man files or to man files directly. Note that in order to compress man pages a path must also be present in brp-compress RPM script and that brp-compress script must be added to RPM configuration by the operating system.

  Regular expressions that are added by default were taken from brp-compress RPM macro:

  - /usr/man/man.*
  - /usr/man/.*/man.*
  - /usr/info.*
  - /usr/share/man/man.*
  - /usr/share/man/.*/man.*
  - /usr/share/info.*
  - /usr/kerberos/man.*
  - /usr/X11R6/man/man.*
  - /usr/lib/perl5/man/man.*
  - /usr/share/doc/.*/man/man.*
  - /usr/lib/.*/man/man.*

`CPACK_RPM_DEFAULT_USER`
`CPACK_RPM_<compName>_DEFAULT_USER`

  default user ownership of RPM content

  - Mandatory : NO
  - Default : root

  Value should be user name and not UID. Note that <compName> must be in upper-case.

`CPACK_RPM_DEFAULT_GROUP`
`CPACK_RPM_<compName>_DEFAULT_GROUP`

  default group ownership of RPM content

  - Mandatory : NO
  - Default : root

  Value should be group name and not GID. Note that <compName> must be in upper-case.

`CPACK_RPM_DEFAULT_FILE_PERMISSIONS`
`CPACK_RPM_<compName>_DEFAULT_FILE_PERMISSIONS`

  default permissions used for packaged files

  - Mandatory : NO
  - Default : - (system default)

  Accepted values are lists with `PERMISSIONS`. Valid permissions are:

  - OWNER_READ
  - OWNER_WRITE
  - OWNER_EXECUTE
  - GROUP_READ
  - GROUP_WRITE
  - GROUP_EXECUTE
  - WORLD_READ
  - WORLD_WRITE
  - WORLD_EXECUTE

  Note that <compName> must be in upper-case.

`CPACK_RPM_DEFAULT_DIR_PERMISSIONS`
`CPACK_RPM_<compName>_DEFAULT_DIR_PERMISSIONS`

  default permissions used for packaged directories

  - Mandatory : NO
  - Default : - (system default)

  Accepted values are lists with PERMISSIONS. Valid permissions are the same as for `CPACK_RPM_DEFAULT_FILE_PERMISSIONS`. Note that <compName> must be in upper-case.

## Packaging of Symbolic Links

CPackRPM supports packaging of symbolic links:

    execute_process(COMMAND ${CMAKE_COMMAND}
      -E create_symlink <relative_path_location> <symlink_name>)
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/<symlink_name>
      DESTINATION <symlink_location> COMPONENT libraries)

Symbolic links will be optimized (paths will be shortened if possible) before being added to the package or if multiple relocation paths are detected, a post install symlink relocation script will be generated.

Symbolic links may point to locations that are not packaged by the same package (either a different component or even not packaged at all) but those locations will be treated as if they were a part of the package while determining if symlink should be either created or present in a post install script - depending on relocation paths.

Symbolic links that point to locations outside packaging path produce a warning and are treated as non relocatable permanent symbolic links.

Currently there are a few limitations though:

- For component based packaging component interdependency is not checked when processing symbolic links. Symbolic links pointing to content of a different component are treated the same way as if pointing to location that will not be packaged.
- Symbolic links pointing to a location through one or more intermediate symbolic links will not be handled differently - if the intermediate symbolic link(s) is also on a relocatable path, relocating it during package installation may cause initial symbolic link to point to an invalid location.