CPack AppImage Generator

Added in version 4.2.

The CPack AppImage generator enables bundling an application into the AppImage format. It uses appimagetool to pack the application and patchelf to set the application RPATH to a relative path based on where the AppImage will be mounted.

The appimagetool does not scan for libraries dependencies. It only packs the installed content and checks if the provided .desktop file was properly created. For best compatibility, it's recommended to build on an old LTS distribution and to include any dependencies in the generated file.

The snippet below can be added to your CMakeLists.txt file. Replace my_application_target with your application target. The example will do a best effort to identify the libraries your application links to and copy them to the install location.

install(CODE [[
    file(GET_RUNTIME_DEPENDENCIES
        EXECUTABLES $<TARGET_FILE:my_application_target>
        RESOLVED_DEPENDENCIES_VAR resolved_deps
    )

    foreach(dep ${resolved_deps})
        # copy the symlink
        file(COPY ${dep} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)

        # Resolve the real path of the dependency (follows symlinks)
        file(REAL_PATH ${dep} resolved_dep_path)

        # Copy the resolved file to the destination
        file(COPY ${resolved_dep_path} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
    endforeach()
]])

The CPack AppImage generator will generate a default AppRun based on the provided .desktop entry. Alternatively, a custom AppRun can be provided by setting CPACK_APPIMAGE_APPRUN_FILE, or by installing it to the top level of the AppDir, e.g., via the install() command. In both cases it will be used instead of the generated one. The variable is preferred because it does not depend on CPACK_PACKAGING_INSTALL_PREFIX.

For Qt-based projects, it is recommended to call qt_generate_deploy_app_script() or qt_generate_deploy_qml_app_script() and install the files generated by the script. This will install the Qt plugins.

You must also set CPACK_PACKAGE_ICON with the same value listed in the Desktop file.

Note

The appimagetool uses environment variables to define its behavior. These variables are exposed here for convenience, but it is also possible to pass environment variables to it by setting the environment of a Package Preset in a CMakePresets.json file, see cmake-presets(7).

Variables Specific to CPack AppImage Generator

CPACK_APPIMAGE_TOOL_EXECUTABLE

Name of the appimagetool executable. If not given as an absolute path, logic based on find_program() will be used internally with this value to find the executable.

Default:

appimagetool

CPACK_APPIMAGE_PATCHELF_EXECUTABLE

Name of the patchelf executable. If not given as an absolute path, logic based on find_program() will be used internally with this value to find the executable.

Default:

patchelf

CPACK_APPIMAGE_DESKTOP_FILE

Name of the freedesktop.org desktop file to be installed. If not specified, the first .desktop file found in the list of files to be installed will be used. There must be a valid .desktop file for the package, and it must include an Icon entry that matches CPACK_PACKAGE_ICON without the file extension. The actual installed location of the icon should follow the freedesktop.org specification.

Default:

Unset

CPACK_APPIMAGE_APPRUN_FILE

Added in version 4.6.

Absolute path to a custom AppRun file. The file is copied to the top level of the AppDir and made executable, taking precedence over both the generated AppRun and an AppRun installed by the project.

Default:

Unset

CPACK_APPIMAGE_UPDATE_INFORMATION

Embed the value of this variable as the update information. See the appimagetool source code for the supported values and formats of the --updateinformation option. It is highly recommended to have the zsyncmake tool installed if using zsync update information.

Default:

Unset

CPACK_APPIMAGE_GUESS_UPDATE_INFORMATION

When this variable is true, add the --guess option to the appimagetool invocation. This directs the tool to try to guess appropriate update information based on GitHub or GitLab environment variables.

Default:

Unset

CPACK_APPIMAGE_COMPRESSOR

Override the appimagetool's default type of squashfs compression (zstd). This corresponds to the appimagetool --comp option.

Default:

Unset

CPACK_APPIMAGE_MKSQUASHFS_OPTIONS

List of arguments to pass through to mksquashfs. Each of these will be preceded by --mksquashfs-opt on the appimagetool command line.

Default:

Unset

CPACK_APPIMAGE_NO_APPSTREAM

If set to true, do not check AppStream metadata. This passes the --no-appstream option to appimagetool.

Default:

Unset

CPACK_APPIMAGE_EXCLUDE_FILE

Use the specified file as an exclude file for mksquashfs, in addition to .appimageignore. This uses the --exclude-file option to appimagetool.

Default:

Unset

CPACK_APPIMAGE_RUNTIME_FILE

Specify a runtime file to use instead of letting the appimagetool download a runtime to embed in the generated AppImage.

Default:

Unset

CPACK_APPIMAGE_SIGN

When set to true, sign the generated AppImage with gpg[2]. CPACK_APPIMAGE_SIGN_KEY should also be specified if using this option.

Default:

Unset

CPACK_APPIMAGE_SIGN_KEY

Key ID to use for gpg[2] signatures when signing is enabled with CPACK_APPIMAGE_SIGN.

Default:

Unset

CPACK_APPIMAGE_SIGN_PASSPHRASE

Added in version 4.6.

If the CPACK_APPIMAGE_SIGN_KEY is encrypted and requires a passphrase to be used for signing (and, for some reason, GnuPG cannot be used interactively, e.g., in a CI environment), this environment variable can be used to safely pass the key.

Default:

Unset

CPACK_APPIMAGE_ARCH

Added in version 4.6.

Architecture of the AppImage, passed to appimagetool in the ARCH environment variable. The CPack module derives it from the CMAKE_SYSTEM_PROCESSOR of the project, so it matches the target when cross-compiling. The supported values are x86_64, i686, aarch64, and armhf.

It needs to be set when the processor cannot be mapped to one of those values and appimagetool cannot automatically determine the architecture of the binaries inside the AppDir to choose a suitable runtime (e.g., when binaries for multiple architectures or just shell scripts are contained in there).

Default:

Derived from CMAKE_SYSTEM_PROCESSOR on Linux

CPACK_APPIMAGE_VERSION

Added in version 4.6.

This value will be inserted by appimagetool into the root desktop file.

Default:

CPACK_PACKAGE_VERSION