Skip to content

Instantly share code, notes, and snippets.

@chsbuffer
Created June 27, 2024 15:04
Show Gist options
  • Select an option

  • Save chsbuffer/8eb050de50f9cec8867a46abf6d3b7a4 to your computer and use it in GitHub Desktop.

Select an option

Save chsbuffer/8eb050de50f9cec8867a46abf6d3b7a4 to your computer and use it in GitHub Desktop.
# Windows (mingw-w64-i686) hosted cross toolchains
# AArch64 GNU/Linux target (aarch64-none-linux-gnu)
# 1. Download the ARM GNU Toolchain for Windows host from
# https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
# Extract the downloaded archive to a convenient location, such as C:\bin.
# 2. [optional] You might need to modify the toolchain variable based on
# your extraction location and toolchain version.
# 3. Install MSYS2 (https://www.msys2.org/) if you don't have it already.
# It provides a Unix-like environment for Windows, including package management tools.
# Once installed, launch the MSYS2 UCRT64 terminal.
# 4. Install CMake and Ninja using the package manager within the MSYS2 terminal:
# $ pacman -S mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-ninja
# 5. Configure your CMake source:
# Replace <path/to/toolchain.cmake> with the actual path to the file
# within your extracted toolchain directory.
# $ cmake -DCMAKE_TOOLCHAIN_FILE=</path/to/toolchain.cmake> . -G Ninja
set(toolchain C:/bin/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-aarch64-none-linux-gnu)
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER ${toolchain}/bin/aarch64-none-linux-gnu-gcc.exe)
set(CMAKE_CXX_COMPILER ${toolchain}/bin/aarch64-none-linux-gnu-g++.exe)
# where is the target environment located
set(CMAKE_FIND_ROOT_PATH ${toolchain})
# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# Toolchain file document:
# https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html#toolchain-files
# https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment