Our project links to a number of pre-compiled 3rd party libraries, for which we set up “find modules” using find_library(), find_package_handle_standard_args(), and add_library(... IMPORTED).
On macOS some of these libraries come as separate .a files per architecture (x86_64/arm64). How can we link the right library for the architecture when doing a multi-arch build (CMAKE_OSX_ARCHITECTURES = "x86_64;arm64")?
In Xcode we link the libraries using -l<libname> and using $(CURRENT_ARCH) as part of the library search path, which works because Xcode builds and links each architecture separately and then uses lipo to merge it, but CMake seems to build and link both architectures in one go using multiple -arch options (at least when using the Ninja and Clang).
Is there any CMake option we could use for this, or is there maybe a linker option that would allow us to specify per-architecture linker search paths?
What about creating two imported library targets, one per arch that has the correct binary as its IMPORTED_LOCATION and sets its OSX_ARCHITRCTURES to only its arch? And then the find module would publicly expose an interface library that links to both of those.
Thanks for the suggestions! I ended up using lipo to create a multi-arch library from the existing ones via a custom target like this, which works great: