CPack AppImage generator

Added in version 4.2.

CPack AppImage generator allows to bundle an application into 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 check if the provided .desktop file was properly created. For best compatibility it's recommended to choose some old LTS distro and built it there, as well as including most dependencies on the generated file.

The snipped below can be added to your CMakeLists.txt file replacing my_application_target with your application target, it will do a best effort to scan and copy the libraries your application links to and copy to 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()
]])

For Qt based projects it's 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 Qt module's plugins.

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

Variables specific to CPack AppImage generator

CPACK_APPIMAGE_TOOL_EXECUTABLE

Name of the appimagetool executable, might be located in the build dir, full path or reachable in PATH.

Default:

appimagetool CPACK_PACKAGE_FILE_NAME

CPACK_APPIMAGE_PATCHELF_EXECUTABLE

Name of the patchelf executable, might be located in the build dir, full path or reachable in PATH.

Default:

patchelf CPACK_APPIMAGE_PATCHELF_EXECUTABLE

CPACK_APPIMAGE_DESKTOP_FILE

Name of freedesktop.org desktop file installed.

Mandatory:

Yes

Default:

CPACK_APPIMAGE_DESKTOP_FILE

CPACK_APPIMAGE_UPDATE_INFORMATION

Embed update information STRING; if zsyncmake is installed, generate zsync file.

Default:

CPACK_APPIMAGE_UPDATE_INFORMATION

CPACK_APPIMAGE_GUESS_UPDATE_INFORMATION

Guess update information based on GitHub or GitLab environment variables.

Default:

CPACK_APPIMAGE_GUESS_UPDATE_INFORMATION

CPACK_APPIMAGE_COMPRESSOR

Squashfs compression.

Default:

CPACK_APPIMAGE_COMPRESSOR

CPACK_APPIMAGE_MKSQUASHFS_OPTIONS

Arguments to pass through to mksquashfs.

Default:

CPACK_APPIMAGE_MKSQUASHFS_OPTIONS

CPACK_APPIMAGE_NO_APPSTREAM

Do not check AppStream metadata.

Default:

CPACK_APPIMAGE_NO_APPSTREAM

CPACK_APPIMAGE_EXCLUDE_FILE

Uses given file as exclude file for mksquashfs, in addition to .appimageignore.

Default:

CPACK_APPIMAGE_EXCLUDE_FILE

CPACK_APPIMAGE_RUNTIME_FILE

Runtime file to use, if not set a bash script will be generated.

Default:

CPACK_APPIMAGE_RUNTIME_FILE

CPACK_APPIMAGE_SIGN

Sign with gpg[2].

Default:

CPACK_APPIMAGE_SIGN

CPACK_APPIMAGE_SIGN_KEY

Key ID to use for gpg[2] signatures.

Default:

CPACK_APPIMAGE_SIGN_KEY