# Cross-compile for Linux on ARM64 (aarch64-linux-gnu) from x86_64. # # clang-21 + libc++ (for `import std;`) with the arm64 libc++ and SDL3 taken # from Ubuntu's arm64 packages (installed with dpkg multiarch), and the arm64 # glibc headers/libs from `gcc-aarch64-linux-gnu`. lld links the result; the C # multiarch include directory is added explicitly because clang does not always # infer Debian's `bits/` layout from the target triple alone. # The `import std` gate must be set before the compiler is probed; a toolchain # file is processed earlier than the project's own top-level settings. set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444") set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR aarch64) set(OPENRA3_AARCH64_TRIPLE "aarch64-linux-gnu") # Multiarch paths the arm64 packages install into. set(OPENRA3_AARCH64_INCLUDE "/usr/include/${OPENRA3_AARCH64_TRIPLE}") set(OPENRA3_AARCH64_LIB "/usr/lib/${OPENRA3_AARCH64_TRIPLE}") # Compiler + libc++ module description are cache vars so a distro with a # differently-versioned clang (e.g. Debian's clang-19) can override on the # command line. set(OPENRA3_AARCH64_CC "clang-21" CACHE STRING "aarch64 C compiler") set(OPENRA3_AARCH64_CXX "clang++-21" CACHE STRING "aarch64 C++ compiler") set(OPENRA3_AARCH64_STDLIB_MODULES_JSON "/usr/lib/llvm-21/lib/libc++.modules.json" CACHE FILEPATH "libc++ std module description for the aarch64 target") set(CMAKE_C_COMPILER ${OPENRA3_AARCH64_CC}) set(CMAKE_CXX_COMPILER ${OPENRA3_AARCH64_CXX}) set(CMAKE_C_COMPILER_TARGET ${OPENRA3_AARCH64_TRIPLE}) set(CMAKE_CXX_COMPILER_TARGET ${OPENRA3_AARCH64_TRIPLE}) # CMake's standard-library detection does not pass COMPILER_TARGET, so without # this it probes the host standard library. set(CMAKE_C_COMPILER_ARG1 "--target=${OPENRA3_AARCH64_TRIPLE}") set(CMAKE_CXX_COMPILER_ARG1 "--target=${OPENRA3_AARCH64_TRIPLE}") # libc++ standard-library module description for the aarch64 target. On a # multiarch image only the arm64 libc++ is installed, so the standard path # already resolves to the aarch64 module description. set(CMAKE_CXX_STDLIB_MODULES_JSON "${OPENRA3_AARCH64_STDLIB_MODULES_JSON}") # Strip with the cross binutils, so CPack can strip the arm64 binary. set(CMAKE_STRIP aarch64-linux-gnu-strip) set(CMAKE_C_FLAGS_INIT "-isystem ${OPENRA3_AARCH64_INCLUDE}") set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++ -isystem ${OPENRA3_AARCH64_INCLUDE}") set(CMAKE_EXE_LINKER_FLAGS_INIT "-stdlib=libc++ -fuse-ld=lld -L${OPENRA3_AARCH64_LIB}") set(CMAKE_SHARED_LINKER_FLAGS_INIT "-stdlib=libc++ -fuse-ld=lld -L${OPENRA3_AARCH64_LIB}") # Run arm64 test binaries through qemu when it is installed, so `ctest` works # during the image build; harmless when the tests are only cross-compiled. set(CMAKE_CROSSCOMPILING_EMULATOR qemu-aarch64-static)