Is your feature request related to a problem? Please describe.
The auto-detection of WAMR_BUILD_TARGET based on the CPU architecture is duplicated across many CMake files in the project with at least 3 different patterns, each supporting a slightly different subset of architectures. ARM auto-detection, which is the reason why I started to investigate, is missing — scripts detect AARCH64 but not ARM or THUMB. Some files use CMAKE_SYSTEM_PROCESSOR, others use CMAKE_HOST_SYSTEM_PROCESSOR. Some files detect AMD_64, MIPS, or XTENSA; most do not. This makes the build system inconsistent and harder to maintain.
Describe the solution you'd like
A single, centralized CMake module (e.g. build-scripts/detect_target.cmake) that handles all architecture auto-detection in one place, with the following behavior:
- Only runs when
WAMR_BUILD_TARGET is not already defined (preserving override).
- Checks
CMAKE_SYSTEM_PROCESSOR and (if empty) falls back to CMAKE_HOST_SYSTEM_PROCESSOR to support both cross-compilation and native builds.
- Detects all targets currently used across the project:
AARCH64 — arm64 / aarch64
ARM / THUMB — arm* / thumb* (with or without VFP variants)
RISCV64 / RISCV32 — riscv64 / riscv32
MIPS — mips*
XTENSA — xtensa*
X86_32 — i686 / x86 / i386
X86_64 — x86_64
AMD_64 — amd64
- Normalizes via
string(TOUPPER ...).
- Falls back to
CMAKE_SIZEOF_VOID_P (→ X86_64 on 64-bit, X86_32 on 32-bit).
- Emits
SEND_ERROR / FATAL_ERROR on unknown architectures.
- Prints
message(STATUS "WAMR_BUILD_TARGET: ${WAMR_BUILD_TARGET}").
All files that currently contain an if (NOT DEFINED WAMR_BUILD_TARGET) block would be replaced by a single include(build-scripts/detect_target) line. Per-target logic like WAMR_BUILD_SIMD (currently set inline in product-mini/platforms/linux/CMakeLists.txt and samples/wasm-c-api/CMakeLists.txt) would stay in those files, right after the include.
Files that hardcode a single target (e.g. zephyr/simple/CMakeLists.txt → X86_32, riot/CMakeLists.txt → X86_32, android/CMakeLists.txt) would remain unchanged, as they represent constrained platforms where auto-detection is not meaningful.
Describe alternatives you've considered
- Leave as-is — auto-detection remains fragmented, and new architectures or bugfixes must be patched in dozens of files.
- Add only ARM detection — solves the immediate ARM problem but does not address the broader duplication and inconsistency (missing MIPS, XTENSA, THUMB, AMD_64 in many files).
- Use a function/macro instead of a standalone module — functionally equivalent, but a module is simpler to include and does not rely on function visibility order.
Additional context
Files and their current auto-detection patterns (abbreviated):
| Pattern |
Key difference |
Files using it |
CMAKE_SYSTEM_PROCESSOR — detects AARCH64, RISCV64, X86_64, X86_32 |
No ARM, THUMB, MIPS, XTENSA |
Root CMakeLists.txt, product-mini platforms, samples, test files |
Same + WAMR_BUILD_SIMD |
Adds SIMD default for AARCH64/X86_64 |
product-mini/platforms/linux, samples/wasm-c-api |
CMAKE_HOST_SYSTEM_PROCESSOR — detects 9 targets |
Uses CMAKE_HOST_*, adds ARM_32/MIPS_32/XTENSA_32, does TOUPPER |
wamr-compiler/CMakeLists.txt |
CMAKE_SIZEOF_VOID_P only |
No arch-specific detection at all |
product-mini/platforms/windows, product-mini/platforms/vxworks, tests/unit/unit_common.cmake |
Questions
- Should wamr-compiler always use
CMAKE_HOST_SYSTEM_PROCESSOR, because it's host-only tool and shouldn't be built in cross-compilation scenario?
- Naming convention: use
ARM or ARM_32?
- Should
WAMR_BUILD_SIMD defaults (for AARCH64/X86_64) be moved into the common module? (It could be a separate feature flag.)
- How to handle the
_VFP and _LP64D / _LP64 / _ILP32 / _ILP32D / _ILP32F ABI suffixes (ARM and RISC-V)? Should the detector try to auto-detect ABI from CMAKE_SYSTEM_PROCESSOR, or use most compatible ABI?
Is your feature request related to a problem? Please describe.
The auto-detection of
WAMR_BUILD_TARGETbased on the CPU architecture is duplicated across many CMake files in the project with at least 3 different patterns, each supporting a slightly different subset of architectures.ARMauto-detection, which is the reason why I started to investigate, is missing — scripts detectAARCH64but notARMorTHUMB. Some files useCMAKE_SYSTEM_PROCESSOR, others useCMAKE_HOST_SYSTEM_PROCESSOR. Some files detectAMD_64,MIPS, orXTENSA; most do not. This makes the build system inconsistent and harder to maintain.Describe the solution you'd like
A single, centralized CMake module (e.g.
build-scripts/detect_target.cmake) that handles all architecture auto-detection in one place, with the following behavior:WAMR_BUILD_TARGETis not already defined (preserving override).CMAKE_SYSTEM_PROCESSORand (if empty) falls back toCMAKE_HOST_SYSTEM_PROCESSORto support both cross-compilation and native builds.AARCH64—arm64/aarch64ARM/THUMB—arm*/thumb*(with or without VFP variants)RISCV64/RISCV32—riscv64/riscv32MIPS—mips*XTENSA—xtensa*X86_32—i686/x86/i386X86_64—x86_64AMD_64—amd64string(TOUPPER ...).CMAKE_SIZEOF_VOID_P(→ X86_64 on 64-bit, X86_32 on 32-bit).SEND_ERROR/FATAL_ERRORon unknown architectures.message(STATUS "WAMR_BUILD_TARGET: ${WAMR_BUILD_TARGET}").All files that currently contain an
if (NOT DEFINED WAMR_BUILD_TARGET)block would be replaced by a singleinclude(build-scripts/detect_target)line. Per-target logic likeWAMR_BUILD_SIMD(currently set inline inproduct-mini/platforms/linux/CMakeLists.txtandsamples/wasm-c-api/CMakeLists.txt) would stay in those files, right after the include.Files that hardcode a single target (e.g.
zephyr/simple/CMakeLists.txt→X86_32,riot/CMakeLists.txt→X86_32,android/CMakeLists.txt) would remain unchanged, as they represent constrained platforms where auto-detection is not meaningful.Describe alternatives you've considered
Additional context
Files and their current auto-detection patterns (abbreviated):
CMAKE_SYSTEM_PROCESSOR— detects AARCH64, RISCV64, X86_64, X86_32WAMR_BUILD_SIMDproduct-mini/platforms/linux,samples/wasm-c-apiCMAKE_HOST_SYSTEM_PROCESSOR— detects 9 targetsCMAKE_HOST_*, adds ARM_32/MIPS_32/XTENSA_32, doesTOUPPERwamr-compiler/CMakeLists.txtCMAKE_SIZEOF_VOID_Ponlyproduct-mini/platforms/windows,product-mini/platforms/vxworks,tests/unit/unit_common.cmakeQuestions
CMAKE_HOST_SYSTEM_PROCESSOR, because it's host-only tool and shouldn't be built in cross-compilation scenario?ARMorARM_32?WAMR_BUILD_SIMDdefaults (for AARCH64/X86_64) be moved into the common module? (It could be a separate feature flag.)_VFPand_LP64D/_LP64/_ILP32/_ILP32D/_ILP32FABI suffixes (ARM and RISC-V)? Should the detector try to auto-detect ABI fromCMAKE_SYSTEM_PROCESSOR, or use most compatible ABI?