Apple Universal Application with SIMD

2 days ago 3
ARTICLE AD BOX

I want to build a Apple Universial Binary with CMake.
My code contains SIMD code for different architectures (e.g. AVX2, AVX512 for x86_64, NEON for AMD64). In CMake (for other platforms) I just collect all source and header files for compilation in case that the feature is supported. Which works for building for Windows x64, x86, AMD64 and Linux likewise.. as all builds are just for a single architecture.

It also works for MacOS as long as I build for a specific archictecture but fails when I want to build the universal app.

In the source code itself i guard the includes and SIMD commands with pre-compilers - depending on which architecture is currently being used.

Now for compiling it tells me to provide AVX when building that I need to enable support for AVX (e.g. passing -mavx2).

The issue is when I pass it i do get (during the compile step for AMD64) that -mavx2 is not a supported option for the compiler and the compilation is stopped.

Is there a way to pass this option specifically for certain source files, e.g. image_op_avx2.cpp which contains AVX2 implementations, depending on the current compile step that I am in?
When I try using

set_source_files_properties( image_op_avx2.cpp PROPERTIES COMPILE_OPTIONS "-mavx2" )

The issue is that it tries to apply the flag during both compile steps (x86_64 and AMD64) which makes the compilation fail again.
Is there an option for the compiler to ignore unavailable flags?

Read Entire Article