CMake: Add support for cross compiling to aarch64-linux-gnu

This commit is contained in:
2025-08-23 20:59:39 -04:00
parent 58dbc7e320
commit cd63593ae5
2 changed files with 40 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
# Cross-compilation toolchain file for aarch64-linux-gnu
# This file should be used with cmake -DCMAKE_TOOLCHAIN_FILE=cmake/aarch64-linux-gnu.cmake
# Disable some features that might not be available in cross-compilation
set(CMAKE_CROSSCOMPILING TRUE)
# Target OS.
set(CMAKE_SYSTEM_NAME Linux)
# Use whatever the host system version is.
# set(CMAKE_SYSTEM_VERSION ${CMAKE_HOST_SYSTEM_VERSION})
set(CMAKE_SYSTEM_PROCESSOR aarch64)
# Specify the cross compilers.
# We could do some more advanced stuff here to search for the correct
# cross-compiler based on CMAKE_SYSTEM_NAME & CMAKE_SYSTEM_PROCESSOR.
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
# These are necessary for CLang.
# set(CMAKE_C_COMPILER_TARGET aarch64-linux-gnu)
# set(CMAKE_CXX_COMPILER_TARGET aarch64-linux-gnu)
# Set architecture-specific flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a -mtune=cortex-a72")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a -mtune=cortex-a72")
# Set the target environment
set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu)
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
# Set pkg-config to use the cross-compiled libraries
set(ENV{PKG_CONFIG_PATH} "/usr/aarch64-linux-gnu/lib/pkgconfig:/usr/lib/aarch64-linux-gnu/pkgconfig")
+3
View File
@@ -9,6 +9,9 @@
#define CONFIG_MIND_VOSCILLATOR_PERIOD_MS @MIND_VOSCILLATOR_PERIOD_MS@
#define CONFIG_MIND_VOSCILLATOR_FREQ_MS @MIND_VOSCILLATOR_FREQ_MS@
/* Cross-compilation configuration */
#cmakedefine CMAKE_CROSSCOMPILING
/* Common Libraries */
#cmakedefine CONFIG_LIB_XCBXORG_ENABLED
#cmakedefine CONFIG_LIB_ALSA_ENABLED