From 078f28f16bd71906205b2d755caa6ca247b4e486 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Thu, 8 Jan 2026 14:25:44 +0100 Subject: 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 --- Help/cpack_gen/appimage.rst | 7 +++++++ Source/CPack/cmCPackAppImageGenerator.cxx | 15 +++++++++++++-- .../AppImageTestApp-cpack-AppImage-stdout.txt | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Help/cpack_gen/appimage.rst b/Help/cpack_gen/appimage.rst index 03d02b8..42dec8e 100644 --- a/Help/cpack_gen/appimage.rst +++ b/Help/cpack_gen/appimage.rst @@ -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 diff --git a/Source/CPack/cmCPackAppImageGenerator.cxx b/Source/CPack/cmCPackAppImageGenerator.cxx index 373dcfa..c6d4d8a 100644 --- a/Source/CPack/cmCPackAppImageGenerator.cxx +++ b/Source/CPack/cmCPackAppImageGenerator.cxx @@ -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 diff --git a/Tests/RunCMake/CPack_AppImage/AppImageTestApp-cpack-AppImage-stdout.txt b/Tests/RunCMake/CPack_AppImage/AppImageTestApp-cpack-AppImage-stdout.txt index 67d5a51..c8ec5f5 100644 --- a/Tests/RunCMake/CPack_AppImage/AppImageTestApp-cpack-AppImage-stdout.txt +++ b/Tests/RunCMake/CPack_AppImage/AppImageTestApp-cpack-AppImage-stdout.txt @@ -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 -- cgit v0.12