I found myself needing to compile a library today with M1 support. Googling a little, I found CMAKE_OSX_ARCHITECTURES. This worked great for most of our code!
But then I came across our libjpeg_turbo dependency - which uses different files depending on the architecture. This is for SIMD support. We have a couple others like this as well.
I googled around quite a bit but couldn’t really find a solution for this. The best I found is to use ifdef guards to only compile in the correct arch and just include all the files. I would rather not do that if I don’t have to, but that would definitely work.
Multiarch targeting is more compiler magic than CMake magic. It just so happens that the compiler knows how to run itself twice for codegen and put it in a single object file. If both passes cannot handle the content of a single file, it needs to be conditional in some way. If you don’t want to modify the files directly, you can instead make a wrapper source and add it to the list of source files: