CPack/AppImage: Add support for a custom AppRun file

Allow the users to install a custom AppRun file.
Otherwise create a default one.

Fixes: #27478
This commit is contained in:
Mathieu
2026-01-08 14:25:44 +01:00
committed by Brad King
parent 884b86e8c8
commit 078f28f16b
3 changed files with 21 additions and 2 deletions
+7
View File
@@ -40,6 +40,13 @@ application links to and copy them to the install location.
endforeach()
]])
The CPack AppImage generator will generate a default `AppRun`_ based on the
provided ``.desktop`` entry. Alternatively, if a custom ``AppRun`` is
installed, e.g., via the :command:`install` command, it will be used instead
of the generated one.
.. _`AppRun`: https://docs.appimage.org/introduction/software-overview.html#apprun
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
+13 -2
View File
@@ -18,6 +18,7 @@
#include "cmCPackLog.h"
#include "cmELF.h"
#include "cmGeneratedFileStream.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmValue.h"
@@ -182,8 +183,18 @@ int cmCPackAppImageGenerator::PackageFiles()
}
std::string const appRunFile = this->toplevel + "/AppRun";
{
// AppRun script will run our application
if (cmSystemTools::PathExists(appRunFile)) {
// User provided an AppRun file
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
cmStrCat("Found AppRun file: \"", appRunFile, '"')
<< std::endl);
} else {
// Generate a default AppRun script that will run our application
cmCPackLogger(
cmCPackLog::LOG_OUTPUT,
cmStrCat("No AppRun found, generating a default one that will run: \"",
application, '"')
<< std::endl);
cmGeneratedFileStream appRun(appRunFile);
appRun << R"sh(#! /usr/bin/env bash
@@ -7,6 +7,7 @@ CPack: Found Desktop file: "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1
CPack: Desktop file destination: "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux/com\.example\.app\.desktop"
CPack: Icon file: "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux/share/icons/hicolor/64x64/apps/ApplicationIcon\.png"
CPack: Icon link destination: "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux/ApplicationIcon\.png"
CPack: No AppRun found, generating a default one that will run: "bin/app"
CPack: Running AppImageTool: "[^"]*" "[^"]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux" "\.\./GeneratorTest-1\.2\.3-Linux\.AppImage" "--runtime-file" "[^"]*"
[^
]*/_CPack_Packages/Linux/AppImage/GeneratorTest-1\.2\.3-Linux should be packaged as \.\./GeneratorTest-1\.2\.3-Linux\.AppImage