TL; DR
Have a try at setting SET(APPLE FALSE).
I've encountered a similar problem when cross-compiling a RISC-V project on my MacBook with macOS Sonoma. I found that CMake will set -arch arm64 by default, and there is an option controlling the argument to -arch called CMAKE_OSX_ARCHITECTURES. However, setting this argument to false does not help since CMake still applies a default value of arm64 which is the architecture of the build host.
I'm rather curious about why there's not much information about this question on the Internet; both on StackOverflow and GitHub are some questions/issues on this problem but no one gave a sharp and clear answer, at least none solved my issue.
So, I dived into the source code of CMake and found that if the target is set as Apple platforms, there will be a hardcoded appending to the compilation flags, which caused this problem. Finally, we can avoid this by setting APPLE variable to false, effectively simulating building on other platforms if you do not need to build a universal package which is almost always the case today.
arm none eabi gcc - unrecognized command-line option '-arch'; did you mean '-march='? - Stack Overflow
arm-none-eabi-gcc-10.3.1: error: arm64
Missing libraries in arm-none-eabi-* ?
Arch Linux ARM • View topic - Failure trying to build arm-none-eabi-gcc (for qmk)
I was trying to compile for arm-none-eabi target. But then ld said that it couldn't find -ldl, -lrt, -lgcc_s, -lutil and -lpthread. I also searched everywhere with stuff like ``locate dl | grep arm`` or ``pacman -Fl arm-none-eabi-newlib | grep dl`` and variations with the other libraries but didn't find anything.
Im kind of lost here because it worked fine on ubuntu. Help?