From cd63593ae560077645e4c25cb722f42eb3eaa837 Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Sat, 23 Aug 2025 20:59:39 -0400 Subject: [PATCH] CMake: Add support for cross compiling to aarch64-linux-gnu --- cmake/aarch64-linux-gnu.cmake | 37 +++++++++++++++++++++++++++++++++++ include/config.h.in | 3 +++ 2 files changed, 40 insertions(+) create mode 100644 cmake/aarch64-linux-gnu.cmake diff --git a/cmake/aarch64-linux-gnu.cmake b/cmake/aarch64-linux-gnu.cmake new file mode 100644 index 0000000..6767693 --- /dev/null +++ b/cmake/aarch64-linux-gnu.cmake @@ -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") diff --git a/include/config.h.in b/include/config.h.in index c5831db..9680bab 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -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