Просмотр исходного кода

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
Mathieu 2 недель назад
Родитель
Сommit
078f28f16b

+ 7 - 0
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

+ 13 - 2
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
 

+ 1 - 0
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