# Cross-compile for Windows on ARM64 (aarch64-w64-mingw32) with llvm-mingw: # clang + libc++ + the libc++ `std` module, targeting the MSVCRT MinGW runtime. # The same llvm-mingw release is multi-target, so only the target triple, the # SDL3 SDK and the sysroot paths differ from the x86_64 toolchain. # 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 Windows) set(CMAKE_SYSTEM_PROCESSOR aarch64) set(OPENRA3_LLVM_MINGW_ROOT "/opt/llvm-mingw" CACHE PATH "llvm-mingw installation root") if(NOT EXISTS "${OPENRA3_LLVM_MINGW_ROOT}/bin/clang++") message(FATAL_ERROR "llvm-mingw not found at ${OPENRA3_LLVM_MINGW_ROOT} (expected bin/clang++)") endif() # llvm-mingw's per-target prefix/sysroot for the ARM64 target. set(OPENRA3_MINGW_TRIPLE "aarch64-w64-mingw32") set(CMAKE_C_COMPILER "${OPENRA3_LLVM_MINGW_ROOT}/bin/clang") set(CMAKE_CXX_COMPILER "${OPENRA3_LLVM_MINGW_ROOT}/bin/clang++") set(CMAKE_C_COMPILER_TARGET ${OPENRA3_MINGW_TRIPLE}) set(CMAKE_CXX_COMPILER_TARGET ${OPENRA3_MINGW_TRIPLE}) # CMake's standard-library detection does not pass COMPILER_TARGET, so without # this it probes the host standard library. Putting the target in ARG1 makes # the probe see libc++ (the MinGW target's library). set(CMAKE_C_COMPILER_ARG1 "--target=${OPENRA3_MINGW_TRIPLE}") set(CMAKE_CXX_COMPILER_ARG1 "--target=${OPENRA3_MINGW_TRIPLE}") # libc++ standard-library module description for the MinGW target. Must be set # before the compiler is probed so CMake can build `import std;`. set(CMAKE_CXX_STDLIB_MODULES_JSON "${OPENRA3_LLVM_MINGW_ROOT}/${OPENRA3_MINGW_TRIPLE}/lib/libc++.modules.json") # Select libc++ explicitly so CMake's `import std` detection recognises the # standard library (llvm-mingw defaults to it, but CMake keys off -stdlib=). set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++") set(CMAKE_EXE_LINKER_FLAGS_INIT "-stdlib=libc++") set(CMAKE_SHARED_LINKER_FLAGS_INIT "-stdlib=libc++") # SDL3 for aarch64-w64-mingw32. The official SDL release ships no MinGW ARM64 # dev package, so the image stages one from MSYS2's clangarm64 repo under this # root in the same `/{include,lib,bin}` layout. set(OPENRA3_SDL3_ROOT "/opt/sdl3-aarch64" CACHE PATH "SDL3 aarch64 MinGW development package root") set(OPENRA3_SDL3_MINGW_TRIPLE "${OPENRA3_MINGW_TRIPLE}" CACHE STRING "SDL3 MinGW triple subdirectory") set(CMAKE_FIND_ROOT_PATH "${OPENRA3_LLVM_MINGW_ROOT}/${OPENRA3_MINGW_TRIPLE}") set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)