I have a Swift package with a library product that has a C target to perform some number crunching. Depending on the OS and compilation flags, the library uses either Apple's Accelerate framework, Intel's Math Kernel Library, Integrated Performance Primitives and Threading Building Blocks or has its own implementation as a fallback.
Compiling this Package with Accelerate support is trivial. But compiling with MKL/IPP/TBB support requires an incredibly large amount of compilation flags, environment variables, etc. to be set. So I thought of using an LLVM modulemap file to make this process easier and use
link statements in the modulemap file to achieve this. But by just using
link statements in my modulemap, I lose platform independence. I can no longer choose, whether I want to link those libraries or not and if I try to compile on a system that doesn't have these libraries and headers, the compilation and linking will fail.
So I was wondering: Is there a way to use compilation flags (or even environment variables) as conditions in module maps? Can I for example use
-Xcc -DENABLE_INTEL_LIBRARIES to conditionally link all the required libraries? Or is there another way to simplify this whole linking and compilation process?