diff --git a/Help/cpack_gen/appimage.rst b/Help/cpack_gen/appimage.rst index b4d8e85191..10e363893e 100644 --- a/Help/cpack_gen/appimage.rst +++ b/Help/cpack_gen/appimage.rst @@ -58,6 +58,14 @@ Qt plugins. You must also set :variable:`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 + :ref:`Package Preset` in a ``CMakePresets.json`` file, see + :manual:`cmake-presets(7)`. + Variables Specific to CPack AppImage Generator ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -166,3 +174,34 @@ Variables Specific to CPack AppImage Generator :variable:`CPACK_APPIMAGE_SIGN`. :Default: Unset + +.. variable:: CPACK_APPIMAGE_SIGN_PASSPHRASE + + .. versionadded:: 4.6 + + If the :variable:`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 + +.. variable:: CPACK_APPIMAGE_ARCH + + .. versionadded:: 4.6 + + Needs to be set whenever :variable:`CMAKE_SYSTEM_PROCESSOR` is not transformed + to a proper architecture 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: CMAKE_SYSTEM_PROCESSOR + +.. variable:: CPACK_APPIMAGE_VERSION + + .. versionadded:: 4.6 + + This value will be inserted by appimagetool into the root desktop file. + + :Default: :variable:`CPACK_PACKAGE_VERSION` diff --git a/Help/release/dev/cpack-appimage.rst b/Help/release/dev/cpack-appimage.rst new file mode 100644 index 0000000000..58a7ddc160 --- /dev/null +++ b/Help/release/dev/cpack-appimage.rst @@ -0,0 +1,7 @@ +cpack-appimage +-------------- + +* The :cpack_gen:`CPack AppImage Generator` gained + :variable:`CPACK_APPIMAGE_VERSION`, + :variable:`CPACK_APPIMAGE_ARCH`, and + :variable:`CPACK_APPIMAGE_SIGN_PASSPHRASE` options. diff --git a/Source/CPack/cmCPackAppImageGenerator.cxx b/Source/CPack/cmCPackAppImageGenerator.cxx index 17a9da3bb5..13ea88d5b1 100644 --- a/Source/CPack/cmCPackAppImageGenerator.cxx +++ b/Source/CPack/cmCPackAppImageGenerator.cxx @@ -58,6 +58,30 @@ int cmCPackAppImageGenerator::InitializeInternal() return 0; } + if (cmValue packageVersion = this->GetOption("CPACK_PACKAGE_VERSION")) { + this->SetOptionIfNotSet("CPACK_APPIMAGE_VERSION", packageVersion); + } + + if (!this->IsSet("CPACK_APPIMAGE_ARCH")) { + if (cmValue systemProcessor = this->GetOption("CMAKE_SYSTEM_PROCESSOR")) { + if (systemProcessor == "x86_64" || systemProcessor == "amd64") { + this->SetOption("CPACK_APPIMAGE_ARCH", "x86_64"); + } else if (systemProcessor == "i386" || systemProcessor == "i686" || + systemProcessor == "x86") { + this->SetOption("CPACK_APPIMAGE_ARCH", "i686"); + } else if (systemProcessor == "aarch64" || systemProcessor == "arm64") { + this->SetOption("CPACK_APPIMAGE_ARCH", "aarch64"); + } else if (cmSystemTools::StringStartsWith(systemProcessor, "arm")) { + this->SetOption("CPACK_APPIMAGE_ARCH", "armhf"); + } else { + cmCPackLogger(cmCPackLog::LOG_OUTPUT, + "Could not transform CMAKE_SYSTEM_PROCESSOR, counting " + "on appimagetool architecture detection." + << std::endl); + } + } + } + return Superclass::InitializeInternal(); } @@ -298,6 +322,13 @@ int cmCPackAppImageGenerator::PackageFiles() } }; + auto addEnvOption = [this](std::string const& op, std::string envName) { + auto opt = this->GetOption(op); + if (opt) { + cmSystemTools::PutEnv(cmStrCat(envName, '=', *opt)); + } + }; + addOption("CPACK_APPIMAGE_UPDATE_INFORMATION", "--updateinformation"); addOptionFlag("CPACK_APPIMAGE_GUESS_UPDATE_INFORMATION", "--guess"); @@ -316,6 +347,13 @@ int cmCPackAppImageGenerator::PackageFiles() addOption("CPACK_APPIMAGE_SIGN_KEY", "--sign-key"); + addEnvOption("CPACK_APPIMAGE_ARCH", "ARCH"); + + addEnvOption("CPACK_APPIMAGE_SIGN_PASSPHRASE", + "APPIMAGETOOL_SIGN_PASSPHRASE"); + + addEnvOption("CPACK_APPIMAGE_VERSION", "VERSION"); + cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Running AppImageTool: " << cmSystemTools::PrintSingleCommand(command) << std::endl);