Cross-building glfw from x86_64 source to arm64

My host machine is a Linux x86_64.
My target is a SoC Linux arm64.

They both have the required graphics processors.

I 'm provided with a custom toolchain with gcc/g++ compilers and a sysroot.

How to build the glfw library on my machine and for the target using CMake?

Have you read the cross compile documentation from CMake?

I haven’t tried this myself, but it looks like a good start.

I tried using the following cmake build settings.

cmake -S ../glfw-3.4/ -B build-arm
-DCMAKE_SYSTEM_NAME=Linux
-DCMAKE_SYSTEM_PROCESSOR=aarch64
-DCMAKE_C_COMPILER=toolchain/aarch64/bin/aarch64-linux-gnu-gcc
-DCMAKE_CXX_COMPILER=toolchain/aarch64/bin/aarch64-linux-gnu-g++
-DCMAKE_SYSROOT=toolchain/aarch64/aarch64-linux-gnu/sysroot
-DGLFW_BUILD_WAYLAND=OFF
-DGLFW_BUILD_X11=ON

After I run make in build-arm folder I get
Scanning dependencies of target glfw
[ 1%] Building C object src/CMakeFiles/glfw.dir/context.c.o
In file included from /glfw-3.4/src/platform.h:81,
from /glfw-3.4/src/internal.h:325,
from /glfw-3.4/src/context.c:28:
/glfw-3.4/src/x11_platform.h:32:10: fatal error: X11/Xlib.h: No such file or directory
#include <X11/Xlib.h>

Is it possible that the sysroot don’t have X11 installed?

First I would check that you can build GLFW normally for your Linux x86_64 system and then try a cross compile, making sure to read the CMake cross compile instructions carefully. I have no experience myself with this so probably can’t help any further.