'Target Architecture on Clang++ with Mac M1

I just received a brand new Macbook Pro with an M1 (March 2022) inside. The existing build chain is a custom set of scripts that mesh together a myriad assortment of code into an application. It works, but is very manual. I would like to understand how to set target architecture to support the M1 and also support the existing and widely-used x86 architectures. My thought is to try and target x86 and see if Rosetta will work hoping that is the same as a universal build, or create one x86 and one arm targeted build and provide links on the website to each separately.

The existing code has compiler flags set in a bash script as:

CXXFLAGS="-march=core2 -mno-avx ${CXXFLAGS} -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}"

but this produces the error clang: error: the clang compiler does not support '-march=core2'. As of this writing, so does setting -march=native and -march=x86-74-v.

I can run clang++ --print-supported-cpus and see a list, but plugging in the first of these gives the same error.

Why is core2 now wrong and what is the proper way to transition this property under the circumstances?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source