CPack/AppImage: Derive CPACK_APPIMAGE_ARCH from the target processor

cpack only knows the host CMAKE_SYSTEM_PROCESSOR, so cross-compiled
AppImages got the host architecture.  Set the default in the CPack
module instead, where the project's target processor is known.

Closes: #27556
This commit is contained in:
Daniel Nicoletti authored and Brad King committed 2026-11-02 16:24:35 -05:00
1 parent fb398e1000
commit 370c27de22
8 files changed
+38 -26

No files matched your search

+12 -6
View File
@@ -190,13 +190,19 @@ Variables Specific to CPack AppImage Generator
.. 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).
Architecture of the AppImage, passed to ``appimagetool`` in the ``ARCH``
environment variable. The :module:`CPack` module derives it from the
:variable:`CMAKE_SYSTEM_PROCESSOR` of the project, so it matches the target
when cross-compiling. The supported values are ``x86_64``, ``i686``,
``aarch64``, and ``armhf``.
:Default: CMAKE_SYSTEM_PROCESSOR
It needs to be set when the processor cannot be mapped to one of those
values 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: Derived from :variable:`CMAKE_SYSTEM_PROCESSOR` on Linux
.. variable:: CPACK_APPIMAGE_VERSION
+13
View File
@@ -930,6 +930,19 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
_cpack_set_default(CPACK_INNOSETUP_ARCHITECTURE "x64")
endif()
# AppImage specific variables
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$")
_cpack_set_default(CPACK_APPIMAGE_ARCH "x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i386|i686|x86)$")
_cpack_set_default(CPACK_APPIMAGE_ARCH "i686")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$")
_cpack_set_default(CPACK_APPIMAGE_ARCH "aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
_cpack_set_default(CPACK_APPIMAGE_ARCH "armhf")
endif()
endif()
# WiX specific variables
_cpack_set_default(CPACK_WIX_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
if(NOT DEFINED CPACK_WIX_INSTALL_SCOPE)
-20
View File
@@ -62,26 +62,6 @@ int cmCPackAppImageGenerator::InitializeInternal()
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();
}
@@ -0,0 +1,3 @@
include(${RunCMake_SOURCE_DIR}/check.cmake)
test_variable(CPACK_APPIMAGE_ARCH "aarch64")
@@ -0,0 +1,3 @@
# Simulate cross-compiling to a target processor that differs from the host
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm64)
@@ -0,0 +1,3 @@
include(${RunCMake_SOURCE_DIR}/check.cmake)
test_variable(CPACK_APPIMAGE_ARCH "")
@@ -0,0 +1,2 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv64)
@@ -11,6 +11,8 @@ run_cmake(CMP0172-WARN)
run_cmake(CMP0206-NEW)
run_cmake(CMP0206-OLD)
run_cmake(CMP0206-WARN)
run_cmake(AppImageArch)
run_cmake(AppImageArchUnknown)
run_cmake(Simple)
run_cmake(Default)
run_cmake(Special)